");
+ jQuery(document.body).append(this.options.overlay);
+ }
+ this.options.overlay.on('click', jQuery.proxy(this.options.editable.turnOff, this.options.editable));
+ }
+ this.options.overlay.show();
+ if (this.options.background === null) {
+ if (jQuery("#halloBackground").length > 0) {
+ this.options.background = jQuery("#halloBackground");
+ } else {
+ this.options.background = jQuery("
");
+ jQuery(document.body).append(this.options.background);
+ }
+ }
+ this.resizeOverlay();
+ this.options.background.show();
+ if (!this.options.originalZIndex) {
+ this.options.originalZIndex = this.options.currentEditable.css("z-index");
+ }
+ return this.options.currentEditable.css('z-index', '350');
+ },
+ resizeOverlay: function() {
+ var offset;
+ offset = this.options.currentEditable.offset();
+ return this.options.background.css({
+ top: offset.top - this.options.padding,
+ left: offset.left - this.options.padding,
+ width: this.options.currentEditable.width() + 2 * this.options.padding,
+ height: this.options.currentEditable.height() + 2 * this.options.padding
+ });
+ },
+ hideOverlay: function() {
+ this.options.visible = false;
+ this.options.overlay.hide();
+ this.options.background.hide();
+ return this.options.currentEditable.css('z-index', this.options.originalZIndex);
+ },
+ _findBackgroundColor: function(jQueryfield) {
+ var color;
+ color = jQueryfield.css("background-color");
+ if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') {
+ return color;
+ }
+ if (jQueryfield.is("body")) {
+ return "white";
+ } else {
+ return this._findBackgroundColor(jQueryfield.parent());
+ }
+ }
+ });
+ })(jQuery);
+
+}).call(this);
+
+(function() {
+ (function(jQuery) {
+ return jQuery.widget("IKS.halloreundo", {
+ options: {
+ editable: null,
+ toolbar: null,
+ uuid: '',
+ buttonCssClass: null
+ },
+ populateToolbar: function(toolbar) {
+ var buttonize, buttonset,
+ _this = this;
+ buttonset = jQuery("
");
+ buttonize = function(cmd, label) {
+ var buttonElement;
+ buttonElement = jQuery('
');
+ buttonElement.hallobutton({
+ uuid: _this.options.uuid,
+ editable: _this.options.editable,
+ label: label,
+ icon: cmd === 'undo' ? 'icon-undo' : 'icon-repeat',
+ command: cmd,
+ queryState: false,
+ cssClass: _this.options.buttonCssClass
+ });
+ return buttonset.append(buttonElement);
+ };
+ buttonize("undo", "Undo");
+ buttonize("redo", "Redo");
+ buttonset.hallobuttonset();
+ return toolbar.append(buttonset);
+ }
+ });
+ })(jQuery);
+
+}).call(this);
+
+(function() {
+ (function(jQuery) {
+ return jQuery.widget("IKS.hallotoolbarlinebreak", {
options: {
editable: null,
uuid: "",
@@ -2095,226 +2616,139 @@
});
})(jQuery);
+}).call(this);
+
+(function() {
(function(jQuery) {
- jQuery.widget('IKS.hallobutton', {
- button: null,
- isChecked: false,
+ return jQuery.widget('IKS.halloToolbarContextual', {
+ toolbar: null,
options: {
- uuid: '',
- label: null,
- icon: null,
+ parentElement: 'body',
editable: null,
- command: null,
- commandValue: null,
- queryState: true,
- cssClass: null
+ toolbar: null,
+ positionAbove: false
},
_create: function() {
- var hoverclass, id, opts, _base, _ref,
- _this = this;
- if ((_ref = (_base = this.options).icon) == null) {
- _base.icon = "icon-" + (this.options.label.toLowerCase());
- }
- id = "" + this.options.uuid + "-" + this.options.label;
- opts = this.options;
- this.button = this._createButton(id, opts.command, opts.label, opts.icon);
- this.element.append(this.button);
- if (this.options.cssClass) {
- this.button.addClass(this.options.cssClass);
- }
- if (this.options.editable.options.touchScreen) {
- this.button.addClass('btn-large');
- }
- this.button.data('hallo-command', this.options.command);
- if (this.options.commandValue) {
- this.button.data('hallo-command-value', this.options.commandValue);
- }
- hoverclass = 'ui-state-hover';
- this.button.on('mouseenter', function(event) {
- if (_this.isEnabled()) {
- return _this.button.addClass(hoverclass);
- }
- });
- return this.button.on('mouseleave', function(event) {
- return _this.button.removeClass(hoverclass);
+ var _this = this;
+ this.toolbar = this.options.toolbar;
+ jQuery(this.options.parentElement).append(this.toolbar);
+ this._bindEvents();
+ return jQuery(window).resize(function(event) {
+ return _this._updatePosition(_this._getPosition(event));
});
},
- _init: function() {
- var editableElement, events, queryState,
- _this = this;
- if (!this.button) {
- this.button = this._prepareButton();
- }
- this.element.append(this.button);
- if (this.options.queryState === true) {
- queryState = function(event) {
- var compared, value;
- if (!_this.options.command) {
- return;
- }
- try {
- if (_this.options.commandValue) {
- value = document.queryCommandValue(_this.options.command);
- compared = value.match(new RegExp(_this.options.commandValue, "i"));
- return _this.checked(compared ? true : false);
- } else {
- return _this.checked(document.queryCommandState(_this.options.command));
- }
- } catch (e) {
-
- }
- };
- } else {
- queryState = this.options.queryState;
- }
- if (this.options.command) {
- this.button.on('click', function(event) {
- if (_this.options.commandValue) {
- _this.options.editable.execute(_this.options.command, _this.options.commandValue);
- } else {
- _this.options.editable.execute(_this.options.command);
- }
- queryState();
- return false;
- });
- }
- if (!this.options.queryState) {
+ _getPosition: function(event, selection) {
+ var eventType, position;
+ if (!event) {
return;
}
- editableElement = this.options.editable.element;
- events = 'keyup paste change mouseup hallomodified';
- editableElement.on(events, queryState);
- editableElement.on('halloenabled', function() {
- return editableElement.on(events, queryState);
- });
- return editableElement.on('hallodisabled', function() {
- return editableElement.off(events, queryState);
- });
+ eventType = event.type;
+ switch (eventType) {
+ case 'keydown':
+ case 'keyup':
+ case 'keypress':
+ return this._getCaretPosition(selection);
+ case 'click':
+ case 'mousedown':
+ case 'mouseup':
+ return position = {
+ top: event.pageY,
+ left: event.pageX
+ };
+ }
},
- enable: function() {
- return this.button.removeAttr('disabled');
+ _getCaretPosition: function(range) {
+ var newRange, position, tmpSpan;
+ tmpSpan = jQuery("
");
+ newRange = rangy.createRange();
+ newRange.setStart(range.endContainer, range.endOffset);
+ newRange.insertNode(tmpSpan.get(0));
+ position = {
+ top: tmpSpan.offset().top,
+ left: tmpSpan.offset().left
+ };
+ tmpSpan.remove();
+ return position;
},
- disable: function() {
- return this.button.attr('disabled', 'true');
+ setPosition: function() {
+ if (this.options.parentElement !== 'body') {
+ this.options.parentElement = 'body';
+ jQuery(this.options.parentElement).append(this.toolbar);
+ }
+ this.toolbar.css('position', 'absolute');
+ this.toolbar.css('top', this.element.offset().top - 20);
+ return this.toolbar.css('left', this.element.offset().left);
},
- isEnabled: function() {
- return this.button.attr('disabled') !== 'true';
- },
- refresh: function() {
- if (this.isChecked) {
- return this.button.addClass('ui-state-active');
+ _updatePosition: function(position, selection) {
+ var left, selectionRect, toolbar_height_offset, top, top_offset;
+ if (selection == null) {
+ selection = null;
+ }
+ if (!position) {
+ return;
+ }
+ if (!(position.top && position.left)) {
+ return;
+ }
+ toolbar_height_offset = this.toolbar.outerHeight() + 10;
+ if (selection && !selection.collapsed && selection.nativeRange) {
+ selectionRect = selection.nativeRange.getBoundingClientRect();
+ if (this.options.positionAbove) {
+ top_offset = selectionRect.top - toolbar_height_offset;
+ } else {
+ top_offset = selectionRect.bottom + 10;
+ }
+ top = jQuery(window).scrollTop() + top_offset;
+ left = jQuery(window).scrollLeft() + selectionRect.left;
} else {
- return this.button.removeClass('ui-state-active');
+ if (this.options.positionAbove) {
+ top_offset = -10 - toolbar_height_offset;
+ } else {
+ top_offset = 20;
+ }
+ top = position.top + top_offset;
+ left = position.left - this.toolbar.outerWidth() / 2 + 30;
}
+ this.toolbar.css('top', top);
+ return this.toolbar.css('left', left);
},
- checked: function(checked) {
- this.isChecked = checked;
- return this.refresh();
- },
- _createButton: function(id, command, label, icon) {
- var classes;
- classes = ['ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all', 'ui-button-text-only', "" + command + "_button"];
- return jQuery("
");
- }
- });
- return jQuery.widget('IKS.hallobuttonset', {
- buttons: null,
- _create: function() {
- return this.element.addClass('ui-buttonset');
- },
- _init: function() {
- return this.refresh();
- },
- refresh: function() {
- var rtl;
- rtl = this.element.css('direction') === 'rtl';
- this.buttons = this.element.find('.ui-button');
- this.buttons.removeClass('ui-corner-all ui-corner-left ui-corner-right');
- if (rtl) {
- this.buttons.filter(':first').addClass('ui-corner-right');
- return this.buttons.filter(':last').addClass('ui-corner-left');
- } else {
- this.buttons.filter(':first').addClass('ui-corner-left');
- return this.buttons.filter(':last').addClass('ui-corner-right');
- }
- }
- });
- })(jQuery);
-
- (function(jQuery) {
- return jQuery.widget('IKS.hallodropdownbutton', {
- button: null,
- options: {
- uuid: '',
- label: null,
- icon: null,
- editable: null,
- target: '',
- cssClass: null
- },
- _create: function() {
- var _base, _ref;
- return (_ref = (_base = this.options).icon) != null ? _ref : _base.icon = "icon-" + (this.options.label.toLowerCase());
- },
- _init: function() {
- var target,
- _this = this;
- target = jQuery(this.options.target);
- target.css('position', 'absolute');
- target.addClass('dropdown-menu');
- target.hide();
- if (!this.button) {
- this.button = this._prepareButton();
- }
- this.button.on('click', function() {
- if (target.hasClass('open')) {
- _this._hideTarget();
+ _bindEvents: function() {
+ var _this = this;
+ this.element.on('click', function(event, data) {
+ var position, scrollTop;
+ position = {};
+ scrollTop = $('window').scrollTop();
+ position.top = event.clientY + scrollTop;
+ position.left = event.clientX;
+ _this._updatePosition(position, null);
+ if (_this.toolbar.html() !== '') {
+ return _this.toolbar.show();
+ }
+ });
+ this.element.on('halloselected', function(event, data) {
+ var position;
+ position = _this._getPosition(data.originalEvent, data.selection);
+ if (!position) {
return;
}
- return _this._showTarget();
+ _this._updatePosition(position, data.selection);
+ if (_this.toolbar.html() !== '') {
+ return _this.toolbar.show();
+ }
});
- target.on('click', function() {
- return _this._hideTarget();
+ this.element.on('hallounselected', function(event, data) {
+ return _this.toolbar.hide();
});
- this.options.editable.element.on('hallodeactivated', function() {
- return _this._hideTarget();
+ return this.element.on('hallodeactivated', function(event, data) {
+ return _this.toolbar.hide();
});
- return this.element.append(this.button);
- },
- _showTarget: function() {
- var target;
- target = jQuery(this.options.target);
- this._updateTargetPosition();
- target.addClass('open');
- return target.show();
- },
- _hideTarget: function() {
- var target;
- target = jQuery(this.options.target);
- target.removeClass('open');
- return target.hide();
- },
- _updateTargetPosition: function() {
- var left, target, top, _ref;
- target = jQuery(this.options.target);
- _ref = this.button.position(), top = _ref.top, left = _ref.left;
- top += this.button.outerHeight();
- target.css('top', top);
- return target.css('left', left - 20);
- },
- _prepareButton: function() {
- var buttonEl, classes, id;
- id = "" + this.options.uuid + "-" + this.options.label;
- classes = ['ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all', 'ui-button-text-only'];
- buttonEl = jQuery("
");
- if (this.options.cssClass) {
- buttonEl.addClass(this.options.cssClass);
- }
- return buttonEl;
}
});
})(jQuery);
+}).call(this);
+
+(function() {
(function(jQuery) {
return jQuery.widget('IKS.halloToolbarFixed', {
toolbar: null,
@@ -2411,8 +2845,11 @@
});
})(jQuery);
+}).call(this);
+
+(function() {
(function(jQuery) {
- return jQuery.widget('IKS.halloToolbarContextual', {
+ return jQuery.widget('IKS.halloToolbarInstant', {
toolbar: null,
options: {
parentElement: 'body',
@@ -2506,6 +2943,17 @@
},
_bindEvents: function() {
var _this = this;
+ this.element.on('click', function(event, data) {
+ var position, scrollTop;
+ position = {};
+ scrollTop = $('window').scrollTop();
+ position.top = event.clientY + scrollTop;
+ position.left = event.clientX;
+ _this._updatePosition(position, null);
+ if (_this.toolbar.html() !== '') {
+ return _this.toolbar.show();
+ }
+ });
this.element.on('halloselected', function(event, data) {
var position;
position = _this._getPosition(data.originalEvent, data.selection);
@@ -2527,423 +2975,232 @@
});
})(jQuery);
- /*
- Hallo 1.0.2 - a rich text editing jQuery UI widget
- (c) 2011 Henri Bergius, IKS Consortium
- Hallo may be freely distributed under the MIT license
- http://hallojs.org
- */
-
+}).call(this);
+(function() {
(function(jQuery) {
- return jQuery.widget('IKS.hallo', {
- toolbar: null,
- bound: false,
- originalContent: '',
- previousContent: '',
- uuid: '',
- selection: null,
- _keepActivated: false,
- originalHref: null,
+ jQuery.widget('IKS.hallobutton', {
+ button: null,
+ isChecked: false,
options: {
- editable: true,
- plugins: {},
- toolbar: 'halloToolbarContextual',
- parentElement: 'body',
- buttonCssClass: null,
- toolbarCssClass: null,
- toolbarPositionAbove: false,
- toolbarOptions: {},
- placeholder: '',
- forceStructured: true,
- checkTouch: true,
- touchScreen: null
+ uuid: '',
+ label: null,
+ icon: null,
+ editable: null,
+ command: null,
+ commandValue: null,
+ queryState: true,
+ cssClass: null
},
_create: function() {
- var options, plugin, _ref,
+ var hoverclass, id, opts, _base,
_this = this;
- this.id = this._generateUUID();
- if (this.options.checkTouch && this.options.touchScreen === null) {
- this.checkTouch();
+ if ((_base = this.options).icon == null) {
+ _base.icon = "icon-" + (this.options.label.toLowerCase());
}
- _ref = this.options.plugins;
- for (plugin in _ref) {
- options = _ref[plugin];
- if (!jQuery.isPlainObject(options)) {
- options = {};
+ id = "" + this.options.uuid + "-" + this.options.label;
+ opts = this.options;
+ this.button = this._createButton(id, opts.command, opts.label, opts.icon);
+ this.element.append(this.button);
+ if (this.options.cssClass) {
+ this.button.addClass(this.options.cssClass);
+ }
+ if (this.options.editable.options.touchScreen) {
+ this.button.addClass('btn-large');
+ }
+ this.button.data('hallo-command', this.options.command);
+ if (this.options.commandValue) {
+ this.button.data('hallo-command-value', this.options.commandValue);
+ }
+ hoverclass = 'ui-state-hover';
+ this.button.on('mouseenter', function(event) {
+ if (_this.isEnabled()) {
+ return _this.button.addClass(hoverclass);
}
- jQuery.extend(options, {
- editable: this,
- uuid: this.id,
- buttonCssClass: this.options.buttonCssClass
- });
- jQuery(this.element)[plugin](options);
- }
- this.element.one('halloactivated', function() {
- return _this._prepareToolbar();
});
- return this.originalContent = this.getContents();
+ return this.button.on('mouseleave', function(event) {
+ return _this.button.removeClass(hoverclass);
+ });
},
_init: function() {
- if (this.options.editable) {
- return this.enable();
+ var editableElement, events, queryState,
+ _this = this;
+ if (!this.button) {
+ this.button = this._prepareButton();
+ }
+ this.element.append(this.button);
+ if (this.options.queryState === true) {
+ queryState = function(event) {
+ var compared, e, value;
+ if (!_this.options.command) {
+ return;
+ }
+ try {
+ if (_this.options.commandValue) {
+ value = document.queryCommandValue(_this.options.command);
+ compared = value.match(new RegExp(_this.options.commandValue, "i"));
+ return _this.checked(compared ? true : false);
+ } else {
+ return _this.checked(document.queryCommandState(_this.options.command));
+ }
+ } catch (_error) {
+ e = _error;
+ }
+ };
} else {
- return this.disable();
+ queryState = this.options.queryState;
}
- },
- destroy: function() {
- var options, plugin, _ref;
- this.disable();
- if (this.toolbar) {
- this.toolbar.remove();
- this.element[this.options.toolbar]('destroy');
+ if (this.options.command) {
+ this.button.on('click', function(event) {
+ if (_this.options.commandValue) {
+ _this.options.editable.execute(_this.options.command, _this.options.commandValue);
+ } else {
+ _this.options.editable.execute(_this.options.command);
+ }
+ if (typeof queryState === 'function') {
+ queryState();
+ }
+ return false;
+ });
}
- _ref = this.options.plugins;
- for (plugin in _ref) {
- options = _ref[plugin];
- jQuery(this.element)[plugin]('destroy');
+ if (!this.options.queryState) {
+ return;
}
- return jQuery.Widget.prototype.destroy.call(this);
- },
- disable: function() {
- var _this = this;
- this.element.attr("contentEditable", false);
- this.element.off("focus", this._activated);
- this.element.off("blur", this._deactivated);
- this.element.off("keyup paste change", this._checkModified);
- this.element.off("keyup", this._keys);
- this.element.off("keyup mouseup", this._checkSelection);
- this.bound = false;
- jQuery(this.element).removeClass('isModified');
- jQuery(this.element).removeClass('inEditMode');
- this.element.parents('a').andSelf().each(function(idx, elem) {
- var element;
- element = jQuery(elem);
- if (!element.is('a')) {
- return;
- }
- if (!_this.originalHref) {
- return;
- }
- return element.attr('href', _this.originalHref);
+ editableElement = this.options.editable.element;
+ events = 'keyup paste change mouseup hallomodified';
+ editableElement.on(events, queryState);
+ editableElement.on('halloenabled', function() {
+ return editableElement.on(events, queryState);
+ });
+ return editableElement.on('hallodisabled', function() {
+ return editableElement.off(events, queryState);
});
- return this._trigger("disabled", null);
},
enable: function() {
- var _this = this;
- this.element.parents('a[href]').andSelf().each(function(idx, elem) {
- var element;
- element = jQuery(elem);
- if (!element.is('a[href]')) {
- return;
- }
- _this.originalHref = element.attr('href');
- return element.removeAttr('href');
- });
- this.element.attr("contentEditable", true);
- if (!this.element.html().trim()) {
- this.element.html(this.options.placeholder);
- this.element.css({
- 'min-width': this.element.innerWidth(),
- 'min-height': this.element.innerHeight()
- });
- }
- if (!this.bound) {
- this.element.on("focus", this, this._activated);
- this.element.on("blur", this, this._deactivated);
- this.element.on("keyup paste change", this, this._checkModified);
- this.element.on("keyup", this, this._keys);
- this.element.on("keyup mouseup", this, this._checkSelection);
- this.bound = true;
- }
- if (this.options.forceStructured) {
- this._forceStructured();
- }
- return this._trigger("enabled", null);
+ return this.button.removeAttr('disabled');
},
- activate: function() {
- return this.element.focus();
+ disable: function() {
+ return this.button.attr('disabled', 'true');
},
- containsSelection: function() {
- var range;
- range = this.getSelection();
- return this.element.has(range.startContainer).length > 0;
+ isEnabled: function() {
+ return this.button.attr('disabled') !== 'true';
},
- getSelection: function() {
- var range, sel;
- sel = rangy.getSelection();
- range = null;
- if (sel.rangeCount > 0) {
- range = sel.getRangeAt(0);
+ refresh: function() {
+ if (this.isChecked) {
+ return this.button.addClass('ui-state-active');
} else {
- range = rangy.createRange();
+ return this.button.removeClass('ui-state-active');
}
- return range;
},
- restoreSelection: function(range) {
- var sel;
- sel = rangy.getSelection();
- return sel.setSingleRange(range);
+ checked: function(checked) {
+ this.isChecked = checked;
+ return this.refresh();
},
- replaceSelection: function(cb) {
- var newTextNode, r, range, sel, t;
- if (navigator.appName === 'Microsoft Internet Explorer') {
- t = document.selection.createRange().text;
- r = document.selection.createRange();
- return r.pasteHTML(cb(t));
+ _createButton: function(id, command, label, icon) {
+ var classes;
+ classes = ['ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all', 'ui-button-text-only', "" + command + "_button"];
+ return jQuery("
");
+ }
+ });
+ return jQuery.widget('IKS.hallobuttonset', {
+ buttons: null,
+ _create: function() {
+ return this.element.addClass('ui-buttonset');
+ },
+ _init: function() {
+ return this.refresh();
+ },
+ refresh: function() {
+ var rtl;
+ rtl = this.element.css('direction') === 'rtl';
+ this.buttons = this.element.find('.ui-button');
+ this.buttons.removeClass('ui-corner-all ui-corner-left ui-corner-right');
+ if (rtl) {
+ this.buttons.filter(':first').addClass('ui-corner-right');
+ return this.buttons.filter(':last').addClass('ui-corner-left');
} else {
- sel = window.getSelection();
- range = sel.getRangeAt(0);
- newTextNode = document.createTextNode(cb(range.extractContents()));
- range.insertNode(newTextNode);
- range.setStartAfter(newTextNode);
- sel.removeAllRanges();
- return sel.addRange(range);
+ this.buttons.filter(':first').addClass('ui-corner-left');
+ return this.buttons.filter(':last').addClass('ui-corner-right');
}
- },
- removeAllSelections: function() {
- if (navigator.appName === 'Microsoft Internet Explorer') {
- return range.empty();
- } else {
- return window.getSelection().removeAllRanges();
- }
- },
- getContents: function() {
- var cleanup, contentClone, plugin;
- contentClone = this.element.clone();
- for (plugin in this.options.plugins) {
- cleanup = jQuery(this.element).data('IKS-' + plugin).cleanupContentClone;
- if (!jQuery.isFunction(cleanup)) {
- continue;
- }
- jQuery(this.element)[plugin]('cleanupContentClone', contentClone);
- }
- return contentClone.html();
- },
- setContents: function(contents) {
- return this.element.html(contents);
- },
- isModified: function() {
- if (!this.previousContent) {
- this.previousContent = this.originalContent;
- }
- return this.previousContent !== this.getContents();
- },
- setUnmodified: function() {
- jQuery(this.element).removeClass('isModified');
- return this.previousContent = this.getContents();
- },
- setModified: function() {
- jQuery(this.element).addClass('isModified');
- return this._trigger('modified', null, {
- editable: this,
- content: this.getContents()
- });
- },
- restoreOriginalContent: function() {
- return this.element.html(this.originalContent);
- },
- execute: function(command, value) {
- if (document.execCommand(command, false, value)) {
- return this.element.trigger("change");
- }
- },
- protectFocusFrom: function(el) {
- var _this = this;
- return el.on("mousedown", function(event) {
- event.preventDefault();
- _this._protectToolbarFocus = true;
- return setTimeout(function() {
- return _this._protectToolbarFocus = false;
- }, 300);
- });
- },
- keepActivated: function(_keepActivated) {
- this._keepActivated = _keepActivated;
- },
- _generateUUID: function() {
- var S4;
- S4 = function() {
- return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
- };
- return "" + (S4()) + (S4()) + "-" + (S4()) + "-" + (S4()) + "-" + (S4()) + "-" + (S4()) + (S4()) + (S4());
- },
- _prepareToolbar: function() {
- var defaults, plugin, populate, toolbarOptions;
- this.toolbar = jQuery('
').hide();
- if (this.options.toolbarCssClass) {
- this.toolbar.addClass(this.options.toolbarCssClass);
- }
- defaults = {
- editable: this,
- parentElement: this.options.parentElement,
- toolbar: this.toolbar,
- positionAbove: this.options.toolbarPositionAbove
- };
- toolbarOptions = $.extend({}, defaults, this.options.toolbarOptions);
- this.element[this.options.toolbar](toolbarOptions);
- for (plugin in this.options.plugins) {
- populate = jQuery(this.element).data('IKS-' + plugin).populateToolbar;
- if (!jQuery.isFunction(populate)) {
- continue;
- }
- this.element[plugin]('populateToolbar', this.toolbar);
- }
- this.element[this.options.toolbar]('setPosition');
- return this.protectFocusFrom(this.toolbar);
- },
- changeToolbar: function(element, toolbar, hide) {
- var originalToolbar;
- if (hide == null) {
- hide = false;
- }
- originalToolbar = this.options.toolbar;
- this.options.parentElement = element;
- if (toolbar) {
- this.options.toolbar = toolbar;
- }
- if (!this.toolbar) {
- return;
- }
- this.element[originalToolbar]('destroy');
- this.toolbar.remove();
- this._prepareToolbar();
- if (hide) {
- return this.toolbar.hide();
- }
- },
- _checkModified: function(event) {
- var widget;
- widget = event.data;
- if (widget.isModified()) {
- return widget.setModified();
- }
- },
- _keys: function(event) {
- var old, widget;
- widget = event.data;
- if (event.keyCode === 27) {
- old = widget.getContents();
- widget.restoreOriginalContent(event);
- widget._trigger("restored", null, {
- editable: widget,
- content: widget.getContents(),
- thrown: old
- });
- return widget.turnOff();
- }
- },
- _rangesEqual: function(r1, r2) {
- if (r1.startContainer !== r2.startContainer) {
- return false;
- }
- if (r1.startOffset !== r2.startOffset) {
- return false;
- }
- if (r1.endContainer !== r2.endContainer) {
- return false;
- }
- if (r1.endOffset !== r2.endOffset) {
- return false;
- }
- return true;
- },
- _checkSelection: function(event) {
- var widget;
- if (event.keyCode === 27) {
- return;
- }
- widget = event.data;
- return setTimeout(function() {
- var sel;
- sel = widget.getSelection();
- if (widget._isEmptySelection(sel) || widget._isEmptyRange(sel)) {
- if (widget.selection) {
- widget.selection = null;
- widget._trigger("unselected", null, {
- editable: widget,
- originalEvent: event
- });
- }
- return;
- }
- if (!widget.selection || !widget._rangesEqual(sel, widget.selection)) {
- widget.selection = sel.cloneRange();
- return widget._trigger("selected", null, {
- editable: widget,
- selection: widget.selection,
- ranges: [widget.selection],
- originalEvent: event
- });
- }
- }, 0);
- },
- _isEmptySelection: function(selection) {
- if (selection.type === "Caret") {
- return true;
- }
- return false;
- },
- _isEmptyRange: function(range) {
- if (range.collapsed) {
- return true;
- }
- if (range.isCollapsed) {
- if (typeof range.isCollapsed === 'function') {
- return range.isCollapsed();
- }
- return range.isCollapsed;
- }
- return false;
- },
- turnOn: function() {
- if (this.getContents() === this.options.placeholder) {
- this.setContents('');
- }
- jQuery(this.element).addClass('inEditMode');
- return this._trigger("activated", null, this);
- },
- turnOff: function() {
- jQuery(this.element).removeClass('inEditMode');
- this._trigger("deactivated", null, this);
- if (!this.getContents()) {
- return this.setContents(this.options.placeholder);
- }
- },
- _activated: function(event) {
- return event.data.turnOn();
- },
- _deactivated: function(event) {
- if (event.data._keepActivated) {
- return;
- }
- if (event.data._protectToolbarFocus !== true) {
- return event.data.turnOff();
- } else {
- return setTimeout(function() {
- return jQuery(event.data.element).focus();
- }, 300);
- }
- },
- _forceStructured: function(event) {
- try {
- return document.execCommand('styleWithCSS', 0, false);
- } catch (e) {
- try {
- return document.execCommand('useCSS', 0, true);
- } catch (e) {
- try {
- return document.execCommand('styleWithCSS', false, false);
- } catch (e) {
-
- }
- }
- }
- },
- checkTouch: function() {
- return this.options.touchScreen = !!('createTouch' in document);
}
});
})(jQuery);
}).call(this);
+
+(function() {
+ (function(jQuery) {
+ return jQuery.widget('IKS.hallodropdownbutton', {
+ button: null,
+ options: {
+ uuid: '',
+ label: null,
+ icon: null,
+ editable: null,
+ target: '',
+ cssClass: null
+ },
+ _create: function() {
+ var _base;
+ return (_base = this.options).icon != null ? (_base = this.options).icon : _base.icon = "icon-" + (this.options.label.toLowerCase());
+ },
+ _init: function() {
+ var target,
+ _this = this;
+ target = jQuery(this.options.target);
+ target.css('position', 'absolute');
+ target.addClass('dropdown-menu');
+ target.hide();
+ if (!this.button) {
+ this.button = this._prepareButton();
+ }
+ this.button.on('click', function() {
+ if (target.hasClass('open')) {
+ _this._hideTarget();
+ return;
+ }
+ return _this._showTarget();
+ });
+ target.on('click', function() {
+ return _this._hideTarget();
+ });
+ this.options.editable.element.on('hallodeactivated', function() {
+ return _this._hideTarget();
+ });
+ return this.element.append(this.button);
+ },
+ _showTarget: function() {
+ var target;
+ target = jQuery(this.options.target);
+ this._updateTargetPosition();
+ target.addClass('open');
+ return target.show();
+ },
+ _hideTarget: function() {
+ var target;
+ target = jQuery(this.options.target);
+ target.removeClass('open');
+ return target.hide();
+ },
+ _updateTargetPosition: function() {
+ var left, target, top, _ref;
+ target = jQuery(this.options.target);
+ _ref = this.button.position(), top = _ref.top, left = _ref.left;
+ top += this.button.outerHeight();
+ target.css('top', top);
+ return target.css('left', left - 20);
+ },
+ _prepareButton: function() {
+ var buttonEl, classes, id;
+ id = "" + this.options.uuid + "-" + this.options.label;
+ classes = ['ui-button', 'ui-widget', 'ui-state-default', 'ui-corner-all', 'ui-button-text-only'];
+ buttonEl = jQuery("
");
+ if (this.options.cssClass) {
+ buttonEl.addClass(this.options.cssClass);
+ }
+ return buttonEl;
+ }
+ });
+ })(jQuery);
+
+}).call(this);
\ No newline at end of file