hallo_rails 0.2.2 → 0.2.3

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