-
-
Notifications
You must be signed in to change notification settings - Fork 301
Adding promise polyfill #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 32 additions & 28 deletions
60
contentcuration/contentcuration/static/js/bundle_modules/base.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,62 +1,66 @@ | ||
| var attachfastclick = require("fastclick"); | ||
| var attachfastclick = require('fastclick'); | ||
|
|
||
| var $ = require("jquery"); | ||
| var get_cookie = require("utils/get_cookie"); | ||
| var $ = require('jquery'); | ||
| var get_cookie = require('utils/get_cookie'); | ||
| global.$ = $; | ||
| global.jQuery = $; | ||
| require("handlebars/helpers"); | ||
| require('handlebars/helpers'); | ||
|
|
||
| require("../../less/styles.less"); | ||
| require("bootstrap/dist/js/npm.js"); | ||
| require("../../js/utils/jquery-ui"); | ||
| // require("../../../../../node_modules/jquery-ui/ui/widgets/sortable"); | ||
| require('../../less/styles.less'); | ||
| require('bootstrap/dist/js/npm.js'); | ||
| require('../../js/utils/jquery-ui'); | ||
|
|
||
| var csrftoken = get_cookie("csrftoken") || ""; | ||
| // Promise polyfill | ||
| if(!global.Promise) { | ||
| global.Promise = require('promise-polyfill'); | ||
| } | ||
|
|
||
| var csrftoken = get_cookie('csrftoken') || ''; | ||
|
|
||
| function csrfSafeMethod(method) { | ||
| // these HTTP methods do not require CSRF protection | ||
| return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); | ||
| return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); | ||
| } | ||
|
|
||
| function sameOrigin(url) { | ||
| // test that a given url is a same-origin URL | ||
| // url could be relative or scheme relative or absolute | ||
| var host = document.location.host; // host + port | ||
| var protocol = document.location.protocol; | ||
| var sr_origin = '//' + host; | ||
| var origin = protocol + sr_origin; | ||
| var host = document.location.host; // host + port | ||
| var protocol = document.location.protocol; | ||
| var sr_origin = '//' + host; | ||
| var origin = protocol + sr_origin; | ||
| // Allow absolute or scheme relative URLs to same origin | ||
| return (url === origin || url.slice(0, origin.length + 1) === origin + '/') || | ||
| return (url === origin || url.slice(0, origin.length + 1) === origin + '/') || | ||
| (url === sr_origin || url.slice(0, sr_origin.length + 1) === sr_origin + '/') || | ||
| // or any other URL that isn't scheme relative or absolute i.e relative. | ||
| !(/^(\/\/|http:|https:).*/.test(url)); | ||
| } | ||
|
|
||
| $.ajaxSetup({ | ||
| cache: false, | ||
| beforeSend: function(xhr, settings) { | ||
| if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) { | ||
| cache: false, | ||
| beforeSend: function(xhr, settings) { | ||
| if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) { | ||
| // Send the token to same-origin, relative URLs only. | ||
| // Send the token only if the method warrants CSRF protection | ||
| // Using the CSRFToken value acquired earlier | ||
| xhr.setRequestHeader("X-CSRFToken", csrftoken); | ||
| } | ||
| } | ||
| xhr.setRequestHeader('X-CSRFToken', csrftoken); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| $.extend( $.expr[ ":" ], { | ||
| data: $.expr.createPseudo ? | ||
| $.extend( $.expr[ ':' ], { | ||
| data: $.expr.createPseudo ? | ||
| $.expr.createPseudo(function( dataName ) { | ||
| return function( elem ) { | ||
| return !!$.data( elem, dataName ); | ||
| }; | ||
| return function( elem ) { | ||
| return !!$.data( elem, dataName ); | ||
| }; | ||
| }) : | ||
| // support: jQuery <1.8 | ||
| function( elem, i, match ) { | ||
| return !!$.data( elem, match[ 3 ] ); | ||
| return !!$.data( elem, match[ 3 ] ); | ||
| } | ||
| }); | ||
|
|
||
| $(function() { | ||
| attachfastclick(document.body); | ||
| attachfastclick(document.body); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.