diff --git a/bower.json b/bower.json
index f3dee421a..c2464fbde 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "trumbowyg",
- "version": "2.2.0",
+ "version": "2.3.0",
"homepage": "https://github.com/Alex-D/Trumbowyg",
"authors": [
{
diff --git a/examples/plugins/template.html b/examples/plugins/template.html
new file mode 100644
index 000000000..7902c4371
--- /dev/null
+++ b/examples/plugins/template.html
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
Lorem ipsum dolor sit amet
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus, aliquam, minima fugiat placeat provident optio nam reiciendis eius beatae quibusdam!
+
+
+ The text is derived from Cicero's De Finibus Bonorum et Malorum (On the Ends of Goods and Evils, or alternatively [About] The Purposes of Good and Evil ). The original passage began: Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit (Translation: "Neither is there anyone who loves grief itself since it is grief and thus wants to obtain it").
+
+
+
+
The code
+
+
+ $('#editor')
+ .trumbowyg({
+ btns: ['template'],
+ plugins: {
+ templates: [
+ {
+ name: 'Template 1',
+ html: '<p>I am a template!</p>'
+ },
+ {
+ name: 'Template 2',
+ html: '<p>I am a different template!</p>'
+ }
+ ]
+ }
+ });
+
+
+
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 683bfa5a5..d4c23670c 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "trumbowyg",
"title": "Trumbowyg",
"description": "A lightweight WYSIWYG editor",
- "version": "2.2.0",
+ "version": "2.3.0",
"main": "dist/trumbowyg.js",
"homepage": "http://alex-d.github.io/Trumbowyg",
"author": {
diff --git a/plugins/base64/trumbowyg.base64.js b/plugins/base64/trumbowyg.base64.js
index a480eb2c9..f9958f5d3 100644
--- a/plugins/base64/trumbowyg.base64.js
+++ b/plugins/base64/trumbowyg.base64.js
@@ -13,13 +13,18 @@
return typeof FileReader !== 'undefined';
};
+ var isValidImage = function (type) {
+ return /^data:image\/[a-z]?/i.test(type);
+ };
+
$.extend(true, $.trumbowyg, {
langs: {
// jshint camelcase:false
en: {
base64: 'Image as base64',
file: 'File',
- errFileReaderNotSupported: 'FileReader is not supported by your browser.'
+ errFileReaderNotSupported: 'FileReader is not supported by your browser.',
+ errInvalidImage: 'Invalid image file.'
},
fr: {
base64: 'Image en base64',
@@ -32,6 +37,10 @@
zh_cn: {
base64: '图片(Base64编码)',
file: '文件'
+ },
+ nl: {
+ errFileReaderNotSupported: 'Uw browser ondersteunt deze functionaliteit niet.',
+ errInvalidImage: 'De gekozen afbeelding is ongeldig.'
}
},
// jshint camelcase:true
@@ -44,9 +53,9 @@
isSupported: isSupported,
fn: function () {
trumbowyg.saveRange();
-
+
var file;
- trumbowyg.openModalInsert(
+ var $modal = trumbowyg.openModalInsert(
// Title
trumbowyg.lang.base64,
@@ -54,7 +63,10 @@
{
file: {
type: 'file',
- required: true
+ required: true,
+ attributes: {
+ accept: 'image/*'
+ }
},
alt: {
label: 'description',
@@ -66,10 +78,17 @@
function (values) {
var fReader = new FileReader();
- fReader.onloadend = function () {
- trumbowyg.execCmd('insertImage', fReader.result);
- $(['img[src="', fReader.result, '"]:not([alt])'].join(''), trumbowyg.$box).attr('alt', values.alt);
- trumbowyg.closeModal();
+ fReader.onloadend = function (e) {
+ if (isValidImage(e.target.result)) {
+ trumbowyg.execCmd('insertImage', fReader.result);
+ $(['img[src="', fReader.result, '"]:not([alt])'].join(''), trumbowyg.$box).attr('alt', values.alt);
+ trumbowyg.closeModal();
+ } else {
+ trumbowyg.addErrorOnModalField(
+ $('input[type=file]', $modal),
+ trumbowyg.lang.errInvalidImage
+ );
+ }
};
fReader.readAsDataURL(file);
diff --git a/plugins/template/trumbowyg.template.js b/plugins/template/trumbowyg.template.js
new file mode 100644
index 000000000..6c82c4874
--- /dev/null
+++ b/plugins/template/trumbowyg.template.js
@@ -0,0 +1,52 @@
+(function($) {
+ 'use strict';
+
+ // Adds the language variables
+ $.extend(true, $.trumbowyg, {
+ langs: {
+ en: {
+ template: 'Template'
+ },
+ nl: {
+ template: 'Sjabloon'
+ }
+ }
+ });
+
+ // Adds the extra button definition
+ $.extend(true, $.trumbowyg, {
+ plugins: {
+ template: {
+ shouldInit: function(trumbowyg) {
+ return trumbowyg.o.plugins.hasOwnProperty('templates');
+ },
+ init: function(trumbowyg) {
+ trumbowyg.addBtnDef('template', {
+ dropdown: templateSelector(trumbowyg),
+ hasIcon: false,
+ text: trumbowyg.lang.template
+ });
+ }
+ }
+ }
+ });
+
+ // Creates the template-selector dropdown.
+ function templateSelector(trumbowyg) {
+ var available = trumbowyg.o.plugins.templates;
+ var templates = [];
+
+ $.each(available, function(index, template) {
+ trumbowyg.addBtnDef('template_' + index, {
+ fn: function(){
+ trumbowyg.html(template.html);
+ },
+ hasIcon: false,
+ title: template.name
+ });
+ templates.push('template_' + index);
+ });
+
+ return templates;
+ }
+})(jQuery);
\ No newline at end of file
diff --git a/plugins/upload/trumbowyg.upload.js b/plugins/upload/trumbowyg.upload.js
index 6fb0f5a36..7e8490f93 100644
--- a/plugins/upload/trumbowyg.upload.js
+++ b/plugins/upload/trumbowyg.upload.js
@@ -1,11 +1,14 @@
/* ===========================================================
- * trumbowyg.upload.js v1.1
+ * trumbowyg.upload.js v1.2
* Upload plugin for Trumbowyg
* http://alex-d.github.com/Trumbowyg
* ===========================================================
* Author : Alexandre Demode (Alex-D)
* Twitter : @AlexandreDemode
* Website : alex-d.fr
+ * Mod by : Aleksandr-ru
+ * Twitter : @Aleksandr_ru
+ * Website : aleksandr.ru
*/
(function ($) {
@@ -68,6 +71,11 @@
upload: '上传',
file: '文件',
uploadError: '错误'
+ },
+ ru: {
+ upload: 'Загрузка',
+ file: 'Файл',
+ uploadError: 'Ошибка'
}
},
// jshint camelcase:true
@@ -91,7 +99,10 @@
{
file: {
type: 'file',
- required: true
+ required: true,
+ attributes: {
+ accept: 'image/*'
+ }
},
alt: {
label: 'description',
@@ -138,23 +149,28 @@
}, 200);
},
- success: trumbowyg.o.plugins.upload.success || function (data) {
- 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);
- setTimeout(function () {
- trumbowyg.closeModal();
- }, 250);
- trumbowyg.$c.trigger('tbwuploadsuccess', [trumbowyg, data, url]);
+ success: function (data) {
+ if (trumbowyg.o.plugins.upload.success) {
+ trumbowyg.o.plugins.upload.success(data, trumbowyg, $modal, values);
} else {
- trumbowyg.addErrorOnModalField(
- $('input[type=file]', $modal),
- trumbowyg.lang[data.message]
- );
- trumbowyg.$c.trigger('tbwuploaderror', [trumbowyg, data]);
+ 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);
+ setTimeout(function () {
+ trumbowyg.closeModal();
+ }, 250);
+ trumbowyg.$c.trigger('tbwuploadsuccess', [trumbowyg, data, url]);
+ } else {
+ trumbowyg.addErrorOnModalField(
+ $('input[type=file]', $modal),
+ trumbowyg.lang[data.message]
+ );
+ trumbowyg.$c.trigger('tbwuploaderror', [trumbowyg, data]);
+ }
}
},
+
error: trumbowyg.o.plugins.upload.error || function () {
trumbowyg.addErrorOnModalField(
$('input[type=file]', $modal),
diff --git a/src/langs/ar.js b/src/langs/ar.js
index ed18aaa20..a2f1e6bf9 100644
--- a/src/langs/ar.js
+++ b/src/langs/ar.js
@@ -5,6 +5,8 @@
* ===========================================================
* Author : Abo Mokh ahmed (abomokhahmed)
* Github : https://github.com/abomokhahmed
+ * Reviewed by : Abdellah Chadidi (chadidi)
+ * Github : https://github.com/chadidi
*/
jQuery.trumbowyg.langs.ar = {
@@ -12,11 +14,15 @@ jQuery.trumbowyg.langs.ar = {
viewHTML: 'إعرض-HTML',
- formatting: 'تصميم',
+ undo: 'تراجع',
+ redo: 'إعادة',
+
+ formatting: 'تنسيق',
+
p: 'فقرة',
blockquote: 'اقتباس',
code: 'كود',
- header: 'رئيسي',
+ header: 'رأس',
bold: 'عريض',
italic: 'مائل',
@@ -27,30 +33,35 @@ jQuery.trumbowyg.langs.ar = {
em: 'تغميق',
del: 'حذف',
+ superscript: 'الأس',
+ subscript: 'أس سفلي',
+
unorderedList: 'قائمة غير مرتّبة',
orderedList: 'قائمة مرتّبة',
- insertImage: 'إدخال صورة',
- insertVideo: 'إدخال فيديو',
+
+ insertImage: 'إدراج صورة',
+ insertVideo: 'إدراج فيديو',
link: 'رابط',
createLink: 'انشاء رابط',
unlink: 'حذف رابط',
justifyLeft: 'تصحيح للشمال',
- justifyCenter: 'تصحيح للمركز',
+ justifyCenter: 'توسيط',
justifyRight: 'تصحيح لليمين',
justifyFull: 'تصحيح لكلا الإتّجاهين',
- horizontalRule: 'إدخال خطّ أفقي',
+ horizontalRule: 'إدراج خطّ أفقي',
- fullscreen: 'شاشة واسعة',
+ fullscreen: 'ملء الشاشة',
close: 'إغلاق',
- submit: 'أرسل',
- reset: 'تهيئة من حديد',
+ submit: 'إرسال',
+ reset: 'إعادة تعيين',
required: 'إلزامي',
description: 'وصف',
title: 'عنوان',
- text: 'نصّ'
-};
\ No newline at end of file
+ text: 'نصّ',
+ target: 'الهدف'
+};
diff --git a/src/trumbowyg.js b/src/trumbowyg.js
index 904f8aafa..1b4894533 100644
--- a/src/trumbowyg.js
+++ b/src/trumbowyg.js
@@ -250,10 +250,12 @@ jQuery.trumbowyg = {
},
bold: {
- key: 'B'
+ key: 'B',
+ tag: 'b'
},
italic: {
- key: 'I'
+ key: 'I',
+ tag: 'i'
},
underline: {
tag: 'u'
@@ -685,12 +687,13 @@ jQuery.trumbowyg = {
prefix = t.o.prefix,
btn = t.btnsDef[btnName],
isDropdown = btn.dropdown,
+ hasIcon = btn.hasIcon != null ? btn.hasIcon : true,
textDef = t.lang[btnName] || btnName,
$btn = $('