diff options
author | Andrew Dolgov <[email protected]> | 2012-08-14 18:59:10 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-08-14 18:59:18 +0400 |
commit | 1354d17270961fff662d40f90521223f8fd0d73b (patch) | |
tree | e9266be71587e47c800303446e968a6d3565e2cf /lib/dijit/_editor/selection.js | |
parent | d04f8c826f5283765f52cf6b98b42a1ed8f2d6bc (diff) |
update dojo to 1.7.3
Diffstat (limited to 'lib/dijit/_editor/selection.js')
-rw-r--r-- | lib/dijit/_editor/selection.js | 371 |
1 files changed, 2 insertions, 369 deletions
diff --git a/lib/dijit/_editor/selection.js b/lib/dijit/_editor/selection.js index 6fed82770..55d8ee23b 100644 --- a/lib/dijit/_editor/selection.js +++ b/lib/dijit/_editor/selection.js @@ -1,369 +1,2 @@ -/* - Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. - Available via Academic Free License >= 2.1 OR the modified BSD license. - see: http://dojotoolkit.org/license for details -*/ - - -if(!dojo._hasResource["dijit._editor.selection"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. -dojo._hasResource["dijit._editor.selection"] = true; -dojo.provide("dijit._editor.selection"); - - -dojo.getObject("_editor.selection", true, dijit); - -// FIXME: -// all of these methods branch internally for IE. This is probably -// sub-optimal in terms of runtime performance. We should investigate the -// size difference for differentiating at definition time. - -dojo.mixin(dijit._editor.selection, { - getType: function(){ - // summary: - // Get the selection type (like dojo.doc.select.type in IE). - if(dojo.isIE < 9){ - return dojo.doc.selection.type.toLowerCase(); - }else{ - var stype = "text"; - - // Check if the actual selection is a CONTROL (IMG, TABLE, HR, etc...). - var oSel; - try{ - oSel = dojo.global.getSelection(); - }catch(e){ /*squelch*/ } - - if(oSel && oSel.rangeCount == 1){ - var oRange = oSel.getRangeAt(0); - if( (oRange.startContainer == oRange.endContainer) && - ((oRange.endOffset - oRange.startOffset) == 1) && - (oRange.startContainer.nodeType != 3 /* text node*/) - ){ - stype = "control"; - } - } - return stype; //String - } - }, - - getSelectedText: function(){ - // summary: - // Return the text (no html tags) included in the current selection or null if no text is selected - if(dojo.isIE < 9){ - if(dijit._editor.selection.getType() == 'control'){ - return null; - } - return dojo.doc.selection.createRange().text; - }else{ - var selection = dojo.global.getSelection(); - if(selection){ - return selection.toString(); //String - } - } - return ''; - }, - - getSelectedHtml: function(){ - // summary: - // Return the html text of the current selection or null if unavailable - if(dojo.isIE < 9){ - if(dijit._editor.selection.getType() == 'control'){ - return null; - } - return dojo.doc.selection.createRange().htmlText; - }else{ - var selection = dojo.global.getSelection(); - if(selection && selection.rangeCount){ - var i; - var html = ""; - for(i = 0; i < selection.rangeCount; i++){ - //Handle selections spanning ranges, such as Opera - var frag = selection.getRangeAt(i).cloneContents(); - var div = dojo.doc.createElement("div"); - div.appendChild(frag); - html += div.innerHTML; - } - return html; //String - } - return null; - } - }, - - getSelectedElement: function(){ - // summary: - // Retrieves the selected element (if any), just in the case that - // a single element (object like and image or a table) is - // selected. - if(dijit._editor.selection.getType() == "control"){ - if(dojo.isIE < 9){ - var range = dojo.doc.selection.createRange(); - if(range && range.item){ - return dojo.doc.selection.createRange().item(0); - } - }else{ - var selection = dojo.global.getSelection(); - return selection.anchorNode.childNodes[ selection.anchorOffset ]; - } - } - return null; - }, - - getParentElement: function(){ - // summary: - // Get the parent element of the current selection - if(dijit._editor.selection.getType() == "control"){ - var p = this.getSelectedElement(); - if(p){ return p.parentNode; } - }else{ - if(dojo.isIE < 9){ - var r = dojo.doc.selection.createRange(); - r.collapse(true); - return r.parentElement(); - }else{ - var selection = dojo.global.getSelection(); - if(selection){ - var node = selection.anchorNode; - while(node && (node.nodeType != 1)){ // not an element - node = node.parentNode; - } - return node; - } - } - } - return null; - }, - - hasAncestorElement: function(/*String*/tagName /* ... */){ - // summary: - // Check whether current selection has a parent element which is - // of type tagName (or one of the other specified tagName) - // tagName: String - // The tag name to determine if it has an ancestor of. - return this.getAncestorElement.apply(this, arguments) != null; //Boolean - }, - - getAncestorElement: function(/*String*/tagName /* ... */){ - // summary: - // Return the parent element of the current selection which is of - // type tagName (or one of the other specified tagName) - // tagName: String - // The tag name to determine if it has an ancestor of. - var node = this.getSelectedElement() || this.getParentElement(); - return this.getParentOfType(node, arguments); //DOMNode - }, - - isTag: function(/*DomNode*/ node, /*String[]*/ tags){ - // summary: - // Function to determine if a node is one of an array of tags. - // node: - // The node to inspect. - // tags: - // An array of tag name strings to check to see if the node matches. - if(node && node.tagName){ - var _nlc = node.tagName.toLowerCase(); - for(var i=0; i<tags.length; i++){ - var _tlc = String(tags[i]).toLowerCase(); - if(_nlc == _tlc){ - return _tlc; // String - } - } - } - return ""; - }, - - getParentOfType: function(/*DomNode*/ node, /*String[]*/ tags){ - // summary: - // Function to locate a parent node that matches one of a set of tags - // node: - // The node to inspect. - // tags: - // An array of tag name strings to check to see if the node matches. - while(node){ - if(this.isTag(node, tags).length){ - return node; // DOMNode - } - node = node.parentNode; - } - return null; - }, - - collapse: function(/*Boolean*/beginning){ - // summary: - // Function to collapse (clear), the current selection - // beginning: Boolean - // Boolean to indicate whether to collapse the cursor to the beginning of the selection or end. - if(window.getSelection){ - var selection = dojo.global.getSelection(); - if(selection.removeAllRanges){ // Mozilla - if(beginning){ - selection.collapseToStart(); - }else{ - selection.collapseToEnd(); - } - }else{ // Safari - // pulled from WebCore/ecma/kjs_window.cpp, line 2536 - selection.collapse(beginning); - } - }else if(dojo.isIE){ // IE - var range = dojo.doc.selection.createRange(); - range.collapse(beginning); - range.select(); - } - }, - - remove: function(){ - // summary: - // Function to delete the currently selected content from the document. - var sel = dojo.doc.selection; - if(dojo.isIE < 9){ - if(sel.type.toLowerCase() != "none"){ - sel.clear(); - } - return sel; //Selection - }else{ - sel = dojo.global.getSelection(); - sel.deleteFromDocument(); - return sel; //Selection - } - }, - - selectElementChildren: function(/*DomNode*/element,/*Boolean?*/nochangefocus){ - // summary: - // clear previous selection and select the content of the node - // (excluding the node itself) - // element: DOMNode - // The element you wish to select the children content of. - // nochangefocus: Boolean - // Boolean to indicate if the foxus should change or not. - var win = dojo.global; - var doc = dojo.doc; - var range; - element = dojo.byId(element); - if(doc.selection && dojo.isIE < 9 && dojo.body().createTextRange){ // IE - range = element.ownerDocument.body.createTextRange(); - range.moveToElementText(element); - if(!nochangefocus){ - try{ - range.select(); // IE throws an exception here if the widget is hidden. See #5439 - }catch(e){ /* squelch */} - } - }else if(win.getSelection){ - var selection = dojo.global.getSelection(); - if(dojo.isOpera){ - //Opera's selectAllChildren doesn't seem to work right - //against <body> nodes and possibly others ... so - //we use the W3C range API - if(selection.rangeCount){ - range = selection.getRangeAt(0); - }else{ - range = doc.createRange(); - } - range.setStart(element, 0); - range.setEnd(element,(element.nodeType == 3)?element.length:element.childNodes.length); - selection.addRange(range); - }else{ - selection.selectAllChildren(element); - } - } - }, - - selectElement: function(/*DomNode*/element,/*Boolean?*/nochangefocus){ - // summary: - // clear previous selection and select element (including all its children) - // element: DOMNode - // The element to select. - // nochangefocus: Boolean - // Boolean indicating if the focus should be changed. IE only. - var range; - var doc = dojo.doc; - var win = dojo.global; - element = dojo.byId(element); - if(dojo.isIE < 9 && dojo.body().createTextRange){ - try{ - var tg = element.tagName ? element.tagName.toLowerCase() : ""; - if(tg === "img" || tg === "table"){ - range = dojo.body().createControlRange(); - }else{ - range = dojo.body().createRange(); - } - range.addElement(element); - if(!nochangefocus){ - range.select(); - } - }catch(e){ - this.selectElementChildren(element,nochangefocus); - } - }else if(dojo.global.getSelection){ - var selection = win.getSelection(); - range = doc.createRange(); - if(selection.removeAllRanges){ // Mozilla - // FIXME: does this work on Safari? - if(dojo.isOpera){ - //Opera works if you use the current range on - //the selection if present. - if(selection.getRangeAt(0)){ - range = selection.getRangeAt(0); - } - } - range.selectNode(element); - selection.removeAllRanges(); - selection.addRange(range); - } - } - }, - - inSelection: function(node){ - // summary: - // This function determines if 'node' is - // in the current selection. - // tags: - // public - if(node){ - var newRange; - var doc = dojo.doc; - var range; - - if(dojo.global.getSelection){ - //WC3 - var sel = dojo.global.getSelection(); - if(sel && sel.rangeCount > 0){ - range = sel.getRangeAt(0); - } - if(range && range.compareBoundaryPoints && doc.createRange){ - try{ - newRange = doc.createRange(); - newRange.setStart(node, 0); - if(range.compareBoundaryPoints(range.START_TO_END, newRange) === 1){ - return true; - } - }catch(e){ /* squelch */} - } - }else if(doc.selection){ - // Probably IE, so we can't use the range object as the pseudo - // range doesn't implement the boundry checking, we have to - // use IE specific crud. - range = doc.selection.createRange(); - try{ - newRange = node.ownerDocument.body.createControlRange(); - if(newRange){ - newRange.addElement(node); - } - }catch(e1){ - try{ - newRange = node.ownerDocument.body.createTextRange(); - newRange.moveToElementText(node); - }catch(e2){/* squelch */} - } - if(range && newRange){ - // We can finally compare similar to W3C - if(range.compareEndPoints("EndToStart", newRange) === 1){ - return true; - } - } - } - } - return false; // boolean - } - -}); - -} +//>>built +define("dijit/_editor/selection",["dojo/dom","dojo/_base/lang","dojo/_base/sniff","dojo/_base/window",".."],function(_1,_2,_3,_4,_5){_2.getObject("_editor.selection",true,_5);_2.mixin(_5._editor.selection,{getType:function(){if(_3("ie")<9){return _4.doc.selection.type.toLowerCase();}else{var _6="text";var _7;try{_7=_4.global.getSelection();}catch(e){}if(_7&&_7.rangeCount==1){var _8=_7.getRangeAt(0);if((_8.startContainer==_8.endContainer)&&((_8.endOffset-_8.startOffset)==1)&&(_8.startContainer.nodeType!=3)){_6="control";}}return _6;}},getSelectedText:function(){if(_3("ie")<9){if(_5._editor.selection.getType()=="control"){return null;}return _4.doc.selection.createRange().text;}else{var _9=_4.global.getSelection();if(_9){return _9.toString();}}return "";},getSelectedHtml:function(){if(_3("ie")<9){if(_5._editor.selection.getType()=="control"){return null;}return _4.doc.selection.createRange().htmlText;}else{var _a=_4.global.getSelection();if(_a&&_a.rangeCount){var i;var _b="";for(i=0;i<_a.rangeCount;i++){var _c=_a.getRangeAt(i).cloneContents();var _d=_4.doc.createElement("div");_d.appendChild(_c);_b+=_d.innerHTML;}return _b;}return null;}},getSelectedElement:function(){if(_5._editor.selection.getType()=="control"){if(_3("ie")<9){var _e=_4.doc.selection.createRange();if(_e&&_e.item){return _4.doc.selection.createRange().item(0);}}else{var _f=_4.global.getSelection();return _f.anchorNode.childNodes[_f.anchorOffset];}}return null;},getParentElement:function(){if(_5._editor.selection.getType()=="control"){var p=this.getSelectedElement();if(p){return p.parentNode;}}else{if(_3("ie")<9){var r=_4.doc.selection.createRange();r.collapse(true);return r.parentElement();}else{var _10=_4.global.getSelection();if(_10){var _11=_10.anchorNode;while(_11&&(_11.nodeType!=1)){_11=_11.parentNode;}return _11;}}}return null;},hasAncestorElement:function(_12){return this.getAncestorElement.apply(this,arguments)!=null;},getAncestorElement:function(_13){var _14=this.getSelectedElement()||this.getParentElement();return this.getParentOfType(_14,arguments);},isTag:function(_15,_16){if(_15&&_15.tagName){var _17=_15.tagName.toLowerCase();for(var i=0;i<_16.length;i++){var _18=String(_16[i]).toLowerCase();if(_17==_18){return _18;}}}return "";},getParentOfType:function(_19,_1a){while(_19){if(this.isTag(_19,_1a).length){return _19;}_19=_19.parentNode;}return null;},collapse:function(_1b){if(window.getSelection){var _1c=_4.global.getSelection();if(_1c.removeAllRanges){if(_1b){_1c.collapseToStart();}else{_1c.collapseToEnd();}}else{_1c.collapse(_1b);}}else{if(_3("ie")){var _1d=_4.doc.selection.createRange();_1d.collapse(_1b);_1d.select();}}},remove:function(){var sel=_4.doc.selection;if(_3("ie")<9){if(sel.type.toLowerCase()!="none"){sel.clear();}return sel;}else{sel=_4.global.getSelection();sel.deleteFromDocument();return sel;}},selectElementChildren:function(_1e,_1f){var _20=_4.global;var doc=_4.doc;var _21;_1e=_1.byId(_1e);if(doc.selection&&_3("ie")<9&&_4.body().createTextRange){_21=_1e.ownerDocument.body.createTextRange();_21.moveToElementText(_1e);if(!_1f){try{_21.select();}catch(e){}}}else{if(_20.getSelection){var _22=_4.global.getSelection();if(_3("opera")){if(_22.rangeCount){_21=_22.getRangeAt(0);}else{_21=doc.createRange();}_21.setStart(_1e,0);_21.setEnd(_1e,(_1e.nodeType==3)?_1e.length:_1e.childNodes.length);_22.addRange(_21);}else{_22.selectAllChildren(_1e);}}}},selectElement:function(_23,_24){var _25;var doc=_4.doc;var _26=_4.global;_23=_1.byId(_23);if(_3("ie")<9&&_4.body().createTextRange){try{var tg=_23.tagName?_23.tagName.toLowerCase():"";if(tg==="img"||tg==="table"){_25=_4.body().createControlRange();}else{_25=_4.body().createRange();}_25.addElement(_23);if(!_24){_25.select();}}catch(e){this.selectElementChildren(_23,_24);}}else{if(_26.getSelection){var _27=_26.getSelection();_25=doc.createRange();if(_27.removeAllRanges){if(_3("opera")){if(_27.getRangeAt(0)){_25=_27.getRangeAt(0);}}_25.selectNode(_23);_27.removeAllRanges();_27.addRange(_25);}}}},inSelection:function(_28){if(_28){var _29;var doc=_4.doc;var _2a;if(_4.global.getSelection){var sel=_4.global.getSelection();if(sel&&sel.rangeCount>0){_2a=sel.getRangeAt(0);}if(_2a&&_2a.compareBoundaryPoints&&doc.createRange){try{_29=doc.createRange();_29.setStart(_28,0);if(_2a.compareBoundaryPoints(_2a.START_TO_END,_29)===1){return true;}}catch(e){}}}else{if(doc.selection){_2a=doc.selection.createRange();try{_29=_28.ownerDocument.body.createControlRange();if(_29){_29.addElement(_28);}}catch(e1){try{_29=_28.ownerDocument.body.createTextRange();_29.moveToElementText(_28);}catch(e2){}}if(_2a&&_29){if(_2a.compareEndPoints("EndToStart",_29)===1){return true;}}}}}return false;}});return _5._editor.selection;});
\ No newline at end of file |