Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-D committed Aug 30, 2016
2 parents 3e2c91a + 87c510c commit d6c6444
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 64 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trumbowyg",
"version": "2.2.0",
"version": "2.3.0",
"homepage": "https://github.com/Alex-D/Trumbowyg",
"authors": [
{
Expand Down
73 changes: 73 additions & 0 deletions examples/plugins/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Template plugin | Trumbowyg by Alex-D</title>
<link rel="stylesheet" href="../css/main.css">
<link rel="stylesheet" href="../../dist/ui/trumbowyg.css">
</head>
<body>
<div id="main" role="main">
<header>
<h1>Template plugin for Trumbowyg</h1>

<p>
This plugin allows you to add a template-dropdown.
</p>
</header>

<div id="editor">
<h2>Lorem ipsum dolor sit amet</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus, aliquam, minima fugiat placeat provident optio nam reiciendis eius beatae quibusdam!
</p>
<p>
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: &quot;Neither is there anyone who loves grief itself since it is grief and thus wants to obtain it&quot;).
</p>
</div>

<h2>The code</h2>
<code>
<pre>
$('#editor')
.trumbowyg({
btns: ['template'],
plugins: {
templates: [
{
name: 'Template 1',
html: '&lt;p&gt;I am a template!&lt;/p&gt;'
},
{
name: 'Template 2',
html: '&lt;p&gt;I am a different template!&lt;/p&gt;'
}
]
}
});
</pre>
</code>
</div>
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../../dist/trumbowyg.js"></script>
<script src="../../dist/plugins/template/trumbowyg.template.js"></script>
<script>
$('#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>'
}
]
}
});
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
35 changes: 27 additions & 8 deletions plugins/base64/trumbowyg.base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -44,17 +53,20 @@
isSupported: isSupported,
fn: function () {
trumbowyg.saveRange();

var file;
trumbowyg.openModalInsert(
var $modal = trumbowyg.openModalInsert(
// Title
trumbowyg.lang.base64,

// Fields
{
file: {
type: 'file',
required: true
required: true,
attributes: {
accept: 'image/*'
}
},
alt: {
label: 'description',
Expand All @@ -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);
Expand Down
52 changes: 52 additions & 0 deletions plugins/template/trumbowyg.template.js
Original file line number Diff line number Diff line change
@@ -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);
48 changes: 32 additions & 16 deletions plugins/upload/trumbowyg.upload.js
Original file line number Diff line number Diff line change
@@ -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 ($) {
Expand Down Expand Up @@ -68,6 +71,11 @@
upload: '上传',
file: '文件',
uploadError: '错误'
},
ru: {
upload: 'Загрузка',
file: 'Файл',
uploadError: 'Ошибка'
}
},
// jshint camelcase:true
Expand All @@ -91,7 +99,10 @@
{
file: {
type: 'file',
required: true
required: true,
attributes: {
accept: 'image/*'
}
},
alt: {
label: 'description',
Expand Down Expand Up @@ -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),
Expand Down
33 changes: 22 additions & 11 deletions src/langs/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
* ===========================================================
* Author : Abo Mokh ahmed (abomokhahmed)
* Github : https://github.com/abomokhahmed
* Reviewed by : Abdellah Chadidi (chadidi)
* Github : https://github.com/chadidi
*/

jQuery.trumbowyg.langs.ar = {
_dir: 'rtl',

viewHTML: 'إعرض-HTML',

formatting: 'تصميم',
undo: 'تراجع',
redo: 'إعادة',

formatting: 'تنسيق',

p: 'فقرة',
blockquote: 'اقتباس',
code: 'كود',
header: 'رئيسي',
header: 'رأس',

bold: 'عريض',
italic: 'مائل',
Expand All @@ -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: 'نصّ'
};
text: 'نصّ',
target: 'الهدف'
};
Loading

0 comments on commit d6c6444

Please sign in to comment.