Changes to support Spoiler Alert plugin

This commit is contained in:
Robin Ward 2013-09-19 17:59:17 -07:00
parent 147887bc63
commit e3a56864dd
4 changed files with 44 additions and 19 deletions

View File

@ -208,6 +208,17 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
} }
}, },
/**
Add an initializer hook for after the Discourse Application starts up.
@method addInitializer
@param {Function} init the initializer to add.
**/
addInitializer: function(init) {
Discourse.initializers = Discourse.initializers || [];
Discourse.initializers.push(init);
},
/** /**
Start up the Discourse application. Start up the Discourse application.
@ -223,6 +234,12 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
// Developer specific functions // Developer specific functions
Discourse.Development.observeLiveChanges(); Discourse.Development.observeLiveChanges();
Discourse.subscribeUserToNotifications(); Discourse.subscribeUserToNotifications();
if (Discourse.initializers) {
Discourse.initializers.forEach(function (init) {
init.call(this);
});
}
} }
}); });

View File

@ -8,7 +8,7 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.ComposerView = Discourse.View.extend({ Discourse.ComposerView = Discourse.View.extend(Ember.Evented, {
templateName: 'composer', templateName: 'composer',
elementId: 'reply-control', elementId: 'reply-control',
classNameBindings: ['model.creatingPrivateMessage:private-message', classNameBindings: ['model.creatingPrivateMessage:private-message',
@ -49,18 +49,17 @@ Discourse.ComposerView = Discourse.View.extend({
}.property('model.createdPost'), }.property('model.createdPost'),
observeReplyChanges: function() { observeReplyChanges: function() {
var composerView = this; var self = this;
if (this.get('model.hidePreview')) return; if (this.get('model.hidePreview')) return;
Ember.run.next(null, function() { Ember.run.next(function() {
var $wmdPreview, caretPosition; if (self.editor) {
if (composerView.editor) { self.editor.refreshPreview();
composerView.editor.refreshPreview();
// if the caret is on the last line ensure preview scrolled to bottom // if the caret is on the last line ensure preview scrolled to bottom
caretPosition = Discourse.Utilities.caretPosition(composerView.wmdInput[0]); var caretPosition = Discourse.Utilities.caretPosition(self.wmdInput[0]);
if (!composerView.wmdInput.val().substring(caretPosition).match(/\n/)) { if (!self.wmdInput.val().substring(caretPosition).match(/\n/)) {
$wmdPreview = $('#wmd-preview'); var $wmdPreview = $('#wmd-preview');
if ($wmdPreview.is(':visible')) { if ($wmdPreview.is(':visible')) {
return $wmdPreview.scrollTop($wmdPreview[0].scrollHeight); $wmdPreview.scrollTop($wmdPreview[0].scrollHeight);
} }
} }
} }
@ -129,8 +128,8 @@ Discourse.ComposerView = Discourse.View.extend({
Discourse.SyntaxHighlighting.apply($wmdPreview); Discourse.SyntaxHighlighting.apply($wmdPreview);
var post = this.get('model.post'); var post = this.get('model.post'),
var refresh = false; refresh = false;
// If we are editing a post, we'll refresh its contents once. This is a feature that // If we are editing a post, we'll refresh its contents once. This is a feature that
// allows a user to refresh its contents once. // allows a user to refresh its contents once.
@ -146,6 +145,8 @@ Discourse.ComposerView = Discourse.View.extend({
$('span.mention', $wmdPreview).each(function(i, e) { $('span.mention', $wmdPreview).each(function(i, e) {
Discourse.Mention.load(e, refresh); Discourse.Mention.load(e, refresh);
}); });
this.trigger('previewRefreshed', $wmdPreview);
}, 100), }, 100),
initEditor: function() { initEditor: function() {

View File

@ -6,7 +6,7 @@
@namespace Discourse @namespace Discourse
@module Discourse @module Discourse
**/ **/
Discourse.PostView = Discourse.GroupedView.extend({ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
classNames: ['topic-post', 'clearfix'], classNames: ['topic-post', 'clearfix'],
templateName: 'post', templateName: 'post',
classNameBindings: ['postTypeClass', classNameBindings: ['postTypeClass',
@ -193,8 +193,9 @@ Discourse.PostView = Discourse.GroupedView.extend({
}, },
didInsertElement: function() { didInsertElement: function() {
var $post = this.$(); var $post = this.$(),
var post = this.get('post'); post = this.get('post');
this.showLinkCounts(); this.showLinkCounts();
// Track this post // Track this post
@ -204,6 +205,8 @@ Discourse.PostView = Discourse.GroupedView.extend({
Discourse.SyntaxHighlighting.apply($post); Discourse.SyntaxHighlighting.apply($post);
Discourse.Lightbox.apply($post); Discourse.Lightbox.apply($post);
this.trigger('postViewInserted', $post);
// Find all the quotes // Find all the quotes
this.insertQuoteControls(); this.insertQuoteControls();

View File

@ -102,7 +102,7 @@ class Plugin::Instance
def automatic_assets def automatic_assets
css = "" css = ""
js = "(function(){" js = ""
css = @styles.join("\n") if @styles css = @styles.join("\n") if @styles
js = @javascripts.join("\n") if @javascripts js = @javascripts.join("\n") if @javascripts
@ -127,10 +127,14 @@ class Plugin::Instance
end end
end end
js << "})();" # Generate an IIFE for the JS
js = "(function(){#{js}})();" if js.present?
# TODO don't serve blank assets result = []
[[css,"css"],[js,"js"]].map do |asset, extension| result << [css, 'css'] if css.present?
result << [js, 'js'] if js.present?
result.map do |asset, extension|
hash = Digest::SHA1.hexdigest asset hash = Digest::SHA1.hexdigest asset
["#{auto_generated_path}/plugin_#{hash}.#{extension}", asset] ["#{auto_generated_path}/plugin_#{hash}.#{extension}", asset]
end end