");
+ tabs = jQuery('.tabs', this.options.dialog);
+ tabContent = jQuery('.dialogcontent', this.options.dialog);
if (widget.options.suggestions) {
- this._addGuiTabSuggestions(jQuery(".tabs", this.options.dialog), jQuery(".dialogcontent", this.options.dialog));
+ this._addGuiTabSuggestions(tabs, tabContent);
}
if (widget.options.search || widget.options.searchUrl) {
- this._addGuiTabSearch(jQuery(".tabs", this.options.dialog), jQuery(".dialogcontent", this.options.dialog));
+ this._addGuiTabSearch(tabs, tabContent);
}
if (widget.options.upload || widget.options.uploadUrl) {
- this._addGuiTabUpload(jQuery(".tabs", this.options.dialog), jQuery(".dialogcontent", this.options.dialog));
+ this._addGuiTabUpload(tabs, tabContent);
}
this.current = jQuery('
').halloimagecurrent({
uuid: this.options.uuid,
@@ -1478,20 +2040,20 @@ http://hallojs.org
});
buttonset.append(buttonHolder);
this.button = buttonHolder;
- this.button.bind("change", function(event) {
+ this.button.on("click", function(event) {
if (widget.options.dialog.dialog("isOpen")) {
- return widget._closeDialog();
+ widget._closeDialog();
} else {
- return widget._openDialog();
+ widget._openDialog();
}
+ return false;
});
- this.options.editable.element.bind("hallodeactivated", function(event) {
+ this.options.editable.element.on("hallodeactivated", function(event) {
return widget._closeDialog();
});
jQuery(this.options.editable.element).delegate("img", "click", function(event) {
return widget._openDialog();
});
- buttonset.buttonset();
toolbar.append(buttonset);
this.options.dialog.dialog(this.options.dialogOpts);
return this._handleTabs();
@@ -1502,17 +2064,20 @@ http://hallojs.org
_handleTabs: function() {
var widget;
widget = this;
- jQuery('.nav li', this.options.dialog).bind('click', function() {
- var id;
+ jQuery('.nav li', this.options.dialog).on('click', function() {
+ var id, left;
jQuery("." + widget.widgetName + "-tab").hide();
id = jQuery(this).attr('id');
jQuery("#" + id + "-content").show();
- return jQuery("#" + widget.options.uuid + "-tab-activeIndicator").css("margin-left", jQuery(this).position().left + (jQuery(this).width() / 2));
+ left = jQuery(this).position().left + (jQuery(this).width() / 2);
+ return jQuery("#" + widget.options.uuid + "-tab-activeIndicator").css({
+ "margin-left": left
+ });
});
return jQuery('.nav li', this.options.dialog).first().click();
},
_openDialog: function() {
- var cleanUp, widget, xposition, yposition,
+ var cleanUp, editableEl, getActive, suggestionSelector, toolbarEl, widget, xposition, yposition,
_this = this;
widget = this;
cleanUp = function() {
@@ -1528,17 +2093,24 @@ http://hallojs.org
});
}, 15000);
};
- jQuery("#" + this.options.uuid + "-sugg-activeImage").attr("src", jQuery("#" + this.options.uuid + "-tab-suggestions-content .imageThumbnailActive").first().attr("src"));
- jQuery("#" + this.options.uuid + "-sugg-activeImageBg").attr("src", jQuery("#" + this.options.uuid + "-tab-suggestions-content .imageThumbnailActive").first().attr("src"));
+ suggestionSelector = "#" + this.options.uuid + "-tab-suggestions-content";
+ getActive = function() {
+ return jQuery('.imageThumbnailActive', suggestionSelector).first().attr("src");
+ };
+ jQuery("#" + this.options.uuid + "-sugg-activeImage").attr("src", getActive());
+ jQuery("#" + this.options.uuid + "-sugg-activeImageBg").attr("src", getActive());
this.lastSelection = this.options.editable.getSelection();
- xposition = jQuery(this.options.editable.element).offset().left + jQuery(this.options.editable.element).outerWidth() - 3;
- yposition = jQuery(this.options.toolbar).offset().top - jQuery(document).scrollTop() - 29;
+ editableEl = jQuery(this.options.editable.element);
+ toolbarEl = jQuery(this.options.toolbar);
+ xposition = editableEl.offset().left + editableEl.outerWidth() - 3;
+ yposition = toolbarEl.offset().top + toolbarEl.outerHeight() + 29;
+ yposition -= jQuery(document).scrollTop();
this.options.dialog.dialog("option", "position", [xposition, yposition]);
cleanUp();
widget.options.loaded = 1;
this.options.editable.keepActivated(true);
this.options.dialog.dialog("open");
- return this.options.dialog.bind('dialogclose', function() {
+ return this.options.dialog.on('dialogclose', function() {
jQuery('label', _this.button).removeClass('ui-state-active');
_this.options.editable.element.focus();
return _this.options.editable.keepActivated(false);
@@ -1549,8 +2121,8 @@ http://hallojs.org
},
_addGuiTabSuggestions: function(tabs, element) {
var tab;
- tabs.append(jQuery("
Upload"));
- tab = jQuery("
");
+ tabs.append(jQuery("
Suggestions "));
+ tab = jQuery("
");
element.append(tab);
return tab.halloimagesuggestions({
uuid: this.options.uuid,
@@ -1562,8 +2134,8 @@ http://hallojs.org
var dialogId, tab, widget;
widget = this;
dialogId = "" + this.options.uuid + "-image-dialog";
- tabs.append(jQuery("
Search"));
- tab = jQuery("
");
+ tabs.append(jQuery("
Search "));
+ tab = jQuery("
");
element.append(tab);
return tab.halloimagesearch({
uuid: this.options.uuid,
@@ -1576,8 +2148,8 @@ http://hallojs.org
},
_addGuiTabUpload: function(tabs, element) {
var tab;
- tabs.append(jQuery("
Upload"));
- tab = jQuery("
");
+ tabs.append(jQuery("
Upload "));
+ tab = jQuery("
");
element.append(tab);
return tab.halloimageupload({
uuid: this.options.uuid,
@@ -1586,30 +2158,31 @@ http://hallojs.org
imageWidget: this,
entity: this.options.entity
});
- /*
- insertImage = () ->
- #This may need to insert an image that does not have the same URL as the preview image, since it may be a different size
-
- # Check if we have a selection and fall back to @lastSelection otherwise
- try
- if not widget.options.editable.getSelection()
- throw new Error "SelectionNotSet"
- catch error
- widget.options.editable.restoreSelection(widget.lastSelection)
-
- document.execCommand "insertImage", null, jQuery(this).attr('src')
- img = document.getSelection().anchorNode.firstChild
- jQuery(img).attr "alt", jQuery(".caption").value
-
- triggerModified = () ->
- widget.element.trigger "hallomodified"
- window.setTimeout triggerModified, 100
- widget._closeDialog()
-
- @options.dialog.find(".halloimage-activeImage, ##{widget.options.uuid}-#{widget.widgetName}-addimage").click insertImage
- */
-
}
+ /*
+ insertImage = () ->
+ # This may need to insert an image that does not have the same URL as
+ # the preview image, since it may be a different size
+ # Check if we have a selection and fall back to @lastSelection otherwise
+ try
+ if not widget.options.editable.getSelection()
+ throw new Error "SelectionNotSet"
+ catch error
+ widget.options.editable.restoreSelection(widget.lastSelection)
+
+ document.execCommand "insertImage", null, jQuery(this).attr('src')
+ img = document.getSelection().anchorNode.firstChild
+ jQuery(img).attr "alt", jQuery(".caption").value
+
+ triggerModified = () ->
+ widget.element.trigger "hallomodified"
+ window.setTimeout triggerModified, 100
+ widget._closeDialog()
+
+ addImage = "##{widget.options.uuid}-#{widget.widgetName-addimage"
+ @options.dialog.find(".halloimage-activeImage, addImage).click insertImage
+ */
+
});
})(jQuery);
@@ -1617,7 +2190,7 @@ http://hallojs.org
return jQuery.widget("IKS.halloformat", {
options: {
editable: null,
- uuid: "",
+ uuid: '',
formattings: {
bold: true,
italic: true,
@@ -1646,11 +2219,12 @@ http://hallojs.org
_ref = this.options.formattings;
for (format in _ref) {
enabled = _ref[format];
- if (enabled) {
- buttonize(format);
+ if (!enabled) {
+ continue;
}
+ buttonize(format);
}
- buttonset.buttonset();
+ buttonset.hallobuttonset();
return toolbar.append(buttonset);
}
});
@@ -1684,10 +2258,9 @@ http://hallojs.org
};
buttonize("undo", "Undo");
buttonize("redo", "Redo");
- buttonset.buttonset();
+ buttonset.hallobuttonset();
return toolbar.append(buttonset);
- },
- _init: function() {}
+ }
});
})(jQuery);
@@ -1705,9 +2278,10 @@ http://hallojs.org
buttonset = jQuery("
");
contentId = "" + this.options.uuid + "-" + this.widgetName + "-data";
target = this._prepareDropdown(contentId);
+ toolbar.append(buttonset);
+ buttonset.hallobuttonset();
buttonset.append(target);
- buttonset.append(this._prepareButton(target));
- return toolbar.append(buttonset);
+ return buttonset.append(this._prepareButton(target));
},
_prepareDropdown: function(contentId) {
var addElement, containingElement, contentArea, element, _i, _len, _ref,
@@ -1715,19 +2289,25 @@ http://hallojs.org
contentArea = jQuery("
");
containingElement = this.options.editable.element.get(0).tagName.toLowerCase();
addElement = function(element) {
- var el, queryState;
- el = jQuery("<" + element + " class=\"menu-item\">" + element + "" + element + ">");
+ var el, events, queryState;
+ el = jQuery("
");
if (containingElement === element) {
el.addClass('selected');
}
if (containingElement !== 'div') {
el.addClass('disabled');
}
- el.bind('click', function() {
+ el.on('click', function() {
+ var tagName;
+ tagName = element.toUpperCase();
if (el.hasClass('disabled')) {
return;
}
- return _this.options.editable.execute('formatBlock', element.toUpperCase());
+ if (jQuery.browser.msie) {
+ _this.options.editable.execute('FormatBlock', "<" + tagName + ">");
+ return;
+ }
+ return _this.options.editable.execute('formatBlock', tagName);
});
queryState = function(event) {
var block;
@@ -1738,11 +2318,13 @@ http://hallojs.org
}
return el.removeClass('selected');
};
- _this.options.editable.element.bind('halloenabled', function() {
- return _this.options.editable.element.bind('keyup paste change mouseup', queryState);
+ events = 'keyup paste change mouseup';
+ _this.options.editable.element.on(events, queryState);
+ _this.options.editable.element.on('halloenabled', function() {
+ return _this.options.editable.element.on(events, queryState);
});
- _this.options.editable.element.bind('hallodisabled', function() {
- return _this.options.editable.element.unbind('keyup paste change mouseup', queryState);
+ _this.options.editable.element.on('hallodisabled', function() {
+ return _this.options.editable.element.off(events, queryState);
});
return el;
};
@@ -1782,35 +2364,50 @@ http://hallojs.org
width: 540,
height: 95,
title: "Enter Link",
+ buttonTitle: "Insert",
modal: true,
resizable: false,
draggable: false,
dialogClass: 'hallolink-dialog'
},
- butonCssClass: null
+ buttonCssClass: null
},
populateToolbar: function(toolbar) {
- var buttonize, buttonset, dialog, dialogId, dialogSubmitCb, urlInput, widget,
+ var butTitle, buttonize, buttonset, dialog, dialogId, dialogSubmitCb, isEmptyLink, urlInput, widget,
_this = this;
widget = this;
dialogId = "" + this.options.uuid + "-dialog";
- dialog = jQuery("
");
+ butTitle = this.options.dialogOpts.buttonTitle;
+ dialog = jQuery("
");
urlInput = jQuery('input[name=url]', dialog).focus(function(e) {
return this.select();
});
+ isEmptyLink = function(link) {
+ if ((new RegExp(/^\s*$/)).test(link)) {
+ return true;
+ }
+ if (link === widget.options.defaultUrl) {
+ return true;
+ }
+ return false;
+ };
dialogSubmitCb = function(event) {
- var link;
+ var link, selectionStart;
event.preventDefault();
link = urlInput.val();
widget.options.editable.restoreSelection(widget.lastSelection);
- if (((new RegExp(/^\s*$/)).test(link)) || link === widget.options.defaultUrl) {
+ if (isEmptyLink(link)) {
+ selectionStart = widget.lastSelection.startContainer;
if (widget.lastSelection.collapsed) {
- widget.lastSelection.setStartBefore(widget.lastSelection.startContainer);
- widget.lastSelection.setEndAfter(widget.lastSelection.startContainer);
+ widget.lastSelection.setStartBefore(selectionStart);
+ widget.lastSelection.setEndAfter(selectionStart);
window.getSelection().addRange(widget.lastSelection);
}
document.execCommand("unlink", null, "");
} else {
+ if (!(/:\/\//.test(link)) && !(/^mailto:/.test(link))) {
+ link = 'http://' + link;
+ }
if (widget.lastSelection.startContainer.parentNode.href === void 0) {
document.execCommand("createLink", null, link);
} else {
@@ -1839,27 +2436,34 @@ http://hallojs.org
});
buttonset.append(buttonHolder);
button = buttonHolder;
- button.bind("change", function(event) {
+ button.on("click", function(event) {
+ var selectionParent;
widget.lastSelection = widget.options.editable.getSelection();
urlInput = jQuery('input[name=url]', dialog);
- if (widget.lastSelection.startContainer.parentNode.href === void 0) {
+ selectionParent = widget.lastSelection.startContainer.parentNode;
+ if (!selectionParent.href) {
urlInput.val(widget.options.defaultUrl);
} else {
- urlInput.val(jQuery(widget.lastSelection.startContainer.parentNode).attr('href'));
+ urlInput.val(jQuery(selectionParent).attr('href'));
jQuery(urlInput[0].form).find('input[type=submit]').val('update');
}
widget.options.editable.keepActivated(true);
dialog.dialog('open');
- return dialog.bind('dialogclose', function() {
+ dialog.on('dialogclose', function() {
jQuery('label', buttonHolder).removeClass('ui-state-active');
widget.options.editable.element.focus();
return widget.options.editable.keepActivated(false);
});
+ return false;
});
- return _this.element.bind("keyup paste change mouseup", function(event) {
+ return _this.element.on("keyup paste change mouseup", function(event) {
var nodeName, start;
start = jQuery(widget.options.editable.getSelection().startContainer);
- nodeName = start.prop('nodeName') ? start.prop('nodeName') : start.parent().prop('nodeName');
+ if (start.prop('nodeName')) {
+ nodeName = start.prop('nodeName');
+ } else {
+ nodeName = start.parent().prop('nodeName');
+ }
if (nodeName && nodeName.toUpperCase() === "A") {
jQuery('label', button).addClass('ui-state-active');
return;
@@ -1871,12 +2475,11 @@ http://hallojs.org
buttonize("A");
}
if (this.options.link) {
- buttonset.buttonset();
toolbar.append(buttonset);
+ buttonset.hallobuttonset();
return dialog.dialog(this.options.dialogOpts);
}
- },
- _init: function() {}
+ }
});
})(jQuery);
@@ -1908,16 +2511,16 @@ http://hallojs.org
buttonize("Left");
buttonize("Center");
buttonize("Right");
- buttonset.buttonset();
+ buttonset.hallobuttonset();
return toolbar.append(buttonset);
- },
- _init: function() {}
+ }
});
})(jQuery);
(function(jQuery) {
- return jQuery.widget('IKS.hallobutton', {
+ jQuery.widget('IKS.hallobutton', {
button: null,
+ isChecked: false,
options: {
uuid: '',
label: null,
@@ -1928,39 +2531,39 @@ http://hallojs.org
cssClass: null
},
_create: function() {
- var id, _base, _ref;
+ 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;
- this.element.append(this._createButton(id, this.options.command));
- this.element.append(this._createLabel(id, this.options.command, this.options.label, this.options.icon));
- if (this.options.cssClass) {
- this.element.find('label').addClass(this.options.cssClass);
- }
- this.button = this.element.find('input');
- this.button.button();
+ 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);
}
- return this.button.data('hallo-command', this.options.command);
+ if (this.options.editable.options.touchScreen) {
+ this.button.addClass('btn-large');
+ }
+ this.button.data('hallo-command', this.options.command);
+ 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);
+ });
},
_init: function() {
- var editableElement, queryState,
+ var editableElement, events, queryState,
_this = this;
if (!this.button) {
this.button = this._prepareButton();
}
this.element.append(this.button);
- if (this.options.command) {
- this.button.bind('change', function(event) {
- return _this.options.editable.execute(_this.options.command);
- });
- }
- if (!this.options.queryState) {
- return;
- }
- editableElement = this.options.editable.element;
queryState = function(event) {
if (!_this.options.command) {
return;
@@ -1971,32 +2574,73 @@ http://hallojs.org
}
};
- editableElement.bind('keyup paste change mouseup hallomodified', queryState);
- editableElement.bind('halloenabled', function() {
- return editableElement.bind('keyup paste change mouseup hallomodified', queryState);
+ if (this.options.command) {
+ this.button.on('click', function(event) {
+ _this.options.editable.execute(_this.options.command);
+ queryState;
+
+ return false;
+ });
+ }
+ if (!this.options.queryState) {
+ 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.bind('hallodisabled', function() {
- return editableElement.unbind('keyup paste change mouseup hallomodified', queryState);
+ return editableElement.on('hallodisabled', function() {
+ return editableElement.off(events, queryState);
});
},
enable: function() {
- return this.button.button('enable');
+ return this.button.removeAttr('disabled');
},
disable: function() {
- return this.button.button('disable');
+ return this.button.attr('disabled', 'true');
+ },
+ isEnabled: function() {
+ return this.button.attr('disabled') !== 'true';
},
refresh: function() {
- return this.button.button('refresh');
+ if (this.isChecked) {
+ return this.button.addClass('ui-state-active');
+ } else {
+ return this.button.removeClass('ui-state-active');
+ }
},
checked: function(checked) {
- this.button.attr('checked', checked);
+ this.isChecked = checked;
return this.refresh();
},
- _createButton: function(id) {
- return jQuery("
");
+ _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();
},
- _createLabel: function(id, command, label, icon) {
- return jQuery("
");
+ 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);
@@ -2026,17 +2670,17 @@ http://hallojs.org
if (!this.button) {
this.button = this._prepareButton();
}
- this.button.bind('click', function() {
+ this.button.on('click', function() {
if (target.hasClass('open')) {
_this._hideTarget();
return;
}
return _this._showTarget();
});
- target.bind('click', function() {
+ target.on('click', function() {
return _this._hideTarget();
});
- this.options.editable.element.bind('hallodeactivated', function() {
+ this.options.editable.element.on('hallodeactivated', function() {
return _this._hideTarget();
});
return this.element.append(this.button);
@@ -2055,21 +2699,22 @@ http://hallojs.org
return target.hide();
},
_updateTargetPosition: function() {
- var bottom, left, target, _ref;
+ var left, target, top, _ref;
target = jQuery(this.options.target);
- _ref = this.element.position(), bottom = _ref.bottom, left = _ref.left;
- target.css('top', bottom);
+ _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 button, buttonEl, id;
+ var buttonEl, classes, id;
id = "" + this.options.uuid + "-" + this.options.label;
- buttonEl = jQuery("
");
+ 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);
}
- button = buttonEl.button();
- return button;
+ return buttonEl;
}
});
})(jQuery);
@@ -2080,7 +2725,8 @@ http://hallojs.org
options: {
parentElement: 'body',
editable: null,
- toolbar: null
+ toolbar: null,
+ positionAbove: false
},
_create: function() {
var _this = this;
@@ -2092,24 +2738,29 @@ http://hallojs.org
});
},
_getPosition: function(event, selection) {
- var position;
+ var eventType, position;
if (!event) {
return;
}
- if (event.originalEvent instanceof KeyboardEvent) {
- return this._getCaretPosition(selection);
- }
- if (event.originalEvent instanceof MouseEvent) {
- return position = {
- top: event.pageY,
- left: event.pageX
- };
+ 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
+ };
}
},
_getCaretPosition: function(range) {
var newRange, position, tmpSpan;
tmpSpan = jQuery("
");
- newRange = document.createRange();
+ newRange = rangy.createRange();
newRange.setStart(range.endContainer, range.endOffset);
newRange.insertNode(tmpSpan.get(0));
position = {
@@ -2128,31 +2779,56 @@ http://hallojs.org
this.toolbar.css('top', this.element.offset().top - 20);
return this.toolbar.css('left', this.element.offset().left);
},
- _updatePosition: function(position) {
+ _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;
}
- this.toolbar.css('top', position.top);
- return this.toolbar.css('left', position.left);
+ 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 = $(window).scrollTop() + top_offset;
+ left = $(window).scrollLeft() + selectionRect.left;
+ } else {
+ 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);
},
_bindEvents: function() {
var _this = this;
- this.element.bind('halloselected', function(event, data) {
+ this.element.on('halloselected', function(event, data) {
var position;
position = _this._getPosition(data.originalEvent, data.selection);
if (!position) {
return;
}
- _this._updatePosition(position);
- return _this.toolbar.show();
+ _this._updatePosition(position, data.selection);
+ if (_this.toolbar.html() !== '') {
+ return _this.toolbar.show();
+ }
});
- this.element.bind('hallounselected', function(event, data) {
+ this.element.on('hallounselected', function(event, data) {
return _this.toolbar.hide();
});
- return this.element.bind('hallodeactivated', function(event, data) {
+ return this.element.on('hallodeactivated', function(event, data) {
return _this.toolbar.hide();
});
}
@@ -2175,9 +2851,9 @@ http://hallojs.org
jQuery(this.options.parentElement).append(this.toolbar);
this._bindEvents();
jQuery(window).resize(function(event) {
- return _this._updatePosition(_this._getPosition(event));
+ return _this.setPosition();
});
- if (this.options.parentElement === 'body' && !this.options.floating) {
+ if (this.options.parentElement === 'body') {
el = jQuery(this.element);
widthToAdd = parseFloat(el.css('padding-left'));
widthToAdd += parseFloat(el.css('padding-right'));
@@ -2189,11 +2865,12 @@ http://hallojs.org
}
},
_getPosition: function(event, selection) {
- var offset, position;
+ var offset, position, width;
if (!event) {
return;
}
- offset = parseFloat(this.element.css('outline-width')) + parseFloat(this.element.css('outline-offset'));
+ width = parseFloat(this.element.css('outline-width'));
+ offset = width + parseFloat(this.element.css('outline-offset'));
return position = {
top: this.element.offset().top - this.toolbar.outerHeight() - offset,
left: this.element.offset().left - offset
@@ -2202,7 +2879,7 @@ http://hallojs.org
_getCaretPosition: function(range) {
var newRange, position, tmpSpan;
tmpSpan = jQuery("
");
- newRange = document.createRange();
+ newRange = rangy.createRange();
newRange.setStart(range.endContainer, range.endOffset);
newRange.insertNode(tmpSpan.get(0));
position = {
@@ -2218,16 +2895,16 @@ http://hallojs.org
}
this.toolbar.css('position', 'absolute');
this.toolbar.css('top', this.element.offset().top - this.toolbar.outerHeight());
- return this.toolbar.css('left', this.element.offset().left);
+ return this.toolbar.css('left', this.element.offset().left + 10);
},
_updatePosition: function(position) {},
_bindEvents: function() {
var _this = this;
- this.element.bind('halloactivated', function(event, data) {
- _this._updatePosition(_this._getPosition(event));
+ this.element.on('halloactivated', function(event, data) {
+ _this.setPosition();
return _this.toolbar.show();
});
- return this.element.bind('hallodeactivated', function(event, data) {
+ return this.element.on('hallodeactivated', function(event, data) {
return _this.toolbar.hide();
});
}