diff --git a/common/static/common/js/components/views/feedback_alert.js b/common/static/common/js/components/views/feedback_alert.js index 8f3f716a58cc..1b21974ce11f 100644 --- a/common/static/common/js/components/views/feedback_alert.js +++ b/common/static/common/js/components/views/feedback_alert.js @@ -2,7 +2,7 @@ 'use strict'; define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"], function($, _, str, SystemFeedbackView) { - str = str || _.str; + var Alert = SystemFeedbackView.extend({ options: $.extend({}, SystemFeedbackView.prototype.options, { type: "alert" diff --git a/common/static/common/js/components/views/feedback_notification.js b/common/static/common/js/components/views/feedback_notification.js index 2fb74f691d14..34910cb59efc 100644 --- a/common/static/common/js/components/views/feedback_notification.js +++ b/common/static/common/js/components/views/feedback_notification.js @@ -2,7 +2,7 @@ 'use strict'; define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"], function($, _, str, SystemFeedbackView) { - str = str || _.str; + var Notification = SystemFeedbackView.extend({ options: $.extend({}, SystemFeedbackView.prototype.options, { type: "notification", diff --git a/common/static/common/js/components/views/feedback_prompt.js b/common/static/common/js/components/views/feedback_prompt.js index 31c1e9b4ad97..be69d3001e84 100644 --- a/common/static/common/js/components/views/feedback_prompt.js +++ b/common/static/common/js/components/views/feedback_prompt.js @@ -2,7 +2,7 @@ 'use strict'; define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"], function($, _, str, SystemFeedbackView) { - str = str || _.str; + var Prompt = SystemFeedbackView.extend({ options: $.extend({}, SystemFeedbackView.prototype.options, { type: "prompt", diff --git a/common/static/common/js/utils/edx.utils.validate.js b/common/static/common/js/utils/edx.utils.validate.js index 4d82f9ff7a3d..4afb247ba1b9 100644 --- a/common/static/common/js/utils/edx.utils.validate.js +++ b/common/static/common/js/utils/edx.utils.validate.js @@ -15,9 +15,6 @@ * by the access view, but doing it here helps keep the * utility self-contained. */ - if (_.isUndefined(_s)) { - _s = _.str; - } _.mixin( _s.exports() ); utils = (function(){ diff --git a/lms/envs/common.py b/lms/envs/common.py index e58e58395359..5b024bf3f381 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1219,6 +1219,7 @@ 'js/vendor/jquery.cookie.js', 'js/vendor/url.min.js', 'js/vendor/underscore-min.js', + 'js/vendor/underscore.string.min.js', 'js/vendor/require.js', 'js/RequireJS-namespace-undefine.js', 'js/vendor/URI.min.js', diff --git a/lms/static/js/certificates/models/certificate_exception.js b/lms/static/js/certificates/models/certificate_exception.js index fe6bec94238c..c07a473fe8d6 100644 --- a/lms/static/js/certificates/models/certificate_exception.js +++ b/lms/static/js/certificates/models/certificate_exception.js @@ -12,7 +12,6 @@ ], function(_, str, Backbone, gettext){ - str = str || _.str; return Backbone.Model.extend({ idAttribute: 'id', diff --git a/lms/static/js/certificates/models/certificate_invalidation.js b/lms/static/js/certificates/models/certificate_invalidation.js index d7880807b133..a58dad859eab 100644 --- a/lms/static/js/certificates/models/certificate_invalidation.js +++ b/lms/static/js/certificates/models/certificate_invalidation.js @@ -8,7 +8,6 @@ ['underscore', 'underscore.string', 'gettext', 'backbone'], function(_, str, gettext, Backbone) { - str = str || _.str; return Backbone.Model.extend({ idAttribute: 'id', diff --git a/lms/static/js/spec/main.js b/lms/static/js/spec/main.js index 059c1300be65..11b8d3b992ae 100644 --- a/lms/static/js/spec/main.js +++ b/lms/static/js/spec/main.js @@ -181,22 +181,7 @@ }, 'underscore': { deps: ['underscore.string'], - exports: '_', - init: function(UnderscoreString) { - /* Mix non-conflicting functions from underscore.string - * (all but include, contains, and reverse) into the - * Underscore namespace. This allows the login, register, - * and password reset templates to render independent of the - * access view. - */ - _.mixin(UnderscoreString.exports()); - - /* Since the access view is not using RequireJS, we also - * expose underscore.string at _.str, so that the access - * view can perform the mixin on its own. - */ - _.str = UnderscoreString; - } + exports: '_' }, 'backbone': { deps: ['underscore', 'jquery'], @@ -370,7 +355,12 @@ }, 'js/verify_student/views/step_view': { exports: 'edx.verify_student.StepView', - deps: [ 'jquery', 'underscore', 'underscore.string', 'backbone', 'gettext' ] + deps: [ 'jquery', 'underscore', 'underscore.string', 'backbone', 'gettext' ], + init: function() { + // Set global variables that the payment code is expecting to be defined + window._ = require('underscore'); + window._.str = require('underscore.string'); + } }, 'js/verify_student/views/intro_step_view': { exports: 'edx.verify_student.IntroStepView', diff --git a/lms/static/js/student_account/views/AccessView.js b/lms/static/js/student_account/views/AccessView.js index 0459e451f5b9..a2dce464b9ad 100644 --- a/lms/static/js/student_account/views/AccessView.js +++ b/lms/static/js/student_account/views/AccessView.js @@ -19,10 +19,6 @@ function($, utility, _, _s, Backbone, LoginModel, PasswordResetModel, RegisterModel, LoginView, PasswordResetView, RegisterView, InstitutionLoginView, HintedLoginView) { - if (_.isUndefined(_s)) { - _s = _.str; - } - return Backbone.View.extend({ tpl: '#access-tpl', events: { diff --git a/lms/static/js/verify_student/views/step_view.js b/lms/static/js/verify_student/views/step_view.js index 016fa5f12284..b752e0393b8f 100644 --- a/lms/static/js/verify_student/views/step_view.js +++ b/lms/static/js/verify_student/views/step_view.js @@ -1,3 +1,5 @@ +/*global jQuery, _, Backbone, gettext */ + /** * Base view for defining steps in the payment/verification flow. * @@ -8,7 +10,7 @@ */ var edx = edx || {}; - (function( $, _, _s, Backbone, gettext ) { + (function( $, _, Backbone, gettext ) { 'use strict'; edx.verify_student = edx.verify_student || {}; @@ -21,13 +23,8 @@ /* Mix non-conflicting functions from underscore.string * (all but include, contains, and reverse) into the * Underscore namespace. - * - * TODO: when running unit tests, _s is not defined. My first attempt at upgrading - * underscore.string did not solve this issue. */ - if (_s) { - _.mixin(_s.exports()); - } + _.mixin(_.str.exports()); }, render: function() { @@ -106,4 +103,4 @@ }); - })( jQuery, _, _.str, Backbone, gettext ); + })( jQuery, _, Backbone, gettext ); diff --git a/lms/static/lms/js/build.js b/lms/static/lms/js/build.js index 75ccb6964e76..eb61aaafd1f4 100644 --- a/lms/static/lms/js/build.js +++ b/lms/static/lms/js/build.js @@ -66,6 +66,7 @@ 'jquery.url': 'empty:', 'backbone': 'empty:', 'underscore': 'empty:', + 'underscore.string': 'empty:', 'logger': 'empty:', 'utility': 'empty:', 'URI': 'empty:', diff --git a/lms/static/lms/js/require-config.js b/lms/static/lms/js/require-config.js index 2674176e7da1..1176c49d55af 100644 --- a/lms/static/lms/js/require-config.js +++ b/lms/static/lms/js/require-config.js @@ -19,6 +19,12 @@ }; defineDependency("jQuery", "jquery"); defineDependency("_", "underscore"); + if (window._ && window._.str) { + define("underscore.string", [], function () {return window._.str;}); + } + else { + console.error("Expected _.str (underscore.string) to be on the window object, but not found."); + } defineDependency("gettext", "gettext"); defineDependency("Logger", "logger"); defineDependency("URI", "URI"); diff --git a/lms/templates/commerce/checkout_receipt.html b/lms/templates/commerce/checkout_receipt.html index c07e21462c12..fe8a57f18078 100644 --- a/lms/templates/commerce/checkout_receipt.html +++ b/lms/templates/commerce/checkout_receipt.html @@ -19,7 +19,6 @@ <%block name="js_extra"> - diff --git a/lms/templates/verify_student/incourse_reverify.html b/lms/templates/verify_student/incourse_reverify.html index 3c7be5e68a32..d107275575b7 100644 --- a/lms/templates/verify_student/incourse_reverify.html +++ b/lms/templates/verify_student/incourse_reverify.html @@ -18,7 +18,6 @@ % endfor <%block name="js_extra"> - <%static:js group='incourse_reverify'/> diff --git a/lms/templates/verify_student/pay_and_verify.html b/lms/templates/verify_student/pay_and_verify.html index 6c1882ff1d2f..0f862a682f09 100644 --- a/lms/templates/verify_student/pay_and_verify.html +++ b/lms/templates/verify_student/pay_and_verify.html @@ -41,7 +41,6 @@ % endfor <%block name="js_extra"> - <%static:js group='verify_student'/> diff --git a/lms/templates/verify_student/reverify.html b/lms/templates/verify_student/reverify.html index d3e6340115ca..6a0669849fe4 100644 --- a/lms/templates/verify_student/reverify.html +++ b/lms/templates/verify_student/reverify.html @@ -16,7 +16,6 @@ % endfor <%block name="js_extra"> - <%static:js group='reverify'/>