From bcc7ad9a41f09bb894abe2a94a9e9b7b13213bdc Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Wed, 2 Oct 2013 11:39:34 +0200 Subject: [PATCH] Disable filestorage closes #937 - fixed bug where ![] is replaced with ![](http://) for image url - added fileStorage setting to uploader - added fileStorage helper (could become standard way of providing config data for frontend???) - added data element to editor and settings - if no config value is set fileStorage: true is default --- ghost/admin/assets/lib/uploader.js | 14 ++++++++++---- ghost/admin/models/uploadModal.js | 7 ++++--- ghost/admin/views/editor.js | 3 ++- ghost/admin/views/settings.js | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ghost/admin/assets/lib/uploader.js b/ghost/admin/assets/lib/uploader.js index 28b8ce93ff..2d2144436f 100644 --- a/ghost/admin/assets/lib/uploader.js +++ b/ghost/admin/assets/lib/uploader.js @@ -139,6 +139,10 @@ this.removeExtras(); this.buildExtras(); this.bindFileUpload(); + if (!settings.fileStorage) { + self.initUrl(); + return; + } $dropzone.find('a.image-url').on('click', function () { self.initUrl(); }); @@ -148,7 +152,9 @@ this.removeExtras(); $dropzone.addClass('image-uploader-url').removeClass('pre-image-uploader'); $dropzone.find('.js-fileupload').addClass('right'); - $dropzone.append($cancel); + if (settings.fileStorage) { + $dropzone.append($cancel); + } $dropzone.find('.js-cancel').on('click', function () { $dropzone.find('.js-url').remove(); $dropzone.find('.js-fileupload').removeClass('right'); @@ -162,9 +168,9 @@ $dropzone.find('div.description').before($url); $dropzone.find('.js-button-accept').on('click', function () { + val = $('#uploadurl').val(); $dropzone.trigger('uploadstart', [$dropzone.attr('id')]); $dropzone.find('div.description').hide(); - val = $('#uploadurl').val(); $dropzone.find('.js-fileupload').removeClass('right'); $dropzone.find('.js-url').remove(); $dropzone.find('button.centre').remove(); @@ -205,9 +211,9 @@ $.fn.upload = function (options) { var settings = $.extend({ progressbar: true, - editor: false + editor: false, + fileStorage: true }, options); - return this.each(function () { var $dropzone = $(this), ui; diff --git a/ghost/admin/models/uploadModal.js b/ghost/admin/models/uploadModal.js index 2c8aabb9ea..68dff9ba6e 100644 --- a/ghost/admin/models/uploadModal.js +++ b/ghost/admin/models/uploadModal.js @@ -1,4 +1,4 @@ -/*global Ghost, Backbone */ +/*global Ghost, Backbone, $ */ (function () { 'use strict'; Ghost.Models.uploadModal = Backbone.Model.extend({ @@ -8,8 +8,9 @@ type: 'action', style: ["wide"], animation: 'fade', - afterRender: function () { - this.$('.js-drop-zone').upload(); + afterRender: function (id) { + var filestorage = $('#' + this.options.model.id).data('filestorage'); + this.$('.js-drop-zone').upload({fileStorage: filestorage}); }, confirm: { reject: { diff --git a/ghost/admin/views/editor.js b/ghost/admin/views/editor.js index c8802b5bc5..34e68390f8 100644 --- a/ghost/admin/views/editor.js +++ b/ghost/admin/views/editor.js @@ -432,7 +432,8 @@ }, initUploads: function () { - this.$('.js-drop-zone').upload({editor: true}); + var filestorage = $('#entry-markdown-content').data('filestorage'); + this.$('.js-drop-zone').upload({editor: true, fileStorage: filestorage}); this.$('.js-drop-zone').on('uploadstart', $.proxy(this.disableEditor, this)); this.$('.js-drop-zone').on('uploadstart', this.uploadMgr.handleDownloadStart); this.$('.js-drop-zone').on('uploadfailure', $.proxy(this.enableEditor, this)); diff --git a/ghost/admin/views/settings.js b/ghost/admin/views/settings.js index 3cbbd9fbfc..3ac12b88e0 100644 --- a/ghost/admin/views/settings.js +++ b/ghost/admin/views/settings.js @@ -200,7 +200,7 @@ this.showUpload('cover', settings.cover); }, showUpload: function (key, src) { - var self = this, upload = new Ghost.Models.uploadModal({'key': key, 'src': src, 'accept': { + var self = this, upload = new Ghost.Models.uploadModal({'key': key, 'src': src, 'id': this.id, 'accept': { func: function () { // The function called on acceptance var data = {}; if (this.$('#uploadurl').val()) { @@ -257,7 +257,7 @@ this.showUpload('image', user.image); }, showUpload: function (key, src) { - var self = this, upload = new Ghost.Models.uploadModal({'key': key, 'src': src, 'accept': { + var self = this, upload = new Ghost.Models.uploadModal({'key': key, 'src': src, 'id': this.id, 'accept': { func: function () { // The function called on acceptance var data = {}; if (this.$('#uploadurl').val()) {