Replace `Discourse.script` global with a module
This commit is contained in:
parent
fc962eb378
commit
fb726cfa0c
|
@ -5,10 +5,6 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
|
||||||
rootElement: '#main',
|
rootElement: '#main',
|
||||||
_docTitle: document.title,
|
_docTitle: document.title,
|
||||||
|
|
||||||
script: function(url) {
|
|
||||||
return $LAB.script(this.getURL(url));
|
|
||||||
},
|
|
||||||
|
|
||||||
getURL: function(url) {
|
getURL: function(url) {
|
||||||
if (!url) { return url; }
|
if (!url) { return url; }
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
/**
|
import loadScript from 'discourse/lib/load-script';
|
||||||
Use the message bus for live reloading of components for faster development.
|
|
||||||
**/
|
// Use the message bus for live reloading of components for faster development.
|
||||||
export default {
|
export default {
|
||||||
name: "live-development",
|
name: "live-development",
|
||||||
initialize: function() {
|
initialize() {
|
||||||
|
|
||||||
// subscribe to any site customizations that are loaded
|
// subscribe to any site customizations that are loaded
|
||||||
$('link.custom-css').each(function() {
|
$('link.custom-css').each(function() {
|
||||||
var split = this.href.split("/"),
|
const split = this.href.split("/"),
|
||||||
id = split[split.length - 1].split(".css")[0],
|
id = split[split.length - 1].split(".css")[0],
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ export default {
|
||||||
if (!$(self).data('orig')) {
|
if (!$(self).data('orig')) {
|
||||||
$(self).data('orig', self.href);
|
$(self).data('orig', self.href);
|
||||||
}
|
}
|
||||||
var orig = $(self).data('orig');
|
const orig = $(self).data('orig');
|
||||||
|
|
||||||
self.href = orig.replace(/v=.*/, "v=" + data);
|
self.href = orig.replace(/v=.*/, "v=" + data);
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ export default {
|
||||||
|
|
||||||
// Custom header changes
|
// Custom header changes
|
||||||
$('header.custom').each(function() {
|
$('header.custom').each(function() {
|
||||||
var header = $(this);
|
const header = $(this);
|
||||||
return Discourse.MessageBus.subscribe("/header-change/" + $(this).data('key'), function(data) {
|
return Discourse.MessageBus.subscribe("/header-change/" + $(this).data('key'), function(data) {
|
||||||
return header.html(data);
|
return header.html(data);
|
||||||
});
|
});
|
||||||
|
@ -40,10 +40,9 @@ export default {
|
||||||
} else if (me.name.substr(-10) === "hbs") {
|
} else if (me.name.substr(-10) === "hbs") {
|
||||||
|
|
||||||
// Reload handlebars
|
// Reload handlebars
|
||||||
var js = me.name.replace(".hbs", "").replace("app/assets/javascripts", "/assets");
|
const js = me.name.replace(".hbs", "").replace("app/assets/javascripts", "/assets");
|
||||||
Discourse.script(js + "?hash=" + me.hash).wait(function() {
|
loadScript(js + "?hash=" + me.hash).then(function() {
|
||||||
var templateName;
|
const templateName = js.replace(".js", "").replace("/assets/", "");
|
||||||
templateName = js.replace(".js", "").replace("/assets/", "");
|
|
||||||
return _.each(Ember.View.views, function(view) {
|
return _.each(Ember.View.views, function(view) {
|
||||||
if (view.get('templateName') === templateName) {
|
if (view.get('templateName') === templateName) {
|
||||||
view.set('templateName', 'empty');
|
view.set('templateName', 'empty');
|
||||||
|
@ -63,7 +62,7 @@ export default {
|
||||||
if (!$(this).data('orig')) {
|
if (!$(this).data('orig')) {
|
||||||
$(this).data('orig', this.href);
|
$(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;
|
this.href = orig + (orig.indexOf('?') >= 0 ? "&hash=" : "?hash=") + me.hash;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*global hljs:true */
|
/*global hljs:true */
|
||||||
|
|
||||||
|
import loadScript from 'discourse/lib/load-script';
|
||||||
|
|
||||||
export default function highlightSyntax($elem) {
|
export default function highlightSyntax($elem) {
|
||||||
const selector = Discourse.SiteSettings.autohighlight_all_code ? 'pre code' : 'pre code[class]';
|
const selector = Discourse.SiteSettings.autohighlight_all_code ? 'pre code' : 'pre code[class]';
|
||||||
$(selector, $elem).each(function(i, e) {
|
$(selector, $elem).each(function(i, e) {
|
||||||
return Discourse.script("/javascripts/highlight.pack.js").wait(function() {
|
loadScript("/javascripts/highlight.pack.js").then(() => hljs.highlightBlock(e));
|
||||||
return hljs.highlightBlock(e);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import loadScript from 'discourse/lib/load-script';
|
||||||
|
|
||||||
export default function($elem) {
|
export default function($elem) {
|
||||||
$("a.lightbox", $elem).each(function(i, e) {
|
$("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);
|
var $e = $(e);
|
||||||
// do not lightbox spoiled images
|
// do not lightbox spoiled images
|
||||||
if ($e.parents(".spoiler").length > 0 || $e.parents(".spoiled").length > 0) { return; }
|
if ($e.parents(".spoiler").length > 0 || $e.parents(".spoiled").length > 0) { return; }
|
||||||
|
|
|
@ -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 New Issue