Commit a1f73f7b by cahrens Committed by Andy Armstrong

Simplify how underscore.string is referred to.

parent dd2a2036
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
'use strict'; 'use strict';
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"], define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) { function($, _, str, SystemFeedbackView) {
str = str || _.str;
var Alert = SystemFeedbackView.extend({ var Alert = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, { options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "alert" type: "alert"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
'use strict'; 'use strict';
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"], define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) { function($, _, str, SystemFeedbackView) {
str = str || _.str;
var Notification = SystemFeedbackView.extend({ var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, { options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "notification", type: "notification",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
'use strict'; 'use strict';
define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"], define(["jquery", "underscore", "underscore.string", "common/js/components/views/feedback"],
function($, _, str, SystemFeedbackView) { function($, _, str, SystemFeedbackView) {
str = str || _.str;
var Prompt = SystemFeedbackView.extend({ var Prompt = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, { options: $.extend({}, SystemFeedbackView.prototype.options, {
type: "prompt", type: "prompt",
......
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
* by the access view, but doing it here helps keep the * by the access view, but doing it here helps keep the
* utility self-contained. * utility self-contained.
*/ */
if (_.isUndefined(_s)) {
_s = _.str;
}
_.mixin( _s.exports() ); _.mixin( _s.exports() );
utils = (function(){ utils = (function(){
......
...@@ -1237,6 +1237,7 @@ base_vendor_js = [ ...@@ -1237,6 +1237,7 @@ base_vendor_js = [
'js/vendor/jquery.cookie.js', 'js/vendor/jquery.cookie.js',
'js/vendor/url.min.js', 'js/vendor/url.min.js',
'js/vendor/underscore-min.js', 'js/vendor/underscore-min.js',
'js/vendor/underscore.string.min.js',
'js/vendor/requirejs/require.js', 'js/vendor/requirejs/require.js',
'js/RequireJS-namespace-undefine.js', 'js/RequireJS-namespace-undefine.js',
'js/vendor/URI.min.js', 'js/vendor/URI.min.js',
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
], ],
function(_, str, Backbone, gettext){ function(_, str, Backbone, gettext){
str = str || _.str;
return Backbone.Model.extend({ return Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
['underscore', 'underscore.string', 'gettext', 'backbone'], ['underscore', 'underscore.string', 'gettext', 'backbone'],
function(_, str, gettext, Backbone) { function(_, str, gettext, Backbone) {
str = str || _.str;
return Backbone.Model.extend({ return Backbone.Model.extend({
idAttribute: 'id', idAttribute: 'id',
......
...@@ -181,22 +181,7 @@ ...@@ -181,22 +181,7 @@
}, },
'underscore': { 'underscore': {
deps: ['underscore.string'], deps: ['underscore.string'],
exports: '_', 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;
}
}, },
'backbone': { 'backbone': {
deps: ['underscore', 'jquery'], deps: ['underscore', 'jquery'],
...@@ -374,7 +359,12 @@ ...@@ -374,7 +359,12 @@
}, },
'js/verify_student/views/step_view': { 'js/verify_student/views/step_view': {
exports: 'edx.verify_student.StepView', 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': { 'js/verify_student/views/intro_step_view': {
exports: 'edx.verify_student.IntroStepView', exports: 'edx.verify_student.IntroStepView',
......
...@@ -19,10 +19,6 @@ ...@@ -19,10 +19,6 @@
function($, utility, _, _s, Backbone, LoginModel, PasswordResetModel, RegisterModel, LoginView, function($, utility, _, _s, Backbone, LoginModel, PasswordResetModel, RegisterModel, LoginView,
PasswordResetView, RegisterView, InstitutionLoginView, HintedLoginView) { PasswordResetView, RegisterView, InstitutionLoginView, HintedLoginView) {
if (_.isUndefined(_s)) {
_s = _.str;
}
return Backbone.View.extend({ return Backbone.View.extend({
tpl: '#access-tpl', tpl: '#access-tpl',
events: { events: {
......
/*global jQuery, _, Backbone, gettext */
/** /**
* Base view for defining steps in the payment/verification flow. * Base view for defining steps in the payment/verification flow.
* *
...@@ -8,7 +10,7 @@ ...@@ -8,7 +10,7 @@
*/ */
var edx = edx || {}; var edx = edx || {};
(function( $, _, _s, Backbone, gettext ) { (function( $, _, Backbone, gettext ) {
'use strict'; 'use strict';
edx.verify_student = edx.verify_student || {}; edx.verify_student = edx.verify_student || {};
...@@ -21,13 +23,8 @@ ...@@ -21,13 +23,8 @@
/* Mix non-conflicting functions from underscore.string /* Mix non-conflicting functions from underscore.string
* (all but include, contains, and reverse) into the * (all but include, contains, and reverse) into the
* Underscore namespace. * 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(_.str.exports());
_.mixin(_s.exports());
}
}, },
render: function() { render: function() {
...@@ -106,4 +103,4 @@ ...@@ -106,4 +103,4 @@
}); });
})( jQuery, _, _.str, Backbone, gettext ); })( jQuery, _, Backbone, gettext );
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
'jquery.url': 'empty:', 'jquery.url': 'empty:',
'backbone': 'empty:', 'backbone': 'empty:',
'underscore': 'empty:', 'underscore': 'empty:',
'underscore.string': 'empty:',
'logger': 'empty:', 'logger': 'empty:',
'utility': 'empty:', 'utility': 'empty:',
'URI': 'empty:', 'URI': 'empty:',
......
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
}; };
defineDependency("jQuery", "jquery"); defineDependency("jQuery", "jquery");
defineDependency("_", "underscore"); 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("gettext", "gettext");
defineDependency("Logger", "logger"); defineDependency("Logger", "logger");
defineDependency("URI", "URI"); defineDependency("URI", "URI");
......
...@@ -19,7 +19,6 @@ from django.utils.translation import ugettext as _ ...@@ -19,7 +19,6 @@ from django.utils.translation import ugettext as _
</%block> </%block>
<%block name="js_extra"> <%block name="js_extra">
<script src="${static.url('js/vendor/jquery.ajax-retry.js')}"></script> <script src="${static.url('js/vendor/jquery.ajax-retry.js')}"></script>
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script> <script src="${static.url('js/src/tooltip_manager.js')}"></script>
<script src="${static.url('js/commerce/credit.js')}"></script> <script src="${static.url('js/commerce/credit.js')}"></script>
<script src="${static.url('js/commerce/views/receipt_view.js')}"></script> <script src="${static.url('js/commerce/views/receipt_view.js')}"></script>
......
...@@ -18,7 +18,6 @@ from django.utils.translation import ugettext as _ ...@@ -18,7 +18,6 @@ from django.utils.translation import ugettext as _
% endfor % endfor
</%block> </%block>
<%block name="js_extra"> <%block name="js_extra">
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script> <script src="${static.url('js/src/tooltip_manager.js')}"></script>
<%static:js group='incourse_reverify'/> <%static:js group='incourse_reverify'/>
</%block> </%block>
......
...@@ -41,7 +41,6 @@ from lms.djangoapps.verify_student.views import PayAndVerifyView ...@@ -41,7 +41,6 @@ from lms.djangoapps.verify_student.views import PayAndVerifyView
% endfor % endfor
</%block> </%block>
<%block name="js_extra"> <%block name="js_extra">
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script> <script src="${static.url('js/src/tooltip_manager.js')}"></script>
<%static:js group='verify_student'/> <%static:js group='verify_student'/>
</%block> </%block>
......
...@@ -16,7 +16,6 @@ from django.utils.translation import ugettext as _ ...@@ -16,7 +16,6 @@ from django.utils.translation import ugettext as _
% endfor % endfor
</%block> </%block>
<%block name="js_extra"> <%block name="js_extra">
<script src="${static.url('js/vendor/underscore.string.min.js')}"></script>
<script src="${static.url('js/src/tooltip_manager.js')}"></script> <script src="${static.url('js/src/tooltip_manager.js')}"></script>
<%static:js group='reverify'/> <%static:js group='reverify'/>
</%block> </%block>
......
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