mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Replace Discourse.script
global with a module
This commit is contained in:
parent
fc962eb378
commit
fb726cfa0c
5 changed files with 22 additions and 20 deletions
|
@ -5,10 +5,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
|||
rootElement: '#main',
|
||||
_docTitle: document.title,
|
||||
|
||||
script: function(url) {
|
||||
return $LAB.script(this.getURL(url));
|
||||
},
|
||||
|
||||
getURL: function(url) {
|
||||
if (!url) { return url; }
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/**
|
||||
Use the message bus for live reloading of components for faster development.
|
||||
**/
|
||||
import loadScript from 'discourse/lib/load-script';
|
||||
|
||||
// Use the message bus for live reloading of components for faster development.
|
||||
export default {
|
||||
name: "live-development",
|
||||
initialize: function() {
|
||||
initialize() {
|
||||
|
||||
// subscribe to any site customizations that are loaded
|
||||
$('link.custom-css').each(function() {
|
||||
var split = this.href.split("/"),
|
||||
const split = this.href.split("/"),
|
||||
id = split[split.length - 1].split(".css")[0],
|
||||
self = this;
|
||||
|
||||
|
@ -15,7 +15,7 @@ export default {
|
|||
if (!$(self).data('orig')) {
|
||||
$(self).data('orig', self.href);
|
||||
}
|
||||
var orig = $(self).data('orig');
|
||||
const orig = $(self).data('orig');
|
||||
|
||||
self.href = orig.replace(/v=.*/, "v=" + data);
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ export default {
|
|||
|
||||
// Custom header changes
|
||||
$('header.custom').each(function() {
|
||||
var header = $(this);
|
||||
const header = $(this);
|
||||
return Discourse.MessageBus.subscribe("/header-change/" + $(this).data('key'), function(data) {
|
||||
return header.html(data);
|
||||
});
|
||||
|
@ -40,10 +40,9 @@ export default {
|
|||
} else if (me.name.substr(-10) === "hbs") {
|
||||
|
||||
// Reload handlebars
|
||||
var js = me.name.replace(".hbs", "").replace("app/assets/javascripts", "/assets");
|
||||
Discourse.script(js + "?hash=" + me.hash).wait(function() {
|
||||
var templateName;
|
||||
templateName = js.replace(".js", "").replace("/assets/", "");
|
||||
const js = me.name.replace(".hbs", "").replace("app/assets/javascripts", "/assets");
|
||||
loadScript(js + "?hash=" + me.hash).then(function() {
|
||||
const templateName = js.replace(".js", "").replace("/assets/", "");
|
||||
return _.each(Ember.View.views, function(view) {
|
||||
if (view.get('templateName') === templateName) {
|
||||
view.set('templateName', 'empty');
|
||||
|
@ -63,7 +62,7 @@ export default {
|
|||
if (!$(this).data('orig')) {
|
||||
$(this).data('orig', this.href);
|
||||
}
|
||||
var orig = $(this).data('orig');
|
||||
const orig = $(this).data('orig');
|
||||
this.href = orig + (orig.indexOf('?') >= 0 ? "&hash=" : "?hash=") + me.hash;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*global hljs:true */
|
||||
|
||||
import loadScript from 'discourse/lib/load-script';
|
||||
|
||||
export default function highlightSyntax($elem) {
|
||||
const selector = Discourse.SiteSettings.autohighlight_all_code ? 'pre code' : 'pre code[class]';
|
||||
$(selector, $elem).each(function(i, e) {
|
||||
return Discourse.script("/javascripts/highlight.pack.js").wait(function() {
|
||||
return hljs.highlightBlock(e);
|
||||
});
|
||||
loadScript("/javascripts/highlight.pack.js").then(() => hljs.highlightBlock(e));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import loadScript from 'discourse/lib/load-script';
|
||||
|
||||
export default function($elem) {
|
||||
$("a.lightbox", $elem).each(function(i, e) {
|
||||
Discourse.script("/javascripts/jquery.magnific-popup-min.js").wait(function() {
|
||||
loadScript("/javascripts/jquery.magnific-popup-min.js").then(function() {
|
||||
var $e = $(e);
|
||||
// do not lightbox spoiled images
|
||||
if ($e.parents(".spoiler").length > 0 || $e.parents(".spoiled").length > 0) { return; }
|
||||
|
|
5
app/assets/javascripts/discourse/lib/load-script.js.es6
Normal file
5
app/assets/javascripts/discourse/lib/load-script.js.es6
Normal file
|
@ -0,0 +1,5 @@
|
|||
export default function loadScript(url) {
|
||||
return new Ember.RSVP.Promise(function(resolve) {
|
||||
$LAB.script(Discourse.getURL(url)).wait(() => resolve());
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue