Commit db62db29 by Andy Armstrong Committed by Brian Jacobel

Upgrade Underscore.string

FEDX-117
parent f10a3c96
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
"moment-with-locales": "js/vendor/moment-with-locales.min", "moment-with-locales": "js/vendor/moment-with-locales.min",
"text": 'js/vendor/requirejs/text', "text": 'js/vendor/requirejs/text',
"underscore": "common/js/vendor/underscore", "underscore": "common/js/vendor/underscore",
"underscore.string": "js/vendor/underscore.string.min", "underscore.string": "common/js/vendor/underscore.string",
"backbone": "js/vendor/backbone-min", "backbone": "js/vendor/backbone-min",
"backbone-relational" : "js/vendor/backbone-relational.min", "backbone-relational" : "js/vendor/backbone-relational.min",
"backbone.associations": "js/vendor/backbone-associations-min", "backbone.associations": "js/vendor/backbone-associations-min",
......
...@@ -27,7 +27,7 @@ requirejs.config({ ...@@ -27,7 +27,7 @@ requirejs.config({
"moment-with-locales": "xmodule_js/common_static/js/vendor/moment-with-locales.min", "moment-with-locales": "xmodule_js/common_static/js/vendor/moment-with-locales.min",
"text": "xmodule_js/common_static/js/vendor/requirejs/text", "text": "xmodule_js/common_static/js/vendor/requirejs/text",
"underscore": "xmodule_js/common_static/common/js/vendor/underscore", "underscore": "xmodule_js/common_static/common/js/vendor/underscore",
"underscore.string": "xmodule_js/common_static/js/vendor/underscore.string.min", "underscore.string": "xmodule_js/common_static/common/js/vendor/underscore.string",
"backbone": "xmodule_js/common_static/js/vendor/backbone-min", "backbone": "xmodule_js/common_static/js/vendor/backbone-min",
"backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min", "backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min",
"backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min", "backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min",
......
...@@ -23,7 +23,7 @@ requirejs.config({ ...@@ -23,7 +23,7 @@ requirejs.config({
"date": "xmodule_js/common_static/js/vendor/date", "date": "xmodule_js/common_static/js/vendor/date",
"text": "xmodule_js/common_static/js/vendor/requirejs/text", "text": "xmodule_js/common_static/js/vendor/requirejs/text",
"underscore": "xmodule_js/common_static/common/js/vendor/underscore", "underscore": "xmodule_js/common_static/common/js/vendor/underscore",
"underscore.string": "xmodule_js/common_static/js/vendor/underscore.string.min", "underscore.string": "xmodule_js/common_static/common/js/vendor/underscore.string",
"backbone": "xmodule_js/common_static/js/vendor/backbone-min", "backbone": "xmodule_js/common_static/js/vendor/backbone-min",
"backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min", "backbone.associations": "xmodule_js/common_static/js/vendor/backbone-associations-min",
"backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min", "backbone.paginator": "xmodule_js/common_static/js/vendor/backbone.paginator.min",
......
...@@ -104,11 +104,9 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js ...@@ -104,11 +104,9 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js
describe "EditTextbook", -> describe "EditTextbook", ->
describe "Basic", -> describe "Basic", ->
tpl = readFixtures('edit-textbook.underscore') tpl = readFixtures('edit-textbook.underscore')
chapterTpl = readFixtures('edit-chapter.underscore')
beforeEach -> beforeEach ->
setFixtures($("<script>", {id: "edit-textbook-tpl", type: "text/template"}).text(tpl)) setFixtures($("<script>", {id: "edit-textbook-tpl", type: "text/template"}).text(tpl))
appendSetFixtures($("<script>", {id: "edit-chapter-tpl", type: "text/template"}).text(chapterTpl))
appendSetFixtures(sandbox({id: "page-notification"})) appendSetFixtures(sandbox({id: "page-notification"}))
appendSetFixtures(sandbox({id: "page-prompt"})) appendSetFixtures(sandbox({id: "page-prompt"}))
@model = new Textbook({name: "Life Sciences", editing: true}) @model = new Textbook({name: "Life Sciences", editing: true})
...@@ -298,11 +296,8 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js ...@@ -298,11 +296,8 @@ define ["js/models/textbook", "js/models/chapter", "js/collections/chapter", "js
describe "EditChapter", -> describe "EditChapter", ->
tpl = readFixtures("edit-chapter.underscore")
beforeEach -> beforeEach ->
modal_helpers.installModalTemplates() modal_helpers.installModalTemplates()
appendSetFixtures($("<script>", {id: "edit-chapter-tpl", type: "text/template"}).text(tpl))
@model = new Chapter @model = new Chapter
name: "Chapter 1" name: "Chapter 1"
asset_path: "/ch1.pdf" asset_path: "/ch1.pdf"
......
// Backbone.js Application Model: Certificate // Backbone.js Application Model: Certificate
define([ // jshint ignore:line define([
'underscore', 'underscore',
'underscore.string', 'backbone',
'backbone', 'backbone-relational',
'backbone-relational', 'backbone.associations',
'backbone.associations', 'gettext',
'gettext', 'coffee/src/main',
'coffee/src/main', 'js/certificates/models/signatory',
'js/certificates/models/signatory', 'js/certificates/collections/signatories'
'js/certificates/collections/signatories' ],
], function(_, Backbone, BackboneRelational, BackboneAssociations, gettext, CoffeeSrcMain,
function (_, str, Backbone, BackboneRelational, BackboneAssociations, gettext, CoffeeSrcMain, SignatoryModel, SignatoryCollection) {
SignatoryModel, SignatoryCollection) { 'use strict';
'use strict'; var Certificate = Backbone.RelationalModel.extend({
_.str = str; idAttribute: 'id',
var Certificate = Backbone.RelationalModel.extend({ defaults: {
idAttribute: "id", // Metadata fields currently displayed in web forms
defaults: { course_title: '',
// Metadata fields currently displayed in web forms
course_title: '',
// Metadata fields not currently displayed in web forms // Metadata fields not currently displayed in web forms
name: 'Name of the certificate', name: 'Name of the certificate',
description: 'Description of the certificate', description: 'Description of the certificate',
// Internal-use only, not displayed in web forms // Internal-use only, not displayed in web forms
version: 1, version: 1,
is_active: false is_active: false
}, },
// Certificate child collection/model mappings (backbone-relational) // Certificate child collection/model mappings (backbone-relational)
relations: [{ relations: [{
type: Backbone.HasMany, type: Backbone.HasMany,
key: 'signatories', key: 'signatories',
relatedModel: SignatoryModel, relatedModel: SignatoryModel,
collectionType: SignatoryCollection, collectionType: SignatoryCollection,
reverseRelation: { reverseRelation: {
key: 'certificate', key: 'certificate',
includeInJSON: "id" includeInJSON: 'id'
} }
}], }],
initialize: function(attributes, options) { initialize: function(attributes, options) {
// Set up the initial state of the attributes set for this model instance // Set up the initial state of the attributes set for this model instance
this.canBeEmpty = options && options.canBeEmpty; this.canBeEmpty = options && options.canBeEmpty;
if(options.add) { if (options.add) {
// Ensure at least one child Signatory model is defined for any new Certificate model // Ensure at least one child Signatory model is defined for any new Certificate model
attributes.signatories = new SignatoryModel({certificate: this}); attributes.signatories = new SignatoryModel({certificate: this});
} }
this.setOriginalAttributes(); this.setOriginalAttributes();
return this; return this;
}, },
parse: function (response) { parse: function(response) {
// Parse must be defined for the model, but does not need to do anything special right now // Parse must be defined for the model, but does not need to do anything special right now
return response; return response;
}, },
setOriginalAttributes: function() { setOriginalAttributes: function() {
// Remember the current state of this model (enables edit->cancel use cases) // Remember the current state of this model (enables edit->cancel use cases)
this._originalAttributes = this.parse(this.toJSON()); this._originalAttributes = this.parse(this.toJSON());
this.get("signatories").each(function (modelSignatory) { this.get('signatories').each(function(modelSignatory) {
modelSignatory.setOriginalAttributes(); modelSignatory.setOriginalAttributes();
}); });
// If no url is defined for the signatories child collection we'll need to create that here as well // If no url is defined for the signatories child collection we'll need to create that here as well
if(!this.isNew() && !this.get('signatories').url) { if (!this.isNew() && !this.get('signatories').url) {
this.get('signatories').url = this.collection.url + '/' + this.get('id') + '/signatories'; this.get('signatories').url = this.collection.url + '/' + this.get('id') + '/signatories';
} }
}, },
validate: function(attrs) { validate: function(attrs) {
// Ensure the provided attributes set meets our expectations for format, type, etc. // Ensure the provided attributes set meets our expectations for format, type, etc.
if (!_.str.trim(attrs.name)) { if (!attrs.name.trim()) {
return { return {
message: gettext('Certificate name is required.'), message: gettext('Certificate name is required.'),
attributes: {name: true} attributes: {name: true}
}; };
} }
var all_signatories_valid = _.every(attrs.signatories.models, function(signatory){ var allSignatoriesValid = _.every(attrs.signatories.models, function(signatory){
return signatory.isValid(); return signatory.isValid();
}); });
if (!all_signatories_valid) { if (!allSignatoriesValid) {
return { return {
message: gettext('Signatory field(s) has invalid data.'), message: gettext('Signatory field(s) has invalid data.'),
attributes: {signatories: attrs.signatories.models} attributes: {signatories: attrs.signatories.models}
}; };
} }
}, },
reset: function() { reset: function() {
// Revert the attributes of this model instance back to initial state // Revert the attributes of this model instance back to initial state
this.set(this._originalAttributes, { parse: true, validate: true }); this.set(this._originalAttributes, {parse: true, validate: true});
} }
});
return Certificate;
}); });
return Certificate;
});
...@@ -2,17 +2,15 @@ ...@@ -2,17 +2,15 @@
define([ // jshint ignore:line define([ // jshint ignore:line
'underscore', 'underscore',
'underscore.string',
'backbone', 'backbone',
'backbone-relational', 'backbone-relational',
'gettext' 'underscore.string'
], ],
function(_, str, Backbone, BackboneRelational, gettext) { function(_, Backbone) {
'use strict'; 'use strict';
_.str = str;
var Signatory = Backbone.RelationalModel.extend({ var Signatory = Backbone.RelationalModel.extend({
idAttribute: "id", idAttribute: 'id',
defaults: { defaults: {
name: '', name: '',
title: '', title: '',
...@@ -26,7 +24,7 @@ function(_, str, Backbone, BackboneRelational, gettext) { ...@@ -26,7 +24,7 @@ function(_, str, Backbone, BackboneRelational, gettext) {
return this; return this;
}, },
parse: function (response) { parse: function(response) {
// Parse must be defined for the model, but does not need to do anything special right now // Parse must be defined for the model, but does not need to do anything special right now
return response; return response;
}, },
...@@ -38,7 +36,7 @@ function(_, str, Backbone, BackboneRelational, gettext) { ...@@ -38,7 +36,7 @@ function(_, str, Backbone, BackboneRelational, gettext) {
reset: function() { reset: function() {
// Revert the attributes of this model instance back to initial state // Revert the attributes of this model instance back to initial state
this.set(this._originalAttributes, { parse: true, validate: true }); this.set(this._originalAttributes, {parse: true, validate: true});
} }
}); });
return Signatory; return Signatory;
......
define([ define([
'backbone', 'underscore', 'underscore.string', 'gettext', 'js/models/group', 'backbone', 'underscore', 'gettext', 'js/models/group', 'js/collections/group',
'js/collections/group', 'backbone.associations', 'coffee/src/main' 'backbone.associations', 'coffee/src/main'
], ],
function(Backbone, _, str, gettext, GroupModel, GroupCollection) { function(Backbone, _, gettext, GroupModel, GroupCollection) {
'use strict'; 'use strict';
_.str = str;
var GroupConfiguration = Backbone.AssociatedModel.extend({ var GroupConfiguration = Backbone.AssociatedModel.extend({
defaults: function() { defaults: function() {
return { return {
...@@ -49,7 +48,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -49,7 +48,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
}, },
reset: function() { reset: function() {
this.set(this._originalAttributes, { parse: true, validate: true }); this.set(this._originalAttributes, {parse: true, validate: true});
}, },
isDirty: function() { isDirty: function() {
...@@ -84,7 +83,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -84,7 +83,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
}, },
validate: function(attrs) { validate: function(attrs) {
if (!_.str.trim(attrs.name)) { if (!attrs.name.trim()) {
return { return {
message: gettext('Group Configuration name is required.'), message: gettext('Group Configuration name is required.'),
attributes: {name: true} attributes: {name: true}
...@@ -94,7 +93,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -94,7 +93,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
if (!this.canBeEmpty && attrs.groups.length < 1) { if (!this.canBeEmpty && attrs.groups.length < 1) {
return { return {
message: gettext('There must be at least one group.'), message: gettext('There must be at least one group.'),
attributes: { groups: true } attributes: {groups: true}
}; };
} else { } else {
// validate all groups // validate all groups
...@@ -111,7 +110,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -111,7 +110,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
if (!invalidGroups.isEmpty()) { if (!invalidGroups.isEmpty()) {
return { return {
message: gettext('All groups must have a name.'), message: gettext('All groups must have a name.'),
attributes: { groups: invalidGroups.toJSON() } attributes: {groups: invalidGroups.toJSON()}
}; };
} }
...@@ -119,13 +118,13 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) { ...@@ -119,13 +118,13 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
if (groupNames.length !== _.uniq(groupNames).length) { if (groupNames.length !== _.uniq(groupNames).length) {
return { return {
message: gettext('All groups must have a unique name.'), message: gettext('All groups must have a unique name.'),
attributes: { groups: validGroups.toJSON() } attributes: {groups: validGroups.toJSON()}
}; };
} }
} }
}, },
groupRemoved: function () { groupRemoved: function() {
this.setOriginalAttributes(); this.setOriginalAttributes();
} }
}); });
......
/*global course */ /*global course */
define(["js/views/baseview", "underscore", "underscore.string", "jquery", "gettext", "js/models/uploads", "js/views/uploads"], define(['underscore', 'jquery', 'gettext', 'edx-ui-toolkit/js/utils/html-utils',
function(BaseView, _, str, $, gettext, FileUploadModel, UploadDialogView) { 'js/views/baseview', 'js/models/uploads', 'js/views/uploads', 'text!templates/edit-chapter.underscore'],
_.str = str; // used in template function(_, $, gettext, HtmlUtils, BaseView, FileUploadModel, UploadDialogView, editChapterTemplate) {
var EditChapter = BaseView.extend({ 'use strict';
initialize: function() {
this.template = this.loadTemplate('edit-chapter'); var EditChapter = BaseView.extend({
this.listenTo(this.model, "change", this.render); initialize: function() {
}, this.template = HtmlUtils.template(editChapterTemplate);
tagName: "li", this.listenTo(this.model, 'change', this.render);
className: function() { },
return "field-group chapter chapter" + this.model.get('order'); tagName: 'li',
}, className: function() {
render: function() { return 'field-group chapter chapter' + this.model.get('order');
this.$el.html(this.template({ },
name: this.model.get('name'), render: function() {
asset_path: this.model.get('asset_path'), HtmlUtils.setHtml(
order: this.model.get('order'), this.$el,
error: this.model.validationError this.template({
})); name: this.model.get('name'),
return this; asset_path: this.model.get('asset_path'),
}, order: this.model.get('order'),
events: { error: this.model.validationError
"change .chapter-name": "changeName", })
"change .chapter-asset-path": "changeAssetPath", );
"click .action-close": "removeChapter", return this;
"click .action-upload": "openUploadDialog", },
"submit": "uploadAsset" events: {
}, 'change .chapter-name': 'changeName',
changeName: function(e) { 'change .chapter-asset-path': 'changeAssetPath',
if(e && e.preventDefault) { e.preventDefault(); } 'click .action-close': 'removeChapter',
this.model.set({ 'click .action-upload': 'openUploadDialog',
name: this.$(".chapter-name").val() 'submit': 'uploadAsset'
}, {silent: true}); },
return this; changeName: function(e) {
}, if(e && e.preventDefault) { e.preventDefault(); }
changeAssetPath: function(e) { this.model.set({
if(e && e.preventDefault) { e.preventDefault(); } name: this.$('.chapter-name').val()
this.model.set({ }, {silent: true});
asset_path: this.$(".chapter-asset-path").val() return this;
}, {silent: true}); },
return this; changeAssetPath: function(e) {
}, if(e && e.preventDefault) { e.preventDefault(); }
removeChapter: function(e) { this.model.set({
if(e && e.preventDefault) { e.preventDefault(); } asset_path: this.$('.chapter-asset-path').val()
this.model.collection.remove(this.model); }, {silent: true});
return this.remove(); return this;
}, },
openUploadDialog: function(e) { removeChapter: function(e) {
if(e && e.preventDefault) { e.preventDefault(); } if(e && e.preventDefault) { e.preventDefault(); }
this.model.set({ this.model.collection.remove(this.model);
name: this.$("input.chapter-name").val(), return this.remove();
asset_path: this.$("input.chapter-asset-path").val() },
}); openUploadDialog: function(e) {
var msg = new FileUploadModel({ if(e && e.preventDefault) { e.preventDefault(); }
title: _.template(gettext("Upload a new PDF to “<%= name %>”"))( this.model.set({
{name: course.escape('name')}), name: this.$('input.chapter-name').val(),
message: gettext("Please select a PDF file to upload."), asset_path: this.$('input.chapter-asset-path').val()
mimeTypes: ['application/pdf'] });
}); var msg = new FileUploadModel({
var that = this; title: _.template(gettext('Upload a new PDF to “<%= name %>”'))(
var view = new UploadDialogView({ {name: course.escape('name')}),
model: msg, message: gettext('Please select a PDF file to upload.'),
onSuccess: function(response) { mimeTypes: ['application/pdf']
var options = {}; });
if(!that.model.get('name')) { var that = this;
options.name = response.asset.displayname; var view = new UploadDialogView({
model: msg,
onSuccess: function(response) {
var options = {};
if (!that.model.get('name')) {
options.name = response.asset.displayname;
}
options.asset_path = response.asset.portable_url;
that.model.set(options);
} }
options.asset_path = response.asset.portable_url; });
that.model.set(options); view.show();
} }
}); });
view.show();
}
});
return EditChapter; return EditChapter;
}); });
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
* It is expected to be backed by a Group model. * It is expected to be backed by a Group model.
*/ */
define([ define([
'js/views/baseview', 'underscore', 'underscore.string', 'gettext' 'js/views/baseview'
], ],
function(BaseView, _, str, gettext) { function(BaseView) {
'use strict'; 'use strict';
_.str = str; // used in template
var ExperimentGroupEditView = BaseView.extend({ var ExperimentGroupEditView = BaseView.extend({
tagName: 'li', tagName: 'li',
events: { events: {
......
...@@ -36,7 +36,7 @@ lib_paths: ...@@ -36,7 +36,7 @@ lib_paths:
- xmodule_js/common_static/js/vendor/jquery.cookie.js - xmodule_js/common_static/js/vendor/jquery.cookie.js
- xmodule_js/common_static/js/vendor/jquery.simulate.js - xmodule_js/common_static/js/vendor/jquery.simulate.js
- xmodule_js/common_static/common/js/vendor/underscore.js - xmodule_js/common_static/common/js/vendor/underscore.js
- xmodule_js/common_static/js/vendor/underscore.string.min.js - xmodule_js/common_static/common/js/vendor/underscore.string.js
- xmodule_js/common_static/js/vendor/backbone-min.js - xmodule_js/common_static/js/vendor/backbone-min.js
- xmodule_js/common_static/js/vendor/backbone-associations-min.js - xmodule_js/common_static/js/vendor/backbone-associations-min.js
- xmodule_js/common_static/js/vendor/backbone.paginator.min.js - xmodule_js/common_static/js/vendor/backbone.paginator.min.js
......
...@@ -35,7 +35,7 @@ lib_paths: ...@@ -35,7 +35,7 @@ lib_paths:
- xmodule_js/common_static/js/vendor/jquery-ui.min.js - xmodule_js/common_static/js/vendor/jquery-ui.min.js
- xmodule_js/common_static/js/vendor/jquery.cookie.js - xmodule_js/common_static/js/vendor/jquery.cookie.js
- xmodule_js/common_static/common/js/vendor/underscore.js - xmodule_js/common_static/common/js/vendor/underscore.js
- xmodule_js/common_static/js/vendor/underscore.string.min.js - xmodule_js/common_static/common/js/vendor/underscore.string.js
- xmodule_js/common_static/js/vendor/backbone-min.js - xmodule_js/common_static/js/vendor/backbone-min.js
- xmodule_js/common_static/js/vendor/backbone-associations-min.js - xmodule_js/common_static/js/vendor/backbone-associations-min.js
- xmodule_js/common_static/js/vendor/backbone.paginator.min.js - xmodule_js/common_static/js/vendor/backbone.paginator.min.js
......
...@@ -10,7 +10,7 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json ...@@ -10,7 +10,7 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json
<%block name="bodyclass">is-signedin course view-textbooks</%block> <%block name="bodyclass">is-signedin course view-textbooks</%block>
<%block name="header_extras"> <%block name="header_extras">
% for template_name in ["edit-textbook", "show-textbook", "edit-chapter", "no-textbooks", "basic-modal", "modal-button", "upload-dialog"]: % for template_name in ["edit-textbook", "show-textbook", "no-textbooks", "basic-modal", "modal-button", "upload-dialog"]:
<script type="text/template" id="${template_name}-tpl"> <script type="text/template" id="${template_name}-tpl">
<%static:include path="js/${template_name}.underscore" /> <%static:include path="js/${template_name}.underscore" />
</script> </script>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
'sinon': 'js/vendor/sinon-1.17.0', 'sinon': 'js/vendor/sinon-1.17.0',
'text': 'js/vendor/requirejs/text', 'text': 'js/vendor/requirejs/text',
'underscore': 'common/js/vendor/underscore', 'underscore': 'common/js/vendor/underscore',
'underscore.string': 'js/vendor/underscore.string.min', 'underscore.string': 'common/js/vendor/underscore.string',
'backbone': 'js/vendor/backbone-min', 'backbone': 'js/vendor/backbone-min',
'backbone.associations': 'js/vendor/backbone-associations-min', 'backbone.associations': 'js/vendor/backbone-associations-min',
'backbone.paginator': 'js/vendor/backbone.paginator.min', 'backbone.paginator': 'js/vendor/backbone.paginator.min',
......
!function(e,t){"use strict";var n=t.prototype.trim,r=t.prototype.trimRight,i=t.prototype.trimLeft,s=function(e){return e*1||0},o=function(e,t){if(t<1)return"";var n="";while(t>0)t&1&&(n+=e),t>>=1,e+=e;return n},u=[].slice,a=function(e){return e==null?"\\s":e.source?e.source:"["+p.escapeRegExp(e)+"]"},f={lt:"<",gt:">",quot:'"',apos:"'",amp:"&"},l={};for(var c in f)l[f[c]]=c;var h=function(){function e(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}var n=o,r=function(){return r.cache.hasOwnProperty(arguments[0])||(r.cache[arguments[0]]=r.parse(arguments[0])),r.format.call(null,r.cache[arguments[0]],arguments)};return r.format=function(r,i){var s=1,o=r.length,u="",a,f=[],l,c,p,d,v,m;for(l=0;l<o;l++){u=e(r[l]);if(u==="string")f.push(r[l]);else if(u==="array"){p=r[l];if(p[2]){a=i[s];for(c=0;c<p[2].length;c++){if(!a.hasOwnProperty(p[2][c]))throw new Error(h('[_.sprintf] property "%s" does not exist',p[2][c]));a=a[p[2][c]]}}else p[1]?a=i[p[1]]:a=i[s++];if(/[^s]/.test(p[8])&&e(a)!="number")throw new Error(h("[_.sprintf] expecting number but found %s",e(a)));switch(p[8]){case"b":a=a.toString(2);break;case"c":a=t.fromCharCode(a);break;case"d":a=parseInt(a,10);break;case"e":a=p[7]?a.toExponential(p[7]):a.toExponential();break;case"f":a=p[7]?parseFloat(a).toFixed(p[7]):parseFloat(a);break;case"o":a=a.toString(8);break;case"s":a=(a=t(a))&&p[7]?a.substring(0,p[7]):a;break;case"u":a=Math.abs(a);break;case"x":a=a.toString(16);break;case"X":a=a.toString(16).toUpperCase()}a=/[def]/.test(p[8])&&p[3]&&a>=0?"+"+a:a,v=p[4]?p[4]=="0"?"0":p[4].charAt(1):" ",m=p[6]-t(a).length,d=p[6]?n(v,m):"",f.push(p[5]?a+d:d+a)}}return f.join("")},r.cache={},r.parse=function(e){var t=e,n=[],r=[],i=0;while(t){if((n=/^[^\x25]+/.exec(t))!==null)r.push(n[0]);else if((n=/^\x25{2}/.exec(t))!==null)r.push("%");else{if((n=/^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(t))===null)throw new Error("[_.sprintf] huh?");if(n[2]){i|=1;var s=[],o=n[2],u=[];if((u=/^([a-z_][a-z_\d]*)/i.exec(o))===null)throw new Error("[_.sprintf] huh?");s.push(u[1]);while((o=o.substring(u[0].length))!=="")if((u=/^\.([a-z_][a-z_\d]*)/i.exec(o))!==null)s.push(u[1]);else{if((u=/^\[(\d+)\]/.exec(o))===null)throw new Error("[_.sprintf] huh?");s.push(u[1])}n[2]=s}else i|=2;if(i===3)throw new Error("[_.sprintf] mixing positional and named placeholders is not (yet) supported");r.push(n)}t=t.substring(n[0].length)}return r},r}(),p={VERSION:"2.3.0",isBlank:function(e){return e==null&&(e=""),/^\s*$/.test(e)},stripTags:function(e){return e==null?"":t(e).replace(/<\/?[^>]+>/g,"")},capitalize:function(e){return e=e==null?"":t(e),e.charAt(0).toUpperCase()+e.slice(1)},chop:function(e,n){return e==null?[]:(e=t(e),n=~~n,n>0?e.match(new RegExp(".{1,"+n+"}","g")):[e])},clean:function(e){return p.strip(e).replace(/\s+/g," ")},count:function(e,n){return e==null||n==null?0:t(e).split(n).length-1},chars:function(e){return e==null?[]:t(e).split("")},swapCase:function(e){return e==null?"":t(e).replace(/\S/g,function(e){return e===e.toUpperCase()?e.toLowerCase():e.toUpperCase()})},escapeHTML:function(e){return e==null?"":t(e).replace(/[&<>"']/g,function(e){return"&"+l[e]+";"})},unescapeHTML:function(e){return e==null?"":t(e).replace(/\&([^;]+);/g,function(e,n){var r;return n in f?f[n]:(r=n.match(/^#x([\da-fA-F]+)$/))?t.fromCharCode(parseInt(r[1],16)):(r=n.match(/^#(\d+)$/))?t.fromCharCode(~~r[1]):e})},escapeRegExp:function(e){return e==null?"":t(e).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")},splice:function(e,t,n,r){var i=p.chars(e);return i.splice(~~t,~~n,r),i.join("")},insert:function(e,t,n){return p.splice(e,t,0,n)},include:function(e,n){return n===""?!0:e==null?!1:t(e).indexOf(n)!==-1},join:function(){var e=u.call(arguments),t=e.shift();return t==null&&(t=""),e.join(t)},lines:function(e){return e==null?[]:t(e).split("\n")},reverse:function(e){return p.chars(e).reverse().join("")},startsWith:function(e,n){return n===""?!0:e==null||n==null?!1:(e=t(e),n=t(n),e.length>=n.length&&e.slice(0,n.length)===n)},endsWith:function(e,n){return n===""?!0:e==null||n==null?!1:(e=t(e),n=t(n),e.length>=n.length&&e.slice(e.length-n.length)===n)},succ:function(e){return e==null?"":(e=t(e),e.slice(0,-1)+t.fromCharCode(e.charCodeAt(e.length-1)+1))},titleize:function(e){return e==null?"":t(e).replace(/(?:^|\s)\S/g,function(e){return e.toUpperCase()})},camelize:function(e){return p.trim(e).replace(/[-_\s]+(.)?/g,function(e,t){return t.toUpperCase()})},underscored:function(e){return p.trim(e).replace(/([a-z\d])([A-Z]+)/g,"$1_$2").replace(/[-\s]+/g,"_").toLowerCase()},dasherize:function(e){return p.trim(e).replace(/([A-Z])/g,"-$1").replace(/[-_\s]+/g,"-").toLowerCase()},classify:function(e){return p.titleize(t(e).replace(/_/g," ")).replace(/\s/g,"")},humanize:function(e){return p.capitalize(p.underscored(e).replace(/_id$/,"").replace(/_/g," "))},trim:function(e,r){return e==null?"":!r&&n?n.call(e):(r=a(r),t(e).replace(new RegExp("^"+r+"+|"+r+"+$","g"),""))},ltrim:function(e,n){return e==null?"":!n&&i?i.call(e):(n=a(n),t(e).replace(new RegExp("^"+n+"+"),""))},rtrim:function(e,n){return e==null?"":!n&&r?r.call(e):(n=a(n),t(e).replace(new RegExp(n+"+$"),""))},truncate:function(e,n,r){return e==null?"":(e=t(e),r=r||"...",n=~~n,e.length>n?e.slice(0,n)+r:e)},prune:function(e,n,r){if(e==null)return"";e=t(e),n=~~n,r=r!=null?t(r):"...";if(e.length<=n)return e;var i=function(e){return e.toUpperCase()!==e.toLowerCase()?"A":" "},s=e.slice(0,n+1).replace(/.(?=\W*\w*$)/g,i);return s.slice(s.length-2).match(/\w\w/)?s=s.replace(/\s*\S+$/,""):s=p.rtrim(s.slice(0,s.length-1)),(s+r).length>e.length?e:e.slice(0,s.length)+r},words:function(e,t){return p.isBlank(e)?[]:p.trim(e,t).split(t||/\s+/)},pad:function(e,n,r,i){e=e==null?"":t(e),n=~~n;var s=0;r?r.length>1&&(r=r.charAt(0)):r=" ";switch(i){case"right":return s=n-e.length,e+o(r,s);case"both":return s=n-e.length,o(r,Math.ceil(s/2))+e+o(r,Math.floor(s/2));default:return s=n-e.length,o(r,s)+e}},lpad:function(e,t,n){return p.pad(e,t,n)},rpad:function(e,t,n){return p.pad(e,t,n,"right")},lrpad:function(e,t,n){return p.pad(e,t,n,"both")},sprintf:h,vsprintf:function(e,t){return t.unshift(e),h.apply(null,t)},toNumber:function(e,n){if(e==null||e=="")return 0;e=t(e);var r=s(s(e).toFixed(~~n));return r===0&&!e.match(/^0+$/)?Number.NaN:r},numberFormat:function(e,t,n,r){if(isNaN(e)||e==null)return"";e=e.toFixed(~~t),r=r||",";var i=e.split("."),s=i[0],o=i[1]?(n||".")+i[1]:"";return s.replace(/(\d)(?=(?:\d{3})+$)/g,"$1"+r)+o},strRight:function(e,n){if(e==null)return"";e=t(e),n=n!=null?t(n):n;var r=n?e.indexOf(n):-1;return~r?e.slice(r+n.length,e.length):e},strRightBack:function(e,n){if(e==null)return"";e=t(e),n=n!=null?t(n):n;var r=n?e.lastIndexOf(n):-1;return~r?e.slice(r+n.length,e.length):e},strLeft:function(e,n){if(e==null)return"";e=t(e),n=n!=null?t(n):n;var r=n?e.indexOf(n):-1;return~r?e.slice(0,r):e},strLeftBack:function(e,t){if(e==null)return"";e+="",t=t!=null?""+t:t;var n=e.lastIndexOf(t);return~n?e.slice(0,n):e},toSentence:function(e,t,n,r){t=t||", ",n=n||" and ";var i=e.slice(),s=i.pop();return e.length>2&&r&&(n=p.rtrim(t)+n),i.length?i.join(t)+n+s:s},toSentenceSerial:function(){var e=u.call(arguments);return e[3]=!0,p.toSentence.apply(p,e)},slugify:function(e){if(e==null)return"";var n="ąàáäâãåæćęèéëêìíïîłńòóöôõøùúüûñçżź",r="aaaaaaaaceeeeeiiiilnoooooouuuunczz",i=new RegExp(a(n),"g");return e=t(e).toLowerCase().replace(i,function(e){var t=n.indexOf(e);return r.charAt(t)||"-"}),p.dasherize(e.replace(/[^\w\s-]/g,""))},surround:function(e,t){return[t,e,t].join("")},quote:function(e){return p.surround(e,'"')},exports:function(){var e={};for(var t in this){if(!this.hasOwnProperty(t)||t.match(/^(?:include|contains|reverse)$/))continue;e[t]=this[t]}return e},repeat:function(e,n,r){if(e==null)return"";n=~~n;if(r==null)return o(t(e),n);for(var i=[];n>0;i[--n]=e);return i.join(r)},levenshtein:function(e,n){if(e==null&&n==null)return 0;if(e==null)return t(n).length;if(n==null)return t(e).length;e=t(e),n=t(n);var r=[],i,s;for(var o=0;o<=n.length;o++)for(var u=0;u<=e.length;u++)o&&u?e.charAt(u-1)===n.charAt(o-1)?s=i:s=Math.min(r[u],r[u-1],i)+1:s=o+u,i=r[u],r[u]=s;return r.pop()}};p.strip=p.trim,p.lstrip=p.ltrim,p.rstrip=p.rtrim,p.center=p.lrpad,p.rjust=p.lpad,p.ljust=p.rpad,p.contains=p.include,p.q=p.quote,typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(module.exports=p),exports._s=p):typeof define==="function"&&define.amd?define("underscore.string",[],function(){return p}):(e._=e._||{},e._.string=e._.str=p)}(this,String);
\ No newline at end of file
...@@ -34,7 +34,7 @@ lib_paths: ...@@ -34,7 +34,7 @@ lib_paths:
- js/vendor/jquery.truncate.js - js/vendor/jquery.truncate.js
- js/vendor/mustache.js - js/vendor/mustache.js
- common/js/vendor/underscore.js - common/js/vendor/underscore.js
- js/vendor/underscore.string.min.js - common/js/vendor/underscore.string.js
- js/vendor/backbone-min.js - js/vendor/backbone-min.js
- js/vendor/jquery.timeago.js - js/vendor/jquery.timeago.js
- js/vendor/URI.min.js - js/vendor/URI.min.js
......
...@@ -33,8 +33,8 @@ lib_paths: ...@@ -33,8 +33,8 @@ lib_paths:
- js/vendor/jasmine-imagediff.js - js/vendor/jasmine-imagediff.js
- js/vendor/jquery.simulate.js - js/vendor/jquery.simulate.js
- js/vendor/jquery.truncate.js - js/vendor/jquery.truncate.js
- js/vendor/underscore-min.js - common/js/vendor/underscore.js
- js/vendor/underscore.string.min.js - common/js/vendor/underscore.string.js
- js/vendor/backbone-min.js - js/vendor/backbone-min.js
- js/vendor/backbone.paginator.min.js - js/vendor/backbone.paginator.min.js
- js/vendor/jquery.timeago.js - js/vendor/jquery.timeago.js
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
'moment-with-locales': 'xmodule_js/common_static/js/vendor/moment-with-locales.min', 'moment-with-locales': 'xmodule_js/common_static/js/vendor/moment-with-locales.min',
'text': 'xmodule_js/common_static/js/vendor/requirejs/text', 'text': 'xmodule_js/common_static/js/vendor/requirejs/text',
'underscore': 'xmodule_js/common_static/common/js/vendor/underscore', 'underscore': 'xmodule_js/common_static/common/js/vendor/underscore',
'underscore.string': 'xmodule_js/common_static/js/vendor/underscore.string.min', 'underscore.string': 'xmodule_js/common_static/common/js/vendor/underscore.string',
'backbone': 'xmodule_js/common_static/js/vendor/backbone-min', 'backbone': 'xmodule_js/common_static/js/vendor/backbone-min',
'backbone.associations': 'xmodule_js/common_static/js/vendor/backbone-associations-min', 'backbone.associations': 'xmodule_js/common_static/js/vendor/backbone-associations-min',
'backbone.paginator': 'xmodule_js/common_static/js/vendor/backbone.paginator.min', 'backbone.paginator': 'xmodule_js/common_static/js/vendor/backbone.paginator.min',
......
...@@ -57,7 +57,7 @@ lib_paths: ...@@ -57,7 +57,7 @@ lib_paths:
- xmodule_js/src/xmodule.js - xmodule_js/src/xmodule.js
- xmodule_js/common_static/js/src/ - xmodule_js/common_static/js/src/
- xmodule_js/common_static/common/js/vendor/underscore.js - xmodule_js/common_static/common/js/vendor/underscore.js
- xmodule_js/common_static/js/vendor/underscore.string.min.js - xmodule_js/common_static/common/js/vendor/underscore.string.js
- xmodule_js/common_static/js/vendor/backbone-min.js - xmodule_js/common_static/js/vendor/backbone-min.js
- xmodule_js/common_static/js/vendor/backbone.paginator.min.js - xmodule_js/common_static/js/vendor/backbone.paginator.min.js
- xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min.js - xmodule_js/common_static/js/vendor/edxnotes/annotator-full.min.js
......
...@@ -29,11 +29,11 @@ ...@@ -29,11 +29,11 @@
}; };
defineDependency("jQuery", "jquery"); defineDependency("jQuery", "jquery");
defineDependency("_", "underscore"); defineDependency("_", "underscore");
if (window._ && window._.str) { defineDependency("s", "underscore.string");
define("underscore.string", [], function () {return window._.str;}); // Underscore.string no longer installs itself directly on "_". For compatibility with existing
} // code, add it to "_" with its previous name.
else { if (window._ && window.s) {
console.error("Expected _.str (underscore.string) to be on the window object, but not found."); window._.str = window.s;
} }
defineDependency("gettext", "gettext"); defineDependency("gettext", "gettext");
defineDependency("Logger", "logger"); defineDependency("Logger", "logger");
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
"backbone-super": "js/vendor/backbone-super", "backbone-super": "js/vendor/backbone-super",
"backbone.paginator": "js/vendor/backbone.paginator.min", "backbone.paginator": "js/vendor/backbone.paginator.min",
"underscore": "common/js/vendor/underscore", "underscore": "common/js/vendor/underscore",
"underscore.string": "js/vendor/underscore.string.min", "underscore.string": "common/js/vendor/underscore.string",
"jquery": "js/vendor/jquery.min", "jquery": "js/vendor/jquery.min",
"jquery.cookie": "js/vendor/jquery.cookie", "jquery.cookie": "js/vendor/jquery.cookie",
'jquery.timeago': 'js/vendor/jquery.timeago', 'jquery.timeago': 'js/vendor/jquery.timeago',
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
"edx-ui-toolkit": "0.9.0", "edx-ui-toolkit": "0.9.0",
"requirejs": "~2.1.22", "requirejs": "~2.1.22",
"uglify-js": "2.4.24", "uglify-js": "2.4.24",
"underscore": "~1.8.3" "underscore": "~1.8.3",
"underscore.string": "~3.3.4"
}, },
"devDependencies": { "devDependencies": {
"jshint": "^2.7.0", "jshint": "^2.7.0",
......
...@@ -39,7 +39,8 @@ COMMON_LOOKUP_DIRS = [ ...@@ -39,7 +39,8 @@ COMMON_LOOKUP_DIRS = [
# A list of NPM installed libraries that should be copied into the common # A list of NPM installed libraries that should be copied into the common
# static directory. # static directory.
NPM_INSTALLED_LIBRARIES = [ NPM_INSTALLED_LIBRARIES = [
'underscore/underscore.js' 'underscore/underscore.js',
'underscore.string/dist/underscore.string.js'
] ]
# Directory to install static vendor files # Directory to install static vendor files
......
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