From 86af49e66318cacb5804d6651b2c4a7b7aabaafb Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 5 Mar 2013 15:39:21 -0500 Subject: [PATCH] More Markdown refactoring - fixed bug with Pagedown not showing on user profile - replaced jQuery occurrences with $. --- .../admin_email_logs_controller.js | 12 +- .../javascripts/admin/models/admin_user.js | 26 ++-- .../javascripts/admin/models/email_log.js | 6 +- .../javascripts/admin/models/flagged_post.js | 12 +- app/assets/javascripts/admin/models/report.js | 2 +- .../admin/models/site_customization.js | 14 +- .../javascripts/admin/models/site_setting.js | 4 +- .../javascripts/admin/models/version_check.js | 2 +- app/assets/javascripts/discourse.js | 4 +- .../discourse/components/autocomplete.js | 2 +- .../discourse/components/click_track.js | 4 +- .../discourse/components/development.js | 2 +- .../discourse/components/markdown.js | 128 +++++++++--------- .../discourse/components/mention.js | 2 +- .../discourse/components/message_bus.js | 4 +- .../discourse/components/screen_track.js | 2 +- .../discourse/components/user_search.js | 4 +- .../controllers/static_controller.js | 2 +- .../discourse/models/action_summary.js | 10 +- .../javascripts/discourse/models/category.js | 2 +- .../discourse/models/category_list.js | 2 +- .../javascripts/discourse/models/composer.js | 4 +- .../javascripts/discourse/models/draft.js | 6 +- .../javascripts/discourse/models/invite.js | 2 +- .../discourse/models/invite_list.js | 2 +- .../javascripts/discourse/models/model.js | 6 +- .../javascripts/discourse/models/post.js | 26 ++-- .../javascripts/discourse/models/topic.js | 22 +-- .../discourse/models/topic_list.js | 4 +- .../javascripts/discourse/models/user.js | 18 +-- .../discourse/routes/discourse_location.js | 2 +- .../discourse/views/composer_view.js | 14 +- .../discourse/views/header_view.js | 2 +- .../views/modal/create_account_view.js | 2 +- .../views/modal/forgot_password_view.js | 2 +- .../discourse/views/modal/login_view.js | 2 +- .../views/modal/not_activated_view.js | 2 +- .../discourse/views/pagedown_editor.js | 18 +-- .../javascripts/discourse/views/post_view.js | 2 +- .../discourse/views/search/search_view.js | 2 +- .../javascripts/external/Markdown.Editor.js | 1 + lib/headless-ember.js | 2 +- spec/javascripts/components/onebox_spec.js | 4 +- 43 files changed, 190 insertions(+), 201 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js b/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js index ef088cbaa..8fffd53d2 100644 --- a/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_email_logs_controller.js @@ -1,18 +1,18 @@ /** This controller supports the interface for reviewing email logs. - @class AdminEmailLogsController + @class AdminEmailLogsController @extends Ember.ArrayController @namespace Discourse @module Discourse -**/ +**/ Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Presence, { - + /** Is the "send test email" button disabled? @property sendTestEmailDisabled - **/ + **/ sendTestEmailDisabled: (function() { return this.blank('testEmailAddress'); }).property('testEmailAddress'), @@ -25,7 +25,7 @@ Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Pres sendTestEmail: function() { var _this = this; _this.set('sentTestEmail', false); - jQuery.ajax({ + $.ajax({ url: '/admin/email_logs/test', type: 'POST', data: { email_address: this.get('testEmailAddress') }, @@ -35,5 +35,5 @@ Discourse.AdminEmailLogsController = Ember.ArrayController.extend(Discourse.Pres }); return false; } - + }); diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index c26a93a90..ff2edf73d 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -10,7 +10,7 @@ Discourse.AdminUser = Discourse.Model.extend({ deleteAllPosts: function() { this.set('can_delete_all_posts', false); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}); + $.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}); }, // Revoke the user's admin access @@ -18,14 +18,14 @@ Discourse.AdminUser = Discourse.Model.extend({ this.set('admin', false); this.set('can_grant_admin', true); this.set('can_revoke_admin', false); - return jQuery.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'}); + return $.ajax("/admin/users/" + (this.get('id')) + "/revoke_admin", {type: 'PUT'}); }, grantAdmin: function() { this.set('admin', true); this.set('can_grant_admin', false); this.set('can_revoke_admin', true); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'}); + $.ajax("/admin/users/" + (this.get('id')) + "/grant_admin", {type: 'PUT'}); }, // Revoke the user's moderation access @@ -33,18 +33,18 @@ Discourse.AdminUser = Discourse.Model.extend({ this.set('moderator', false); this.set('can_grant_moderation', true); this.set('can_revoke_moderation', false); - return jQuery.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'}); + return $.ajax("/admin/users/" + (this.get('id')) + "/revoke_moderation", {type: 'PUT'}); }, grantModeration: function() { this.set('moderator', true); this.set('can_grant_moderation', false); this.set('can_revoke_moderation', true); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'}); + $.ajax("/admin/users/" + (this.get('id')) + "/grant_moderation", {type: 'PUT'}); }, refreshBrowsers: function() { - jQuery.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'}); + $.ajax("/admin/users/" + (this.get('id')) + "/refresh_browsers", {type: 'POST'}); bootbox.alert("Message sent to all clients!"); }, @@ -52,7 +52,7 @@ Discourse.AdminUser = Discourse.Model.extend({ this.set('can_approve', false); this.set('approved', true); this.set('approved_by', Discourse.get('currentUser')); - jQuery.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'}); + $.ajax("/admin/users/" + (this.get('id')) + "/approve", {type: 'PUT'}); }, username_lower: (function() { @@ -79,7 +79,7 @@ Discourse.AdminUser = Discourse.Model.extend({ _this = this; if (duration = parseInt(window.prompt(Em.String.i18n('admin.user.ban_duration')), 10)) { if (duration > 0) { - return jQuery.ajax("/admin/users/" + this.id + "/ban", { + return $.ajax("/admin/users/" + this.id + "/ban", { type: 'PUT', data: {duration: duration}, success: function() { @@ -99,7 +99,7 @@ Discourse.AdminUser = Discourse.Model.extend({ unban: function() { var _this = this; - return jQuery.ajax("/admin/users/" + this.id + "/unban", { + return $.ajax("/admin/users/" + this.id + "/unban", { type: 'PUT', success: function() { window.location.reload(); @@ -116,7 +116,7 @@ Discourse.AdminUser = Discourse.Model.extend({ impersonate: function() { var _this = this; - return jQuery.ajax("/admin/impersonate", { + return $.ajax("/admin/impersonate", { type: 'POST', data: { username_or_email: this.get('username') @@ -145,7 +145,7 @@ Discourse.AdminUser.reopenClass({ user.set('can_approve', false); return user.set('selected', false); }); - return jQuery.ajax("/admin/users/approve-bulk", { + return $.ajax("/admin/users/approve-bulk", { type: 'PUT', data: { users: users.map(function(u) { @@ -158,7 +158,7 @@ Discourse.AdminUser.reopenClass({ find: function(username) { var promise; promise = new RSVP.Promise(); - jQuery.ajax({ + $.ajax({ url: "/admin/users/" + username, success: function(result) { return promise.resolve(Discourse.AdminUser.create(result)); @@ -170,7 +170,7 @@ Discourse.AdminUser.reopenClass({ findAll: function(query, filter) { var result; result = Em.A(); - jQuery.ajax({ + $.ajax({ url: "/admin/users/list/" + query + ".json", data: { filter: filter diff --git a/app/assets/javascripts/admin/models/email_log.js b/app/assets/javascripts/admin/models/email_log.js index f7852501e..ab5e4ff3b 100644 --- a/app/assets/javascripts/admin/models/email_log.js +++ b/app/assets/javascripts/admin/models/email_log.js @@ -1,11 +1,11 @@ /** Our data model for representing an email log. - @class EmailLog + @class EmailLog @extends Discourse.Model @namespace Discourse @module Discourse -**/ +**/ Discourse.EmailLog = Discourse.Model.extend({}); Discourse.EmailLog.reopenClass({ @@ -19,7 +19,7 @@ Discourse.EmailLog.reopenClass({ findAll: function(filter) { var result; result = Em.A(); - jQuery.ajax({ + $.ajax({ url: "/admin/email_logs.json", data: { filter: filter }, success: function(logs) { diff --git a/app/assets/javascripts/admin/models/flagged_post.js b/app/assets/javascripts/admin/models/flagged_post.js index cf937dbc8..bab8ea0c3 100644 --- a/app/assets/javascripts/admin/models/flagged_post.js +++ b/app/assets/javascripts/admin/models/flagged_post.js @@ -1,11 +1,11 @@ /** Our data model for interacting with flagged posts. - @class FlaggedPost + @class FlaggedPost @extends Discourse.Post @namespace Discourse @module Discourse -**/ +**/ Discourse.FlaggedPost = Discourse.Post.extend({ flaggers: (function() { @@ -49,7 +49,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({ var promise; promise = new RSVP.Promise(); if (this.get('post_number') === "1") { - return jQuery.ajax("/t/" + this.topic_id, { + return $.ajax("/t/" + this.topic_id, { type: 'DELETE', cache: false, success: function() { @@ -60,7 +60,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({ } }); } else { - return jQuery.ajax("/posts/" + this.id, { + return $.ajax("/posts/" + this.id, { type: 'DELETE', cache: false, success: function() { @@ -76,7 +76,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({ clearFlags: function() { var promise; promise = new RSVP.Promise(); - jQuery.ajax("/admin/flags/clear/" + this.id, { + $.ajax("/admin/flags/clear/" + this.id, { type: 'POST', cache: false, success: function() { @@ -99,7 +99,7 @@ Discourse.FlaggedPost.reopenClass({ findAll: function(filter) { var result; result = Em.A(); - jQuery.ajax({ + $.ajax({ url: "/admin/flags/" + filter + ".json", success: function(data) { var userLookup; diff --git a/app/assets/javascripts/admin/models/report.js b/app/assets/javascripts/admin/models/report.js index 5acca7dce..317b119ae 100644 --- a/app/assets/javascripts/admin/models/report.js +++ b/app/assets/javascripts/admin/models/report.js @@ -3,7 +3,7 @@ Discourse.Report = Discourse.Model.extend({}); Discourse.Report.reopenClass({ find: function(type) { var model = Discourse.Report.create(); - jQuery.ajax("/admin/reports/" + type, { + $.ajax("/admin/reports/" + type, { type: 'GET', success: function(json) { model.mergeAttributes(json.report); diff --git a/app/assets/javascripts/admin/models/site_customization.js b/app/assets/javascripts/admin/models/site_customization.js index 19f2a3bac..dbc3f8618 100644 --- a/app/assets/javascripts/admin/models/site_customization.js +++ b/app/assets/javascripts/admin/models/site_customization.js @@ -1,11 +1,11 @@ /** Our data model for interacting with site customizations. - @class SiteCustomization + @class SiteCustomization @extends Discourse.Model @namespace Discourse @module Discourse -**/ +**/ Discourse.SiteCustomization = Discourse.Model.extend({ trackedProperties: ['enabled', 'name', 'stylesheet', 'header', 'override_default_style'], @@ -13,7 +13,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({ this._super(); return this.startTrackingChanges(); }, - + description: (function() { return "" + this.name + (this.enabled ? ' (*)' : ''); }).property('selected', 'name'), @@ -55,7 +55,7 @@ Discourse.SiteCustomization = Discourse.Model.extend({ header: this.header, override_default_style: this.override_default_style }; - return jQuery.ajax({ + return $.ajax({ url: "/admin/site_customizations" + (this.id ? '/' + this.id : ''), data: { site_customization: data @@ -66,8 +66,8 @@ Discourse.SiteCustomization = Discourse.Model.extend({ "delete": function() { if (!this.id) return; - - return jQuery.ajax({ + + return $.ajax({ url: "/admin/site_customizations/" + this.id, type: 'DELETE' }); @@ -93,7 +93,7 @@ Discourse.SiteCustomization.reopenClass({ content: [], loading: true }); - jQuery.ajax({ + $.ajax({ url: "/admin/site_customizations", dataType: "json", success: function(data) { diff --git a/app/assets/javascripts/admin/models/site_setting.js b/app/assets/javascripts/admin/models/site_setting.js index 6a4f542a9..c8f8b4ae6 100644 --- a/app/assets/javascripts/admin/models/site_setting.js +++ b/app/assets/javascripts/admin/models/site_setting.js @@ -72,7 +72,7 @@ Discourse.SiteSetting = Discourse.Model.extend({ save: function() { // Update the setting var setting = this; - return jQuery.ajax("/admin/site_settings/" + (this.get('setting')), { + return $.ajax("/admin/site_settings/" + (this.get('setting')), { data: { value: this.get('value') }, type: 'PUT', success: function() { @@ -91,7 +91,7 @@ Discourse.SiteSetting.reopenClass({ **/ findAll: function() { var result = Em.A(); - jQuery.get("/admin/site_settings", function(settings) { + $.get("/admin/site_settings", function(settings) { return settings.each(function(s) { s.originalValue = s.value; return result.pushObject(Discourse.SiteSetting.create(s)); diff --git a/app/assets/javascripts/admin/models/version_check.js b/app/assets/javascripts/admin/models/version_check.js index 6a42b1eff..8ef1d79c8 100644 --- a/app/assets/javascripts/admin/models/version_check.js +++ b/app/assets/javascripts/admin/models/version_check.js @@ -23,7 +23,7 @@ Discourse.VersionCheck = Discourse.Model.extend({ Discourse.VersionCheck.reopenClass({ find: function() { var promise = new RSVP.Promise(); - jQuery.ajax({ + $.ajax({ url: '/admin/version_check', dataType: 'json', success: function(json) { diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 4607c6a74..742ff1b77 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -142,7 +142,7 @@ Discourse = Ember.Application.createWithMixins({ // Add a CSRF token to all AJAX requests var csrfToken = $('meta[name=csrf-token]').attr('content'); - jQuery.ajaxPrefilter(function(options, originalOptions, xhr) { + $.ajaxPrefilter(function(options, originalOptions, xhr) { if (!options.crossDomain) { xhr.setRequestHeader('X-CSRF-Token', csrfToken); } @@ -156,7 +156,7 @@ Discourse = Ember.Application.createWithMixins({ **/ logout: function() { Discourse.KeyValueStore.abandonLocal(); - return jQuery.ajax("/session/" + this.get('currentUser.username'), { + return $.ajax("/session/" + this.get('currentUser.username'), { type: 'DELETE', success: function(result) { // To keep lots of our variables unbound, we can handle a redirect on logging out. diff --git a/app/assets/javascripts/discourse/components/autocomplete.js b/app/assets/javascripts/discourse/components/autocomplete.js index 70c8c29a0..9114c3695 100644 --- a/app/assets/javascripts/discourse/components/autocomplete.js +++ b/app/assets/javascripts/discourse/components/autocomplete.js @@ -47,7 +47,7 @@ $.fn.autocomplete = function(options) { } return d.find('a').click(function() { closeAutocomplete(); - inputSelectedItems.splice(jQuery.inArray(item), 1); + inputSelectedItems.splice($.inArray(item), 1); $(this).parent().parent().remove(); if (options.onChangeItems) { return options.onChangeItems(inputSelectedItems); diff --git a/app/assets/javascripts/discourse/components/click_track.js b/app/assets/javascripts/discourse/components/click_track.js index df9b68943..0d8d5c397 100644 --- a/app/assets/javascripts/discourse/components/click_track.js +++ b/app/assets/javascripts/discourse/components/click_track.js @@ -70,7 +70,7 @@ Discourse.ClickTrack = { // if they want to open in a new tab, do an AJAX request if (e.metaKey || e.ctrlKey || e.which === 2) { - jQuery.get("/clicks/track", { + $.get("/clicks/track", { url: href, post_id: postId, topic_id: topicId, @@ -82,7 +82,7 @@ Discourse.ClickTrack = { // If we're on the same site, use the router and track via AJAX if (href.indexOf(window.location.origin) === 0) { - jQuery.get("/clicks/track", { + $.get("/clicks/track", { url: href, post_id: postId, topic_id: topicId, diff --git a/app/assets/javascripts/discourse/components/development.js b/app/assets/javascripts/discourse/components/development.js index 7e1d314fa..1db181e4f 100644 --- a/app/assets/javascripts/discourse/components/development.js +++ b/app/assets/javascripts/discourse/components/development.js @@ -129,7 +129,7 @@ Discourse.Development = { return $LAB.script(js + "?hash=" + me.hash).wait(function() { var templateName; templateName = js.replace(".js", "").replace("/assets/", ""); - return jQuery.each(Ember.View.views, function() { + return $.each(Ember.View.views, function() { var _this = this; if (this.get('templateName') === templateName) { this.set('templateName', 'empty'); diff --git a/app/assets/javascripts/discourse/components/markdown.js b/app/assets/javascripts/discourse/components/markdown.js index 4ede5514c..a3bab2f9e 100644 --- a/app/assets/javascripts/discourse/components/markdown.js +++ b/app/assets/javascripts/discourse/components/markdown.js @@ -1,4 +1,4 @@ -/*global sanitizeHtml:true Markdown:true */ +/*global Markdown:true */ /** Contains methods to help us with markdown formatting. @@ -15,6 +15,7 @@ Discourse.Markdown = { @method cook @param {String} raw the raw string we want to apply markdown to @param {Object} opts the options for the rendering + @return {String} the cooked markdown string **/ cook: function(raw, opts) { if (!opts) opts = {}; @@ -23,60 +24,67 @@ Discourse.Markdown = { if (!raw) return ""; if (raw.length === 0) return ""; - this.converter = this.markdownConverter(opts); - return this.converter.makeHtml(raw); + return this.markdownConverter(opts).makeHtml(raw); }, /** - Creates a new markdown editor + Creates a new pagedown markdown editor, supplying i18n translations. - @method createNewMarkdownEditor - @param {Markdown.Converter} markdownConverter the converter object - @param {String} idPostfix - @param {Object} options the options for the markdown editor + @method createEditor + @param {Object} converterOptions custom options for our markdown converter + @return {Markdown.Editor} the editor instance **/ - createNewMarkdownEditor: function(markdownConverter, idPostfix, options) { - options = options || {}; - options.strings = { - bold: I18n.t("js.composer.bold_title") + " Ctrl+B", - boldexample: I18n.t("js.composer.bold_text"), + createEditor: function(converterOptions) { - italic: I18n.t("js.composer.italic_title") + " Ctrl+I", - italicexample: I18n.t("js.composer.italic_text"), + if (!converterOptions) converterOptions = {}; - link: I18n.t("js.composer.link_title") + " Ctrl+L", - linkdescription: "enter link description here", - linkdialog: "

" + I18n.t("js.composer.link_dialog_title") + "

http://example.com/ \"" + - I18n.t("js.composer.link_optional_text") + "\"

", + // By default we always sanitize content in the editor + converterOptions.sanitize = true; - quote: I18n.t("js.composer.quote_title") + "
Ctrl+Q", - quoteexample: I18n.t("js.composer.quote_text"), + var markdownConverter = Discourse.Markdown.markdownConverter(converterOptions); - code: I18n.t("js.composer.code_title") + "
 Ctrl+K",
-      codeexample: I18n.t("js.composer.code_text"),
+    var editorOptions = {
+      strings: {
+        bold: I18n.t("js.composer.bold_title") + "  Ctrl+B",
+        boldexample: I18n.t("js.composer.bold_text"),
 
-      image: I18n.t("js.composer.image_title") + "  Ctrl+G",
-      imagedescription: I18n.t("js.composer.image_description"),
-      imagedialog: "

" + I18n.t("js.composer.image_dialog_title") + "

http://example.com/images/diagram.jpg \"" + - I18n.t("js.composer.image_optional_text") + "\"

" + I18n.t("js.composer.image_hosting_hint") + "

", + italic: I18n.t("js.composer.italic_title") + " Ctrl+I", + italicexample: I18n.t("js.composer.italic_text"), - olist: I18n.t("js.composer.olist_title") + "
    Ctrl+O", - ulist: I18n.t("js.composer.ulist_title") + "