Commit 9c6d94ad by Brian Jacobel

Require and Webpack can eat the same files

parent 480a3ca6
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
'underscore.string', 'underscore.string',
'backbone', 'backbone',
'gettext', 'gettext',
'../../../../common/static/common/js/components/views/feedback_notification', '../../common/js/components/views/feedback_notification',
'jquery.cookie' 'jquery.cookie'
], function(domReady, $, str, Backbone, gettext, NotificationView) { ], function(domReady, $, str, Backbone, gettext, NotificationView) {
var main, sendJSON; var main, sendJSON;
......
...@@ -116,7 +116,7 @@ define([ ...@@ -116,7 +116,7 @@ define([
Import.reset(); Import.reset();
onComplete(); onComplete();
alert(gettext('Your import has failed.') + '\n\n' + errMsg); alert(gettext('Your import has failed.') + '\n\n' + errMsg); // eslint-disable-line max-len, no-alert
} }
} }
}); });
......
define(['jquery', (function(define) {
'use strict';
define([
'jquery',
'underscore', 'underscore',
'underscore.string', 'underscore.string',
'backbone', 'backbone',
'text!../../../../common/templates/components/system-feedback.underscore'], 'edx-ui-toolkit/js/utils/html-utils',
function($, _, str, Backbone, systemFeedbackTemplate) { 'text!../../../../common/templates/components/system-feedback.underscore'
var tabbable_elements = [ ],
function($, _, str, Backbone, HtmlUtils, systemFeedbackTemplate) {
var tabbableElements = [
"a[href]:not([tabindex='-1'])", "a[href]:not([tabindex='-1'])",
"area[href]:not([tabindex='-1'])", "area[href]:not([tabindex='-1'])",
"input:not([disabled]):not([tabindex='-1'])", "input:not([disabled]):not([tabindex='-1'])",
...@@ -24,8 +29,8 @@ define(['jquery', ...@@ -24,8 +29,8 @@ define(['jquery',
shown: true, // is this view currently being shown? shown: true, // is this view currently being shown?
icon: true, // should we render an icon related to the message intent? icon: true, // should we render an icon related to the message intent?
closeIcon: true, // should we render a close button in the top right corner? closeIcon: true, // should we render a close button in the top right corner?
minShown: 0, // length of time after this view has been shown before it can be hidden (milliseconds) minShown: 0, // ms after this view has been shown before it can be hidden
maxShown: Infinity, // length of time after this view has been shown before it will be automatically hidden (milliseconds) maxShown: Infinity, // ms after this view has been shown before it will be automatically hidden
outFocusElement: null // element to send focus to on hide outFocusElement: null // element to send focus to on hide
/* Could also have an "actions" hash: here is an example demonstrating /* Could also have an "actions" hash: here is an example demonstrating
...@@ -60,11 +65,11 @@ define(['jquery', ...@@ -60,11 +65,11 @@ define(['jquery',
initialize: function(options) { initialize: function(options) {
this.options = _.extend({}, this.options, options); this.options = _.extend({}, this.options, options);
if (!this.options.type) { if (!this.options.type) {
throw 'SystemFeedback: type required (given ' + throw 'SystemFeedback: type required (given ' + // eslint-disable-line no-throw-literal
JSON.stringify(this.options) + ')'; JSON.stringify(this.options) + ')';
} }
if (!this.options.intent) { if (!this.options.intent) {
throw 'SystemFeedback: intent required (given ' + throw 'SystemFeedback: intent required (given ' + // eslint-disable-line no-throw-literal
JSON.stringify(this.options) + ')'; JSON.stringify(this.options) + ')';
} }
this.setElement($('#page-' + this.options.type)); this.setElement($('#page-' + this.options.type));
...@@ -86,15 +91,14 @@ define(['jquery', ...@@ -86,15 +91,14 @@ define(['jquery',
// Make tabs within the prompt loop rather than setting focus // Make tabs within the prompt loop rather than setting focus
// back to the main content of the page. // back to the main content of the page.
tabbables = this.$(tabbable_elements.join()); tabbables = this.$(tabbableElements.join());
tabbables.on('keydown', function(event) { tabbables.on('keydown', function(event) {
// On tab backward from the first tabbable item in the prompt // On tab backward from the first tabbable item in the prompt
if (event.which === 9 && event.shiftKey && event.target === tabbables.first()[0]) { if (event.which === 9 && event.shiftKey && event.target === tabbables.first()[0]) {
event.preventDefault(); event.preventDefault();
tabbables.last().focus(); tabbables.last().focus();
} } else if (event.which === 9 && !event.shiftKey && event.target === tabbables.last()[0]) {
// On tab forward from the last tabbable item in the prompt // On tab forward from the last tabbable item in the prompt
else if (event.which === 9 && !event.shiftKey && event.target === tabbables.last()[0]) {
event.preventDefault(); event.preventDefault();
tabbables.first().focus(); tabbables.first().focus();
} }
...@@ -104,7 +108,7 @@ define(['jquery', ...@@ -104,7 +108,7 @@ define(['jquery',
}, },
outFocus: function() { outFocus: function() {
var tabbables = this.$(tabbable_elements.join()).off('keydown'); this.$(tabbableElements.join()).off('keydown');
if (this.options.outFocusElement) { if (this.options.outFocusElement) {
this.options.outFocusElement.focus(); this.options.outFocusElement.focus();
} }
...@@ -154,7 +158,7 @@ define(['jquery', ...@@ -154,7 +158,7 @@ define(['jquery',
singleton.stopListening(); singleton.stopListening();
singleton.undelegateEvents(); singleton.undelegateEvents();
} }
this.$el.html(_.template(systemFeedbackTemplate)(this.options)); HtmlUtils.setHtml(this.$el, HtmlUtils.template(systemFeedbackTemplate)(this.options));
SystemFeedback['active_' + this.options.type] = this; SystemFeedback['active_' + this.options.type] = this;
return this; return this;
}, },
...@@ -195,3 +199,4 @@ define(['jquery', ...@@ -195,3 +199,4 @@ define(['jquery',
}); });
return SystemFeedback; return SystemFeedback;
}); });
}).call(this, define || RequireJS.define);
define(['jquery', 'underscore', 'underscore.string', '../../../../common/js/components/views/feedback'], (function(define) {
'use strict';
define(['jquery', 'underscore', 'underscore.string', './feedback'],
function($, _, str, SystemFeedbackView) { function($, _, str, SystemFeedbackView) {
var Notification = SystemFeedbackView.extend({ var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, { options: $.extend({}, SystemFeedbackView.prototype.options, {
...@@ -8,7 +10,7 @@ define(['jquery', 'underscore', 'underscore.string', '../../../../common/js/comp ...@@ -8,7 +10,7 @@ define(['jquery', 'underscore', 'underscore.string', '../../../../common/js/comp
}); });
// create Notification.Warning, Notification.Confirmation, etc // create Notification.Warning, Notification.Confirmation, etc
var capitalCamel, intents; var capitalCamel, intents, miniOptions;
capitalCamel = _.compose(str.capitalize, str.camelize); capitalCamel = _.compose(str.capitalize, str.camelize);
intents = ['warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini']; intents = ['warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini'];
_.each(intents, function(intent) { _.each(intents, function(intent) {
...@@ -22,9 +24,11 @@ define(['jquery', 'underscore', 'underscore.string', '../../../../common/js/comp ...@@ -22,9 +24,11 @@ define(['jquery', 'underscore', 'underscore.string', '../../../../common/js/comp
}); });
// set more sensible defaults for Notification.Mini views // set more sensible defaults for Notification.Mini views
var miniOptions = Notification.Mini.prototype.options; miniOptions = Notification.Mini.prototype.options;
miniOptions.minShown = 1250; miniOptions.minShown = 1250;
miniOptions.closeIcon = false; miniOptions.closeIcon = false;
return Notification; return Notification;
}); }
);
}).call(this, define || RequireJS.define);
...@@ -253,17 +253,6 @@ class ImportMixin(ImportExportMixin): ...@@ -253,17 +253,6 @@ class ImportMixin(ImportExportMixin):
""" """
return self.q(css='.choose-file-button').present return self.q(css='.choose-file-button').present
def is_click_handler_registered(self):
"""
Check if the click handler for the file selector button has been registered yet
"""
script = """
var $ = require('jquery'),
buttonEvents = $._data($('a.choose-file-button')[0], 'events');
return buttonEvents && buttonEvents.hasOwnProperty('click');"""
stripped_script = ''.join([line.strip() for line in script.split('\n')])
return self.browser.execute_script(stripped_script)
@staticmethod @staticmethod
def file_path(filename): def file_path(filename):
""" """
...@@ -325,13 +314,6 @@ class ImportMixin(ImportExportMixin): ...@@ -325,13 +314,6 @@ class ImportMixin(ImportExportMixin):
""" """
return self.q(css='#fileupload .error-block').visible return self.q(css='#fileupload .error-block').visible
def wait_for_choose_file_click_handler(self):
"""
Wait for the choose file button click handler to be registered
"""
EmptyPromise(self.is_click_handler_registered, 'Choose File Button Click Handler Registered',
timeout=30).fulfill()
def wait_for_filename_error(self): def wait_for_filename_error(self):
""" """
Wait for the upload field to display an error. Wait for the upload field to display an error.
......
...@@ -168,7 +168,6 @@ class ImportTestMixin(object): ...@@ -168,7 +168,6 @@ class ImportTestMixin(object):
I can select the file and upload it I can select the file and upload it
And the page will give me confirmation that it uploaded successfully And the page will give me confirmation that it uploaded successfully
""" """
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload() self.import_page.wait_for_upload()
...@@ -184,7 +183,6 @@ class ImportTestMixin(object): ...@@ -184,7 +183,6 @@ class ImportTestMixin(object):
# import_page timestamp is in (MM/DD/YYYY at HH:mm) so replacing (second, microsecond) to # import_page timestamp is in (MM/DD/YYYY at HH:mm) so replacing (second, microsecond) to
# keep the comparison consistent # keep the comparison consistent
upload_start_time = datetime.utcnow().replace(microsecond=0, second=0) upload_start_time = datetime.utcnow().replace(microsecond=0, second=0)
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload() self.import_page.wait_for_upload()
...@@ -218,7 +216,6 @@ class ImportTestMixin(object): ...@@ -218,7 +216,6 @@ class ImportTestMixin(object):
Given that I upload a library or course Given that I upload a library or course
A button will appear that contains the URL to the library or course's main page A button will appear that contains the URL to the library or course's main page
""" """
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.assertEqual(self.import_page.finished_target_url(), self.landing_page.url) self.assertEqual(self.import_page.finished_target_url(), self.landing_page.url)
...@@ -228,7 +225,6 @@ class ImportTestMixin(object): ...@@ -228,7 +225,6 @@ class ImportTestMixin(object):
Given that I select a file that is an .mp4 for upload Given that I select a file that is an .mp4 for upload
An error message will appear An error message will appear
""" """
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball('funny_cat_video.mp4') self.import_page.upload_tarball('funny_cat_video.mp4')
self.import_page.wait_for_filename_error() self.import_page.wait_for_filename_error()
...@@ -244,7 +240,6 @@ class ImportTestMixin(object): ...@@ -244,7 +240,6 @@ class ImportTestMixin(object):
# The task list shouldn't be visible to start. # The task list shouldn't be visible to start.
self.assertFalse(self.import_page.is_task_list_showing(), "Task list shown too early.") self.assertFalse(self.import_page.is_task_list_showing(), "Task list shown too early.")
self.import_page.wait_for_tasks() self.import_page.wait_for_tasks()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_tasks(completed=True) self.import_page.wait_for_tasks(completed=True)
self.assertTrue(self.import_page.is_task_list_showing(), "Task list did not display.") self.assertTrue(self.import_page.is_task_list_showing(), "Task list did not display.")
...@@ -258,7 +253,6 @@ class ImportTestMixin(object): ...@@ -258,7 +253,6 @@ class ImportTestMixin(object):
And the 'Updating' task should be marked failed And the 'Updating' task should be marked failed
And the remaining tasks should not be marked as started And the remaining tasks should not be marked as started
""" """
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.bad_tarball_name) self.import_page.upload_tarball(self.bad_tarball_name)
self.import_page.wait_for_tasks(fail_on='Updating') self.import_page.wait_for_tasks(fail_on='Updating')
...@@ -296,7 +290,6 @@ class TestEntranceExamCourseImport(ImportTestMixin, StudioCourseTest): ...@@ -296,7 +290,6 @@ class TestEntranceExamCourseImport(ImportTestMixin, StudioCourseTest):
self.assertRaises(IndexError, self.landing_page.section, "Section") self.assertRaises(IndexError, self.landing_page.section, "Section")
self.assertRaises(IndexError, self.landing_page.section, "Entrance Exam") self.assertRaises(IndexError, self.landing_page.section, "Entrance Exam")
self.import_page.visit() self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload() self.import_page.wait_for_upload()
self.landing_page.visit() self.landing_page.visit()
...@@ -346,7 +339,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest): ...@@ -346,7 +339,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
# Should not exist yet. # Should not exist yet.
self.assertRaises(IndexError, self.landing_page.section, "Section") self.assertRaises(IndexError, self.landing_page.section, "Section")
self.import_page.visit() self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload() self.import_page.wait_for_upload()
self.landing_page.visit() self.landing_page.visit()
...@@ -373,7 +365,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest): ...@@ -373,7 +365,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
Then timestamp is not visible Then timestamp is not visible
""" """
self.import_page.visit() self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload() self.import_page.wait_for_upload()
self.assertTrue(self.import_page.is_timestamp_visible()) self.assertTrue(self.import_page.is_timestamp_visible())
...@@ -419,7 +410,6 @@ class TestLibraryImport(ImportTestMixin, StudioLibraryTest): ...@@ -419,7 +410,6 @@ class TestLibraryImport(ImportTestMixin, StudioLibraryTest):
# No items should be in the library to start. # No items should be in the library to start.
self.assertEqual(len(self.landing_page.xblocks), 0) self.assertEqual(len(self.landing_page.xblocks), 0)
self.import_page.visit() self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name) self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload() self.import_page.wait_for_upload()
self.landing_page.visit() self.landing_page.visit()
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"picturefill": "~3.0.2", "picturefill": "~3.0.2",
"raw-loader": "^0.5.1", "raw-loader": "^0.5.1",
"requirejs": "~2.3.2", "requirejs": "~2.3.2",
"string-replace-webpack-plugin": "^0.1.3",
"uglify-js": "2.7.0", "uglify-js": "2.7.0",
"underscore": "~1.8.3", "underscore": "~1.8.3",
"underscore.string": "~3.3.4", "underscore.string": "~3.3.4",
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
"edx-custom-a11y-rules": "0.1.3", "edx-custom-a11y-rules": "0.1.3",
"eslint-config-edx": "^2.0.1", "eslint-config-edx": "^2.0.1",
"eslint-config-edx-es5": "^2.0.0", "eslint-config-edx-es5": "^2.0.0",
"eslint-import-resolver-webpack": "^0.8.1",
"jasmine-core": "^2.4.1", "jasmine-core": "^2.4.1",
"jasmine-jquery": "^2.1.1", "jasmine-jquery": "^2.1.1",
"karma": "^0.13.22", "karma": "^0.13.22",
......
...@@ -2378,6 +2378,8 @@ class MakoTemplateLinter(BaseLinter): ...@@ -2378,6 +2378,8 @@ class MakoTemplateLinter(BaseLinter):
</script> | # script tag end </script> | # script tag end
<%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version) <%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version)
</%static:require_module(_async)?> | # require js script tag end (optionally the _async version) </%static:require_module(_async)?> | # require js script tag end (optionally the _async version)
<%static:webpack.*?> | # webpack script tag start
</%static:webpack> | # webpack script tag end
<%block[ ]*name=['"]requirejs['"]\w*> | # require js tag start <%block[ ]*name=['"]requirejs['"]\w*> | # require js tag start
</%block> # require js tag end </%block> # require js tag end
""", """,
......
...@@ -5,9 +5,15 @@ ...@@ -5,9 +5,15 @@
var path = require('path'); var path = require('path');
var webpack = require('webpack'); var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker'); var BundleTracker = require('webpack-bundle-tracker');
var StringReplace = require('string-replace-webpack-plugin');
var isProd = process.env.NODE_ENV === 'production'; var isProd = process.env.NODE_ENV === 'production';
var namespacedRequireFiles = [
path.resolve(__dirname, 'common/static/common/js/components/views/feedback_notification.js'),
path.resolve(__dirname, 'common/static/common/js/components/views/feedback.js')
];
var wpconfig = { var wpconfig = {
context: __dirname, context: __dirname,
...@@ -52,8 +58,29 @@ var wpconfig = { ...@@ -52,8 +58,29 @@ var wpconfig = {
module: { module: {
rules: [ rules: [
{ {
test: namespacedRequireFiles,
loader: StringReplace.replace(
['babel-loader'],
{
replacements: [
{
pattern: /\(function ?\(define\) ?\{/,
replacement: function() { return ''; }
},
{
pattern: /\}\)\.call\(this, define \|\| RequireJS\.define\);/,
replacement: function() { return ''; }
}
]
}
)
},
{
test: /\.js$/, test: /\.js$/,
exclude: /node_modules/, exclude: [
/node_modules/,
namespacedRequireFiles
],
use: 'babel-loader' use: 'babel-loader'
}, },
{ {
...@@ -72,7 +99,8 @@ var wpconfig = { ...@@ -72,7 +99,8 @@ var wpconfig = {
use: { use: {
loader: 'imports-loader', loader: 'imports-loader',
options: { options: {
AjaxPrefix: 'exports-loader?this.AjaxPrefix!../../../../common/static/coffee/src/ajax_prefix.coffee' AjaxPrefix:
'exports-loader?this.AjaxPrefix!../../../../common/static/coffee/src/ajax_prefix.coffee'
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment