trigger userContent change without killing ie8
Change-Id: I876006c0cabdb45ac2695b0061913f4f38d5a5a9 Reviewed-on: https://gerrit.instructure.com/9699 Reviewed-by: Zach Wily <zach@instructure.com> Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
parent
892033c2e5
commit
6b5f44f981
|
@ -10,12 +10,13 @@ define [
|
|||
'compiled/discussions/EntryEditor'
|
||||
'compiled/discussions/MarkAsReadWatcher'
|
||||
'str/htmlEscape'
|
||||
'vendor/jquery.ba-tinypubsub'
|
||||
'compiled/jquery.kylemenu'
|
||||
|
||||
# entry_with_replies partials
|
||||
'jst/_avatar'
|
||||
'jst/discussions/_reply_form'
|
||||
], (require, I18n, Backbone, EntryCollection, entryContentPartial, deletedEntriesTemplate, entryWithRepliesTemplate, Reply, EntryEditor, MarkAsReadWatcher, htmlEscape) ->
|
||||
], (require, I18n, Backbone, EntryCollection, entryContentPartial, deletedEntriesTemplate, entryWithRepliesTemplate, Reply, EntryEditor, MarkAsReadWatcher, htmlEscape, {publish}) ->
|
||||
|
||||
# save memory
|
||||
noop = ->
|
||||
|
@ -84,11 +85,11 @@ define [
|
|||
@$el.html entryWithRepliesTemplate @model.toJSON()
|
||||
@$el.attr 'data-id', @model.get 'id'
|
||||
@$el.attr 'id', @model.cid
|
||||
super
|
||||
|
||||
# enhance the media_comments in the message
|
||||
$(document).trigger('user_content_change')
|
||||
publish('userContent/change')
|
||||
|
||||
super
|
||||
|
||||
openMenu: (event, $el) ->
|
||||
@createMenu($el) unless @$menu
|
||||
|
|
|
@ -486,7 +486,16 @@ define([
|
|||
alert(I18n.t('alerts.file_previews_disabled', 'File previews have been disabled for this Canvas site'));
|
||||
});
|
||||
}
|
||||
$(document).bind('user_content_change', $.throttle(50, enhanceUserContent));
|
||||
|
||||
// publishing the 'userContent/change' will run enhanceUserContent at most once every 50ms
|
||||
var enhanceUserContentTimeout;
|
||||
$.subscribe('userContent/change', function(){
|
||||
clearTimeout(enhanceUserContentTimeout);
|
||||
enhanceUserContentTimeout = setTimeout(enhanceUserContent, 50);
|
||||
});
|
||||
|
||||
|
||||
$(document).bind('user_content_change', enhanceUserContent);
|
||||
setInterval(enhanceUserContent, 15000);
|
||||
setTimeout(enhanceUserContent, 1000);
|
||||
|
||||
|
|
|
@ -11,17 +11,17 @@ define(['jquery'], function($){
|
|||
|
||||
// Create a "dummy" jQuery object on which to bind, unbind and trigger event
|
||||
// handlers. Note that $({}) works in jQuery 1.4.3+.
|
||||
var o = $({});
|
||||
var o = $({}), subscribe, unsubscribe, publish;
|
||||
|
||||
// Subscribe to a topic. Works just like bind, except the passed handler
|
||||
// is wrapped in a function so that the event object can be stripped out.
|
||||
// Even though the event object might be useful, it is unnecessary and
|
||||
// will only complicate things in the future should the user decide to move
|
||||
// to a non-$.event-based pub/sub implementation.
|
||||
$.subscribe = function( topic, fn ) {
|
||||
$.subscribe = subscribe = function( topic, fn ) {
|
||||
if ($.isPlainObject(topic)) {
|
||||
return $.each(topic, function(topic, fn) {
|
||||
$.subscribe(topic, fn);
|
||||
subscribe(topic, fn);
|
||||
});
|
||||
}
|
||||
// Call fn, stripping out the 1st argument (the event object).
|
||||
|
@ -38,13 +38,19 @@ define(['jquery'], function($){
|
|||
};
|
||||
|
||||
// Unsubscribe from a topic. Works exactly like unbind.
|
||||
$.unsubscribe = function() {
|
||||
$.unsubscribe = unsubscribe = function() {
|
||||
o.unbind.apply( o, arguments );
|
||||
};
|
||||
|
||||
// Publish a topic. Works exactly like trigger.
|
||||
$.publish = function() {
|
||||
$.publish = publish = function() {
|
||||
o.trigger.apply( o, arguments );
|
||||
};
|
||||
|
||||
return {
|
||||
subscribe: subscribe,
|
||||
unsubscribe: unsubscribe,
|
||||
publish: publish
|
||||
};
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue