From 2e04af953463643791f6362bd8ef4c6ba190abfa Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 18 Apr 2012 13:48:51 -0700 Subject: Squashed commit of the following: commit 2054551bfb01a0f4ca2e138b9d724835462d45cd Merge: 765c2da 616a853 Author: Valerio Virgillito Date: Wed Apr 18 13:48:21 2012 -0700 Merge branch 'refs/heads/master' into integration commit 765c2da8e1aa03550caf42b2bd5f367555ad2843 Author: Valerio Virgillito Date: Tue Apr 17 15:29:41 2012 -0700 updating the picasa carousel Signed-off-by: Valerio Virgillito commit 9484f1c82b81e27edf2dc0a1bcc1fa3b12077406 Merge: d27f2df cacb4a2 Author: Valerio Virgillito Date: Tue Apr 17 15:03:50 2012 -0700 Merge branch 'refs/heads/master' into integration commit d27f2df4d846064444263d7832d213535962abe7 Author: Valerio Virgillito Date: Wed Apr 11 10:39:36 2012 -0700 integrating new picasa carousel component Signed-off-by: Valerio Virgillito commit 6f98384c9ecbc8abe55ccfe1fc25a0c7ce22c493 Author: Valerio Virgillito Date: Tue Apr 10 14:33:00 2012 -0700 fixed the text area case issue Text area was renamed from TextArea to Textarea Signed-off-by: Valerio Virgillito commit 1e83e26652266136802bc7af930379c1ecd631a6 Author: Valerio Virgillito Date: Mon Apr 9 22:10:45 2012 -0700 integrating montage v0.8 into ninja. Signed-off-by: Valerio Virgillito Signed-off-by: Valerio Virgillito --- .../rich-text-linkpopup.js | 274 +++++++++++++++++++++ 1 file changed, 274 insertions(+) create mode 100644 node_modules/montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel/rich-text-linkpopup.js (limited to 'node_modules/montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel/rich-text-linkpopup.js') diff --git a/node_modules/montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel/rich-text-linkpopup.js b/node_modules/montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel/rich-text-linkpopup.js new file mode 100644 index 00000000..90342d81 --- /dev/null +++ b/node_modules/montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel/rich-text-linkpopup.js @@ -0,0 +1,274 @@ +/* + This file contains proprietary software owned by Motorola Mobility, Inc.
+ No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+ (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ +/** + @module "montage/ui/rich-text-editor/overlays/rich-text-resizer.reel" + @requires montage/core/core + @requires montage/ui/component +*/ +var Montage = require("montage").Montage, + Component = require("ui/component").Component; + +/** + @class module:"montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel".RichTextLinkPopup + @extends module:montage/ui/component.Component +*/ +exports.RichTextLinkPopup = Montage.create(Component,/** @lends module:"montage/ui/rich-text-editor/overlays/rich-text-linkpopup.reel".RichTextLinkPopup# */ { + + /** + Description TODO + @private + */ + _isActive: { + enumerable: false, + value: false + }, + /** + Description TODO + @private + */ + _editor: { + enumerable: false, + value: null + }, + + /** + Description TODO + @private + */ + target: { + enumerable: false, + value: null + }, + + /** + Description TODO + @private + */ + _needsReset: { + enumerable: false, + value: false + }, + + /** + Description TODO + @type {Function} + */ + initWithEditor: { + value: function(editor) { + this._editor = editor; + } + }, + + /** + Description TODO + @type {Function} + */ + editorMouseUp: { + value: function(event) { + var element; + + if (this._editor.activeOverlay != this) { + // Check if the caret is inside an image within an anchor element + if (event.target.nodeName == "IMG") { + element = event.target; + while (element && element != this._element) { + if (element.nodeName == "A") { + if (element != this.target) { + this.target = element; + this._needsReset = true; + if (this._isActive) { + this.needsDraw = true; + } else { + this._editor.showOverlay(this); + } + } + return true; + } + element = element.parentElement; + } + } + } + } + }, + + /** + Description TODO + @type {Function} + */ + editorTouchEnd: { + value: function(event) { + this.editorMouseUp(event); + } + }, + + /** + Description TODO + @type {Function} + */ + editorSelectionDidChange: { + value: function(range) { + var element; + + // Check if the caret is inside an anchor element + if (range && range.collapsed) { + element = range.commonAncestorContainer; + while (element && element != this._element) { + if (element.nodeName == "A") { + if (element != this.target) { + this.target = element; + this._needsReset = true; + if (this._isActive) { + this.needsDraw = true; + } else { + this._editor.showOverlay(this); + } + } + return true; + } + element = element.parentElement; + } + } + + if (this._editor.activeOverlay == this) { + this._editor.hideOverlay(); + } + + return false; + } + }, + + /** + Description TODO + @function + */ + didBecomeActive: { + value: function() { + this._isActive = true; + window.addEventListener("resize", this, false); + } + }, + + /** + Description TODO + @function + */ + didBecomeInactive: { + value: function() { + this._isActive = false; + window.removeEventListener("resize", this, false); + + //Reset the resizer internal + this.target = null; + this._needsReset = false; + } + }, + + /** + Description TODO + @function + */ + prepareForDraw: { + enumerable: false, + value: function() { + this._popupExtraWidth = this.element.offsetWidth; + } + }, + + /** + Description TODO + @function + */ + draw: { + enumerable: false, + value: function() { + var element = this.element, + target = this.target, + editorElement = this._editor.innerElement; + + if (this._needsReset) { + var offsetLeft, + offsetTop, + oh = editorElement.offsetHeight, + ow = editorElement.offsetWidth, + st = editorElement.scrollTop, + sl = editorElement.scrollLeft, + w = target.offsetWidth, + h = target.offsetHeight, + l, t, + left, leftWidth, right, rightWidth, + style = ""; + + var _findOffset = function(node) { + offsetTop = node.offsetTop; + offsetLeft = node.offsetLeft; + + while ((node = node.offsetParent) && node != editorElement) { + offsetTop += node.offsetTop; + offsetLeft += node.offsetLeft; + } + }; + _findOffset(target); + + l = offsetLeft; + t = offsetTop; + + // Should we display the popup on top or below the element? + if (t > 60 && t - st + h + 50 > oh) { + style = "bottom: " + (oh - t + 5) + "px;"; + } else { + style = "top: " + (t + h + 5 ) + "px;"; + } + + // Should we display the popup aligned on the left or right of the element? + left = sl; + right = sl + ow; + leftWidth = right - l; + rightWidth = l + w - left; + + if (leftWidth > rightWidth) { + //Let's align the popup to the left of the element or to the far left + if (leftWidth < 150) { + style += " left: " + (left + 5) + "px;"; + style += " max-width: " + (ow - 10 - this._popupExtraWidth) + "px;"; + } else { + style += " left: " + (left + l) + "px;"; + style += " max-width: " + (leftWidth - 5 - this._popupExtraWidth) + "px;"; + } + } else { + if (rightWidth < 150) { + style += " right: " + (left + 5) + "px;"; + style += " max-width: " + (ow - 10 - this._popupExtraWidth) + "px;"; + } else { + style += " right: " + (right - (left + l + w + 1)) + "px;"; + style += " max-width: " + (rightWidth - this._popupExtraWidth) + "px;"; + } + } + + // Position and size the popup + element.setAttribute("style", style); + + // Setup the anchor + this.link.href = target.href; + this.link.textContent = target.href; + + this._needsReset = false; + } + } + }, + + /** + Description TODO + @function + */ + handleResize: { + enumerable: false, + value: function() { + this._needsReset = true; + this.needsDraw = true; + } + } + +}); \ No newline at end of file -- cgit v1.2.3