app/assets/javascripts/activeadmin/trumbowyg/plugins/upload/trumbowyg.upload.js in activeadmin_trumbowyg-0.1.3 vs app/assets/javascripts/activeadmin/trumbowyg/plugins/upload/trumbowyg.upload.js in activeadmin_trumbowyg-0.1.6

- old
+ new

@@ -21,11 +21,12 @@ headers: {}, // Additional headers xhrFields: {}, // Additional fields urlPropertyName: 'file', // How to get url from the json response (for instance 'url' for {url: ....}) statusPropertyName: 'success', // How to get status from the json response success: undefined, // Success callback: function (data, trumbowyg, $modal, values) {} - error: undefined // Error callback: function () {} + error: undefined, // Error callback: function () {} + imageWidthModalEdit: false // Add ability to edit image width }; function getDeep(object, propertyParts) { var mainProperty = propertyParts.shift(), otherProperties = propertyParts; @@ -50,10 +51,15 @@ en: { upload: 'Upload', file: 'File', uploadError: 'Error' }, + da: { + upload: 'Upload', + file: 'Fil', + uploadError: 'Fejl' + }, sk: { upload: 'Nahrať', file: 'Súbor', uploadError: 'Chyba' }, @@ -74,11 +80,11 @@ }, zh_tw: { upload: '上傳', file: '文件', uploadError: '錯誤' - }, + }, ru: { upload: 'Загрузка', file: 'Файл', uploadError: 'Ошибка' }, @@ -90,10 +96,15 @@ pt_br: { upload: 'Enviar do local', file: 'Arquivo', uploadError: 'Erro' }, + tr: { + upload: 'Yükle', + file: 'Dosya', + uploadError: 'Hata' + } }, // jshint camelcase:true plugins: { upload: { @@ -104,40 +115,48 @@ trumbowyg.saveRange(); var file, prefix = trumbowyg.o.prefix; + var fields = { + file: { + type: 'file', + required: true, + attributes: { + accept: 'image/*' + } + }, + alt: { + label: 'description', + value: trumbowyg.getRangeText() + } + }; + + if (trumbowyg.o.plugins.upload.imageWidthModalEdit) { + fields.width = { + value: '' + }; + } + var $modal = trumbowyg.openModalInsert( // Title trumbowyg.lang.upload, // Fields - { - file: { - type: 'file', - required: true, - attributes: { - accept: 'image/*' - } - }, - alt: { - label: 'description', - value: trumbowyg.getRangeText() - } - }, + fields, // Callback function (values) { var data = new FormData(); data.append(trumbowyg.o.plugins.upload.fileFieldName, file); trumbowyg.o.plugins.upload.data.map(function (cur) { data.append(cur.name, cur.value); }); - - $.map(values, function(curr, key){ - if(key !== 'file') { + + $.map(values, function (curr, key) { + if (key !== 'file') { data.append(key, curr); } }); if ($('.' + prefix + 'progress', $modal).length === 0) { @@ -173,11 +192,17 @@ trumbowyg.o.plugins.upload.success(data, trumbowyg, $modal, values); } else { if (!!getDeep(data, trumbowyg.o.plugins.upload.statusPropertyName.split('.'))) { var url = getDeep(data, trumbowyg.o.plugins.upload.urlPropertyName.split('.')); trumbowyg.execCmd('insertImage', url); - $('img[src="' + url + '"]:not([alt])', trumbowyg.$box).attr('alt', values.alt); + var $img = $('img[src="' + url + '"]:not([alt])', trumbowyg.$box); + $img.attr('alt', values.alt); + if (trumbowyg.o.imageWidthModalEdit && parseInt(values.width) > 0) { + $img.attr({ + width: values.width + }); + } setTimeout(function () { trumbowyg.closeModal(); }, 250); trumbowyg.$c.trigger('tbwuploadsuccess', [trumbowyg, data, url]); } else { @@ -216,10 +241,9 @@ trumbowyg.addBtnDef('upload', btnDef); } } } }); - function addXhrProgressEvent() { if (!$.trumbowyg.addedXhrProgressEvent) { // Avoid adding progress event multiple times var originalXhr = $.ajaxSettings.xhr; $.ajaxSetup({