diff --git a/app/assets/javascripts/deprecated.js b/app/assets/javascripts/deprecated.js new file mode 100644 index 00000000000..2303ec5d2c7 --- /dev/null +++ b/app/assets/javascripts/deprecated.js @@ -0,0 +1,25 @@ +(function() { + var Discourse = require('discourse').default; + + Discourse.Markdown = { + whiteListTag: Ember.K, + whiteListIframe: Ember.K + }; + + Discourse.Dialect = { + inlineRegexp: Ember.K, + addPreProcessor: Ember.K, + replaceBlock: Ember.K, + inlineReplace: Ember.K, + registerInline: Ember.K, + registerEmoji: Ember.K + }; + + Discourse.ajax = function() { + var ajax = require('discourse/lib/ajax').ajax; + Ember.warn("Discourse.ajax is deprecated. Import the module and use it instead"); + return ajax.apply(this, arguments); + }; + + window.Discourse = Discourse; +})(); diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js.es6 similarity index 56% rename from app/assets/javascripts/discourse.js rename to app/assets/javascripts/discourse.js.es6 index fb983d94388..23c233c7c4f 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js.es6 @@ -1,19 +1,14 @@ -/*global Favcount:true*/ -var DiscourseResolver = require('discourse/ember/resolver').default; +import DiscourseResolver from 'discourse/ember/resolver'; +import { default as computed, observes } from 'ember-addons/ember-computed-decorators'; -// Allow us to import Ember -define('ember', ['exports'], function(__exports__) { - __exports__.default = Ember; -}); +const _pluginCallbacks = []; -var _pluginCallbacks = []; - -window.Discourse = Ember.Application.extend({ +const Discourse = Ember.Application.extend({ rootElement: '#main', _docTitle: document.title, __TAGS_INCLUDED__: true, - getURL: function(url) { + getURL(url) { if (!url) return url; // if it's a non relative URL, return it. @@ -25,7 +20,7 @@ window.Discourse = Ember.Application.extend({ return Discourse.BaseUri + url; }, - getURLWithCDN: function(url) { + getURLWithCDN(url) { url = Discourse.getURL(url); // only relative urls if (Discourse.CDN && /^\/[^\/]/.test(url)) { @@ -38,78 +33,76 @@ window.Discourse = Ember.Application.extend({ Resolver: DiscourseResolver, - _titleChanged: function() { - var title = this.get('_docTitle') || Discourse.SiteSettings.title; + @observes('_docTitle', 'hasFocus', 'notifyCount') + _titleChanged() { + let title = this.get('_docTitle') || Discourse.SiteSettings.title; // if we change this we can trigger changes on document.title // only set if changed. - if($('title').text() !== title) { + if ($('title').text() !== title) { $('title').text(title); } - var notifyCount = this.get('notifyCount'); + const notifyCount = this.get('notifyCount'); if (notifyCount > 0 && !Discourse.User.currentProp('dynamic_favicon')) { - title = "(" + notifyCount + ") " + title; + title = `(${notifyCount}) ${title}`; } document.title = title; - }.observes('_docTitle', 'hasFocus', 'notifyCount'), + }, - faviconChanged: function() { - if(Discourse.User.currentProp('dynamic_favicon')) { - var url = Discourse.SiteSettings.favicon_url; + @observes('notifyCount') + faviconChanged() { + if (Discourse.User.currentProp('dynamic_favicon')) { + let url = Discourse.SiteSettings.favicon_url; if (/^http/.test(url)) { url = Discourse.getURL("/favicon/proxied?" + encodeURIComponent(url)); } - new Favcount(url).set( - this.get('notifyCount') - ); + new window.Favcount(url).set(this.get('notifyCount')); } - }.observes('notifyCount'), + }, // The classes of buttons to show on a post - postButtons: function() { + @computed + postButtons() { return Discourse.SiteSettings.post_menu.split("|").map(function(i) { return i.replace(/\+/, '').capitalize(); }); - }.property(), + }, - notifyTitle: function(count) { + notifyTitle(count) { this.set('notifyCount', count); }, - notifyBackgroundCountIncrement: function() { + notifyBackgroundCountIncrement() { if (!this.get('hasFocus')) { this.set('backgroundNotify', true); this.set('notifyCount', (this.get('notifyCount') || 0) + 1); } }, - resetBackgroundNotifyCount: function() { + @observes('hasFocus') + resetBackgroundNotifyCount() { if (this.get('hasFocus') && this.get('backgroundNotify')) { this.set('notifyCount', 0); } this.set('backgroundNotify', false); - }.observes('hasFocus'), + }, - authenticationComplete: function(options) { + authenticationComplete(options) { // TODO, how to dispatch this to the controller without the container? - var loginController = Discourse.__container__.lookup('controller:login'); + const loginController = Discourse.__container__.lookup('controller:login'); return loginController.authenticationComplete(options); }, - /** - Start up the Discourse application by running all the initializers we've defined. - - @method start - **/ - start: function() { + // Start up the Discourse application by running all the initializers we've defined. + start() { $('noscript').remove(); Object.keys(requirejs._eak_seen).forEach(function(key) { if (/\/pre\-initializers\//.test(key)) { - var module = require(key, null, null, true); + const module = require(key, null, null, true); if (!module) { throw new Error(key + ' must export an initializer.'); } Discourse.initializer(module.default); } @@ -117,11 +110,11 @@ window.Discourse = Ember.Application.extend({ Object.keys(requirejs._eak_seen).forEach(function(key) { if (/\/initializers\//.test(key)) { - var module = require(key, null, null, true); + const module = require(key, null, null, true); if (!module) { throw new Error(key + ' must export an initializer.'); } - var init = module.default; - var oldInitialize = init.initialize; + const init = module.default; + const oldInitialize = init.initialize; init.initialize = function(app) { oldInitialize.call(this, app.container, Discourse); }; @@ -131,8 +124,8 @@ window.Discourse = Ember.Application.extend({ }); // Plugins that are registered via `