hallo_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2810 @@
1
+ // Generated by CoffeeScript 1.3.3
2
+
3
+ /*
4
+ Hallo 1.0.1dev - a rich text editing jQuery UI widget
5
+ (c) 2011 Henri Bergius, IKS Consortium
6
+ Hallo may be freely distributed under the MIT license
7
+ http://hallojs.org
8
+ */
9
+
10
+
11
+ (function() {
12
+
13
+ (function(jQuery) {
14
+ return jQuery.widget('IKS.hallo', {
15
+ toolbar: null,
16
+ bound: false,
17
+ originalContent: '',
18
+ previousContent: '',
19
+ uuid: '',
20
+ selection: null,
21
+ _keepActivated: false,
22
+ originalHref: null,
23
+ options: {
24
+ editable: true,
25
+ plugins: {},
26
+ toolbar: 'halloToolbarContextual',
27
+ parentElement: 'body',
28
+ buttonCssClass: null,
29
+ toolbarCssClass: null,
30
+ toolbarPositionAbove: false,
31
+ placeholder: '',
32
+ forceStructured: true,
33
+ checkTouch: true,
34
+ touchScreen: null
35
+ },
36
+ _create: function() {
37
+ var options, plugin, _ref,
38
+ _this = this;
39
+ this.id = this._generateUUID();
40
+ if (this.options.checkTouch && this.options.touchScreen === null) {
41
+ this.checkTouch();
42
+ }
43
+ _ref = this.options.plugins;
44
+ for (plugin in _ref) {
45
+ options = _ref[plugin];
46
+ if (!jQuery.isPlainObject(options)) {
47
+ options = {};
48
+ }
49
+ jQuery.extend(options, {
50
+ editable: this,
51
+ uuid: this.id,
52
+ buttonCssClass: this.options.buttonCssClass
53
+ });
54
+ jQuery(this.element)[plugin](options);
55
+ }
56
+ this.element.one('halloactivated', function() {
57
+ return _this._prepareToolbar();
58
+ });
59
+ return this.originalContent = this.getContents();
60
+ },
61
+ _init: function() {
62
+ if (this.options.editable) {
63
+ return this.enable();
64
+ } else {
65
+ return this.disable();
66
+ }
67
+ },
68
+ destroy: function() {
69
+ var options, plugin, _ref;
70
+ this.disable();
71
+ if (this.toolbar) {
72
+ this.toolbar.remove();
73
+ this.element[this.options.toolbar]('destroy');
74
+ }
75
+ _ref = this.options.plugins;
76
+ for (plugin in _ref) {
77
+ options = _ref[plugin];
78
+ jQuery(this.element)[plugin]('destroy');
79
+ }
80
+ return jQuery.Widget.prototype.destroy.call(this);
81
+ },
82
+ disable: function() {
83
+ var _this = this;
84
+ this.element.attr("contentEditable", false);
85
+ this.element.unbind("focus", this._activated);
86
+ this.element.unbind("blur", this._deactivated);
87
+ this.element.unbind("keyup paste change", this._checkModified);
88
+ this.element.unbind("keyup", this._keys);
89
+ this.element.unbind("keyup mouseup", this._checkSelection);
90
+ this.bound = false;
91
+ jQuery(this.element).removeClass('isModified');
92
+ jQuery(this.element).removeClass('inEditMode');
93
+ this.element.parents('a').andSelf().each(function(idx, elem) {
94
+ var element;
95
+ element = jQuery(elem);
96
+ if (!element.is('a')) {
97
+ return;
98
+ }
99
+ if (!_this.originalHref) {
100
+ return;
101
+ }
102
+ return element.attr('href', _this.originalHref);
103
+ });
104
+ return this._trigger("disabled", null);
105
+ },
106
+ enable: function() {
107
+ var _this = this;
108
+ this.element.parents('a[href]').andSelf().each(function(idx, elem) {
109
+ var element;
110
+ element = jQuery(elem);
111
+ if (!element.is('a[href]')) {
112
+ return;
113
+ }
114
+ _this.originalHref = element.attr('href');
115
+ return element.removeAttr('href');
116
+ });
117
+ this.element.attr("contentEditable", true);
118
+ if (!this.element.html()) {
119
+ this.element.html(this.options.placeholder);
120
+ this.element.css({
121
+ 'min-width': this.element.innerWidth(),
122
+ 'min-height': this.element.innerHeight()
123
+ });
124
+ }
125
+ if (!this.bound) {
126
+ this.element.bind("focus", this, this._activated);
127
+ this.element.bind("blur", this, this._deactivated);
128
+ this.element.bind("keyup paste change", this, this._checkModified);
129
+ this.element.bind("keyup", this, this._keys);
130
+ this.element.bind("keyup mouseup", this, this._checkSelection);
131
+ this.bound = true;
132
+ }
133
+ if (this.options.forceStructured) {
134
+ this._forceStructured();
135
+ }
136
+ return this._trigger("enabled", null);
137
+ },
138
+ activate: function() {
139
+ return this.element.focus();
140
+ },
141
+ containsSelection: function() {
142
+ var range;
143
+ range = this.getSelection();
144
+ return this.element.has(range.startContainer).length > 0;
145
+ },
146
+ getSelection: function() {
147
+ var range, sel;
148
+ sel = rangy.getSelection();
149
+ range = null;
150
+ if (sel.rangeCount > 0) {
151
+ range = sel.getRangeAt(0);
152
+ } else {
153
+ range = rangy.createRange();
154
+ }
155
+ return range;
156
+ },
157
+ restoreSelection: function(range) {
158
+ var sel;
159
+ sel = rangy.getSelection();
160
+ return sel.setSingleRange(range);
161
+ },
162
+ replaceSelection: function(cb) {
163
+ var newTextNode, r, range, sel, t;
164
+ if (jQuery.browser.msie) {
165
+ t = document.selection.createRange().text;
166
+ r = document.selection.createRange();
167
+ return r.pasteHTML(cb(t));
168
+ } else {
169
+ sel = window.getSelection();
170
+ range = sel.getRangeAt(0);
171
+ newTextNode = document.createTextNode(cb(range.extractContents()));
172
+ range.insertNode(newTextNode);
173
+ range.setStartAfter(newTextNode);
174
+ sel.removeAllRanges();
175
+ return sel.addRange(range);
176
+ }
177
+ },
178
+ removeAllSelections: function() {
179
+ if (jQuery.browser.msie) {
180
+ return range.empty();
181
+ } else {
182
+ return window.getSelection().removeAllRanges();
183
+ }
184
+ },
185
+ getContents: function() {
186
+ var cleanup, contentClone, plugin;
187
+ contentClone = this.element.clone();
188
+ for (plugin in this.options.plugins) {
189
+ cleanup = jQuery(this.element).data(plugin).cleanupContentClone;
190
+ if (!jQuery.isFunction(cleanup)) {
191
+ continue;
192
+ }
193
+ jQuery(this.element)[plugin]('cleanupContentClone', contentClone);
194
+ }
195
+ return contentClone.html();
196
+ },
197
+ setContents: function(contents) {
198
+ return this.element.html(contents);
199
+ },
200
+ isModified: function() {
201
+ if (!this.previousContent) {
202
+ this.previousContent = this.originalContent;
203
+ }
204
+ return this.previousContent !== this.getContents();
205
+ },
206
+ setUnmodified: function() {
207
+ jQuery(this.element).removeClass('isModified');
208
+ return this.previousContent = this.getContents();
209
+ },
210
+ setModified: function() {
211
+ jQuery(this.element).addClass('isModified');
212
+ return this._trigger('modified', null, {
213
+ editable: this,
214
+ content: this.getContents()
215
+ });
216
+ },
217
+ restoreOriginalContent: function() {
218
+ return this.element.html(this.originalContent);
219
+ },
220
+ execute: function(command, value) {
221
+ if (document.execCommand(command, false, value)) {
222
+ return this.element.trigger("change");
223
+ }
224
+ },
225
+ protectFocusFrom: function(el) {
226
+ var _this = this;
227
+ return el.bind("mousedown", function(event) {
228
+ event.preventDefault();
229
+ _this._protectToolbarFocus = true;
230
+ return setTimeout(function() {
231
+ return _this._protectToolbarFocus = false;
232
+ }, 300);
233
+ });
234
+ },
235
+ keepActivated: function(_keepActivated) {
236
+ this._keepActivated = _keepActivated;
237
+ },
238
+ _generateUUID: function() {
239
+ var S4;
240
+ S4 = function() {
241
+ return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
242
+ };
243
+ return "" + (S4()) + (S4()) + "-" + (S4()) + "-" + (S4()) + "-" + (S4()) + "-" + (S4()) + (S4()) + (S4());
244
+ },
245
+ _prepareToolbar: function() {
246
+ var plugin, populate;
247
+ this.toolbar = jQuery('<div class="hallotoolbar"></div>').hide();
248
+ if (this.options.toolbarCssClass) {
249
+ this.toolbar.addClass(this.options.toolbarCssClass);
250
+ }
251
+ this.element[this.options.toolbar]({
252
+ editable: this,
253
+ parentElement: this.options.parentElement,
254
+ toolbar: this.toolbar,
255
+ positionAbove: this.options.toolbarPositionAbove
256
+ });
257
+ for (plugin in this.options.plugins) {
258
+ populate = jQuery(this.element).data(plugin).populateToolbar;
259
+ if (!jQuery.isFunction(populate)) {
260
+ continue;
261
+ }
262
+ this.element[plugin]('populateToolbar', this.toolbar);
263
+ }
264
+ this.element[this.options.toolbar]('setPosition');
265
+ return this.protectFocusFrom(this.toolbar);
266
+ },
267
+ changeToolbar: function(element, toolbar, hide) {
268
+ var originalToolbar;
269
+ if (hide == null) {
270
+ hide = false;
271
+ }
272
+ originalToolbar = this.options.toolbar;
273
+ this.options.parentElement = element;
274
+ if (toolbar) {
275
+ this.options.toolbar = toolbar;
276
+ }
277
+ if (!this.toolbar) {
278
+ return;
279
+ }
280
+ this.element[originalToolbar]('destroy');
281
+ this.toolbar.remove();
282
+ this._prepareToolbar();
283
+ if (hide) {
284
+ return this.toolbar.hide();
285
+ }
286
+ },
287
+ _checkModified: function(event) {
288
+ var widget;
289
+ widget = event.data;
290
+ if (widget.isModified()) {
291
+ return widget.setModified();
292
+ }
293
+ },
294
+ _keys: function(event) {
295
+ var old, widget;
296
+ widget = event.data;
297
+ if (event.keyCode === 27) {
298
+ old = widget.getContents();
299
+ widget.restoreOriginalContent(event);
300
+ widget._trigger("restored", null, {
301
+ editable: widget,
302
+ content: widget.getContents(),
303
+ thrown: old
304
+ });
305
+ return widget.turnOff();
306
+ }
307
+ },
308
+ _rangesEqual: function(r1, r2) {
309
+ if (r1.startContainer !== r2.startContainer) {
310
+ return false;
311
+ }
312
+ if (r1.startOffset !== r2.startOffset) {
313
+ return false;
314
+ }
315
+ if (r1.endContainer !== r2.endContainer) {
316
+ return false;
317
+ }
318
+ if (r1.endOffset !== r2.endOffset) {
319
+ return false;
320
+ }
321
+ return true;
322
+ },
323
+ _checkSelection: function(event) {
324
+ var widget;
325
+ if (event.keyCode === 27) {
326
+ return;
327
+ }
328
+ widget = event.data;
329
+ return setTimeout(function() {
330
+ var sel;
331
+ sel = widget.getSelection();
332
+ if (widget._isEmptySelection(sel) || widget._isEmptyRange(sel)) {
333
+ if (widget.selection) {
334
+ widget.selection = null;
335
+ widget._trigger("unselected", null, {
336
+ editable: widget,
337
+ originalEvent: event
338
+ });
339
+ return;
340
+ }
341
+ }
342
+ if (!widget.selection || !widget._rangesEqual(sel, widget.selection)) {
343
+ widget.selection = sel.cloneRange();
344
+ return widget._trigger("selected", null, {
345
+ editable: widget,
346
+ selection: widget.selection,
347
+ ranges: [widget.selection],
348
+ originalEvent: event
349
+ });
350
+ }
351
+ }, 0);
352
+ },
353
+ _isEmptySelection: function(selection) {
354
+ if (selection.type === "Caret") {
355
+ return true;
356
+ }
357
+ return false;
358
+ },
359
+ _isEmptyRange: function(range) {
360
+ if (range.collapsed) {
361
+ return true;
362
+ }
363
+ if (range.isCollapsed) {
364
+ if (typeof range.isCollapsed === 'function') {
365
+ return range.isCollapsed();
366
+ }
367
+ return range.isCollapsed;
368
+ }
369
+ return false;
370
+ },
371
+ turnOn: function() {
372
+ if (this.getContents() === this.options.placeholder) {
373
+ this.setContents('');
374
+ }
375
+ jQuery(this.element).addClass('inEditMode');
376
+ return this._trigger("activated", null, this);
377
+ },
378
+ turnOff: function() {
379
+ jQuery(this.element).removeClass('inEditMode');
380
+ this._trigger("deactivated", null, this);
381
+ if (!this.getContents()) {
382
+ return this.setContents(this.options.placeholder);
383
+ }
384
+ },
385
+ _activated: function(event) {
386
+ return event.data.turnOn();
387
+ },
388
+ _deactivated: function(event) {
389
+ if (event.data._keepActivated) {
390
+ return;
391
+ }
392
+ if (event.data._protectToolbarFocus !== true) {
393
+ return event.data.turnOff();
394
+ } else {
395
+ return setTimeout(function() {
396
+ return jQuery(event.data.element).focus();
397
+ }, 300);
398
+ }
399
+ },
400
+ _forceStructured: function(event) {
401
+ try {
402
+ return document.execCommand('styleWithCSS', 0, false);
403
+ } catch (e) {
404
+ try {
405
+ return document.execCommand('useCSS', 0, true);
406
+ } catch (e) {
407
+ try {
408
+ return document.execCommand('styleWithCSS', false, false);
409
+ } catch (e) {
410
+
411
+ }
412
+ }
413
+ }
414
+ },
415
+ checkTouch: function() {
416
+ return this.options.touchScreen = !!('createTouch' in document);
417
+ }
418
+ });
419
+ })(jQuery);
420
+
421
+ (function(jQuery) {
422
+ var z;
423
+ z = null;
424
+ if (this.VIE !== void 0) {
425
+ z = new VIE;
426
+ z.use(new z.StanbolService({
427
+ proxyDisabled: true,
428
+ url: 'http://dev.iks-project.eu:8081'
429
+ }));
430
+ }
431
+ return jQuery.widget('IKS.halloannotate', {
432
+ options: {
433
+ vie: z,
434
+ editable: null,
435
+ toolbar: null,
436
+ uuid: '',
437
+ select: function() {},
438
+ decline: function() {},
439
+ remove: function() {},
440
+ buttonCssClass: null
441
+ },
442
+ _create: function() {
443
+ var editableElement, turnOffAnnotate, widget;
444
+ widget = this;
445
+ if (this.options.vie === void 0) {
446
+ throw new Error('The halloannotate plugin requires VIE');
447
+ return;
448
+ }
449
+ if (typeof this.element.annotate !== 'function') {
450
+ throw new Error('The halloannotate plugin requires annotate.js');
451
+ return;
452
+ }
453
+ this.state = 'off';
454
+ this.instantiate();
455
+ turnOffAnnotate = function() {
456
+ var editable;
457
+ editable = this;
458
+ return jQuery(editable).halloannotate('turnOff');
459
+ };
460
+ editableElement = this.options.editable.element;
461
+ return editableElement.bind('hallodisabled', turnOffAnnotate);
462
+ },
463
+ populateToolbar: function(toolbar) {
464
+ var buttonHolder,
465
+ _this = this;
466
+ buttonHolder = jQuery("<span class=\"" + this.widgetName + "\"></span>");
467
+ this.button = buttonHolder.hallobutton({
468
+ label: 'Annotate',
469
+ icon: 'icon-tags',
470
+ editable: this.options.editable,
471
+ command: null,
472
+ uuid: this.options.uuid,
473
+ cssClass: this.options.buttonCssClass,
474
+ queryState: false
475
+ });
476
+ buttonHolder.bind('change', function(event) {
477
+ if (_this.state === "pending") {
478
+ return;
479
+ }
480
+ if (_this.state === "off") {
481
+ return _this.turnOn();
482
+ }
483
+ return _this.turnOff();
484
+ });
485
+ buttonHolder.buttonset();
486
+ return toolbar.append(this.button);
487
+ },
488
+ cleanupContentClone: function(el) {
489
+ if (this.state === 'on') {
490
+ return el.find(".entity:not([about])").each(function() {
491
+ return jQuery(this).replaceWith(jQuery(this).html());
492
+ });
493
+ }
494
+ },
495
+ instantiate: function() {
496
+ var widget;
497
+ widget = this;
498
+ return this.options.editable.element.annotate({
499
+ vie: this.options.vie,
500
+ debug: false,
501
+ showTooltip: true,
502
+ select: this.options.select,
503
+ remove: this.options.remove,
504
+ success: this.options.success,
505
+ error: this.options.error
506
+ }).bind('annotateselect', function(event, data) {
507
+ return widget.options.editable.setModified();
508
+ }).bind('annotateremove', function() {
509
+ return jQuery.noop();
510
+ });
511
+ },
512
+ turnPending: function() {
513
+ this.state = 'pending';
514
+ this.button.hallobutton('checked', false);
515
+ return this.button.hallobutton('disable');
516
+ },
517
+ turnOn: function() {
518
+ var widget,
519
+ _this = this;
520
+ this.turnPending();
521
+ widget = this;
522
+ try {
523
+ return this.options.editable.element.annotate('enable', function(success) {
524
+ if (!success) {
525
+ return;
526
+ }
527
+ _this.state = 'on';
528
+ _this.button.hallobutton('checked', true);
529
+ return _this.button.hallobutton('enable');
530
+ });
531
+ } catch (e) {
532
+ return alert(e);
533
+ }
534
+ },
535
+ turnOff: function() {
536
+ this.options.editable.element.annotate('disable');
537
+ this.state = 'off';
538
+ if (!this.button) {
539
+ return;
540
+ }
541
+ this.button.attr('checked', false);
542
+ this.button.find("label").removeClass("ui-state-clicked");
543
+ return this.button.button('refresh');
544
+ }
545
+ });
546
+ })(jQuery);
547
+
548
+ (function(jQuery) {
549
+ return jQuery.widget('IKS.halloblacklist', {
550
+ options: {
551
+ tags: []
552
+ },
553
+ _init: function() {
554
+ if (this.options.tags.indexOf('br') !== -1) {
555
+ return this.element.bind('keydown', function(event) {
556
+ if (event.originalEvent.keyCode === 13) {
557
+ return event.preventDefault();
558
+ }
559
+ });
560
+ }
561
+ },
562
+ cleanupContentClone: function(el) {
563
+ var tag, _i, _len, _ref, _results;
564
+ _ref = this.options.tags;
565
+ _results = [];
566
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
567
+ tag = _ref[_i];
568
+ _results.push(jQuery(tag, el).remove());
569
+ }
570
+ return _results;
571
+ }
572
+ });
573
+ })(jQuery);
574
+
575
+ (function(jQuery) {
576
+ return jQuery.widget('IKS.halloblock', {
577
+ options: {
578
+ editable: null,
579
+ toolbar: null,
580
+ uuid: '',
581
+ elements: ['h1', 'h2', 'h3', 'p', 'pre', 'blockquote'],
582
+ buttonCssClass: null
583
+ },
584
+ populateToolbar: function(toolbar) {
585
+ var buttonset, contentId, target;
586
+ buttonset = jQuery("<span class=\"" + this.widgetName + "\"></span>");
587
+ contentId = "" + this.options.uuid + "-" + this.widgetName + "-data";
588
+ target = this._prepareDropdown(contentId);
589
+ toolbar.append(buttonset);
590
+ buttonset.hallobuttonset();
591
+ buttonset.append(target);
592
+ return buttonset.append(this._prepareButton(target));
593
+ },
594
+ _prepareDropdown: function(contentId) {
595
+ var addElement, containingElement, contentArea, element, _i, _len, _ref,
596
+ _this = this;
597
+ contentArea = jQuery("<div id=\"" + contentId + "\"></div>");
598
+ containingElement = this.options.editable.element.get(0).tagName.toLowerCase();
599
+ addElement = function(element) {
600
+ var el, events, queryState;
601
+ el = jQuery("<button class='blockselector'> <" + element + " class=\"menu-item\">" + element + "</" + element + "> </button>");
602
+ if (containingElement === element) {
603
+ el.addClass('selected');
604
+ }
605
+ if (containingElement !== 'div') {
606
+ el.addClass('disabled');
607
+ }
608
+ el.bind('click', function() {
609
+ var tagName;
610
+ tagName = element.toUpperCase();
611
+ if (el.hasClass('disabled')) {
612
+ return;
613
+ }
614
+ if (jQuery.browser.msie) {
615
+ _this.options.editable.execute('FormatBlock', "<" + tagName + ">");
616
+ return;
617
+ }
618
+ return _this.options.editable.execute('formatBlock', tagName);
619
+ });
620
+ queryState = function(event) {
621
+ var block;
622
+ block = document.queryCommandValue('formatBlock');
623
+ if (block.toLowerCase() === element) {
624
+ el.addClass('selected');
625
+ return;
626
+ }
627
+ return el.removeClass('selected');
628
+ };
629
+ events = 'keyup paste change mouseup';
630
+ _this.options.editable.element.bind(events, queryState);
631
+ _this.options.editable.element.bind('halloenabled', function() {
632
+ return _this.options.editable.element.bind(events, queryState);
633
+ });
634
+ _this.options.editable.element.bind('hallodisabled', function() {
635
+ return _this.options.editable.element.unbind(events, queryState);
636
+ });
637
+ return el;
638
+ };
639
+ _ref = this.options.elements;
640
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
641
+ element = _ref[_i];
642
+ contentArea.append(addElement(element));
643
+ }
644
+ return contentArea;
645
+ },
646
+ _prepareButton: function(target) {
647
+ var buttonElement;
648
+ buttonElement = jQuery('<span></span>');
649
+ buttonElement.hallodropdownbutton({
650
+ uuid: this.options.uuid,
651
+ editable: this.options.editable,
652
+ label: 'block',
653
+ icon: 'icon-text-height',
654
+ target: target,
655
+ cssClass: this.options.buttonCssClass
656
+ });
657
+ return buttonElement;
658
+ }
659
+ });
660
+ })(jQuery);
661
+
662
+ (function(jQuery) {
663
+ return jQuery.widget("IKS.halloformat", {
664
+ options: {
665
+ editable: null,
666
+ uuid: '',
667
+ formattings: {
668
+ bold: true,
669
+ italic: true,
670
+ strikeThrough: false,
671
+ underline: false
672
+ },
673
+ buttonCssClass: null
674
+ },
675
+ populateToolbar: function(toolbar) {
676
+ var buttonize, buttonset, enabled, format, widget, _ref,
677
+ _this = this;
678
+ widget = this;
679
+ buttonset = jQuery("<span class=\"" + widget.widgetName + "\"></span>");
680
+ buttonize = function(format) {
681
+ var buttonHolder;
682
+ buttonHolder = jQuery('<span></span>');
683
+ buttonHolder.hallobutton({
684
+ label: format,
685
+ editable: _this.options.editable,
686
+ command: format,
687
+ uuid: _this.options.uuid,
688
+ cssClass: _this.options.buttonCssClass
689
+ });
690
+ return buttonset.append(buttonHolder);
691
+ };
692
+ _ref = this.options.formattings;
693
+ for (format in _ref) {
694
+ enabled = _ref[format];
695
+ if (!enabled) {
696
+ continue;
697
+ }
698
+ buttonize(format);
699
+ }
700
+ buttonset.hallobuttonset();
701
+ return toolbar.append(buttonset);
702
+ }
703
+ });
704
+ })(jQuery);
705
+
706
+ (function(jQuery) {
707
+ return jQuery.widget("IKS.halloheadings", {
708
+ options: {
709
+ editable: null,
710
+ toolbar: null,
711
+ uuid: "",
712
+ headers: [1, 2, 3]
713
+ },
714
+ populateToolbar: function(toolbar) {
715
+ var button, buttonize, buttonset, header, id, label, markup, widget, _i, _len, _ref,
716
+ _this = this;
717
+ widget = this;
718
+ buttonset = jQuery("<span class=\"" + widget.widgetName + "\"></span>");
719
+ id = "" + this.options.uuid + "-paragraph";
720
+ label = "P";
721
+ markup = "<input id=\"" + id + "\" type=\"radio\" name=\"" + widget.options.uuid + "-headings\"/> <label for=\"" + id + "\" class=\"p_button\">" + label + "</label>";
722
+ buttonset.append(jQuery(markup).button());
723
+ button = jQuery("#" + id, buttonset);
724
+ button.attr("hallo-command", "formatBlock");
725
+ button.bind("change", function(event) {
726
+ var cmd;
727
+ cmd = jQuery(this).attr("hallo-command");
728
+ return widget.options.editable.execute(cmd, "P");
729
+ });
730
+ buttonize = function(headerSize) {
731
+ var buttonMarkup;
732
+ label = "H" + headerSize;
733
+ id = "" + _this.options.uuid + "-" + headerSize;
734
+ buttonMarkup = "<input id=\"" + id + "\" type=\"radio\" name=\"" + widget.options.uuid + "-headings\"/> <label for=\"" + id + "\" class=\"h" + headerSize + "_button\">" + label + "</label>";
735
+ buttonset.append(jQuery(buttonMarkup).button());
736
+ button = jQuery("#" + id, buttonset);
737
+ button.attr("hallo-size", "H" + headerSize);
738
+ return button.bind("change", function(event) {
739
+ var size;
740
+ size = jQuery(this).attr("hallo-size");
741
+ return widget.options.editable.execute("formatBlock", size);
742
+ });
743
+ };
744
+ _ref = this.options.headers;
745
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
746
+ header = _ref[_i];
747
+ buttonize(header);
748
+ }
749
+ buttonset.buttonset();
750
+ this.element.bind("keyup paste change mouseup", function(event) {
751
+ var format, formatNumber, labelParent, matches, selectedButton;
752
+ try {
753
+ format = document.queryCommandValue("formatBlock").toUpperCase();
754
+ } catch (e) {
755
+ format = '';
756
+ }
757
+ if (format === "P") {
758
+ selectedButton = jQuery("#" + widget.options.uuid + "-paragraph");
759
+ } else if (matches = format.match(/\d/)) {
760
+ formatNumber = matches[0];
761
+ selectedButton = jQuery("#" + widget.options.uuid + "-" + formatNumber);
762
+ }
763
+ labelParent = jQuery(buttonset);
764
+ labelParent.children("input").attr("checked", false);
765
+ labelParent.children("label").removeClass("ui-state-clicked");
766
+ labelParent.children("input").button("widget").button("refresh");
767
+ if (selectedButton) {
768
+ selectedButton.attr("checked", true);
769
+ selectedButton.next("label").addClass("ui-state-clicked");
770
+ return selectedButton.button("refresh");
771
+ }
772
+ });
773
+ return toolbar.append(buttonset);
774
+ }
775
+ });
776
+ })(jQuery);
777
+
778
+ $.widget("ncri.hallohtml", {
779
+ options: {
780
+ editable: null,
781
+ toolbar: null,
782
+ uuid: "",
783
+ dialogOpts: {
784
+ autoOpen: false,
785
+ width: 600,
786
+ height: 'auto',
787
+ title: "Edit HTML",
788
+ modal: false,
789
+ resizable: true,
790
+ draggable: true,
791
+ dialogClass: 'htmledit-dialog'
792
+ },
793
+ dialog: null,
794
+ buttonCssClass: null,
795
+ button_label: 'Edit HTML'
796
+ },
797
+ populateToolbar: function($toolbar) {
798
+ var $buttonHolder, $buttonset, id, widget;
799
+ widget = this;
800
+ this.options.toolbar = $toolbar;
801
+ this.options.dialog = $("<div>").attr('id', "" + this.options.uuid + "-htmledit-dialog");
802
+ $buttonset = $("<span>").addClass(widget.widgetName);
803
+ id = "" + this.options.uuid + "-htmledit";
804
+ $buttonHolder = $('<span>');
805
+ $buttonHolder.hallobutton({
806
+ label: this.options.button_label,
807
+ icon: 'icon-list-alt',
808
+ editable: this.options.editable,
809
+ command: null,
810
+ queryState: false,
811
+ uuid: this.options.uuid,
812
+ cssClass: this.options.buttonCssClass
813
+ });
814
+ $buttonset.append($buttonHolder);
815
+ this.button = $buttonHolder;
816
+ this.button.click(function() {
817
+ if (widget.options.dialog.dialog("isOpen")) {
818
+ widget._closeDialog();
819
+ } else {
820
+ widget._openDialog();
821
+ }
822
+ return false;
823
+ });
824
+ this.options.editable.element.on("hallodeactivated", function() {
825
+ return widget._closeDialog();
826
+ });
827
+ $toolbar.append($buttonset);
828
+ return this.options.dialog.dialog(this.options.dialogOpts);
829
+ },
830
+ _openDialog: function() {
831
+ var $editableEl, html, widget, xposition, yposition,
832
+ _this = this;
833
+ widget = this;
834
+ $editableEl = $(this.options.editable.element);
835
+ xposition = $editableEl.offset().left + $editableEl.outerWidth() + 10;
836
+ yposition = this.options.toolbar.offset().top - $(document).scrollTop();
837
+ this.options.dialog.dialog("option", "position", [xposition, yposition]);
838
+ this.options.editable.keepActivated(true);
839
+ this.options.dialog.dialog("open");
840
+ this.options.dialog.bind('dialogclose', function() {
841
+ $('label', _this.button).removeClass('ui-state-active');
842
+ _this.options.editable.element.focus();
843
+ return _this.options.editable.keepActivated(false);
844
+ });
845
+ this.options.dialog.html($("<textarea>").addClass('html_source'));
846
+ html = this.options.editable.element.html();
847
+ this.options.dialog.children('.html_source').val(html);
848
+ this.options.dialog.prepend($('<button>Update</button>'));
849
+ return this.options.dialog.on('click', 'button', function() {
850
+ widget.options.editable.element.html(widget.options.dialog.children('.html_source').val());
851
+ widget.options.editable.element.trigger('change');
852
+ return false;
853
+ });
854
+ },
855
+ _closeDialog: function() {
856
+ return this.options.dialog.dialog("close");
857
+ }
858
+ });
859
+
860
+ (function(jQuery) {
861
+ return jQuery.widget('IKS.halloimagecurrent', {
862
+ options: {
863
+ imageWidget: null,
864
+ startPlace: '',
865
+ draggables: [],
866
+ maxWidth: 400,
867
+ maxHeight: 200
868
+ },
869
+ _create: function() {
870
+ this.element.html('<div>\
871
+ <div class="activeImageContainer">\
872
+ <div class="rotationWrapper">\
873
+ <div class="hintArrow"></div>\
874
+ <img src="" class="activeImage" />\
875
+ </div>\
876
+ <img src="" class="activeImage activeImageBg" />\
877
+ </div>\
878
+ </div>');
879
+ this.element.hide();
880
+ return this._prepareDnD();
881
+ },
882
+ _init: function() {
883
+ var editable, widget;
884
+ editable = jQuery(this.options.editable.element);
885
+ widget = this;
886
+ jQuery('img', editable).each(function(index, elem) {
887
+ return widget._initDraggable(elem, editable);
888
+ });
889
+ return jQuery('p', editable).each(function(index, elem) {
890
+ if (jQuery(elem).data('jquery_droppable_initialized')) {
891
+ return;
892
+ }
893
+ jQuery(elem).droppable({
894
+ tolerance: 'pointer',
895
+ drop: function(event, ui) {
896
+ return widget._handleDropEvent(event, ui);
897
+ },
898
+ over: function(event, ui) {
899
+ return widget._handleOverEvent(event, ui);
900
+ },
901
+ out: function(event, ui) {
902
+ return widget._handleLeaveEvent(event, ui);
903
+ }
904
+ });
905
+ return jQuery(elem).data('jquery_droppable_initialized', true);
906
+ });
907
+ },
908
+ _prepareDnD: function() {
909
+ var editable, overlayMiddleConfig, widget;
910
+ widget = this;
911
+ editable = jQuery(this.options.editable.element);
912
+ this.options.offset = editable.offset();
913
+ this.options.third = parseFloat(editable.width() / 3);
914
+ overlayMiddleConfig = {
915
+ width: this.options.third,
916
+ height: editable.height()
917
+ };
918
+ this.overlay = {
919
+ big: jQuery("<div/>").addClass("bigOverlay").css({
920
+ width: this.options.third * 2,
921
+ height: editable.height()
922
+ }),
923
+ left: jQuery("<div/>").addClass("smallOverlay smallOverlayLeft"),
924
+ right: jQuery("<div/>").addClass("smallOverlay smallOverlayRight")
925
+ };
926
+ this.overlay.left.css(overlayMiddleConfig);
927
+ this.overlay.right.css(overlayMiddleConfig).css("left", this.options.third * 2);
928
+ editable.bind('halloactivated', function() {
929
+ return widget._enableDragging();
930
+ });
931
+ return editable.bind('hallodeactivated', function() {
932
+ return widget._disableDragging();
933
+ });
934
+ },
935
+ setImage: function(image) {
936
+ if (!image) {
937
+ return;
938
+ }
939
+ this.element.show();
940
+ jQuery('.activeImage', this.element).attr('src', image.url);
941
+ if (image.label) {
942
+ jQuery('input', this.element).val(image.label);
943
+ }
944
+ return this._initImage(jQuery(this.options.editable.element));
945
+ },
946
+ _delayAction: function(functionToCall, delay) {
947
+ var timer;
948
+ timer = clearTimeout(timer);
949
+ if (!timer) {
950
+ return timer = setTimeout(functionToCall, delay);
951
+ }
952
+ },
953
+ _calcDropPosition: function(offset, event) {
954
+ var position, rightTreshold;
955
+ position = offset.left + this.options.third;
956
+ rightTreshold = offset.left + this.options.third * 2;
957
+ if (event.pageX >= position && event.pageX <= rightTreshold) {
958
+ return 'middle';
959
+ } else if (event.pageX < position) {
960
+ return 'left';
961
+ } else if (event.pageX > rightTreshold) {
962
+ return 'right';
963
+ }
964
+ },
965
+ _createInsertElement: function(image, tmp) {
966
+ var imageInsert, tmpImg;
967
+ imageInsert = jQuery('<img>');
968
+ tmpImg = new Image();
969
+ jQuery(tmpImg).bind('load', function() {});
970
+ tmpImg.src = image.src;
971
+ imageInsert.attr({
972
+ src: tmpImg.src,
973
+ alt: !tmp ? jQuery(image).attr('alt') : void 0,
974
+ "class": tmp ? 'halloTmp' : 'imageInText'
975
+ });
976
+ imageInsert.show();
977
+ return imageInsert;
978
+ },
979
+ _createLineFeedbackElement: function() {
980
+ return jQuery('<div/>').addClass('halloTmpLine');
981
+ },
982
+ _removeFeedbackElements: function() {
983
+ this.overlay.big.remove();
984
+ this.overlay.left.remove();
985
+ this.overlay.right.remove();
986
+ return jQuery('.halloTmp, .halloTmpLine', this.options.editable.element).remove();
987
+ },
988
+ _removeCustomHelper: function() {
989
+ return jQuery('.customHelper').remove();
990
+ },
991
+ _showOverlay: function(position) {
992
+ var eHeight, editable;
993
+ editable = jQuery(this.options.editable.element);
994
+ eHeight = editable.height();
995
+ eHeight += parseFloat(editable.css('paddingTop'));
996
+ eHeight += parseFloat(editable.css('paddingBottom'));
997
+ this.overlay.big.css({
998
+ height: eHeight
999
+ });
1000
+ this.overlay.left.css({
1001
+ height: eHeight
1002
+ });
1003
+ this.overlay.right.css({
1004
+ height: eHeight
1005
+ });
1006
+ switch (position) {
1007
+ case 'left':
1008
+ this.overlay.big.addClass("bigOverlayLeft");
1009
+ this.overlay.big.removeClass("bigOverlayRight");
1010
+ this.overlay.big.css({
1011
+ left: this.options.third
1012
+ });
1013
+ this.overlay.big.show();
1014
+ this.overlay.left.hide();
1015
+ return this.overlay.right.hide();
1016
+ case 'middle':
1017
+ this.overlay.big.removeClass("bigOverlayLeft bigOverlayRight");
1018
+ this.overlay.big.hide();
1019
+ this.overlay.left.show();
1020
+ return this.overlay.right.show();
1021
+ case 'right':
1022
+ this.overlay.big.addClass("bigOverlayRight");
1023
+ this.overlay.big.removeClass("bigOverlayLeft");
1024
+ this.overlay.big.css({
1025
+ left: 0
1026
+ });
1027
+ this.overlay.big.show();
1028
+ this.overlay.left.hide();
1029
+ return this.overlay.right.hide();
1030
+ }
1031
+ },
1032
+ _checkOrigin: function(event) {
1033
+ if (jQuery(event.target).parents("[contenteditable]").length !== 0) {
1034
+ return true;
1035
+ }
1036
+ return false;
1037
+ },
1038
+ _createFeedback: function(image, position) {
1039
+ var el;
1040
+ if (position === 'middle') {
1041
+ return this._createLineFeedbackElement();
1042
+ }
1043
+ el = this._createInsertElement(image, true);
1044
+ return el.addClass("inlineImage-" + position);
1045
+ },
1046
+ _handleOverEvent: function(event, ui) {
1047
+ var editable, postPone, widget;
1048
+ widget = this;
1049
+ editable = jQuery(this.options.editable);
1050
+ postPone = function() {
1051
+ var position, target;
1052
+ window.waitWithTrash = clearTimeout(window.waitWithTrash);
1053
+ position = widget._calcDropPosition(widget.options.offset, event);
1054
+ jQuery('.trashcan', ui.helper).remove();
1055
+ editable[0].element.append(widget.overlay.big);
1056
+ editable[0].element.append(widget.overlay.left);
1057
+ editable[0].element.append(widget.overlay.right);
1058
+ widget._removeFeedbackElements();
1059
+ target = jQuery(event.target);
1060
+ target.prepend(widget._createFeedback(ui.draggable[0], position));
1061
+ if (position === 'middle') {
1062
+ target.prepend(widget._createFeedback(ui.draggable[0], 'right'));
1063
+ jQuery('.halloTmp', event.target).hide();
1064
+ } else {
1065
+ target.prepend(widget._createFeedback(ui.draggable[0], 'middle'));
1066
+ jQuery('.halloTmpLine', event.target).hide();
1067
+ }
1068
+ return widget._showOverlay(position);
1069
+ };
1070
+ return setTimeout(postPone, 5);
1071
+ },
1072
+ _handleDragEvent: function(event, ui) {
1073
+ var position, tmpFeedbackLR, tmpFeedbackMiddle;
1074
+ position = this._calcDropPosition(this.options.offset, event);
1075
+ if (position === this._lastPositionDrag) {
1076
+ return;
1077
+ }
1078
+ this._lastPositionDrag = position;
1079
+ tmpFeedbackLR = jQuery('.halloTmp', this.options.editable.element);
1080
+ tmpFeedbackMiddle = jQuery('.halloTmpLine', this.options.editable.element);
1081
+ if (position === 'middle') {
1082
+ tmpFeedbackMiddle.show();
1083
+ tmpFeedbackLR.hide();
1084
+ } else {
1085
+ tmpFeedbackMiddle.hide();
1086
+ tmpFeedbackLR.removeClass('inlineImage-left inlineImage-right');
1087
+ tmpFeedbackLR.addClass("inlineImage-" + position);
1088
+ tmpFeedbackLR.show();
1089
+ }
1090
+ return this._showOverlay(position);
1091
+ },
1092
+ _handleLeaveEvent: function(event, ui) {
1093
+ var func;
1094
+ func = function() {
1095
+ if (!jQuery('div.trashcan', ui.helper).length) {
1096
+ jQuery(ui.helper).append(jQuery('<div class="trashcan"></div>'));
1097
+ return jQuery('.bigOverlay, .smallOverlay').remove();
1098
+ }
1099
+ };
1100
+ window.waitWithTrash = setTimeout(func, 200);
1101
+ return this._removeFeedbackElements();
1102
+ },
1103
+ _handleStartEvent: function(event, ui) {
1104
+ var internalDrop;
1105
+ internalDrop = this._checkOrigin(event);
1106
+ if (internalDrop) {
1107
+ jQuery(event.target).remove();
1108
+ }
1109
+ jQuery(document).trigger('startPreventSave');
1110
+ return this.options.startPlace = jQuery(event.target);
1111
+ },
1112
+ _handleStopEvent: function(event, ui) {
1113
+ var internalDrop;
1114
+ internalDrop = this._checkOrigin(event);
1115
+ if (internalDrop) {
1116
+ jQuery(event.target).remove();
1117
+ } else {
1118
+ jQuery(this.options.editable.element).trigger('change');
1119
+ }
1120
+ this.overlay.big.hide();
1121
+ this.overlay.left.hide();
1122
+ this.overlay.right.hide();
1123
+ return jQuery(document).trigger('stopPreventSave');
1124
+ },
1125
+ _handleDropEvent: function(event, ui) {
1126
+ var classes, editable, imageInsert, internalDrop, left, position;
1127
+ editable = jQuery(this.options.editable.element);
1128
+ internalDrop = this._checkOrigin(event);
1129
+ position = this._calcDropPosition(this.options.offset, event);
1130
+ this._removeFeedbackElements();
1131
+ this._removeCustomHelper();
1132
+ imageInsert = this._createInsertElement(ui.draggable[0], false);
1133
+ classes = 'inlineImage-middle inlineImage-left inlineImage-right';
1134
+ if (position === 'middle') {
1135
+ imageInsert.show();
1136
+ imageInsert.removeClass(classes);
1137
+ left = editable.width();
1138
+ left += parseFloat(editable.css('paddingLeft'));
1139
+ left += parseFloat(editable.css('paddingRight'));
1140
+ left -= imageInsert.attr('width');
1141
+ imageInsert.addClass("inlineImage-" + position).css({
1142
+ position: 'relative',
1143
+ left: left / 2
1144
+ });
1145
+ imageInsert.insertBefore(jQuery(event.target));
1146
+ } else {
1147
+ imageInsert.removeClass(classes);
1148
+ imageInsert.addClass("inlineImage-" + position);
1149
+ imageInsert.css('display', 'block');
1150
+ jQuery(event.target).prepend(imageInsert);
1151
+ }
1152
+ this.overlay.big.hide();
1153
+ this.overlay.left.hide();
1154
+ this.overlay.right.hide();
1155
+ editable.trigger('change');
1156
+ return this._initImage(editable);
1157
+ },
1158
+ _createHelper: function(event) {
1159
+ return jQuery('<div>').css({
1160
+ backgroundImage: "url(" + (jQuery(event.currentTarget).attr('src')) + ")"
1161
+ }).addClass('customHelper').appendTo('body');
1162
+ },
1163
+ _initDraggable: function(elem, editable) {
1164
+ var widget;
1165
+ widget = this;
1166
+ if (!elem.jquery_draggable_initialized) {
1167
+ elem.jquery_draggable_initialized = true;
1168
+ jQuery(elem).draggable({
1169
+ cursor: 'move',
1170
+ helper: function(event) {
1171
+ return widget._createHelper(event);
1172
+ },
1173
+ drag: function(event, ui) {
1174
+ return widget._handleDragEvent(event, ui);
1175
+ },
1176
+ start: function(event, ui) {
1177
+ return widget._handleStartEvent(event, ui);
1178
+ },
1179
+ stop: function(event, ui) {
1180
+ return widget._handleStopEvent(event, ui);
1181
+ },
1182
+ disabled: !editable.hasClass('inEditMode'),
1183
+ cursorAt: {
1184
+ top: 50,
1185
+ left: 50
1186
+ }
1187
+ });
1188
+ }
1189
+ return widget.options.draggables.push(elem);
1190
+ },
1191
+ _initImage: function(editable) {
1192
+ var widget;
1193
+ widget = this;
1194
+ return jQuery('.rotationWrapper img', this.options.dialog).each(function(index, elem) {
1195
+ return widget._initDraggable(elem, editable);
1196
+ });
1197
+ },
1198
+ _enableDragging: function() {
1199
+ return jQuery.each(this.options.draggables, function(index, d) {
1200
+ return jQuery(d).draggable('option', 'disabled', false);
1201
+ });
1202
+ },
1203
+ _disableDragging: function() {
1204
+ return jQuery.each(this.options.draggables, function(index, d) {
1205
+ return jQuery(d).draggable('option', 'disabled', true);
1206
+ });
1207
+ }
1208
+ });
1209
+ })(jQuery);
1210
+
1211
+ (function(jQuery) {
1212
+ return jQuery.widget('IKS.halloimagesearch', {
1213
+ options: {
1214
+ imageWidget: null,
1215
+ searchCallback: null,
1216
+ searchUrl: null,
1217
+ limit: 5
1218
+ },
1219
+ _create: function() {
1220
+ return this.element.html('<div>\
1221
+ <form method="get">\
1222
+ <input type="text" class="searchInput" placeholder="Search" />\
1223
+ <input type="submit" class="btn searchButton" value="OK" />\
1224
+ </form>\
1225
+ <div class="searchResults imageThumbnailContainer">\
1226
+ <div class="activitySpinner">Loading images...</div>\
1227
+ <ul></ul>\
1228
+ </div>\
1229
+ </div>');
1230
+ },
1231
+ _init: function() {
1232
+ var _this = this;
1233
+ if (this.options.searchUrl && !this.options.searchCallback) {
1234
+ this.options.searchCallback = this._ajaxSearch;
1235
+ }
1236
+ jQuery('.activitySpinner', this.element).hide();
1237
+ return jQuery('form', this.element).submit(function(event) {
1238
+ var query;
1239
+ event.preventDefault();
1240
+ jQuery('.activitySpinner', _this.element).show();
1241
+ query = jQuery('.searchInput', _this.element.element).val();
1242
+ return _this.options.searchCallback(query, _this.options.limit, 0, function(results) {
1243
+ return _this._showResults(results);
1244
+ });
1245
+ });
1246
+ },
1247
+ _showResult: function(image) {
1248
+ var html,
1249
+ _this = this;
1250
+ if (!image.label) {
1251
+ image.label = image.alt;
1252
+ }
1253
+ html = jQuery("<li> <img src=\"" + image.url + "\" class=\"imageThumbnail\" title=\"" + image.label + "\"></li>");
1254
+ html.bind('click', function() {
1255
+ return _this.options.imageWidget.setCurrent(image);
1256
+ });
1257
+ jQuery('img', html).bind('mousedown', function(event) {
1258
+ event.preventDefault();
1259
+ return _this.options.imageWidget.setCurrent(image);
1260
+ });
1261
+ return jQuery('.imageThumbnailContainer ul', this.element).append(html);
1262
+ },
1263
+ _showNextPrev: function(results) {
1264
+ var container,
1265
+ _this = this;
1266
+ container = jQuery('imageThumbnailContainer ul', this.element);
1267
+ container.prepend(jQuery('<div class="pager-prev" style="display:none" />'));
1268
+ container.append(jQuery('<div class="pager-next" style="display:none" />'));
1269
+ if (results.offset > 0) {
1270
+ jQuery('.pager-prev', container).show();
1271
+ }
1272
+ if (results.offset < results.total) {
1273
+ jQuery('.pager-next', container).show();
1274
+ }
1275
+ jQuery('.pager-prev', container).click(function(event) {
1276
+ var offset;
1277
+ offset = results.offset - _this.options.limit;
1278
+ return _this.options.searchCallback(query, _this.options.limit, offset, function(results) {
1279
+ return _this._showResults(results);
1280
+ });
1281
+ });
1282
+ return jQuery('.pager-next', container).click(function(event) {
1283
+ var offset;
1284
+ offset = results.offset + _this.options.limit;
1285
+ return _this.options.searchCallback(query, _this.options.limit, offset, function(results) {
1286
+ return _this._showResults(results);
1287
+ });
1288
+ });
1289
+ },
1290
+ _showResults: function(results) {
1291
+ var image, _i, _len, _ref;
1292
+ jQuery('.activitySpinner', this.element).hide();
1293
+ jQuery('.imageThumbnailContainer ul', this.element).empty();
1294
+ jQuery('.imageThumbnailContainer ul', this.element).show();
1295
+ _ref = results.assets;
1296
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1297
+ image = _ref[_i];
1298
+ this._showResult(image);
1299
+ }
1300
+ this.options.imageWidget.setCurrent(results.assets.shift());
1301
+ return this._showNextPrev(results);
1302
+ },
1303
+ _ajaxSearch: function(query, limit, offset, success) {
1304
+ var searchUrl;
1305
+ searchUrl = this.searchUrl + '?' + jQuery.param({
1306
+ q: query,
1307
+ limit: limit,
1308
+ offset: offset
1309
+ });
1310
+ return jQuery.getJSON(searchUrl, success);
1311
+ }
1312
+ });
1313
+ })(jQuery);
1314
+
1315
+ (function(jQuery) {
1316
+ return jQuery.widget('IKS.halloimagesuggestions', {
1317
+ loaded: false,
1318
+ options: {
1319
+ entity: null,
1320
+ vie: null,
1321
+ dbPediaUrl: null,
1322
+ getSuggestions: null,
1323
+ thumbnailUri: '<http://dbpedia.org/ontology/thumbnail>'
1324
+ },
1325
+ _create: function() {
1326
+ return this.element.html('\
1327
+ <div id="' + this.options.uuid + '-tab-suggestions">\
1328
+ <div class="imageThumbnailContainer">\
1329
+ <div class="activitySpinner">Loading images...</div>\
1330
+ <ul></ul>\
1331
+ </div>\
1332
+ </div>');
1333
+ },
1334
+ _init: function() {
1335
+ return jQuery('.activitySpinner', this.element).hide();
1336
+ },
1337
+ _normalizeRelated: function(related) {
1338
+ if (_.isString(related)) {
1339
+ return related;
1340
+ }
1341
+ if (_.isArray(related)) {
1342
+ return related.join(',');
1343
+ }
1344
+ return related.pluck('@subject').join(',');
1345
+ },
1346
+ _prepareVIE: function() {
1347
+ if (!this.options.vie) {
1348
+ this.options.vie = new VIE;
1349
+ }
1350
+ if (this.options.vie.services.dbpedia) {
1351
+ return;
1352
+ }
1353
+ if (!this.options.dbPediaUrl) {
1354
+ return;
1355
+ }
1356
+ return this.options.vie.use(new vie.DBPediaService({
1357
+ url: this.options.dbPediaUrl,
1358
+ proxyDisabled: true
1359
+ }));
1360
+ },
1361
+ _getSuggestions: function() {
1362
+ var limit, normalizedTags, tags;
1363
+ if (this.loaded) {
1364
+ return;
1365
+ }
1366
+ if (!this.options.entity) {
1367
+ return;
1368
+ }
1369
+ jQuery('.activitySpinner', this.element).show();
1370
+ tags = this.options.entity.get('skos:related');
1371
+ if (tags.length === 0) {
1372
+ jQuery("#activitySpinner").html('No images found.');
1373
+ return;
1374
+ }
1375
+ jQuery('.imageThumbnailContainer ul', this.element).empty();
1376
+ normalizedTags = this._normalizeRelated(tags);
1377
+ limit = this.options.limit;
1378
+ if (this.options.getSuggestions) {
1379
+ this.options.getSuggestions(normalizedTags, limit, 0, this._showSuggestions);
1380
+ }
1381
+ this._prepareVIE();
1382
+ if (this.options.vie.services.dbpedia) {
1383
+ this._getSuggestionsDbPedia(tags);
1384
+ }
1385
+ return this.loaded = true;
1386
+ },
1387
+ _getSuggestionsDbPedia: function(tags) {
1388
+ var thumbId, widget;
1389
+ widget = this;
1390
+ thumbId = 1;
1391
+ return _.each(tags, function(tag) {
1392
+ return vie.load({
1393
+ entity: tag
1394
+ }).using('dbpedia').execute().done(function(entities) {
1395
+ jQuery('.activitySpinner', this.element).hide();
1396
+ return _.each(entities, function(entity) {
1397
+ var img, thumbnail;
1398
+ thumbnail = entity.attributes[widget.options.thumbnailUri];
1399
+ if (!thumbnail) {
1400
+ return;
1401
+ }
1402
+ if (_.isObject(thumbnail)) {
1403
+ img = thumbnail[0].value;
1404
+ }
1405
+ if (_.isString(thumbnail)) {
1406
+ img = widget.options.entity.fromReference(thumbnail);
1407
+ }
1408
+ return widget._showSuggestion({
1409
+ url: img,
1410
+ label: tag
1411
+ });
1412
+ });
1413
+ });
1414
+ });
1415
+ },
1416
+ _showSuggestion: function(image) {
1417
+ var html,
1418
+ _this = this;
1419
+ html = jQuery("<li> <img src=\"" + image.url + "\" class=\"imageThumbnail\" title=\"" + image.label + "\"> </li>");
1420
+ html.bind('click', function() {
1421
+ return _this.options.imageWidget.setCurrent(image);
1422
+ });
1423
+ return jQuery('.imageThumbnailContainer ul', this.element).append(html);
1424
+ },
1425
+ _showSuggestions: function(suggestions) {
1426
+ var _this = this;
1427
+ jQuery('.activitySpinner', this.element).hide();
1428
+ return _.each(suggestions, function(image) {
1429
+ return _this._showSuggestion(image);
1430
+ });
1431
+ }
1432
+ });
1433
+ })(jQuery);
1434
+
1435
+ (function(jQuery) {
1436
+ return jQuery.widget('IKS.halloimageupload', {
1437
+ options: {
1438
+ uploadCallback: null,
1439
+ uploadUrl: null,
1440
+ imageWidget: null,
1441
+ entity: null
1442
+ },
1443
+ _create: function() {
1444
+ return this.element.html('\
1445
+ <form class="upload">\
1446
+ <input type="file" class="file" name="userfile" accept="image/*" />\
1447
+ <input type="hidden" name="tags" value="" />\
1448
+ <input type="text" class="caption" name="caption" placeholder="Title" />\
1449
+ <button class="uploadSubmit">Upload</button>\
1450
+ </form>\
1451
+ ');
1452
+ },
1453
+ _init: function() {
1454
+ var widget;
1455
+ widget = this;
1456
+ if (widget.options.uploadUrl && !widget.options.uploadCallback) {
1457
+ widget.options.uploadCallback = widget._iframeUpload;
1458
+ }
1459
+ return jQuery('.uploadSubmit', this.element).bind('click', function(event) {
1460
+ event.preventDefault();
1461
+ event.stopPropagation();
1462
+ return widget.options.uploadCallback({
1463
+ widget: widget,
1464
+ success: function(url) {
1465
+ return widget.options.imageWidget.setCurrent({
1466
+ url: url,
1467
+ label: ''
1468
+ });
1469
+ }
1470
+ });
1471
+ });
1472
+ },
1473
+ _prepareIframe: function(widget) {
1474
+ var iframe, iframeName;
1475
+ iframeName = "" + widget.widgetName + "_postframe_" + widget.options.uuid;
1476
+ iframeName = iframeName.replace(/-/g, '_');
1477
+ iframe = jQuery("#" + iframeName);
1478
+ if (iframe.length) {
1479
+ return iframe;
1480
+ }
1481
+ iframe = jQuery("<iframe name=\"" + iframeName + "\" id=\"" + iframeName + "\" class=\"hidden\" style=\"display:none\" />");
1482
+ this.element.append(iframe);
1483
+ iframe.get(0).name = iframeName;
1484
+ return iframe;
1485
+ },
1486
+ _iframeUpload: function(data) {
1487
+ var iframe, uploadForm, uploadUrl, widget;
1488
+ widget = data.widget;
1489
+ iframe = widget._prepareIframe(widget);
1490
+ uploadForm = jQuery('form.upload', widget.element);
1491
+ if (typeof widget.options.uploadUrl === 'function') {
1492
+ uploadUrl = widget.options.uploadUrl(widget.options.entity);
1493
+ } else {
1494
+ uploadUrl = widget.options.uploadUrl;
1495
+ }
1496
+ iframe.bind('load', function() {
1497
+ var imageUrl;
1498
+ imageUrl = iframe.get(0).contentWindow.location.href;
1499
+ widget.element.hide();
1500
+ return data.success(imageUrl);
1501
+ });
1502
+ uploadForm.attr('action', uploadUrl);
1503
+ uploadForm.attr('method', 'post');
1504
+ uploadForm.attr('target', iframe.get(0).name);
1505
+ uploadForm.attr('enctype', 'multipart/form-data');
1506
+ uploadForm.attr('encoding', 'multipart/form-data');
1507
+ return uploadForm.submit();
1508
+ }
1509
+ });
1510
+ })(jQuery);
1511
+
1512
+ (function(jQuery) {
1513
+ return jQuery.widget("Liip.halloimage", {
1514
+ options: {
1515
+ editable: null,
1516
+ toolbar: null,
1517
+ uuid: "",
1518
+ limit: 8,
1519
+ search: null,
1520
+ searchUrl: null,
1521
+ suggestions: null,
1522
+ loaded: null,
1523
+ upload: null,
1524
+ uploadUrl: null,
1525
+ dialogOpts: {
1526
+ autoOpen: false,
1527
+ width: 270,
1528
+ height: "auto",
1529
+ title: "Insert Images",
1530
+ modal: false,
1531
+ resizable: false,
1532
+ draggable: true,
1533
+ dialogClass: 'halloimage-dialog'
1534
+ },
1535
+ dialog: null,
1536
+ buttonCssClass: null,
1537
+ entity: null,
1538
+ vie: null,
1539
+ dbPediaUrl: "http://dev.iks-project.eu/stanbolfull",
1540
+ maxWidth: 250,
1541
+ maxHeight: 250
1542
+ },
1543
+ populateToolbar: function(toolbar) {
1544
+ var buttonHolder, buttonset, dialogId, id, tabContent, tabs, widget;
1545
+ this.options.toolbar = toolbar;
1546
+ widget = this;
1547
+ dialogId = "" + this.options.uuid + "-image-dialog";
1548
+ this.options.dialog = jQuery("<div id=\"" + dialogId + "\"> <div class=\"nav\"> <ul class=\"tabs\"> </ul> <div id=\"" + this.options.uuid + "-tab-activeIndicator\" class=\"tab-activeIndicator\" /> </div> <div class=\"dialogcontent\"> </div>");
1549
+ tabs = jQuery('.tabs', this.options.dialog);
1550
+ tabContent = jQuery('.dialogcontent', this.options.dialog);
1551
+ if (widget.options.suggestions) {
1552
+ this._addGuiTabSuggestions(tabs, tabContent);
1553
+ }
1554
+ if (widget.options.search || widget.options.searchUrl) {
1555
+ this._addGuiTabSearch(tabs, tabContent);
1556
+ }
1557
+ if (widget.options.upload || widget.options.uploadUrl) {
1558
+ this._addGuiTabUpload(tabs, tabContent);
1559
+ }
1560
+ this.current = jQuery('<div class="currentImage"></div>').halloimagecurrent({
1561
+ uuid: this.options.uuid,
1562
+ imageWidget: this,
1563
+ editable: this.options.editable,
1564
+ dialog: this.options.dialog,
1565
+ maxWidth: this.options.maxWidth,
1566
+ maxHeight: this.options.maxHeight
1567
+ });
1568
+ jQuery('.dialogcontent', this.options.dialog).append(this.current);
1569
+ buttonset = jQuery("<span class=\"" + widget.widgetName + "\"></span>");
1570
+ id = "" + this.options.uuid + "-image";
1571
+ buttonHolder = jQuery('<span></span>');
1572
+ buttonHolder.hallobutton({
1573
+ label: 'Images',
1574
+ icon: 'icon-picture',
1575
+ editable: this.options.editable,
1576
+ command: null,
1577
+ queryState: false,
1578
+ uuid: this.options.uuid,
1579
+ cssClass: this.options.buttonCssClass
1580
+ });
1581
+ buttonset.append(buttonHolder);
1582
+ this.button = buttonHolder;
1583
+ this.button.bind("click", function(event) {
1584
+ if (widget.options.dialog.dialog("isOpen")) {
1585
+ widget._closeDialog();
1586
+ } else {
1587
+ widget._openDialog();
1588
+ }
1589
+ return false;
1590
+ });
1591
+ this.options.editable.element.bind("hallodeactivated", function(event) {
1592
+ return widget._closeDialog();
1593
+ });
1594
+ jQuery(this.options.editable.element).delegate("img", "click", function(event) {
1595
+ return widget._openDialog();
1596
+ });
1597
+ toolbar.append(buttonset);
1598
+ this.options.dialog.dialog(this.options.dialogOpts);
1599
+ return this._handleTabs();
1600
+ },
1601
+ setCurrent: function(image) {
1602
+ return this.current.halloimagecurrent('setImage', image);
1603
+ },
1604
+ _handleTabs: function() {
1605
+ var widget;
1606
+ widget = this;
1607
+ jQuery('.nav li', this.options.dialog).bind('click', function() {
1608
+ var id, left;
1609
+ jQuery("." + widget.widgetName + "-tab").hide();
1610
+ id = jQuery(this).attr('id');
1611
+ jQuery("#" + id + "-content").show();
1612
+ left = jQuery(this).position().left + (jQuery(this).width() / 2);
1613
+ return jQuery("#" + widget.options.uuid + "-tab-activeIndicator").css({
1614
+ "margin-left": left
1615
+ });
1616
+ });
1617
+ return jQuery('.nav li', this.options.dialog).first().click();
1618
+ },
1619
+ _openDialog: function() {
1620
+ var cleanUp, editableEl, getActive, suggestionSelector, toolbarEl, widget, xposition, yposition,
1621
+ _this = this;
1622
+ widget = this;
1623
+ cleanUp = function() {
1624
+ return window.setTimeout(function() {
1625
+ var thumbnails;
1626
+ thumbnails = jQuery(".imageThumbnail");
1627
+ return jQuery(thumbnails).each(function() {
1628
+ var size;
1629
+ size = jQuery("#" + this.id).width();
1630
+ if (size <= 20) {
1631
+ return jQuery("#" + this.id).parent("li").remove();
1632
+ }
1633
+ });
1634
+ }, 15000);
1635
+ };
1636
+ suggestionSelector = "#" + this.options.uuid + "-tab-suggestions-content";
1637
+ getActive = function() {
1638
+ return jQuery('.imageThumbnailActive', suggestionSelector).first().attr("src");
1639
+ };
1640
+ jQuery("#" + this.options.uuid + "-sugg-activeImage").attr("src", getActive());
1641
+ jQuery("#" + this.options.uuid + "-sugg-activeImageBg").attr("src", getActive());
1642
+ this.lastSelection = this.options.editable.getSelection();
1643
+ editableEl = jQuery(this.options.editable.element);
1644
+ toolbarEl = jQuery(this.options.toolbar);
1645
+ xposition = editableEl.offset().left + editableEl.outerWidth() - 3;
1646
+ yposition = toolbarEl.offset().top - jQuery(document).scrollTop() - 29;
1647
+ this.options.dialog.dialog("option", "position", [xposition, yposition]);
1648
+ cleanUp();
1649
+ widget.options.loaded = 1;
1650
+ this.options.editable.keepActivated(true);
1651
+ this.options.dialog.dialog("open");
1652
+ return this.options.dialog.bind('dialogclose', function() {
1653
+ jQuery('label', _this.button).removeClass('ui-state-active');
1654
+ _this.options.editable.element.focus();
1655
+ return _this.options.editable.keepActivated(false);
1656
+ });
1657
+ },
1658
+ _closeDialog: function() {
1659
+ return this.options.dialog.dialog("close");
1660
+ },
1661
+ _addGuiTabSuggestions: function(tabs, element) {
1662
+ var tab;
1663
+ tabs.append(jQuery("<li id=\"" + this.options.uuid + "-tab-suggestions\" class=\"" + this.widgetName + "-tabselector " + this.widgetName + "-tab-suggestions\"> <span>Suggestions</span> </li>"));
1664
+ tab = jQuery("<div id=\"" + this.options.uuid + "-tab-suggestions-content\" class=\"" + this.widgetName + "-tab tab-suggestions\"></div>");
1665
+ element.append(tab);
1666
+ return tab.halloimagesuggestions({
1667
+ uuid: this.options.uuid,
1668
+ imageWidget: this,
1669
+ entity: this.options.entity
1670
+ });
1671
+ },
1672
+ _addGuiTabSearch: function(tabs, element) {
1673
+ var dialogId, tab, widget;
1674
+ widget = this;
1675
+ dialogId = "" + this.options.uuid + "-image-dialog";
1676
+ tabs.append(jQuery("<li id=\"" + this.options.uuid + "-tab-search\" class=\"" + this.widgetName + "-tabselector " + this.widgetName + "-tab-search\"> <span>Search</span> </li>"));
1677
+ tab = jQuery("<div id=\"" + this.options.uuid + "-tab-search-content\" class=\"" + widget.widgetName + "-tab tab-search\"></div>");
1678
+ element.append(tab);
1679
+ return tab.halloimagesearch({
1680
+ uuid: this.options.uuid,
1681
+ imageWidget: this,
1682
+ searchCallback: this.options.search,
1683
+ searchUrl: this.options.searchUrl,
1684
+ limit: this.options.limit,
1685
+ entity: this.options.entity
1686
+ });
1687
+ },
1688
+ _addGuiTabUpload: function(tabs, element) {
1689
+ var tab;
1690
+ tabs.append(jQuery("<li id=\"" + this.options.uuid + "-tab-upload\" class=\"" + this.widgetName + "-tabselector " + this.widgetName + "-tab-upload\"> <span>Upload</span> </li>"));
1691
+ tab = jQuery("<div id=\"" + this.options.uuid + "-tab-upload-content\" class=\"" + this.widgetName + "-tab tab-upload\"></div>");
1692
+ element.append(tab);
1693
+ return tab.halloimageupload({
1694
+ uuid: this.options.uuid,
1695
+ uploadCallback: this.options.upload,
1696
+ uploadUrl: this.options.uploadUrl,
1697
+ imageWidget: this,
1698
+ entity: this.options.entity
1699
+ });
1700
+ }
1701
+ /*
1702
+ insertImage = () ->
1703
+ # This may need to insert an image that does not have the same URL as
1704
+ # the preview image, since it may be a different size
1705
+ # Check if we have a selection and fall back to @lastSelection otherwise
1706
+ try
1707
+ if not widget.options.editable.getSelection()
1708
+ throw new Error "SelectionNotSet"
1709
+ catch error
1710
+ widget.options.editable.restoreSelection(widget.lastSelection)
1711
+
1712
+ document.execCommand "insertImage", null, jQuery(this).attr('src')
1713
+ img = document.getSelection().anchorNode.firstChild
1714
+ jQuery(img).attr "alt", jQuery(".caption").value
1715
+
1716
+ triggerModified = () ->
1717
+ widget.element.trigger "hallomodified"
1718
+ window.setTimeout triggerModified, 100
1719
+ widget._closeDialog()
1720
+
1721
+ addImage = "##{widget.options.uuid}-#{widget.widgetName-addimage"
1722
+ @options.dialog.find(".halloimage-activeImage, addImage).click insertImage
1723
+ */
1724
+
1725
+ });
1726
+ })(jQuery);
1727
+
1728
+ $.widget("ncri.hallo-image-insert-edit", {
1729
+ options: {
1730
+ editable: null,
1731
+ toolbar: null,
1732
+ uuid: "",
1733
+ insert_file_dialog_ui_url: null,
1734
+ dialogOpts: {
1735
+ autoOpen: false,
1736
+ width: 560,
1737
+ height: 'auto',
1738
+ modal: false,
1739
+ resizable: true,
1740
+ draggable: true,
1741
+ dialogClass: 'insert-image-dialog'
1742
+ },
1743
+ dialog: null,
1744
+ buttonCssClass: null,
1745
+ button_label: 'Insert Image'
1746
+ },
1747
+ dialog_image_selection_ui_loaded: false,
1748
+ $image: null,
1749
+ populateToolbar: function($toolbar) {
1750
+ var $buttonHolder, $buttonset, dialog_html, widget;
1751
+ widget = this;
1752
+ this.options.toolbar = $toolbar;
1753
+ dialog_html = "<div id='hallo_img_properties'></div>";
1754
+ if (this.options.insert_file_dialog_ui_url) {
1755
+ dialog_html += "<div id='hallo_img_file_select_ui'></div>";
1756
+ }
1757
+ this.options.dialog = $("<div>").attr('id', "" + this.options.uuid + "-insert-image-dialog").html(dialog_html);
1758
+ if (this.options.insert_file_dialog_ui_url) {
1759
+ $buttonset = $("<span>").addClass(this.widgetName);
1760
+ $buttonHolder = $('<span>');
1761
+ $buttonHolder.hallobutton({
1762
+ label: this.options.button_label,
1763
+ icon: 'icon-picture',
1764
+ editable: this.options.editable,
1765
+ command: null,
1766
+ queryState: false,
1767
+ uuid: this.options.uuid,
1768
+ cssClass: this.options.buttonCssClass
1769
+ });
1770
+ $buttonset.append($buttonHolder);
1771
+ this.button = $buttonHolder;
1772
+ this.button.click(function() {
1773
+ if (widget.options.dialog.dialog("isOpen")) {
1774
+ widget._closeDialog();
1775
+ } else {
1776
+ widget.lastSelection = widget.options.editable.getSelection();
1777
+ widget._openDialog();
1778
+ }
1779
+ return false;
1780
+ });
1781
+ this.options.editable.element.on("halloselected, hallounselected", function() {
1782
+ if (widget.options.dialog.dialog("isOpen")) {
1783
+ return widget.lastSelection = widget.options.editable.getSelection();
1784
+ }
1785
+ });
1786
+ }
1787
+ this.options.editable.element.on("hallodeactivated", function() {
1788
+ return widget._closeDialog();
1789
+ });
1790
+ $(this.options.editable.element).on("click", "img", function(e) {
1791
+ widget._openDialog($(this));
1792
+ return false;
1793
+ });
1794
+ this.options.editable.element.on('halloselected', function(event, data) {
1795
+ if (widget.options.editable.options.toolbar === "halloToolbarContextual" && $(data.originalEvent.target).is('img')) {
1796
+ $toolbar.hide();
1797
+ return false;
1798
+ }
1799
+ });
1800
+ $toolbar.append($buttonset);
1801
+ return this.options.dialog.dialog(this.options.dialogOpts);
1802
+ },
1803
+ _openDialog: function($image) {
1804
+ var $editableEl, widget, xposition, yposition,
1805
+ _this = this;
1806
+ this.$image = $image;
1807
+ widget = this;
1808
+ $editableEl = $(this.options.editable.element);
1809
+ xposition = $editableEl.offset().left + $editableEl.outerWidth() + 10;
1810
+ if (this.$image) {
1811
+ yposition = this.$image.offset().top - $(document).scrollTop();
1812
+ } else {
1813
+ yposition = this.options.toolbar.offset().top - $(document).scrollTop();
1814
+ }
1815
+ this.options.dialog.dialog("option", "position", [xposition, yposition]);
1816
+ this.options.editable.keepActivated(true);
1817
+ this.options.dialog.dialog("open");
1818
+ if (this.$image) {
1819
+ this.options.dialog.dialog("option", "title", 'Image Properties');
1820
+ this._load_dialog_image_properties_ui();
1821
+ $(document).keyup(function(e) {
1822
+ if (e.keyCode === 46) {
1823
+ $(document).off();
1824
+ widget._closeDialog();
1825
+ widget.$image.remove();
1826
+ return widget.$image = null;
1827
+ }
1828
+ });
1829
+ this.options.editable.element.on("click", function() {
1830
+ widget.$image = null;
1831
+ return widget._closeDialog();
1832
+ });
1833
+ } else {
1834
+ this.options.dialog.children('#hallo_img_properties').hide();
1835
+ this.options.dialog.dialog("option", "title", 'Insert Image');
1836
+ if ($('#hallo_img_file_select_title').length > 0) {
1837
+ $('#hallo_img_file_select_title').text('');
1838
+ }
1839
+ }
1840
+ if (this.options.insert_file_dialog_ui_url && !this.dialog_image_selection_ui_loaded) {
1841
+ this.options.dialog.bind('dialogclose', function() {
1842
+ var scrollbar_pos;
1843
+ $('label', _this.button).removeClass('ui-state-active');
1844
+ scrollbar_pos = $(document).scrollTop();
1845
+ _this.options.editable.element.focus();
1846
+ $(document).scrollTop(scrollbar_pos);
1847
+ return _this.options.editable.keepActivated(false);
1848
+ });
1849
+ this.options.dialog.on('click', ".reload_link", function() {
1850
+ widget._load_dialog_image_selection_ui();
1851
+ return false;
1852
+ });
1853
+ this.options.dialog.on('click', '.file_preview img', function() {
1854
+ var new_source;
1855
+ if (widget.$image) {
1856
+ new_source = $(this).attr('src').replace(/-thumb/, '');
1857
+ widget.$image.attr('src', new_source);
1858
+ $('#hallo_img_source').val(new_source);
1859
+ } else {
1860
+ widget.options.editable.restoreSelection(widget.lastSelection);
1861
+ document.execCommand("insertImage", null, $(this).attr('src').replace(/-thumb/, ''));
1862
+ widget.options.editable.element.trigger('change');
1863
+ widget.options.editable.removeAllSelections();
1864
+ widget._closeDialog();
1865
+ }
1866
+ return false;
1867
+ });
1868
+ return this._load_dialog_image_selection_ui();
1869
+ }
1870
+ },
1871
+ _closeDialog: function() {
1872
+ return this.options.dialog.dialog("close");
1873
+ },
1874
+ _load_dialog_image_selection_ui: function() {
1875
+ var widget;
1876
+ widget = this;
1877
+ return $.ajax({
1878
+ url: this.options.insert_file_dialog_ui_url,
1879
+ success: function(data, textStatus, jqXHR) {
1880
+ var file_select_title;
1881
+ file_select_title = widget.options.dialog.children('#hallo_img_properties').is(':visible') ? 'Change image:' : '';
1882
+ widget.options.dialog.children('#hallo_img_file_select_ui').html(("<div id='hallo_img_file_select_title'>" + file_select_title + "</div>") + data);
1883
+ return widget.dialog_image_selection_ui_loaded = true;
1884
+ },
1885
+ beforeSend: function() {
1886
+ return widget.options.dialog.children('#hallo_img_file_select_ui').html('<div class="hallo_insert_file_loader"></div>');
1887
+ }
1888
+ });
1889
+ },
1890
+ _load_dialog_image_properties_ui: function() {
1891
+ var $img_properties, html, widget;
1892
+ widget = this;
1893
+ $img_properties = this.options.dialog.children('#hallo_img_properties');
1894
+ $img_properties.show();
1895
+ html = this._property_input_html('source', this.$image.attr('src'), {
1896
+ label: 'Source'
1897
+ }) + this._property_input_html('alt', this.$image.attr('alt'), {
1898
+ label: 'Alt text'
1899
+ }) + this._property_row_html(this._property_input_html('width', (this.$image.is('[width]') ? this.$image.attr('width') : ''), {
1900
+ label: 'Width',
1901
+ row: false
1902
+ }) + this._property_input_html('height', (this.$image.is('[height]') ? this.$image.attr('height') : ''), {
1903
+ label: 'Height',
1904
+ row: false
1905
+ })) + this._property_input_html('padding', this.$image.css('padding'), {
1906
+ label: 'Padding'
1907
+ }) + this._property_row_html(this._property_cb_html('float_left', this.$image.css('float') === 'left', {
1908
+ label: 'left',
1909
+ row: false
1910
+ }) + this._property_cb_html('float_right', this.$image.css('float') === 'right', {
1911
+ label: 'right',
1912
+ row: false
1913
+ }) + this._property_cb_html('unfloat', this.$image.css('float') === 'none', {
1914
+ label: 'no',
1915
+ row: false
1916
+ }), 'Float');
1917
+ $img_properties.html(html);
1918
+ if ($('#hallo_img_file_select_title').length > 0) {
1919
+ $('#hallo_img_file_select_title').text('Change image:');
1920
+ }
1921
+ $('#hallo_img_properties #hallo_img_source').keyup(function() {
1922
+ return widget.$image.attr('src', this.value);
1923
+ });
1924
+ $('#hallo_img_properties #hallo_img_alt').keyup(function() {
1925
+ return widget.$image.attr('alt', this.value);
1926
+ });
1927
+ $('#hallo_img_properties #hallo_img_padding').keyup(function() {
1928
+ return widget.$image.css('padding', this.value);
1929
+ });
1930
+ $('#hallo_img_properties #hallo_img_height').keyup(function() {
1931
+ widget.$image.css('height', this.value);
1932
+ return widget.$image.attr('height', this.value);
1933
+ });
1934
+ $('#hallo_img_properties #hallo_img_width').keyup(function() {
1935
+ widget.$image.css('width', this.value);
1936
+ return widget.$image.attr('width', this.value);
1937
+ });
1938
+ $('#hallo_img_properties #hallo_img_float_left').click(function() {
1939
+ if (!this.checked) {
1940
+ return false;
1941
+ }
1942
+ widget.$image.css('float', 'left');
1943
+ $('#hallo_img_properties #hallo_img_float_right').removeAttr('checked');
1944
+ return $('#hallo_img_properties #hallo_img_unfloat').removeAttr('checked');
1945
+ });
1946
+ $('#hallo_img_properties #hallo_img_float_right').click(function() {
1947
+ if (!this.checked) {
1948
+ return false;
1949
+ }
1950
+ widget.$image.css('float', 'right');
1951
+ $('#hallo_img_properties #hallo_img_unfloat').removeAttr('checked');
1952
+ return $('#hallo_img_properties #hallo_img_float_left').removeAttr('checked');
1953
+ });
1954
+ return $('#hallo_img_properties #hallo_img_unfloat').click(function() {
1955
+ if (!this.checked) {
1956
+ return false;
1957
+ }
1958
+ widget.$image.css('float', 'none');
1959
+ $('#hallo_img_properties #hallo_img_float_right').removeAttr('checked');
1960
+ return $('#hallo_img_properties #hallo_img_float_left').removeAttr('checked');
1961
+ });
1962
+ },
1963
+ _property_col_html: function(col_html) {
1964
+ return "<div class='hallo_img_property_col'>" + col_html + "</div>";
1965
+ },
1966
+ _property_row_html: function(row_html, label) {
1967
+ if (label == null) {
1968
+ label = '';
1969
+ }
1970
+ return "<div class='hallo_img_property_row'>" + (this._property_col_html(label) + this._property_col_html(row_html)) + "</div>";
1971
+ },
1972
+ _property_html: function(property_html, options) {
1973
+ if (options == null) {
1974
+ options = {};
1975
+ }
1976
+ if (options.row === false) {
1977
+ if (options.label) {
1978
+ property_html = "<span class='img_property_entry'>" + options.label + " " + property_html + "</span>";
1979
+ }
1980
+ return property_html;
1981
+ } else {
1982
+ return this._property_row_html("<span class='img_property_entry'>" + property_html + "</span>", options.label);
1983
+ }
1984
+ },
1985
+ _property_input_html: function(id, value, options) {
1986
+ if (options == null) {
1987
+ options = {};
1988
+ }
1989
+ return this._property_html("<input type='text' id='hallo_img_" + id + "' value='" + value + "'>", options);
1990
+ },
1991
+ _property_cb_html: function(id, checked, options) {
1992
+ if (options == null) {
1993
+ options = {};
1994
+ }
1995
+ return this._property_html("<input type='checkbox' id='hallo_img_" + id + "' " + (checked ? 'checked=checked' : '') + "'>", options);
1996
+ }
1997
+ });
1998
+
1999
+ (function(jQuery) {
2000
+ return jQuery.widget('IKS.halloindicator', {
2001
+ options: {
2002
+ editable: null,
2003
+ className: 'halloEditIndicator'
2004
+ },
2005
+ _create: function() {
2006
+ var _this = this;
2007
+ return this.element.bind('halloenabled', function() {
2008
+ return _this.buildIndicator();
2009
+ });
2010
+ },
2011
+ populateToolbar: function() {},
2012
+ buildIndicator: function() {
2013
+ var editButton;
2014
+ editButton = jQuery('<div><i class="icon-edit"></i> Edit</div>');
2015
+ editButton.addClass(this.options.className);
2016
+ editButton.hide();
2017
+ this.element.before(editButton);
2018
+ this.bindIndicator(editButton);
2019
+ return this.setIndicatorPosition(editButton);
2020
+ },
2021
+ bindIndicator: function(indicator) {
2022
+ var _this = this;
2023
+ indicator.bind('click', function() {
2024
+ return _this.options.editable.element.focus();
2025
+ });
2026
+ this.element.bind('halloactivated', function() {
2027
+ return indicator.hide();
2028
+ });
2029
+ this.element.bind('hallodisabled', function() {
2030
+ return indicator.remove();
2031
+ });
2032
+ return this.options.editable.element.hover(function() {
2033
+ if (jQuery(this).hasClass('inEditMode')) {
2034
+ return;
2035
+ }
2036
+ return indicator.show();
2037
+ }, function(data) {
2038
+ if (jQuery(this).hasClass('inEditMode')) {
2039
+ return;
2040
+ }
2041
+ if (data.relatedTarget === indicator.get(0)) {
2042
+ return;
2043
+ }
2044
+ return indicator.hide();
2045
+ });
2046
+ },
2047
+ setIndicatorPosition: function(indicator) {
2048
+ var offset;
2049
+ indicator.css('position', 'absolute');
2050
+ offset = this.element.position();
2051
+ indicator.css('top', offset.top + 2);
2052
+ return indicator.css('left', offset.left + 2);
2053
+ }
2054
+ });
2055
+ })(jQuery);
2056
+
2057
+ (function(jQuery) {
2058
+ return jQuery.widget("IKS.hallojustify", {
2059
+ options: {
2060
+ editable: null,
2061
+ toolbar: null,
2062
+ uuid: '',
2063
+ buttonCssClass: null
2064
+ },
2065
+ populateToolbar: function(toolbar) {
2066
+ var buttonize, buttonset,
2067
+ _this = this;
2068
+ buttonset = jQuery("<span class=\"" + this.widgetName + "\"></span>");
2069
+ buttonize = function(alignment) {
2070
+ var buttonElement;
2071
+ buttonElement = jQuery('<span></span>');
2072
+ buttonElement.hallobutton({
2073
+ uuid: _this.options.uuid,
2074
+ editable: _this.options.editable,
2075
+ label: alignment,
2076
+ command: "justify" + alignment,
2077
+ icon: "icon-align-" + (alignment.toLowerCase()),
2078
+ cssClass: _this.options.buttonCssClass
2079
+ });
2080
+ return buttonset.append(buttonElement);
2081
+ };
2082
+ buttonize("Left");
2083
+ buttonize("Center");
2084
+ buttonize("Right");
2085
+ buttonset.hallobuttonset();
2086
+ return toolbar.append(buttonset);
2087
+ }
2088
+ });
2089
+ })(jQuery);
2090
+
2091
+ (function(jQuery) {
2092
+ return jQuery.widget("IKS.hallolink", {
2093
+ options: {
2094
+ editable: null,
2095
+ uuid: "",
2096
+ link: true,
2097
+ image: true,
2098
+ defaultUrl: 'http://',
2099
+ dialogOpts: {
2100
+ autoOpen: false,
2101
+ width: 540,
2102
+ height: 95,
2103
+ title: "Enter Link",
2104
+ modal: true,
2105
+ resizable: false,
2106
+ draggable: false,
2107
+ dialogClass: 'hallolink-dialog'
2108
+ },
2109
+ buttonCssClass: null
2110
+ },
2111
+ populateToolbar: function(toolbar) {
2112
+ var buttonize, buttonset, dialog, dialogId, dialogSubmitCb, isEmptyLink, urlInput, widget,
2113
+ _this = this;
2114
+ widget = this;
2115
+ dialogId = "" + this.options.uuid + "-dialog";
2116
+ dialog = jQuery("<div id=\"" + dialogId + "\"> <form action=\"#\" method=\"post\" class=\"linkForm\"> <input class=\"url\" type=\"text\" name=\"url\" value=\"" + this.options.defaultUrl + "\" /> <input type=\"submit\" id=\"addlinkButton\" value=\"Insert\" /> </form></div>");
2117
+ urlInput = jQuery('input[name=url]', dialog).focus(function(e) {
2118
+ return this.select();
2119
+ });
2120
+ isEmptyLink = function(link) {
2121
+ if ((new RegExp(/^\s*$/)).test(link)) {
2122
+ return true;
2123
+ }
2124
+ if (link === widget.options.defaultUrl) {
2125
+ return true;
2126
+ }
2127
+ return false;
2128
+ };
2129
+ dialogSubmitCb = function(event) {
2130
+ var link, selectionStart;
2131
+ event.preventDefault();
2132
+ link = urlInput.val();
2133
+ widget.options.editable.restoreSelection(widget.lastSelection);
2134
+ if (isEmptyLink(link)) {
2135
+ selectionStart = widget.lastSelection.startContainer;
2136
+ if (widget.lastSelection.collapsed) {
2137
+ widget.lastSelection.setStartBefore(selectionStart);
2138
+ widget.lastSelection.setEndAfter(selectionStart);
2139
+ window.getSelection().addRange(widget.lastSelection);
2140
+ }
2141
+ document.execCommand("unlink", null, "");
2142
+ } else {
2143
+ if (!((new RegExp(/:\/\//)).test(link))) {
2144
+ link = 'http://' + link;
2145
+ }
2146
+ if (widget.lastSelection.startContainer.parentNode.href === void 0) {
2147
+ document.execCommand("createLink", null, link);
2148
+ } else {
2149
+ widget.lastSelection.startContainer.parentNode.href = link;
2150
+ }
2151
+ }
2152
+ widget.options.editable.element.trigger('change');
2153
+ widget.options.editable.removeAllSelections();
2154
+ dialog.dialog('close');
2155
+ return false;
2156
+ };
2157
+ dialog.find("form").submit(dialogSubmitCb);
2158
+ buttonset = jQuery("<span class=\"" + widget.widgetName + "\"></span>");
2159
+ buttonize = function(type) {
2160
+ var button, buttonHolder, id;
2161
+ id = "" + _this.options.uuid + "-" + type;
2162
+ buttonHolder = jQuery('<span></span>');
2163
+ buttonHolder.hallobutton({
2164
+ label: 'Link',
2165
+ icon: 'icon-link',
2166
+ editable: _this.options.editable,
2167
+ command: null,
2168
+ queryState: false,
2169
+ uuid: _this.options.uuid,
2170
+ cssClass: _this.options.buttonCssClass
2171
+ });
2172
+ buttonset.append(buttonHolder);
2173
+ button = buttonHolder;
2174
+ button.bind("click", function(event) {
2175
+ var selectionParent;
2176
+ widget.lastSelection = widget.options.editable.getSelection();
2177
+ urlInput = jQuery('input[name=url]', dialog);
2178
+ selectionParent = widget.lastSelection.startContainer.parentNode;
2179
+ if (!selectionParent.href) {
2180
+ urlInput.val(widget.options.defaultUrl);
2181
+ } else {
2182
+ urlInput.val(jQuery(selectionParent).attr('href'));
2183
+ jQuery(urlInput[0].form).find('input[type=submit]').val('update');
2184
+ }
2185
+ widget.options.editable.keepActivated(true);
2186
+ dialog.dialog('open');
2187
+ dialog.bind('dialogclose', function() {
2188
+ jQuery('label', buttonHolder).removeClass('ui-state-active');
2189
+ widget.options.editable.element.focus();
2190
+ return widget.options.editable.keepActivated(false);
2191
+ });
2192
+ return false;
2193
+ });
2194
+ return _this.element.bind("keyup paste change mouseup", function(event) {
2195
+ var nodeName, start;
2196
+ start = jQuery(widget.options.editable.getSelection().startContainer);
2197
+ if (start.prop('nodeName')) {
2198
+ nodeName = start.prop('nodeName');
2199
+ } else {
2200
+ nodeName = start.parent().prop('nodeName');
2201
+ }
2202
+ if (nodeName && nodeName.toUpperCase() === "A") {
2203
+ jQuery('label', button).addClass('ui-state-active');
2204
+ return;
2205
+ }
2206
+ return jQuery('label', button).removeClass('ui-state-active');
2207
+ });
2208
+ };
2209
+ if (this.options.link) {
2210
+ buttonize("A");
2211
+ }
2212
+ if (this.options.link) {
2213
+ toolbar.append(buttonset);
2214
+ buttonset.hallobuttonset();
2215
+ return dialog.dialog(this.options.dialogOpts);
2216
+ }
2217
+ }
2218
+ });
2219
+ })(jQuery);
2220
+
2221
+ (function(jQuery) {
2222
+ return jQuery.widget("IKS.hallolists", {
2223
+ options: {
2224
+ editable: null,
2225
+ toolbar: null,
2226
+ uuid: '',
2227
+ lists: {
2228
+ ordered: true,
2229
+ unordered: true
2230
+ },
2231
+ buttonCssClass: null
2232
+ },
2233
+ populateToolbar: function(toolbar) {
2234
+ var buttonize, buttonset,
2235
+ _this = this;
2236
+ buttonset = jQuery("<span class=\"" + this.widgetName + "\"></span>");
2237
+ buttonize = function(type, label) {
2238
+ var buttonElement;
2239
+ buttonElement = jQuery('<span></span>');
2240
+ buttonElement.hallobutton({
2241
+ uuid: _this.options.uuid,
2242
+ editable: _this.options.editable,
2243
+ label: label,
2244
+ command: "insert" + type + "List",
2245
+ icon: "icon-list-" + (label.toLowerCase()),
2246
+ cssClass: _this.options.buttonCssClass
2247
+ });
2248
+ return buttonset.append(buttonElement);
2249
+ };
2250
+ if (this.options.lists.ordered) {
2251
+ buttonize("Ordered", "OL");
2252
+ }
2253
+ if (this.options.lists.unordered) {
2254
+ buttonize("Unordered", "UL");
2255
+ }
2256
+ buttonset.hallobuttonset();
2257
+ return toolbar.append(buttonset);
2258
+ }
2259
+ });
2260
+ })(jQuery);
2261
+
2262
+ (function(jQuery) {
2263
+ return jQuery.widget("Liip.hallooverlay", {
2264
+ options: {
2265
+ editable: null,
2266
+ toolbar: null,
2267
+ uuid: "",
2268
+ overlay: null,
2269
+ padding: 10,
2270
+ background: null
2271
+ },
2272
+ _create: function() {
2273
+ var widget;
2274
+ widget = this;
2275
+ if (!this.options.bound) {
2276
+ this.options.bound = true;
2277
+ this.options.editable.element.bind("halloactivated", function(event, data) {
2278
+ widget.options.currentEditable = jQuery(event.target);
2279
+ if (!widget.options.visible) {
2280
+ return widget.showOverlay();
2281
+ }
2282
+ });
2283
+ this.options.editable.element.bind("hallomodified", function(event, data) {
2284
+ widget.options.currentEditable = jQuery(event.target);
2285
+ if (widget.options.visible) {
2286
+ return widget.resizeOverlay();
2287
+ }
2288
+ });
2289
+ return this.options.editable.element.bind("hallodeactivated", function(event, data) {
2290
+ widget.options.currentEditable = jQuery(event.target);
2291
+ if (widget.options.visible) {
2292
+ return widget.hideOverlay();
2293
+ }
2294
+ });
2295
+ }
2296
+ },
2297
+ showOverlay: function() {
2298
+ this.options.visible = true;
2299
+ if (this.options.overlay === null) {
2300
+ if (jQuery("#halloOverlay").length > 0) {
2301
+ this.options.overlay = jQuery("#halloOverlay");
2302
+ } else {
2303
+ this.options.overlay = jQuery("<div id=\"halloOverlay\" class=\"halloOverlay\">");
2304
+ jQuery(document.body).append(this.options.overlay);
2305
+ }
2306
+ this.options.overlay.bind('click', jQuery.proxy(this.options.editable.turnOff, this.options.editable));
2307
+ }
2308
+ this.options.overlay.show();
2309
+ if (this.options.background === null) {
2310
+ if (jQuery("#halloBackground").length > 0) {
2311
+ this.options.background = jQuery("#halloBackground");
2312
+ } else {
2313
+ this.options.background = jQuery("<div id=\"halloBackground\" class=\"halloBackground\">");
2314
+ jQuery(document.body).append(this.options.background);
2315
+ }
2316
+ }
2317
+ this.resizeOverlay();
2318
+ this.options.background.show();
2319
+ if (!this.options.originalZIndex) {
2320
+ this.options.originalZIndex = this.options.currentEditable.css("z-index");
2321
+ }
2322
+ return this.options.currentEditable.css('z-index', '350');
2323
+ },
2324
+ resizeOverlay: function() {
2325
+ var offset;
2326
+ offset = this.options.currentEditable.offset();
2327
+ return this.options.background.css({
2328
+ top: offset.top - this.options.padding,
2329
+ left: offset.left - this.options.padding,
2330
+ width: this.options.currentEditable.width() + 2 * this.options.padding,
2331
+ height: this.options.currentEditable.height() + 2 * this.options.padding
2332
+ });
2333
+ },
2334
+ hideOverlay: function() {
2335
+ this.options.visible = false;
2336
+ this.options.overlay.hide();
2337
+ this.options.background.hide();
2338
+ return this.options.currentEditable.css('z-index', this.options.originalZIndex);
2339
+ },
2340
+ _findBackgroundColor: function(jQueryfield) {
2341
+ var color;
2342
+ color = jQueryfield.css("background-color");
2343
+ if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') {
2344
+ return color;
2345
+ }
2346
+ if (jQueryfield.is("body")) {
2347
+ return "white";
2348
+ } else {
2349
+ return this._findBackgroundColor(jQueryfield.parent());
2350
+ }
2351
+ }
2352
+ });
2353
+ })(jQuery);
2354
+
2355
+ (function(jQuery) {
2356
+ return jQuery.widget("IKS.halloreundo", {
2357
+ options: {
2358
+ editable: null,
2359
+ toolbar: null,
2360
+ uuid: '',
2361
+ buttonCssClass: null
2362
+ },
2363
+ populateToolbar: function(toolbar) {
2364
+ var buttonize, buttonset,
2365
+ _this = this;
2366
+ buttonset = jQuery("<span class=\"" + this.widgetName + "\"></span>");
2367
+ buttonize = function(cmd, label) {
2368
+ var buttonElement;
2369
+ buttonElement = jQuery('<span></span>');
2370
+ buttonElement.hallobutton({
2371
+ uuid: _this.options.uuid,
2372
+ editable: _this.options.editable,
2373
+ label: label,
2374
+ icon: cmd === 'undo' ? 'icon-undo' : 'icon-repeat',
2375
+ command: cmd,
2376
+ queryState: false,
2377
+ cssClass: _this.options.buttonCssClass
2378
+ });
2379
+ return buttonset.append(buttonElement);
2380
+ };
2381
+ buttonize("undo", "Undo");
2382
+ buttonize("redo", "Redo");
2383
+ buttonset.hallobuttonset();
2384
+ return toolbar.append(buttonset);
2385
+ }
2386
+ });
2387
+ })(jQuery);
2388
+
2389
+ (function(jQuery) {
2390
+ return jQuery.widget("Liip.hallotoolbarlinebreak", {
2391
+ options: {
2392
+ editable: null,
2393
+ uuid: "",
2394
+ breakAfter: []
2395
+ },
2396
+ populateToolbar: function(toolbar) {
2397
+ var buttonRow, buttonset, buttonsets, queuedButtonsets, row, rowcounter, _i, _j, _len, _len1, _ref;
2398
+ buttonsets = jQuery('.ui-buttonset', toolbar);
2399
+ queuedButtonsets = jQuery();
2400
+ rowcounter = 0;
2401
+ _ref = this.options.breakAfter;
2402
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2403
+ row = _ref[_i];
2404
+ rowcounter++;
2405
+ buttonRow = "<div class=\"halloButtonrow halloButtonrow-" + rowcounter + "\" />";
2406
+ for (_j = 0, _len1 = buttonsets.length; _j < _len1; _j++) {
2407
+ buttonset = buttonsets[_j];
2408
+ queuedButtonsets = jQuery(queuedButtonsets).add(jQuery(buttonset));
2409
+ if (jQuery(buttonset).hasClass(row)) {
2410
+ queuedButtonsets.wrapAll(buttonRow);
2411
+ buttonsets = buttonsets.not(queuedButtonsets);
2412
+ queuedButtonsets = jQuery();
2413
+ break;
2414
+ }
2415
+ }
2416
+ }
2417
+ if (buttonsets.length > 0) {
2418
+ rowcounter++;
2419
+ buttonRow = "<div class=\"halloButtonrow halloButtonrow-" + rowcounter + "\" />";
2420
+ return buttonsets.wrapAll(buttonRow);
2421
+ }
2422
+ }
2423
+ });
2424
+ })(jQuery);
2425
+
2426
+ (function(jQuery) {
2427
+ return jQuery.widget('Hallo.halloToolbarContextual', {
2428
+ toolbar: null,
2429
+ options: {
2430
+ parentElement: 'body',
2431
+ editable: null,
2432
+ toolbar: null,
2433
+ positionAbove: false
2434
+ },
2435
+ _create: function() {
2436
+ var _this = this;
2437
+ this.toolbar = this.options.toolbar;
2438
+ jQuery(this.options.parentElement).append(this.toolbar);
2439
+ this._bindEvents();
2440
+ return jQuery(window).resize(function(event) {
2441
+ return _this._updatePosition(_this._getPosition(event));
2442
+ });
2443
+ },
2444
+ _getPosition: function(event, selection) {
2445
+ var eventType, position;
2446
+ if (!event) {
2447
+ return;
2448
+ }
2449
+ eventType = event.type;
2450
+ switch (eventType) {
2451
+ case 'keydown':
2452
+ case 'keyup':
2453
+ case 'keypress':
2454
+ return this._getCaretPosition(selection);
2455
+ case 'click':
2456
+ case 'mousedown':
2457
+ case 'mouseup':
2458
+ return position = {
2459
+ top: event.pageY,
2460
+ left: event.pageX
2461
+ };
2462
+ }
2463
+ },
2464
+ _getCaretPosition: function(range) {
2465
+ var newRange, position, tmpSpan;
2466
+ tmpSpan = jQuery("<span/>");
2467
+ newRange = rangy.createRange();
2468
+ newRange.setStart(range.endContainer, range.endOffset);
2469
+ newRange.insertNode(tmpSpan.get(0));
2470
+ position = {
2471
+ top: tmpSpan.offset().top,
2472
+ left: tmpSpan.offset().left
2473
+ };
2474
+ tmpSpan.remove();
2475
+ return position;
2476
+ },
2477
+ setPosition: function() {
2478
+ if (this.options.parentElement !== 'body') {
2479
+ this.options.parentElement = 'body';
2480
+ jQuery(this.options.parentElement).append(this.toolbar);
2481
+ }
2482
+ this.toolbar.css('position', 'absolute');
2483
+ this.toolbar.css('top', this.element.offset().top - 20);
2484
+ return this.toolbar.css('left', this.element.offset().left);
2485
+ },
2486
+ _updatePosition: function(position, selection) {
2487
+ var left, selectionRect, toolbar_height_offset, top, top_offset;
2488
+ if (selection == null) {
2489
+ selection = null;
2490
+ }
2491
+ if (!position) {
2492
+ return;
2493
+ }
2494
+ if (!(position.top && position.left)) {
2495
+ return;
2496
+ }
2497
+ toolbar_height_offset = this.toolbar.outerHeight() + 10;
2498
+ if (selection && !selection.collapsed && selection.nativeRange) {
2499
+ selectionRect = selection.nativeRange.getBoundingClientRect();
2500
+ top_offset = this.options.positionAbove ? selectionRect.top - toolbar_height_offset : selectionRect.bottom + 10;
2501
+ top = $(window).scrollTop() + top_offset;
2502
+ left = $(window).scrollLeft() + selectionRect.left;
2503
+ } else {
2504
+ top_offset = this.options.positionAbove ? -10 - toolbar_height_offset : 20;
2505
+ top = position.top + top_offset;
2506
+ left = position.left - this.toolbar.outerWidth() / 2 + 30;
2507
+ }
2508
+ this.toolbar.css('top', top);
2509
+ return this.toolbar.css('left', left);
2510
+ },
2511
+ _bindEvents: function() {
2512
+ var _this = this;
2513
+ this.element.bind('halloselected', function(event, data) {
2514
+ var position;
2515
+ position = _this._getPosition(data.originalEvent, data.selection);
2516
+ if (!position) {
2517
+ return;
2518
+ }
2519
+ _this._updatePosition(position, data.selection);
2520
+ return _this.toolbar.show();
2521
+ });
2522
+ this.element.bind('hallounselected', function(event, data) {
2523
+ return _this.toolbar.hide();
2524
+ });
2525
+ return this.element.bind('hallodeactivated', function(event, data) {
2526
+ return _this.toolbar.hide();
2527
+ });
2528
+ }
2529
+ });
2530
+ })(jQuery);
2531
+
2532
+ (function(jQuery) {
2533
+ return jQuery.widget('Hallo.halloToolbarFixed', {
2534
+ toolbar: null,
2535
+ options: {
2536
+ parentElement: 'body',
2537
+ editable: null,
2538
+ toolbar: null
2539
+ },
2540
+ _create: function() {
2541
+ var el, widthToAdd,
2542
+ _this = this;
2543
+ this.toolbar = this.options.toolbar;
2544
+ this.toolbar.show();
2545
+ jQuery(this.options.parentElement).append(this.toolbar);
2546
+ this._bindEvents();
2547
+ jQuery(window).resize(function(event) {
2548
+ return _this.setPosition();
2549
+ });
2550
+ if (this.options.parentElement === 'body') {
2551
+ el = jQuery(this.element);
2552
+ widthToAdd = parseFloat(el.css('padding-left'));
2553
+ widthToAdd += parseFloat(el.css('padding-right'));
2554
+ widthToAdd += parseFloat(el.css('border-left-width'));
2555
+ widthToAdd += parseFloat(el.css('border-right-width'));
2556
+ widthToAdd += (parseFloat(el.css('outline-width'))) * 2;
2557
+ widthToAdd += (parseFloat(el.css('outline-offset'))) * 2;
2558
+ return jQuery(this.toolbar).css("width", el.width() + widthToAdd);
2559
+ }
2560
+ },
2561
+ _getPosition: function(event, selection) {
2562
+ var offset, position, width;
2563
+ if (!event) {
2564
+ return;
2565
+ }
2566
+ width = parseFloat(this.element.css('outline-width'));
2567
+ offset = width + parseFloat(this.element.css('outline-offset'));
2568
+ return position = {
2569
+ top: this.element.offset().top - this.toolbar.outerHeight() - offset,
2570
+ left: this.element.offset().left - offset
2571
+ };
2572
+ },
2573
+ _getCaretPosition: function(range) {
2574
+ var newRange, position, tmpSpan;
2575
+ tmpSpan = jQuery("<span/>");
2576
+ newRange = rangy.createRange();
2577
+ newRange.setStart(range.endContainer, range.endOffset);
2578
+ newRange.insertNode(tmpSpan.get(0));
2579
+ position = {
2580
+ top: tmpSpan.offset().top,
2581
+ left: tmpSpan.offset().left
2582
+ };
2583
+ tmpSpan.remove();
2584
+ return position;
2585
+ },
2586
+ setPosition: function() {
2587
+ if (this.options.parentElement !== 'body') {
2588
+ return;
2589
+ }
2590
+ this.toolbar.css('position', 'absolute');
2591
+ this.toolbar.css('top', this.element.offset().top - this.toolbar.outerHeight());
2592
+ return this.toolbar.css('left', this.element.offset().left + 10);
2593
+ },
2594
+ _updatePosition: function(position) {},
2595
+ _bindEvents: function() {
2596
+ var _this = this;
2597
+ this.element.bind('halloactivated', function(event, data) {
2598
+ _this.setPosition();
2599
+ return _this.toolbar.show();
2600
+ });
2601
+ return this.element.bind('hallodeactivated', function(event, data) {
2602
+ return _this.toolbar.hide();
2603
+ });
2604
+ }
2605
+ });
2606
+ })(jQuery);
2607
+
2608
+ (function(jQuery) {
2609
+ jQuery.widget('IKS.hallobutton', {
2610
+ button: null,
2611
+ isChecked: false,
2612
+ options: {
2613
+ uuid: '',
2614
+ label: null,
2615
+ icon: null,
2616
+ editable: null,
2617
+ command: null,
2618
+ queryState: true,
2619
+ cssClass: null
2620
+ },
2621
+ _create: function() {
2622
+ var hoverclass, id, opts, _base, _ref,
2623
+ _this = this;
2624
+ if ((_ref = (_base = this.options).icon) == null) {
2625
+ _base.icon = "icon-" + (this.options.label.toLowerCase());
2626
+ }
2627
+ id = "" + this.options.uuid + "-" + this.options.label;
2628
+ opts = this.options;
2629
+ this.button = this._createButton(id, opts.command, opts.label, opts.icon);
2630
+ this.element.append(this.button);
2631
+ if (this.options.cssClass) {
2632
+ this.button.addClass(this.options.cssClass);
2633
+ }
2634
+ if (this.options.editable.options.touchScreen) {
2635
+ this.button.addClass('btn-large');
2636
+ }
2637
+ this.button.data('hallo-command', this.options.command);
2638
+ hoverclass = 'ui-state-hover';
2639
+ this.button.bind('mouseenter', function(event) {
2640
+ if (_this.isEnabled()) {
2641
+ return _this.button.addClass(hoverclass);
2642
+ }
2643
+ });
2644
+ return this.button.bind('mouseleave', function(event) {
2645
+ return _this.button.removeClass(hoverclass);
2646
+ });
2647
+ },
2648
+ _init: function() {
2649
+ var editableElement, events, queryState,
2650
+ _this = this;
2651
+ if (!this.button) {
2652
+ this.button = this._prepareButton();
2653
+ }
2654
+ this.element.append(this.button);
2655
+ queryState = function(event) {
2656
+ if (!_this.options.command) {
2657
+ return;
2658
+ }
2659
+ try {
2660
+ return _this.checked(document.queryCommandState(_this.options.command));
2661
+ } catch (e) {
2662
+
2663
+ }
2664
+ };
2665
+ if (this.options.command) {
2666
+ this.button.bind('click', function(event) {
2667
+ _this.options.editable.execute(_this.options.command);
2668
+ queryState;
2669
+
2670
+ return false;
2671
+ });
2672
+ }
2673
+ if (!this.options.queryState) {
2674
+ return;
2675
+ }
2676
+ editableElement = this.options.editable.element;
2677
+ events = 'keyup paste change mouseup hallomodified';
2678
+ editableElement.bind(events, queryState);
2679
+ editableElement.bind('halloenabled', function() {
2680
+ return editableElement.bind(events, queryState);
2681
+ });
2682
+ return editableElement.bind('hallodisabled', function() {
2683
+ return editableElement.unbind(events, queryState);
2684
+ });
2685
+ },
2686
+ enable: function() {
2687
+ return this.button.removeAttr('disabled');
2688
+ },
2689
+ disable: function() {
2690
+ return this.button.attr('disabled', 'true');
2691
+ },
2692
+ isEnabled: function() {
2693
+ return this.button.attr('disabled') !== 'true';
2694
+ },
2695
+ refresh: function() {
2696
+ if (this.isChecked) {
2697
+ return this.button.addClass('ui-state-active');
2698
+ } else {
2699
+ return this.button.removeClass('ui-state-active');
2700
+ }
2701
+ },
2702
+ checked: function(checked) {
2703
+ this.isChecked = checked;
2704
+ return this.refresh();
2705
+ },
2706
+ _createButton: function(id, command, label, icon) {
2707
+ var classes;
2708
+ classes = ['ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all', 'ui-button-text-only', "" + command + "_button"];
2709
+ return jQuery("<button id=\"" + id + "\" class=\"" + (classes.join(' ')) + "\" title=\"" + label + "\"> <span class=\"ui-button-text\"> <i class=\"" + icon + "\"></i> </span> </button>");
2710
+ }
2711
+ });
2712
+ return jQuery.widget('IKS.hallobuttonset', {
2713
+ buttons: null,
2714
+ _create: function() {
2715
+ return this.element.addClass('ui-buttonset');
2716
+ },
2717
+ _init: function() {
2718
+ return this.refresh();
2719
+ },
2720
+ refresh: function() {
2721
+ var rtl;
2722
+ rtl = this.element.css('direction') === 'rtl';
2723
+ this.buttons = this.element.find('.ui-button');
2724
+ this.buttons.removeClass('ui-corner-all ui-corner-left ui-corner-right');
2725
+ if (rtl) {
2726
+ this.buttons.filter(':first').addClass('ui-corner-right');
2727
+ return this.buttons.filter(':last').addClass('ui-corner-left');
2728
+ } else {
2729
+ this.buttons.filter(':first').addClass('ui-corner-left');
2730
+ return this.buttons.filter(':last').addClass('ui-corner-right');
2731
+ }
2732
+ }
2733
+ });
2734
+ })(jQuery);
2735
+
2736
+ (function(jQuery) {
2737
+ return jQuery.widget('IKS.hallodropdownbutton', {
2738
+ button: null,
2739
+ options: {
2740
+ uuid: '',
2741
+ label: null,
2742
+ icon: null,
2743
+ editable: null,
2744
+ target: '',
2745
+ cssClass: null
2746
+ },
2747
+ _create: function() {
2748
+ var _base, _ref;
2749
+ return (_ref = (_base = this.options).icon) != null ? _ref : _base.icon = "icon-" + (this.options.label.toLowerCase());
2750
+ },
2751
+ _init: function() {
2752
+ var target,
2753
+ _this = this;
2754
+ target = jQuery(this.options.target);
2755
+ target.css('position', 'absolute');
2756
+ target.addClass('dropdown-menu');
2757
+ target.hide();
2758
+ if (!this.button) {
2759
+ this.button = this._prepareButton();
2760
+ }
2761
+ this.button.bind('click', function() {
2762
+ if (target.hasClass('open')) {
2763
+ _this._hideTarget();
2764
+ return;
2765
+ }
2766
+ return _this._showTarget();
2767
+ });
2768
+ target.bind('click', function() {
2769
+ return _this._hideTarget();
2770
+ });
2771
+ this.options.editable.element.bind('hallodeactivated', function() {
2772
+ return _this._hideTarget();
2773
+ });
2774
+ return this.element.append(this.button);
2775
+ },
2776
+ _showTarget: function() {
2777
+ var target;
2778
+ target = jQuery(this.options.target);
2779
+ this._updateTargetPosition();
2780
+ target.addClass('open');
2781
+ return target.show();
2782
+ },
2783
+ _hideTarget: function() {
2784
+ var target;
2785
+ target = jQuery(this.options.target);
2786
+ target.removeClass('open');
2787
+ return target.hide();
2788
+ },
2789
+ _updateTargetPosition: function() {
2790
+ var left, target, top, _ref;
2791
+ target = jQuery(this.options.target);
2792
+ _ref = this.button.position(), top = _ref.top, left = _ref.left;
2793
+ top += this.button.outerHeight();
2794
+ target.css('top', top);
2795
+ return target.css('left', left - 20);
2796
+ },
2797
+ _prepareButton: function() {
2798
+ var buttonEl, classes, id;
2799
+ id = "" + this.options.uuid + "-" + this.options.label;
2800
+ classes = ['ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all', 'ui-button-text-only'];
2801
+ buttonEl = jQuery("<button id=\"" + id + "\" class=\"" + (classes.join(' ')) + "\" title=\"" + this.options.label + "\"> <i class=\"" + this.options.icon + "\"></i> </button>");
2802
+ if (this.options.cssClass) {
2803
+ buttonEl.addClass(this.options.cssClass);
2804
+ }
2805
+ return buttonEl.button();
2806
+ }
2807
+ });
2808
+ })(jQuery);
2809
+
2810
+ }).call(this);