ckeditor-base64image 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/README.md +17 -0
  4. data/Rakefile +2 -0
  5. data/lib/ckeditor/base64image.rb +10 -0
  6. data/lib/ckeditor/base64image/version.rb +5 -0
  7. data/vendor/assets/images/ckeditor/plugins/base64image/icons/base64image.png +0 -0
  8. data/vendor/assets/images/ckeditor/plugins/base64image/icons/hidpi/base64image.png +0 -0
  9. data/vendor/assets/javascripts/ckeditor/base64image.js +4 -0
  10. data/vendor/assets/javascripts/ckeditor/plugins/base64image/dialogs/base64image.js +503 -0
  11. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/af.js +12 -0
  12. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ar.js +12 -0
  13. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/bg.js +12 -0
  14. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/bn.js +12 -0
  15. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/bs.js +12 -0
  16. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ca.js +12 -0
  17. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/cs.js +12 -0
  18. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/cy.js +12 -0
  19. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/da.js +12 -0
  20. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/de.js +12 -0
  21. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/el.js +12 -0
  22. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/en-au.js +12 -0
  23. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/en-ca.js +12 -0
  24. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/en-gb.js +12 -0
  25. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/en.js +12 -0
  26. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/eo.js +12 -0
  27. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/es.js +12 -0
  28. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/et.js +12 -0
  29. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/eu.js +12 -0
  30. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/fa.js +12 -0
  31. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/fi.js +12 -0
  32. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/fo.js +12 -0
  33. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/fr-ca.js +12 -0
  34. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/fr.js +12 -0
  35. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/gl.js +12 -0
  36. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/gu.js +12 -0
  37. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/he.js +12 -0
  38. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/hi.js +12 -0
  39. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/hr.js +12 -0
  40. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/hu.js +12 -0
  41. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/id.js +12 -0
  42. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/is.js +12 -0
  43. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/it.js +12 -0
  44. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ja.js +12 -0
  45. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ka.js +12 -0
  46. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/km.js +12 -0
  47. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ko.js +12 -0
  48. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ku.js +12 -0
  49. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/lt.js +12 -0
  50. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/lv.js +12 -0
  51. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/mk.js +12 -0
  52. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/mn.js +12 -0
  53. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ms.js +12 -0
  54. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/nb.js +12 -0
  55. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/nl.js +12 -0
  56. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/no.js +12 -0
  57. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/pl.js +12 -0
  58. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/pt-br.js +12 -0
  59. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/pt.js +12 -0
  60. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ro.js +12 -0
  61. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ru.js +12 -0
  62. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/si.js +12 -0
  63. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/sk.js +12 -0
  64. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/sl.js +12 -0
  65. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/sq.js +12 -0
  66. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/sr-latn.js +12 -0
  67. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/sr.js +12 -0
  68. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/sv.js +12 -0
  69. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/th.js +12 -0
  70. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/tr.js +12 -0
  71. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/ug.js +12 -0
  72. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/uk.js +12 -0
  73. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/vi.js +12 -0
  74. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/zh-cn.js +12 -0
  75. data/vendor/assets/javascripts/ckeditor/plugins/base64image/lang/zh.js +12 -0
  76. data/vendor/assets/javascripts/ckeditor/plugins/base64image/plugin.js +57 -0
  77. metadata +140 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8baefba7b093e8e424d99617c8dbbae877693a16
4
+ data.tar.gz: 90afed2f74af1f2520a52073c120454cf651091b
5
+ SHA512:
6
+ metadata.gz: f592c581e614ddff0e043a0a4957a37a677d2428d9bab5441a977d181a4d1490f37019aef4c12bd2e95d06a60637e7ac785cc9eb90b1caf09b446d2e4b4dcf7f
7
+ data.tar.gz: 0c01e8bdc6a4a7f159ebd3309a71ad0c61c40298c7f53b7786615b9b3af3099cd1b57268ac71c33925bebed78f873ebf772840c62fa4b649e447d510aeb09e06
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2014 Mobile Event Guide
2
+
3
+ This program is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU Lesser General Public License as published by
5
+ the Free Software Foundation, either version 3 of the License, or
6
+ (at your option) any later version.
7
+
8
+ This program is distributed in the hope that it will be useful,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ GNU Lesser General Public License for more details.
12
+
13
+ You should have received a copy of the GNU Lesser General Public License
14
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Ckeditor::Base64image
2
+
3
+ Asset gem for [nmmf/base64image](https://github.com/nmmf/base64image).
4
+
5
+ ## Usage
6
+
7
+ Add to Gemfile
8
+
9
+ ```ruby
10
+ gem 'ckeditor-base64image'
11
+ ```
12
+
13
+ Add to `application.js`
14
+
15
+ ```javascript
16
+ //= require ckeditor/base64image
17
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,10 @@
1
+ require "ckeditor/base64image/version"
2
+
3
+ module Ckeditor
4
+ module Base64image
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Ckeditor
2
+ module Base64image
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ //= require ./plugins/base64image/plugin
2
+ //= require ./plugins/base64image/dialogs/base64image
3
+ //= require ./plugins/base64image/lang/en
4
+ //= require ./plugins/base64image/lang/de
@@ -0,0 +1,503 @@
1
+ /*
2
+ * Created by ALL-INKL.COM - Neue Medien Muennich - 04. Feb 2014
3
+ * Licensed under the terms of GPL, LGPL and MPL licenses.
4
+ */
5
+ CKEDITOR.dialog.add("base64imageDialog", function(editor){
6
+
7
+ var t = null,
8
+ selectedImg = null,
9
+ orgWidth = null, orgHeight = null,
10
+ imgPreview = null, urlCB = null, urlI = null, fileCB = null, imgScal = 1, lock = true;
11
+
12
+ /* Check File Reader Support */
13
+ function fileSupport() {
14
+ var r = false, n = null;
15
+ try {
16
+ if(FileReader) {
17
+ var n = document.createElement("input");
18
+ if(n && "files" in n) r = true;
19
+ }
20
+ } catch(e) { r = false; }
21
+ n = null;
22
+ return r;
23
+ }
24
+ var fsupport = fileSupport();
25
+
26
+ /* Load preview image */
27
+ function imagePreviewLoad(s) {
28
+
29
+ /* no preview */
30
+ if(typeof(s) != "string" || !s) {
31
+ imgPreview.getElement().setHtml("");
32
+ return;
33
+ }
34
+
35
+ /* Create image */
36
+ var i = new Image();
37
+
38
+ /* Display loading text in preview element */
39
+ imgPreview.getElement().setHtml("Loading...");
40
+
41
+ /* When image is loaded */
42
+ i.onload = function() {
43
+
44
+ /* Remove preview */
45
+ imgPreview.getElement().setHtml("");
46
+
47
+ /* Set attributes */
48
+ if(orgWidth == null || orgHeight == null) {
49
+ t.setValueOf("tab-properties", "width", this.width);
50
+ t.setValueOf("tab-properties", "height", this.height);
51
+ imgScal = 1;
52
+ if(this.height > 0 && this.width > 0) imgScal = this.width / this.height;
53
+ if(imgScal <= 0) imgScal = 1;
54
+ } else {
55
+ orgWidth = null;
56
+ orgHeight = null;
57
+ }
58
+ this.id = editor.id+"previewimage";
59
+ this.setAttribute("style", "max-width:400px;max-height:100px;");
60
+ this.setAttribute("alt", "");
61
+
62
+ /* Insert preview image */
63
+ try {
64
+ var p = imgPreview.getElement().$;
65
+ if(p) p.appendChild(this);
66
+ } catch(e) {}
67
+
68
+ };
69
+
70
+ /* Error Function */
71
+ i.onerror = function(){ imgPreview.getElement().setHtml(""); };
72
+ i.onabort = function(){ imgPreview.getElement().setHtml(""); };
73
+
74
+ /* Load image */
75
+ i.src = s;
76
+ }
77
+
78
+ /* Change input values and preview image */
79
+ function imagePreview(src){
80
+
81
+ /* Remove preview */
82
+ imgPreview.getElement().setHtml("");
83
+
84
+ if(src == "base64") {
85
+
86
+ /* Disable Checkboxes */
87
+ if(urlCB) urlCB.setValue(false, true);
88
+ if(fileCB) fileCB.setValue(false, true);
89
+
90
+ } else if(src == "url") {
91
+
92
+ /* Ensable Image URL Checkbox */
93
+ if(urlCB) urlCB.setValue(true, true);
94
+ if(fileCB) fileCB.setValue(false, true);
95
+
96
+ /* Load preview image */
97
+ if(urlI) imagePreviewLoad(urlI.getValue());
98
+
99
+ } else if(fsupport) {
100
+
101
+ /* Ensable Image File Checkbox */
102
+ if(urlCB) urlCB.setValue(false, true);
103
+ if(fileCB) fileCB.setValue(true, true);
104
+
105
+ /* Read file and load preview */
106
+ var fileI = t.getContentElement("tab-source", "file");
107
+ var n = null;
108
+ try { n = fileI.getInputElement().$; } catch(e) { n = null; }
109
+ if(n && "files" in n && n.files && n.files.length > 0 && n.files[0]) {
110
+ if("type" in n.files[0] && !n.files[0].type.match("image.*")) return;
111
+ if(!FileReader) return;
112
+ imgPreview.getElement().setHtml("Loading...");
113
+ var fr = new FileReader();
114
+ fr.onload = (function(f) { return function(e) {
115
+ imgPreview.getElement().setHtml("");
116
+ imagePreviewLoad(e.target.result);
117
+ }; })(n.files[0]);
118
+ fr.onerror = function(){ imgPreview.getElement().setHtml(""); };
119
+ fr.onabort = function(){ imgPreview.getElement().setHtml(""); };
120
+ fr.readAsDataURL(n.files[0]);
121
+ }
122
+ }
123
+ };
124
+
125
+ /* Calculate image dimensions */
126
+ function getImageDimensions() {
127
+ var o = {
128
+ "w" : t.getContentElement("tab-properties", "width").getValue(),
129
+ "h" : t.getContentElement("tab-properties", "height").getValue(),
130
+ "uw" : "px",
131
+ "uh" : "px"
132
+ };
133
+ if(o.w.indexOf("%") >= 0) o.uw = "%";
134
+ if(o.h.indexOf("%") >= 0) o.uh = "%";
135
+ o.w = parseInt(o.w, 10);
136
+ o.h = parseInt(o.h, 10);
137
+ if(isNaN(o.w)) o.w = 0;
138
+ if(isNaN(o.h)) o.h = 0;
139
+ return o;
140
+ }
141
+
142
+ /* Set image dimensions */
143
+ function imageDimensions(src) {
144
+ var o = getImageDimensions();
145
+ var u = "px";
146
+ if(src == "width") {
147
+ if(o.uw == "%") u = "%";
148
+ o.h = Math.round(o.w / imgScal);
149
+ } else {
150
+ if(o.uh == "%") u = "%";
151
+ o.w = Math.round(o.h * imgScal);
152
+ }
153
+ if(u == "%") {
154
+ o.w += "%";
155
+ o.h += "%";
156
+ }
157
+ t.getContentElement("tab-properties", "width").setValue(o.w),
158
+ t.getContentElement("tab-properties", "height").setValue(o.h)
159
+ }
160
+
161
+ /* Set integer Value */
162
+ function integerValue(elem) {
163
+ var v = elem.getValue(), u = "";
164
+ if(v.indexOf("%") >= 0) u = "%";
165
+ v = parseInt(v, 10);
166
+ if(isNaN(v)) v = 0;
167
+ elem.setValue(v+u);
168
+ }
169
+
170
+ if(fsupport) {
171
+
172
+ /* Dialog with file and url image source */
173
+ var sourceElements = [
174
+ {
175
+ type: "hbox",
176
+ widths: ["70px"],
177
+ children: [
178
+ {
179
+ type: "checkbox",
180
+ id: "urlcheckbox",
181
+ style: "margin-top:5px",
182
+ label: editor.lang.common.url+":"
183
+ },
184
+ {
185
+ type: "text",
186
+ id: "url",
187
+ label: "",
188
+ onChange: function(){ imagePreview("url"); }
189
+ }
190
+ ]
191
+ },
192
+ {
193
+ type: "hbox",
194
+ widths: ["70px"],
195
+ children: [
196
+ {
197
+ type: "checkbox",
198
+ id: "filecheckbox",
199
+ style: "margin-top:5px",
200
+ label: editor.lang.common.upload+":"
201
+ },
202
+ {
203
+ type: "file",
204
+ id: "file",
205
+ label: "",
206
+ onChange: function(){ imagePreview("file"); }
207
+ }
208
+ ]
209
+ },
210
+ {
211
+ type: "html",
212
+ id: "preview",
213
+ html: new CKEDITOR.template("<div style=\"text-align:center;\"></div>").output()
214
+ }
215
+ ];
216
+
217
+ } else {
218
+
219
+ /* Dialog with url image source */
220
+ var sourceElements = [
221
+ {
222
+ type: "text",
223
+ id: "url",
224
+ label: editor.lang.common.url,
225
+ onChange: function(){ imagePreview("url"); }
226
+ },
227
+ {
228
+ type: "html",
229
+ id: "preview",
230
+ html: new CKEDITOR.template("<div style=\"text-align:center;\"></div>").output()
231
+ }
232
+ ];
233
+ }
234
+
235
+ /* Dialog */
236
+ return {
237
+ title: editor.lang.common.image,
238
+ minWidth: 450,
239
+ minHeight: 180,
240
+ onLoad: function(){
241
+
242
+ if(fsupport) {
243
+
244
+ /* Get checkboxes */
245
+ urlCB = this.getContentElement("tab-source", "urlcheckbox");
246
+ fileCB = this.getContentElement("tab-source", "filecheckbox");
247
+
248
+ /* Checkbox Events */
249
+ urlCB.getInputElement().on("click", function(){ imagePreview("url"); });
250
+ fileCB.getInputElement().on("click", function(){ imagePreview("file"); });
251
+
252
+ }
253
+
254
+ /* Get url input element */
255
+ urlI = this.getContentElement("tab-source", "url");
256
+
257
+ /* Get image preview element */
258
+ imgPreview = this.getContentElement("tab-source", "preview");
259
+
260
+ /* Constrain proportions or not */
261
+ this.getContentElement("tab-properties", "lock").getInputElement().on("click", function(){
262
+ if(this.getValue()) lock = true; else lock = false;
263
+ if(lock) imageDimensions("width");
264
+ }, this.getContentElement("tab-properties", "lock"));
265
+
266
+ /* Change Attributes Events */
267
+ this.getContentElement("tab-properties", "width").getInputElement().on("keyup", function(){ if(lock) imageDimensions("width"); });
268
+ this.getContentElement("tab-properties", "height").getInputElement().on("keyup", function(){ if(lock) imageDimensions("height"); });
269
+ this.getContentElement("tab-properties", "vmargin").getInputElement().on("keyup", function(){ integerValue(this); }, this.getContentElement("tab-properties", "vmargin"));
270
+ this.getContentElement("tab-properties", "hmargin").getInputElement().on("keyup", function(){ integerValue(this); }, this.getContentElement("tab-properties", "hmargin"));
271
+ this.getContentElement("tab-properties", "border").getInputElement().on("keyup", function(){ integerValue(this); }, this.getContentElement("tab-properties", "border"));
272
+
273
+ },
274
+ onShow: function(){
275
+
276
+ /* Remove preview */
277
+ imgPreview.getElement().setHtml("");
278
+
279
+ t = this, orgWidth = null, orgHeight = null, imgScal = 1, lock = true;
280
+
281
+ /* selected image or null */
282
+ selectedImg = editor.getSelection();
283
+ if(selectedImg) selectedImg = selectedImg.getSelectedElement();
284
+ if(!selectedImg || selectedImg.getName() !== "img") selectedImg = null;
285
+
286
+ /* Set input values */
287
+ t.setValueOf("tab-properties", "lock", lock);
288
+ t.setValueOf("tab-properties", "vmargin", "0");
289
+ t.setValueOf("tab-properties", "hmargin", "0");
290
+ t.setValueOf("tab-properties", "border", "0");
291
+ t.setValueOf("tab-properties", "align", "none");
292
+ if(selectedImg) {
293
+
294
+ /* Set input values from selected image */
295
+ if(typeof(selectedImg.getAttribute("width")) == "string") orgWidth = selectedImg.getAttribute("width");
296
+ if(typeof(selectedImg.getAttribute("height")) == "string") orgHeight = selectedImg.getAttribute("height");
297
+ if((orgWidth == null || orgHeight == null) && selectedImg.$) {
298
+ orgWidth = selectedImg.$.width;
299
+ orgHeight = selectedImg.$.height;
300
+ }
301
+ if(orgWidth != null && orgHeight != null) {
302
+ t.setValueOf("tab-properties", "width", orgWidth);
303
+ t.setValueOf("tab-properties", "height", orgHeight);
304
+ orgWidth = parseInt(orgWidth, 10);
305
+ orgHeight = parseInt(orgHeight, 10);
306
+ imgScal = 1;
307
+ if(!isNaN(orgWidth) && !isNaN(orgHeight) && orgHeight > 0 && orgWidth > 0) imgScal = orgWidth / orgHeight;
308
+ if(imgScal <= 0) imgScal = 1;
309
+ }
310
+
311
+ if(typeof(selectedImg.getAttribute("src")) == "string") {
312
+ if(selectedImg.getAttribute("src").indexOf("data:") === 0) {
313
+ imagePreview("base64");
314
+ imagePreviewLoad(selectedImg.getAttribute("src"));
315
+ } else {
316
+ t.setValueOf("tab-source", "url", selectedImg.getAttribute("src"));
317
+ }
318
+ }
319
+ if(typeof(selectedImg.getAttribute("alt")) == "string") t.setValueOf("tab-properties", "alt", selectedImg.getAttribute("alt"));
320
+ if(typeof(selectedImg.getAttribute("hspace")) == "string") t.setValueOf("tab-properties", "hmargin", selectedImg.getAttribute("hspace"));
321
+ if(typeof(selectedImg.getAttribute("vspace")) == "string") t.setValueOf("tab-properties", "vmargin", selectedImg.getAttribute("vspace"));
322
+ if(typeof(selectedImg.getAttribute("border")) == "string") t.setValueOf("tab-properties", "border", selectedImg.getAttribute("border"));
323
+ if(typeof(selectedImg.getAttribute("align")) == "string") {
324
+ switch(selectedImg.getAttribute("align")) {
325
+ case "top":
326
+ case "text-top":
327
+ t.setValueOf("tab-properties", "align", "top");
328
+ break;
329
+ case "baseline":
330
+ case "bottom":
331
+ case "text-bottom":
332
+ t.setValueOf("tab-properties", "align", "bottom");
333
+ break;
334
+ case "left":
335
+ t.setValueOf("tab-properties", "align", "left");
336
+ break;
337
+ case "right":
338
+ t.setValueOf("tab-properties", "align", "right");
339
+ break;
340
+ }
341
+ }
342
+ t.selectPage("tab-properties");
343
+ }
344
+
345
+ },
346
+ onOk : function(){
347
+
348
+ /* Get image source */
349
+ var src = "";
350
+ try { src = CKEDITOR.document.getById(editor.id+"previewimage").$.src; } catch(e) { src = ""; }
351
+ if(typeof(src) != "string" || src == null || src === "") return;
352
+
353
+ /* selected image or new image */
354
+ if(selectedImg) var newImg = selectedImg; else var newImg = editor.document.createElement("img");
355
+ newImg.setAttribute("src", src);
356
+ src = null;
357
+
358
+ /* Set attributes */
359
+ newImg.setAttribute("alt", t.getValueOf("tab-properties", "alt").replace(/^\s+/, "").replace(/\s+$/, ""));
360
+ var attr = {
361
+ "width" : ["width", "width:#;", "integer", 1],
362
+ "height" : ["height", "height:#;", "integer", 1],
363
+ "vmargin" : ["vspace", "margin-top:#;margin-bottom:#;", "integer", 0],
364
+ "hmargin" : ["hspace", "margin-left:#;margin-right:#;", "integer", 0],
365
+ "align" : ["align", ""],
366
+ "border" : ["border", "border:# solid black;", "integer", 0]
367
+ }, css = [], value, cssvalue, attrvalue, k;
368
+ for(k in attr) {
369
+
370
+ value = t.getValueOf("tab-properties", k);
371
+ attrvalue = value;
372
+ cssvalue = value;
373
+ unit = "px";
374
+
375
+ if(k == "align") {
376
+ switch(value) {
377
+ case "top":
378
+ case "bottom":
379
+ attr[k][1] = "vertical-align:#;";
380
+ break;
381
+ case "left":
382
+ case "right":
383
+ attr[k][1] = "float:#;";
384
+ break;
385
+ default:
386
+ value = null;
387
+ break;
388
+ }
389
+ }
390
+
391
+ if(attr[k][2] == "integer") {
392
+ if(value.indexOf("%") >= 0) unit = "%";
393
+ value = parseInt(value, 10);
394
+ if(isNaN(value)) value = null; else if(value < attr[k][3]) value = null;
395
+ if(value != null) {
396
+ if(unit == "%") {
397
+ attrvalue = value+"%";
398
+ cssvalue = value+"%";
399
+ } else {
400
+ attrvalue = value;
401
+ cssvalue = value+"px";
402
+ }
403
+ }
404
+ }
405
+
406
+ if(value != null) {
407
+ newImg.setAttribute(attr[k][0], attrvalue);
408
+ css.push(attr[k][1].replace(/#/g, cssvalue));
409
+ }
410
+
411
+ }
412
+ if(css.length > 0) newImg.setAttribute("style", css.join(""));
413
+
414
+ /* Insert new image */
415
+ if(!selectedImg) editor.insertElement(newImg);
416
+
417
+ /* Resize image */
418
+ if(editor.plugins.imageresize) editor.plugins.imageresize.resize(editor, newImg, 800, 800);
419
+
420
+ },
421
+
422
+ /* Dialog form */
423
+ contents: [
424
+ {
425
+ id: "tab-source",
426
+ label: editor.lang.common.generalTab,
427
+ elements: sourceElements
428
+ },
429
+ {
430
+ id: "tab-properties",
431
+ label: editor.lang.common.advancedTab,
432
+ elements: [
433
+ {
434
+ type: "text",
435
+ id: "alt",
436
+ label: editor.lang.base64image.alt
437
+ },
438
+ {
439
+ type: 'hbox',
440
+ widths: ["15%", "15%", "70%"],
441
+ children: [
442
+ {
443
+ type: "text",
444
+ width: "45px",
445
+ id: "width",
446
+ label: editor.lang.common.width
447
+ },
448
+ {
449
+ type: "text",
450
+ width: "45px",
451
+ id: "height",
452
+ label: editor.lang.common.height
453
+ },
454
+ {
455
+ type: "checkbox",
456
+ id: "lock",
457
+ label: editor.lang.base64image.lockRatio,
458
+ style: "margin-top:18px;"
459
+ }
460
+ ]
461
+ },
462
+ {
463
+ type: 'hbox',
464
+ widths: ["23%", "30%", "30%", "17%"],
465
+ style: "margin-top:10px;",
466
+ children: [
467
+ {
468
+ type: "select",
469
+ id: "align",
470
+ label: editor.lang.common.align,
471
+ items: [
472
+ [editor.lang.common.notSet, "none"],
473
+ [editor.lang.common.alignTop, "top"],
474
+ [editor.lang.common.alignBottom, "bottom"],
475
+ [editor.lang.common.alignLeft, "left"],
476
+ [editor.lang.common.alignRight, "right"]
477
+ ]
478
+ },
479
+ {
480
+ type: "text",
481
+ width: "45px",
482
+ id: "vmargin",
483
+ label: editor.lang.base64image.vSpace
484
+ },
485
+ {
486
+ type: "text",
487
+ width: "45px",
488
+ id: "hmargin",
489
+ label: editor.lang.base64image.hSpace
490
+ },
491
+ {
492
+ type: "text",
493
+ width: "45px",
494
+ id: "border",
495
+ label: editor.lang.base64image.border
496
+ }
497
+ ]
498
+ }
499
+ ]
500
+ }
501
+ ]
502
+ };
503
+ });