scratch – Blame information for rev 125
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
58 | office | 1 | /* =========================================================== |
2 | * trumbowyg.base64.js v1.0 |
||
3 | * Base64 plugin for Trumbowyg |
||
4 | * http://alex-d.github.com/Trumbowyg |
||
5 | * =========================================================== |
||
6 | * Author : Cyril Biencourt (lizardK) |
||
7 | */ |
||
8 | |||
9 | (function ($) { |
||
10 | 'use strict'; |
||
11 | |||
12 | var isSupported = function () { |
||
13 | return typeof FileReader !== 'undefined'; |
||
14 | }; |
||
15 | |||
16 | var isValidImage = function (type) { |
||
17 | return /^data:image\/[a-z]?/i.test(type); |
||
18 | }; |
||
19 | |||
20 | $.extend(true, $.trumbowyg, { |
||
21 | langs: { |
||
22 | // jshint camelcase:false |
||
23 | en: { |
||
24 | base64: 'Image as base64', |
||
25 | file: 'File', |
||
26 | errFileReaderNotSupported: 'FileReader is not supported by your browser.', |
||
27 | errInvalidImage: 'Invalid image file.' |
||
28 | }, |
||
29 | fr: { |
||
30 | base64: 'Image en base64', |
||
31 | file: 'Fichier' |
||
32 | }, |
||
33 | cs: { |
||
34 | base64: 'Vložit obrázek', |
||
35 | file: 'Soubor' |
||
36 | }, |
||
37 | zh_cn: { |
||
38 | base64: '图片(Base64编码)', |
||
39 | file: '文件' |
||
40 | }, |
||
41 | nl: { |
||
42 | errFileReaderNotSupported: 'Uw browser ondersteunt deze functionaliteit niet.', |
||
43 | errInvalidImage: 'De gekozen afbeelding is ongeldig.' |
||
125 | office | 44 | }, |
45 | ja: { |
||
46 | base64: '画像 (Base64形式)', |
||
47 | file: 'ファイル', |
||
48 | errFileReaderNotSupported: 'あなたのブラウザーはFileReaderをサポートしていません', |
||
49 | errInvalidImage: '画像形式が正しくありません' |
||
58 | office | 50 | } |
51 | }, |
||
52 | // jshint camelcase:true |
||
53 | |||
54 | plugins: { |
||
55 | base64: { |
||
56 | shouldInit: isSupported, |
||
57 | init: function (trumbowyg) { |
||
58 | var btnDef = { |
||
59 | isSupported: isSupported, |
||
60 | fn: function () { |
||
61 | trumbowyg.saveRange(); |
||
62 | |||
63 | var file; |
||
64 | var $modal = trumbowyg.openModalInsert( |
||
65 | // Title |
||
66 | trumbowyg.lang.base64, |
||
67 | |||
68 | // Fields |
||
69 | { |
||
70 | file: { |
||
71 | type: 'file', |
||
72 | required: true, |
||
73 | attributes: { |
||
74 | accept: 'image/*' |
||
75 | } |
||
76 | }, |
||
77 | alt: { |
||
78 | label: 'description', |
||
79 | value: trumbowyg.getRangeText() |
||
80 | } |
||
81 | }, |
||
82 | |||
83 | // Callback |
||
84 | function (values) { |
||
85 | var fReader = new FileReader(); |
||
86 | |||
87 | fReader.onloadend = function (e) { |
||
88 | if (isValidImage(e.target.result)) { |
||
89 | trumbowyg.execCmd('insertImage', fReader.result); |
||
90 | $(['img[src="', fReader.result, '"]:not([alt])'].join(''), trumbowyg.$box).attr('alt', values.alt); |
||
91 | trumbowyg.closeModal(); |
||
92 | } else { |
||
93 | trumbowyg.addErrorOnModalField( |
||
94 | $('input[type=file]', $modal), |
||
95 | trumbowyg.lang.errInvalidImage |
||
96 | ); |
||
97 | } |
||
98 | }; |
||
99 | |||
100 | fReader.readAsDataURL(file); |
||
101 | } |
||
102 | ); |
||
103 | |||
104 | $('input[type=file]').on('change', function (e) { |
||
105 | file = e.target.files[0]; |
||
106 | }); |
||
107 | } |
||
108 | }; |
||
109 | |||
110 | trumbowyg.addBtnDef('base64', btnDef); |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | }); |
||
115 | })(jQuery); |