Commit e9e5b5bd by Christina Roberts

Merge pull request #8765 from edx/christina/lms-requirejs/notes

Optimize edxnotes files.
parents ad16f9f9 497d76fa
...@@ -60,7 +60,11 @@ source, template_path = _loader.load_template_source(path) ...@@ -60,7 +60,11 @@ source, template_path = _loader.load_template_source(path)
${caller.body()} ${caller.body()}
}); });
% else: % else:
require(['${staticfiles_storage.url(module_name + ".js")}'], function () { ## The "raw" parameter is specified to avoid the URL from being further maninpulated by
## static_replace calls (as woudl happen if require_module is used within courseware).
## Without specifying "raw", a call to static_replace would result in the MD5 hash being
## being appended more than once, causing the import to fail in production environments.
require(['${staticfiles_storage.url(module_name + ".js") + "?raw"}'], function () {
require(['${module_name}'], function (${class_name}) { require(['${module_name}'], function (${class_name}) {
${caller.body()} ${caller.body()}
}); });
......
...@@ -3,6 +3,7 @@ import json ...@@ -3,6 +3,7 @@ import json
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from student.models import anonymous_id_for_user from student.models import anonymous_id_for_user
%> %>
<%namespace name='static' file='/static_content.html'/>
<% <%
if user: if user:
params.update({'user': anonymous_id_for_user(user, None)}) params.update({'user': anonymous_id_for_user(user, None)})
...@@ -10,11 +11,7 @@ from student.models import anonymous_id_for_user ...@@ -10,11 +11,7 @@ from student.models import anonymous_id_for_user
<div id="edx-notes-wrapper-${uid}" class="edx-notes-wrapper"> <div id="edx-notes-wrapper-${uid}" class="edx-notes-wrapper">
<div class="edx-notes-wrapper-content">${content}</div> <div class="edx-notes-wrapper-content">${content}</div>
</div> </div>
<script type="text/javascript"> <%static:require_module module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory">
(function (require) { var element = document.getElementById('edx-notes-wrapper-${uid}');
require(['js/edxnotes/views/visibility_decorator'], function(EdxnotesVisibilityDecorator) { NotesVisibilityFactory.VisibilityDecorator.factory(element, ${json.dumps(params)}, ${edxnotes_visibility});
var element = document.getElementById('edx-notes-wrapper-${uid}'); </%static:require_module>
EdxnotesVisibilityDecorator.factory(element, ${json.dumps(params)}, ${edxnotes_visibility});
});
}).call(this, require || RequireJS.require);
</script>
;(function (define) { ;(function (define) {
'use strict'; 'use strict';
define(['backbone', 'js/edxnotes/utils/utils', 'underscore.string'], function (Backbone, Utils) { define(['backbone', 'js/edxnotes/utils/utils', 'underscore.string'], function (Backbone, Utils, str) {
var NoteModel = Backbone.Model.extend({ var NoteModel = Backbone.Model.extend({
defaults: { defaults: {
'id': null, 'id': null,
...@@ -47,7 +47,7 @@ define(['backbone', 'js/edxnotes/utils/utils', 'underscore.string'], function (B ...@@ -47,7 +47,7 @@ define(['backbone', 'js/edxnotes/utils/utils', 'underscore.string'], function (B
var message = this.get('quote'); var message = this.get('quote');
if (!this.get('is_expanded') && this.get('show_link')) { if (!this.get('is_expanded') && this.get('show_link')) {
message = _.str.prune(message, this.textSize); message = str.prune(message, this.textSize);
} }
return message; return message;
......
;(function (define, undefined) { ;(function (define, undefined) {
'use strict'; 'use strict';
define([ define([
'underscore', 'annotator_1.2.9', 'underscore.string' 'underscore', 'annotator_1.2.9'
], function (_, Annotator) { ], function (_, Annotator) {
/** /**
* Modifies Annotator.Plugin.Store.annotationCreated to make it trigger a new * Modifies Annotator.Plugin.Store.annotationCreated to make it trigger a new
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
define([ define([
'jquery', 'underscore', 'backbone', 'gettext', 'jquery', 'underscore', 'backbone', 'gettext',
'annotator_1.2.9', 'js/edxnotes/views/visibility_decorator', 'js/utils/animation' 'annotator_1.2.9', 'js/edxnotes/views/visibility_decorator', 'js/utils/animation'
], function($, _, Backbone, gettext, Annotator, EdxnotesVisibilityDecorator) { ], function($, _, Backbone, gettext, Annotator, VisibilityDecorator) {
var ToggleNotesView = Backbone.View.extend({ var ToggleVisibilityView = Backbone.View.extend({
events: { events: {
'click .action-toggle-notes': 'toggleHandler' 'click .action-toggle-notes': 'toggleHandler'
}, },
...@@ -52,14 +52,14 @@ define([ ...@@ -52,14 +52,14 @@ define([
}, },
enableNotes: function () { enableNotes: function () {
_.each($('.edx-notes-wrapper'), EdxnotesVisibilityDecorator.enableNote); _.each($('.edx-notes-wrapper'), VisibilityDecorator.enableNote);
this.actionLink.addClass('is-active'); this.actionLink.addClass('is-active');
this.label.text(gettext('Hide notes')); this.label.text(gettext('Hide notes'));
this.actionToggleMessage.text(gettext('Notes visible')); this.actionToggleMessage.text(gettext('Notes visible'));
}, },
disableNotes: function () { disableNotes: function () {
EdxnotesVisibilityDecorator.disableNotes(); VisibilityDecorator.disableNotes();
this.actionLink.removeClass('is-active'); this.actionLink.removeClass('is-active');
this.label.text(gettext('Show notes')); this.label.text(gettext('Show notes'));
this.actionToggleMessage.text(gettext('Notes hidden')); this.actionToggleMessage.text(gettext('Notes hidden'));
...@@ -93,12 +93,16 @@ define([ ...@@ -93,12 +93,16 @@ define([
} }
}); });
return function (visibility, visibilityUrl) { return {
return new ToggleNotesView({ ToggleVisibilityView: function (visibility, visibilityUrl) {
el: $('.edx-notes-visibility').get(0), return new ToggleVisibilityView({
visibility: visibility, el: $('.edx-notes-visibility').get(0),
visibilityUrl: visibilityUrl visibility: visibility,
}); visibilityUrl: visibilityUrl
});
},
VisibilityDecorator: VisibilityDecorator
}; };
}); });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
define([ define([
'jquery', 'annotator_1.2.9', 'common/js/spec_helpers/ajax_helpers', 'js/edxnotes/views/visibility_decorator', 'jquery', 'underscore', 'annotator_1.2.9', 'common/js/spec_helpers/ajax_helpers',
'js/edxnotes/views/toggle_notes_factory', 'js/spec/edxnotes/helpers', 'js/edxnotes/views/notes_visibility_factory', 'js/spec/edxnotes/helpers',
'js/spec/edxnotes/custom_matchers', 'jasmine-jquery' 'js/spec/edxnotes/custom_matchers', 'jasmine-jquery'
], function( ], function(
$, Annotator, AjaxHelpers, VisibilityDecorator, ToggleNotesFactory, Helpers, $, _, Annotator, AjaxHelpers, NotesVisibilityFactory, Helpers, customMatchers
customMatchers
) { ) {
'use strict'; 'use strict';
describe('EdxNotes ToggleNotesFactory', function() { describe('EdxNotes ToggleNotesFactory', function() {
...@@ -23,13 +22,13 @@ define([ ...@@ -23,13 +22,13 @@ define([
'js/fixtures/edxnotes/edxnotes_wrapper.html', 'js/fixtures/edxnotes/edxnotes_wrapper.html',
'js/fixtures/edxnotes/toggle_notes.html' 'js/fixtures/edxnotes/toggle_notes.html'
); );
VisibilityDecorator.factory( NotesVisibilityFactory.VisibilityDecorator.factory(
document.getElementById('edx-notes-wrapper-123'), params, true document.getElementById('edx-notes-wrapper-123'), params, true
); );
VisibilityDecorator.factory( NotesVisibilityFactory.VisibilityDecorator.factory(
document.getElementById('edx-notes-wrapper-456'), params, true document.getElementById('edx-notes-wrapper-456'), params, true
); );
this.toggleNotes = ToggleNotesFactory(true, '/test_url'); this.toggleNotes = NotesVisibilityFactory.ToggleVisibilityView(true, '/test_url');
this.button = $('.action-toggle-notes'); this.button = $('.action-toggle-notes');
this.label = this.button.find('.utility-control-label'); this.label = this.button.find('.utility-control-label');
this.toggleMessage = $('.action-toggle-message'); this.toggleMessage = $('.action-toggle-message');
...@@ -37,7 +36,7 @@ define([ ...@@ -37,7 +36,7 @@ define([
}); });
afterEach(function () { afterEach(function () {
VisibilityDecorator._setVisibility(null); NotesVisibilityFactory.VisibilityDecorator._setVisibility(null);
_.invoke(Annotator._instances, 'destroy'); _.invoke(Annotator._instances, 'destroy');
$('.annotator-notice').remove(); $('.annotator-notice').remove();
}); });
......
...@@ -580,7 +580,7 @@ ...@@ -580,7 +580,7 @@
'lms/include/js/spec/edxnotes/views/tabs/course_structure_spec.js', 'lms/include/js/spec/edxnotes/views/tabs/course_structure_spec.js',
'lms/include/js/spec/edxnotes/views/tabs/tags_spec.js', 'lms/include/js/spec/edxnotes/views/tabs/tags_spec.js',
'lms/include/js/spec/edxnotes/views/visibility_decorator_spec.js', 'lms/include/js/spec/edxnotes/views/visibility_decorator_spec.js',
'lms/include/js/spec/edxnotes/views/toggle_notes_factory_spec.js', 'lms/include/js/spec/edxnotes/views/notes_visibility_factory_spec.js',
'lms/include/js/spec/edxnotes/models/tab_spec.js', 'lms/include/js/spec/edxnotes/models/tab_spec.js',
'lms/include/js/spec/edxnotes/models/note_spec.js', 'lms/include/js/spec/edxnotes/models/note_spec.js',
'lms/include/js/spec/edxnotes/plugins/accessibility_spec.js', 'lms/include/js/spec/edxnotes/plugins/accessibility_spec.js',
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
*/ */
modules: getModulesList([ modules: getModulesList([
'js/discovery/discovery_factory', 'js/discovery/discovery_factory',
'js/edxnotes/views/notes_visibility_factory',
'js/edxnotes/views/page_factory',
'js/groups/views/cohorts_dashboard_factory', 'js/groups/views/cohorts_dashboard_factory',
'js/search/course/course_search_factory', 'js/search/course/course_search_factory',
'js/search/dashboard/dashboard_search_factory', 'js/search/dashboard/dashboard_search_factory',
......
...@@ -102,17 +102,14 @@ import json ...@@ -102,17 +102,14 @@ import json
</script> </script>
% endfor % endfor
</%block> </%block>
<%block name="js_extra">
% if notes: % if notes:
<script type="text/javascript"> <%block name="js_extra">
(function (require) { <%static:require_module module_name="js/edxnotes/views/page_factory" class_name="NotesPageFactory">
require(['js/edxnotes/views/page_factory'], function (NotesPageFactory) { NotesPageFactory({
var pageView = new NotesPageFactory({ notesList: ${notes if notes is not None else []},
notesList: ${notes}, debugMode: ${debug}
debugMode: ${debug} });
}); </%static:require_module>
}); </%block>
}).call(this, require || RequireJS.require);
</script>
% endif % endif
</%block>
...@@ -3,6 +3,7 @@ import json ...@@ -3,6 +3,7 @@ import json
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
%> %>
<%namespace name='static' file='/static_content.html'/>
<%page args="course"/> <%page args="course"/>
<% <%
...@@ -20,10 +21,7 @@ from django.core.urlresolvers import reverse ...@@ -20,10 +21,7 @@ from django.core.urlresolvers import reverse
% endif % endif
</button> </button>
</div> </div>
<script type="text/javascript">
(function (require) { <%static:require_module module_name="js/edxnotes/views/notes_visibility_factory" class_name="NotesVisibilityFactory">
require(['js/edxnotes/views/toggle_notes_factory'], function(ToggleNotesFactory) { NotesVisibilityFactory.ToggleVisibilityView(${json.dumps(edxnotes_visibility)}, '${edxnotes_visibility_url}');
ToggleNotesFactory(${json.dumps(edxnotes_visibility)}, '${edxnotes_visibility_url}'); </%static:require_module>
});
}).call(this, require || RequireJS.require);
</script>
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