runtastic-tiny_mce_curblyadvimage 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,499 @@
1
+ function select_image(element){
2
+ element = $(element);
3
+ element.up('ul').select('li').invoke("removeClassName", "selected");
4
+ element.up('li').addClassName('selected');
5
+ }
6
+
7
+ function select_thumb(element) {
8
+ element = $(element);
9
+ li = element.up('li');
10
+ src = element.getAttribute('href');
11
+ curbly_insert_image(src, element.getAttribute('alt') );
12
+ }
13
+
14
+ function upload_image_callback(url, alt_text, photo_id){
15
+ $('image_uploaded_data').clear();
16
+ new Ajax.Request("/manage_photos?photo_id="+photo_id, {asynchronous:true, evalScripts:true, method:'get'});
17
+ }
18
+
19
+ function curbly_insert_image(url, alt_text){
20
+ var formObj = formElement();
21
+ formObj.src.value = url;
22
+ formObj.alt.value = alt_text;
23
+ mcTabs.displayTab('general_tab','general_panel');
24
+ ImageDialog.showPreviewImage(url);
25
+ }
26
+ function formElement() {
27
+ return document.forms[1];
28
+ }
29
+ function ts_onload(){
30
+ $('dynamic_images_list').update("Uploading...<br /><img src='/images/spinner.gif'>");
31
+ mcTabs.displayTab('dynamic_select_tab','dynamic_select_panel');
32
+
33
+ var iframe1=ts_ce('iframe','html_editor_image_upload_frame');
34
+ iframe1.setAttribute('src','about:blank');
35
+ iframe1.style.border="0px none";
36
+ iframe1.style.position="absolute";
37
+ iframe1.style.width="1px";
38
+ iframe1.style.height="1px";
39
+ iframe1.style.visibility="hidden";
40
+ iframe1.setAttribute('id','html_editor_image_upload_frame');
41
+ $('image-upload').appendChild(iframe1);
42
+ $('image_upload_form').setAttribute("action", ts_upload_image_path());
43
+ }
44
+ function ts_upload_image_path() {
45
+ // path_prefix = window.parent.location.pathname.split("/")[1];
46
+ // to_path = "/" + path_prefix + "/photos.js";
47
+ // to_path = "/manage_photos.js";
48
+ // bugfix for runtastic-nginx-webserver which serves .js-files from public-folder - and doesn't route it to rails
49
+        return '/create_photo.rtjs';
50
+ }
51
+ function ts_ce(tag,name){
52
+ if (name && window.ActiveXObject){
53
+ element = document.createElement('<'+tag+' name="'+name+'">');
54
+ }else{
55
+ element = document.createElement(tag);
56
+ element.setAttribute('name',name);
57
+ }
58
+ return element;
59
+ }
60
+
61
+
62
+ var ImageDialog = {
63
+ preInit : function() {
64
+ var url;
65
+
66
+ tinyMCEPopup.requireLangPack();
67
+
68
+ if (url = tinyMCEPopup.getParam("external_image_list_url"))
69
+ document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
70
+ },
71
+
72
+ init : function(ed) {
73
+ var f = formElement(), nl = f.elements, ed = tinyMCEPopup.editor, dom = ed.dom, n = ed.selection.getNode();
74
+
75
+ tinyMCEPopup.resizeToInnerSize();
76
+ this.fillClassList('class_list');
77
+ this.fillFileList('src_list', 'tinyMCEImageList');
78
+ this.fillFileList('over_list', 'tinyMCEImageList');
79
+ this.fillFileList('out_list', 'tinyMCEImageList');
80
+
81
+ if (n.nodeName == 'IMG') {
82
+ nl.src.value = dom.getAttrib(n, 'src');
83
+ nl.width.value = dom.getAttrib(n, 'width');
84
+ nl.height.value = dom.getAttrib(n, 'height');
85
+ nl.alt.value = dom.getAttrib(n, 'alt');
86
+ nl.title.value = dom.getAttrib(n, 'title');
87
+ nl.vspace.value = this.getAttrib(n, 'vspace');
88
+ nl.hspace.value = this.getAttrib(n, 'hspace');
89
+ nl.border.value = this.getAttrib(n, 'border');
90
+ selectByValue(f, 'align', this.getAttrib(n, 'align'));
91
+ selectByValue(f, 'class_list', dom.getAttrib(n, 'class'));
92
+ nl.style.value = dom.getAttrib(n, 'style');
93
+ nl.id.value = dom.getAttrib(n, 'id');
94
+ nl.dir.value = dom.getAttrib(n, 'dir');
95
+ nl.lang.value = dom.getAttrib(n, 'lang');
96
+ nl.usemap.value = dom.getAttrib(n, 'usemap');
97
+ nl.longdesc.value = dom.getAttrib(n, 'longdesc');
98
+ nl.insert.value = ed.getLang('update');
99
+
100
+ if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseover')))
101
+ nl.onmouseoversrc.value = dom.getAttrib(n, 'onmouseover').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
102
+
103
+ if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseout')))
104
+ nl.onmouseoutsrc.value = dom.getAttrib(n, 'onmouseout').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
105
+
106
+ if (ed.settings.inline_styles) {
107
+ // Move attribs to styles
108
+ if (dom.getAttrib(n, 'align'))
109
+ this.updateStyle('align');
110
+
111
+ if (dom.getAttrib(n, 'hspace'))
112
+ this.updateStyle('hspace');
113
+
114
+ if (dom.getAttrib(n, 'border'))
115
+ this.updateStyle('border');
116
+
117
+ if (dom.getAttrib(n, 'vspace'))
118
+ this.updateStyle('vspace');
119
+ }
120
+ }
121
+
122
+ // Setup browse button
123
+ document.getElementById('srcbrowsercontainer').innerHTML = getBrowserHTML('srcbrowser','src','image','theme_advanced_image');
124
+ if (isVisible('srcbrowser'))
125
+ document.getElementById('src').style.width = '260px';
126
+
127
+ // Setup browse button
128
+ // document.getElementById('onmouseoversrccontainer').innerHTML = getBrowserHTML('overbrowser','onmouseoversrc','image','theme_advanced_image');
129
+ // if (isVisible('overbrowser'))
130
+ // document.getElementById('onmouseoversrc').style.width = '260px';
131
+ //
132
+ // // Setup browse button
133
+ // document.getElementById('onmouseoutsrccontainer').innerHTML = getBrowserHTML('outbrowser','onmouseoutsrc','image','theme_advanced_image');
134
+ // if (isVisible('outbrowser'))
135
+ // document.getElementById('onmouseoutsrc').style.width = '260px';
136
+
137
+ // If option enabled default contrain proportions to checked
138
+ if (ed.getParam("advimage_constrain_proportions", true))
139
+ f.constrain.checked = true;
140
+
141
+ // Check swap image if valid data
142
+ // if (nl.onmouseoversrc.value || nl.onmouseoutsrc.value)
143
+ // this.setSwapImage(true);
144
+ // else
145
+ // this.setSwapImage(false);
146
+
147
+ this.changeAppearance();
148
+ this.showPreviewImage(nl.src.value, 1);
149
+ },
150
+
151
+ insert : function(file, title) {
152
+ var ed = tinyMCEPopup.editor, t = this, f = formElement();
153
+
154
+ if (f.src.value === '') {
155
+ if (ed.selection.getNode().nodeName == 'IMG') {
156
+ ed.dom.remove(ed.selection.getNode());
157
+ ed.execCommand('mceRepaint');
158
+ }
159
+
160
+ tinyMCEPopup.close();
161
+ return;
162
+ }
163
+
164
+ if (tinyMCEPopup.getParam("accessibility_warnings", 1)) {
165
+ if (!f.alt.value) {
166
+ tinyMCEPopup.editor.windowManager.confirm(tinyMCEPopup.getLang('advimage_dlg.missing_alt'), function(s) {
167
+ if (s)
168
+ t.insertAndClose();
169
+ });
170
+
171
+ return;
172
+ }
173
+ }
174
+
175
+ t.insertAndClose();
176
+ },
177
+
178
+ insertAndClose : function() {
179
+ var ed = tinyMCEPopup.editor, f = formElement(), nl = f.elements, v, args = {}, el;
180
+
181
+ // Fixes crash in Safari
182
+ if (tinymce.isWebKit)
183
+ ed.getWin().focus();
184
+
185
+ if (!ed.settings.inline_styles) {
186
+ args = {
187
+ vspace : nl.vspace.value,
188
+ hspace : nl.hspace.value,
189
+ border : nl.border.value,
190
+ align : getSelectValue(f, 'align')
191
+ };
192
+ } else {
193
+ // Remove deprecated values
194
+ args = {
195
+ vspace : '',
196
+ hspace : '',
197
+ border : '',
198
+ align : ''
199
+ };
200
+ }
201
+
202
+ tinymce.extend(args, {
203
+ src : nl.src.value,
204
+ width : nl.width.value,
205
+ height : nl.height.value,
206
+ alt : nl.alt.value,
207
+ title : nl.title.value,
208
+ 'class' : getSelectValue(f, 'class_list'),
209
+ style : nl.style.value
210
+ // id : nl.id.value,
211
+ // dir : nl.dir.value,
212
+ // lang : nl.lang.value,
213
+ // usemap : nl.usemap.value,
214
+ // longdesc : nl.longdesc.value
215
+ });
216
+
217
+ // args.onmouseover = args.onmouseout = '';
218
+
219
+ // if (f.onmousemovecheck.checked) {
220
+ // if (nl.onmouseoversrc.value)
221
+ // args.onmouseover = "this.src='" + nl.onmouseoversrc.value + "';";
222
+ //
223
+ // if (nl.onmouseoutsrc.value)
224
+ // args.onmouseout = "this.src='" + nl.onmouseoutsrc.value + "';";
225
+ // }
226
+
227
+ el = ed.selection.getNode();
228
+
229
+ if (el && el.nodeName == 'IMG') {
230
+ ed.dom.setAttribs(el, args);
231
+ } else {
232
+ ed.execCommand('mceInsertContent', false, '<img id="__mce_tmp" src="javascript:;" />', {skip_undo : 1});
233
+ ed.dom.setAttribs('__mce_tmp', args);
234
+ ed.dom.setAttrib('__mce_tmp', 'id', '');
235
+ ed.undoManager.add();
236
+ }
237
+
238
+ tinyMCEPopup.close();
239
+ },
240
+
241
+ getAttrib : function(e, at) {
242
+ var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
243
+
244
+ if (ed.settings.inline_styles) {
245
+ switch (at) {
246
+ case 'align':
247
+ if (v = dom.getStyle(e, 'float'))
248
+ return v;
249
+
250
+ if (v = dom.getStyle(e, 'vertical-align'))
251
+ return v;
252
+
253
+ break;
254
+
255
+ case 'hspace':
256
+ v = dom.getStyle(e, 'margin-left')
257
+ v2 = dom.getStyle(e, 'margin-right');
258
+
259
+ if (v && v == v2)
260
+ return parseInt(v.replace(/[^0-9]/g, ''));
261
+
262
+ break;
263
+
264
+ case 'vspace':
265
+ v = dom.getStyle(e, 'margin-top')
266
+ v2 = dom.getStyle(e, 'margin-bottom');
267
+ if (v && v == v2)
268
+ return parseInt(v.replace(/[^0-9]/g, ''));
269
+
270
+ break;
271
+
272
+ case 'border':
273
+ v = 0;
274
+
275
+ tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
276
+ sv = dom.getStyle(e, 'border-' + sv + '-width');
277
+
278
+ // False or not the same as prev
279
+ if (!sv || (sv != v && v !== 0)) {
280
+ v = 0;
281
+ return false;
282
+ }
283
+
284
+ if (sv)
285
+ v = sv;
286
+ });
287
+
288
+ if (v)
289
+ return parseInt(v.replace(/[^0-9]/g, ''));
290
+
291
+ break;
292
+ }
293
+ }
294
+
295
+ if (v = dom.getAttrib(e, at))
296
+ return v;
297
+
298
+ return '';
299
+ },
300
+
301
+ setSwapImage : function(st) {
302
+ var f = formElement();
303
+
304
+ f.onmousemovecheck.checked = st;
305
+ setBrowserDisabled('overbrowser', !st);
306
+ setBrowserDisabled('outbrowser', !st);
307
+
308
+ if (f.over_list)
309
+ f.over_list.disabled = !st;
310
+
311
+ if (f.out_list)
312
+ f.out_list.disabled = !st;
313
+
314
+ f.onmouseoversrc.disabled = !st;
315
+ f.onmouseoutsrc.disabled = !st;
316
+ },
317
+
318
+ fillClassList : function(id) {
319
+ var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
320
+
321
+ if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
322
+ cl = [];
323
+
324
+ tinymce.each(v.split(';'), function(v) {
325
+ var p = v.split('=');
326
+
327
+ cl.push({'title' : p[0], 'class' : p[1]});
328
+ });
329
+ } else
330
+ cl = tinyMCEPopup.editor.dom.getClasses();
331
+
332
+ if (cl.length > 0) {
333
+ lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
334
+
335
+ tinymce.each(cl, function(o) {
336
+ lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
337
+ });
338
+ } else
339
+ dom.remove(dom.getParent(id, 'tr'));
340
+ },
341
+
342
+ fillFileList : function(id, l) {
343
+ var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
344
+
345
+ l = window[l];
346
+
347
+ if (l && l.length > 0) {
348
+ lst.options[lst.options.length] = new Option('', '');
349
+
350
+ tinymce.each(l, function(o) {
351
+ lst.options[lst.options.length] = new Option(o[0], o[1]);
352
+ });
353
+ } else
354
+ dom.remove(dom.getParent(id, 'tr'));
355
+ },
356
+
357
+ resetImageData : function() {
358
+ var f = formElement();
359
+
360
+ f.elements.width.value = f.elements.height.value = '';
361
+ },
362
+
363
+ updateImageData : function(img, st) {
364
+ var f = formElement();
365
+
366
+ if (!st) {
367
+ f.elements.width.value = img.width;
368
+ f.elements.height.value = img.height;
369
+ }
370
+
371
+ this.preloadImg = img;
372
+ },
373
+
374
+ changeAppearance : function() {
375
+ var ed = tinyMCEPopup.editor, f = formElement(), img = document.getElementById('alignSampleImg');
376
+
377
+ if (img) {
378
+ if (ed.getParam('inline_styles')) {
379
+ ed.dom.setAttrib(img, 'style', f.style.value);
380
+ } else {
381
+ img.align = f.align.value;
382
+ img.border = f.border.value;
383
+ img.hspace = f.hspace.value;
384
+ img.vspace = f.vspace.value;
385
+ }
386
+ }
387
+ },
388
+
389
+ changeHeight : function() {
390
+ var f = formElement(), tp, t = this;
391
+
392
+ if (!f.constrain.checked || !t.preloadImg) {
393
+ return;
394
+ }
395
+
396
+ if (f.width.value == "" || f.height.value == "")
397
+ return;
398
+
399
+ tp = (parseInt(f.width.value) / parseInt(t.preloadImg.width)) * t.preloadImg.height;
400
+ f.height.value = tp.toFixed(0);
401
+ },
402
+
403
+ changeWidth : function() {
404
+ var f = formElement(), tp, t = this;
405
+
406
+ if (!f.constrain.checked || !t.preloadImg) {
407
+ return;
408
+ }
409
+
410
+ if (f.width.value == "" || f.height.value == "")
411
+ return;
412
+
413
+ tp = (parseInt(f.height.value) / parseInt(t.preloadImg.height)) * t.preloadImg.width;
414
+ f.width.value = tp.toFixed(0);
415
+ },
416
+
417
+ updateStyle : function(ty) {
418
+ var dom = tinyMCEPopup.dom, st, v, f = formElement(), img = dom.create('img', {style : dom.get('style').value});
419
+
420
+ if (tinyMCEPopup.editor.settings.inline_styles) {
421
+ // Handle align
422
+ if (ty == 'align') {
423
+ dom.setStyle(img, 'float', '');
424
+ dom.setStyle(img, 'vertical-align', '');
425
+
426
+ v = getSelectValue(f, 'align');
427
+ if (v) {
428
+ if (v == 'left' || v == 'right')
429
+ dom.setStyle(img, 'float', v);
430
+ else
431
+ img.style.verticalAlign = v;
432
+ }
433
+ }
434
+
435
+ // Handle border
436
+ if (ty == 'border') {
437
+ dom.setStyle(img, 'border', '');
438
+
439
+ v = f.border.value;
440
+ if (v || v == '0') {
441
+ if (v == '0')
442
+ img.style.border = '';
443
+ else
444
+ img.style.border = v + 'px solid black';
445
+ }
446
+ }
447
+
448
+ // Handle hspace
449
+ if (ty == 'hspace') {
450
+ dom.setStyle(img, 'marginLeft', '');
451
+ dom.setStyle(img, 'marginRight', '');
452
+
453
+ v = f.hspace.value;
454
+ if (v) {
455
+ img.style.marginLeft = v + 'px';
456
+ img.style.marginRight = v + 'px';
457
+ }
458
+ }
459
+
460
+ // Handle vspace
461
+ if (ty == 'vspace') {
462
+ dom.setStyle(img, 'marginTop', '');
463
+ dom.setStyle(img, 'marginBottom', '');
464
+
465
+ v = f.vspace.value;
466
+ if (v) {
467
+ img.style.marginTop = v + 'px';
468
+ img.style.marginBottom = v + 'px';
469
+ }
470
+ }
471
+
472
+ // Merge
473
+ dom.get('style').value = dom.serializeStyle(dom.parseStyle(img.style.cssText));
474
+ }
475
+ },
476
+
477
+ changeMouseMove : function() {
478
+ },
479
+
480
+ showPreviewImage : function(u, st) {
481
+ if (!u) {
482
+ tinyMCEPopup.dom.setHTML('prev', '');
483
+ return;
484
+ }
485
+
486
+ if (!st && tinyMCEPopup.getParam("advimage_update_dimensions_onchange", true))
487
+ this.resetImageData();
488
+
489
+ u = tinyMCEPopup.editor.documentBaseURI.toAbsolute(u);
490
+
491
+ if (!st)
492
+ tinyMCEPopup.dom.setHTML('prev', '<img id="previewImg" src="' + u + '" border="0" onload="ImageDialog.updateImageData(this);" onerror="ImageDialog.resetImageData();" />');
493
+ else
494
+ tinyMCEPopup.dom.setHTML('prev', '<img id="previewImg" src="' + u + '" border="0" onload="ImageDialog.updateImageData(this, 1);" />');
495
+ }
496
+ };
497
+
498
+ ImageDialog.preInit();
499
+ tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);