Changeset 530
- Timestamp:
- 08/30/08 21:52:54 (3 months ago)
- Files:
-
- trunk/src/wymeditor/jquery.wymeditor.explorer.js (modified) (2 diffs)
- trunk/src/wymeditor/jquery.wymeditor.js (modified) (5 diffs)
- trunk/src/wymeditor/jquery.wymeditor.mozilla.js (modified) (2 diffs)
- trunk/src/wymeditor/jquery.wymeditor.opera.js (modified) (2 diffs)
- trunk/src/wymeditor/jquery.wymeditor.safari.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/wymeditor/jquery.wymeditor.explorer.js
r485 r530 76 76 this._wym.bindEvents(); 77 77 78 // NOTE v.mische this part will be changed on event-hacking79 jQuery(this._doc).bind("keydown", this.handleKeydown);80 81 78 //post-init functions 82 79 if(jQuery.isFunction(this._options.postInit)) this._options.postInit(this); … … 150 147 }; 151 148 152 WYMeditor.WymClassExplorer.prototype.handleKeydown = function(evt) {153 154 //'this' is the doc155 var wym = WYMeditor.INSTANCES[this.title];156 157 // "start" Selection API158 var sel = wym.selection.getSelection();159 160 /*161 // some small tests for the Selection API162 var containers = WYMeditor.MAIN_CONTAINERS.join(",");163 if (sel.isAtStart(containers))164 alert("isAtStart: "+sel.startNode.parentNode.nodeName);165 if (sel.isAtEnd(containers))166 alert("isAtEnd: "+sel.endNode.parentNode.nodeName);167 if (evt.keyCode==WYMeditor.KEY.DELETE) {168 // if deleteIfExpanded wouldn't work, no selected text would be169 // deleted if you press del-key170 if (sel.deleteIfExpanded())171 return false;172 }173 if (evt.keyCode==WYMeditor.KEY.HOME) {174 // if cursorToStart won't work, the cursor won't be set to start175 // if you press home-key176 sel.cursorToStart(sel.container);177 return false;178 }179 if (evt.keyCode==WYMeditor.KEY.END)180 {181 // if cursorToEnd won't work, the cursor won't be set to the end182 // if you press end-key183 sel.cursorToEnd(sel.container);184 return false;185 }186 */187 };188 189 /********** SELECTION API **********/190 /*191 Class: WymSelExplorer192 Implementation of the Selection API for Microsoft Internet Explorer193 194 Properties:195 original - (object) Selection Object196 isCollapsed - (boolean) True if selection is collapsed to single position197 startNode - (DOM node) Node where the selection starts198 startOffset - (integer) Offset of the position in startNode199 endNode - (DOM node) Node where the selection ends200 endOffset - (integer) Offset of the position in endNode201 container - (DOM node) Node which includes the whole selection202 203 Example:204 "|" marks the start and the end of the selection.205 (start code)206 <p>A <b>sm|all</b> examp|le.</p>207 (end code)208 209 isCollapsed - false210 startNode - "small"211 startOffset - 2212 endNode - " example"213 endOffset - 6214 container - <p>...</p>215 */216 WYMeditor.WymSelExplorer = function(wym) {217 this._wym = wym;218 };219 220 WYMeditor.WymSelExplorer.prototype = {221 /*222 Property: getSelection223 Return a Selection API object224 225 Example:226 (start code)227 var sel = wym.selection.getSelection();228 (end code)229 230 Returns:231 (object) Selection API object232 */233 getSelection: function() {234 var sel = this._wym._iframe.contentWindow.document.selection;235 var range = sel.createRange();236 237 this.original = sel;238 239 if (sel.type == "None")240 this.isCollapsed = true;241 else242 this.isCollapsed = false;243 244 // get start of the selection (resp. cursor position if collapsed)245 var selStart = this._getNodeAndOffset(range.duplicate(), true);246 this.startNode = selStart.node;247 this.startOffset = selStart.offset;248 249 if (this.isCollapsed) {250 this.endNode = this.startNode;251 this.endOffset = this.startOffset;252 }253 else {254 var selEnd = this._getNodeAndOffset(range.duplicate(), false);255 this.endNode = selEnd.node;256 this.endOffset = selEnd.offset;257 }258 259 this.container = jQuery(range.parentElement()).parentsOrSelf(260 WYMeditor.MAIN_CONTAINERS.join(","))[0];261 262 return this;263 },264 265 266 _getNodeAndOffset: function(range, collapseToStart) {267 var parentElement = range.parentElement();268 269 // range from the beginning of parentElement to cursor position270 var parentRange = range.duplicate();271 272 // length of parentElement's text273 var parentLength;274 275 // offset from the beginning of parentElements to the cursor position276 var parentOffset = 0;277 278 // offset of the position to its node279 var offset = 0;280 281 // collapse to start or end282 range.collapse(collapseToStart);283 // select parent node and set range from the beginning of that node to284 // the cursor position285 parentRange.moveToElementText(parentElement);286 parentLength = parentRange.text.length;287 // XXX v.mische fix it288 var backwardRange = parentRange.duplicate();289 var searchRange = parentRange.duplicate();290 291 292 parentRange.setEndPoint("EndToStart", range);293 parentOffset = parentRange.text.length;294 295 // direction to search296 // 1 = forward297 // -1 = backward298 var direction = 1;299 300 // where to start to find the position301 var childPosition = 0;302 303 // ratio of the cursor position to the total parentElement text length304 var offsetRatio = parentOffset/parentLength;305 306 // offset from start (if search direction==-1: end) to the child node307 // we are currently at while searching the position308 // finally: position of the cursor within its node309 var offset = 0;310 311 var childNodes = parentElement.childNodes;312 313 // try to find a better start position for searching314 //if (childNodes.length>20 && offsetRatio>0.1) {315 if (childNodes.length>20 && offsetRatio>0.1) {316 // range around the appropriate node317 var childRange = searchRange.duplicate();318 // length from start to the beginning of a node near the node319 // of the position we are looking for320 //var childOffsetRange = parentRange.duplicate();321 322 childPosition = Math.round(offsetRatio * childNodes.length-1);323 324 if (childPosition <= 0)325 childPosition = 1;326 327 // moveToElementText doesn't work with text nodes328 while ((childNodes[childPosition].nodeType == WYMeditor.NODE.TEXT329 || childNodes[childPosition].nodeName == "BR")330 && childPosition > 0) {331 childPosition--;332 }333 334 if (childPosition > 0) {335 childRange.moveToElementText(childNodes[childPosition]);336 // Range from start of parent node to the start of the proposed337 // child node338 childRange.setEndPoint("EndToStart", searchRange);339 340 // search forward341 if (parentOffset > childRange.text.length) {342 direction = 1;343 searchRange.setEndPoint("StartToEnd", childRange);344 searchRange.setEndPoint("EndToEnd", parentRange);345 }346 // search backwards347 else {348 direction = -1;349 searchRange.setEndPoint("StartToEnd", parentRange);350 searchRange.setEndPoint("EndToEnd", childRange);351 352 // caused by ranges353 childPosition--;354 }355 356 }357 // start at the beginning358 else {359 direction = 1;360 searchRange = parentRange.duplicate();361 }362 }363 else {364 if (direction == 1)365 searchRange = parentRange.duplicate();366 else {367 searchRange = backwardRange.duplicate();368 searchRange.setEndPoint("StartToEnd", parentRange);369 }370 }371 372 var node=parentElement.childNodes[childPosition];373 374 375 var currentOffsetRange = searchRange.duplicate();376 if (direction==1) {377 // text length of the current node378 var nodeLength = 0;379 var br = 0;380 381 while (node) {382 if (node.nodeName == 'BR')383 br++;384 nodeLength = this._getTextLength(node);385 if (currentOffsetRange.text.length > nodeLength) {386 currentOffsetRange.moveStart('character', nodeLength + br);387 br = 0;388 }389 else390 break;391 392 node = node.nextSibling;393 }394 offset = currentOffsetRange.text.length;395 }396 // go backwards397 else {398 var nodeLength = 0;399 var br = 0;400 401 while (node) {402 if (node.nodeName == 'BR')403 br++;404 nodeLength = this._getTextLength(node);405 406 if (currentOffsetRange.text.length > nodeLength) {407 var length = currentOffsetRange.text.length;408 currentOffsetRange.moveEnd('character', -(nodeLength+br));409 // NOTE v.mische Sometimes the range isn't move as far as410 // expected. I don't know whenwhy it happens, but it does411 if (br == 0) {412 var diff = (length-nodeLength) - currentOffsetRange.text.length;413 currentOffsetRange.moveEnd('character', diff);414 }415 br = 0;416 }417 else418 break;419 420 if (node.previousSibling)421 node = node.previousSibling;422 else423 break;424 }425 426 offset = nodeLength - currentOffsetRange.text.length;427 }428 429 return {'node': node, 'offset': offset};430 },431 432 /*433 Property: _getTextLength434 Get the length of the text of a DOM node.435 436 Arguments:437 node - (DOM node) [required] The node you what to know the length of.438 439 Example:440 (start code)441 var node = document.createTextNode("foo");442 _getTextLength(node) // returns 3443 (end code)444 445 Returns:446 (int) Length of a DOM node.447 */448 _getTextLength: function(node) {449 if (node.nodeType == WYMeditor.NODE.ELEMENT)450 return node.innerText.length;451 else if (node.nodeType == WYMeditor.NODE.TEXT)452 return node.data.length;453 },454 455 /*456 Property: deleteIfExpanded457 Delete contents of a selection458 459 Example:460 (start code)461 var sel = wym.selection.getSelection();462 sel.deleteIfExpanded();463 (end code)464 465 Returns:466 (boolean) True if it was expanded and thus deleted467 */468 deleteIfExpanded: function() {469 if(!this.isCollapsed) {470 this.original.clear();471 return true;472 }473 return false;474 }475 };476 trunk/src/wymeditor/jquery.wymeditor.js
r529 r530 104 104 */ 105 105 106 VERSION : "0.5-a 1",106 VERSION : "0.5-a2", 107 107 INSTANCES : [], 108 108 STRINGS : [], … … 270 270 this._options.jQueryPath = this._options.jQueryPath 271 271 || this.computeJqueryPath(); 272 273 //instanciate a WYMeditor Selection API class274 this.selection = new WYMeditor.WymSelection();275 272 276 273 //initialize the editor instance … … 688 685 if (jQuery.browser.msie) { 689 686 var WymClass = new WYMeditor.WymClassExplorer(this); 690 var WymSel = new WYMeditor.WymSelExplorer(this);691 687 } 692 688 else if (jQuery.browser.mozilla) { 693 689 var WymClass = new WYMeditor.WymClassMozilla(this); 694 var WymSel = new WYMeditor.WymSelMozilla(this);695 690 } 696 691 else if (jQuery.browser.opera) { 697 692 var WymClass = new WYMeditor.WymClassOpera(this); 698 var WymSel = new WYMeditor.WymSelOpera(this);699 693 } 700 694 else if (jQuery.browser.safari) { 701 695 var WymClass = new WYMeditor.WymClassSafari(this); 702 var WymSel = new WYMeditor.WymSelSafari(this);703 696 } 704 697 … … 810 803 this.loadSkin(); 811 804 812 }813 814 if(WymSel) {815 816 //extend the selection object817 //don't use jQuery.extend since 1.1.4818 //jQuery.extend(this.selection, WymSel);819 for (prop in WymSel) { this.selection[prop] = WymSel[prop]; }820 805 } 821 806 }; … … 1521 1506 wym._options.postInitDialog(wym,window); 1522 1507 1523 };1524 1525 1526 1527 /********** SELECTION API **********/1528 1529 WYMeditor.WymSelection = function() {1530 this.test = "test from WymSelection";1531 };1532 1533 1534 WYMeditor.WymSelection.prototype = {1535 /* The following properties are set in the browser specific file (in1536 * getSelection()):1537 * this.original1538 * this.startNode1539 * this.endNode1540 * this.startOffset1541 * this.endOffset1542 * this.iscollapsed1543 * this.container1544 */1545 1546 /* The following methods are implemented in browser specific file:1547 * - deleteIfExpanded()1548 * - cursorToStart()1549 * - cursorToEnd()1550 */1551 1552 1553 isAtStart: function(jqexpr) {1554 var parent = jQuery(this.startNode).parentsOrSelf(jqexpr);1555 1556 // jqexpr isn't a parent of the current cursor position1557 if (parent.length==0)1558 return false;1559 1560 var startNode = this.startNode;1561 if (startNode.nodeType == WYMeditor.NODE.TEXT) {1562 // 1. startNode ist first child1563 // 2. offset needs to be 0 to be at the start (or the previous1564 // characters are whitespaces)1565 if ((startNode.previousSibling1566 && !WYMeditor.isPhantomNode(startNode.previousSibling))1567 || (this.startOffset != 0 && !WYMeditor.isPhantomString(1568 startNode.data.substring(0, this.startOffset))))1569 return false;1570 else1571 startNode = startNode.parentNode;1572 }1573 // cursor can be at the start of a text node and have a startOffset > 01574 // (if the node contains trailign whitespaces)1575 else if (this.startOffset != 0)1576 return false;1577 1578 1579 for (var n=jQuery(startNode); n[0]!=parent[0]; n=n.parent()) {1580 var firstChild = n.parent().children(':first');1581 1582 // node isn't first child => cursor can't be at the beginning1583 if (firstChild[0] != n[0]1584 || (firstChild[0].previousSibling1585 && !WYMeditor.isPhantomNode(firstChild[0].previousSibling)))1586 return false;1587 }1588 1589 return true;1590 },1591 1592 isAtEnd: function(jqexpr) {1593 var parent = jQuery(this.endNode).parentsOrSelf(jqexpr);1594 1595 // jqexpr isn't a parent of the current cursor position1596 if (parent.length==0)1597 return false;1598 else1599 parent = parent[0];1600 1601 1602 // This is the case if, e.g ("|" = cursor): <p>textnode|<br/></p>,1603 // there the offset of endNode (endOffset) is 1 (behind the first node1604 // of <p>)1605 if (this.endNode == parent) {1606 // NOTE I don't know if it is a good idea to delete the <br>1607 // here, as "atEnd()" probably shouldn't change the dom tree,1608 // but only searching it1609 if (this.endNode.lastChild.nodeName == "BR")1610 this.endNode.removeChild(endNode.lastChild);1611 1612 // if cursor is really at the end1613 if (this.endOffset == 0)1614 return false;1615 else {1616 for (var nNext=this.endNode.childNodes[this.endOffset-1].nextSibling;1617 nNext==null || nNext.nodeName == "BR";1618 nNext=nNext.nextSibling)1619 1620 if (nNext==null)1621 return true;1622 }1623 1624 }1625 else {1626 var endNode = this.endNode;1627 if (endNode.nodeType == WYMeditor.NODE.TEXT) {1628 if ((endNode.nextSibling1629 && !WYMeditor.isPhantomNode(endNode.nextSibling))1630 || (this.endOffset != endNode.data.length))1631 return false;1632 else1633 endNode = endNode.parentNode;1634 }1635 1636 for (var n=endNode; n!=parent; n=n.parentNode) {1637 var lastChild = n.parentNode.lastChild;1638 // node isn't last child => cursor can't be at the end1639 // (is this true?) in gecko there the last child could be a1640 // phantom node1641 1642 // sometimes also whitespacenodes which aren't phatom nodes1643 // get stripped, but this is ok, as this is a wysiwym editor1644 if ((lastChild != n) ||1645 (WYMeditor.isPhantomNode(lastChild)1646 && lastChild.previousSibling != n)) {1647 return false;1648 }1649 }1650 }1651 1652 if (this.endOffset == this.endNode.length)1653 return true;1654 else1655 return false;1656 }1657 1508 }; 1658 1509 trunk/src/wymeditor/jquery.wymeditor.mozilla.js
r503 r530 166 166 var wym = WYMeditor.INSTANCES[this.title]; 167 167 168 // "start" Selection API169 var sel = wym.selection.getSelection();170 171 /*172 // some small tests for the Selection API173 var containers = WYMeditor.MAIN_CONTAINERS.join(",");174 if (sel.isAtStart(containers))175 alert("isAtStart: "+sel.startNode.parentNode.nodeName);176 if (sel.isAtEnd(containers))177 alert("isAtEnd: "+sel.endNode.parentNode.nodeName);178 if (evt.keyCode==WYMeditor.KEY.DELETE) {179 // if deleteIfExpanded wouldn't work, no selected text would be180 // deleted if you press del-key181 if (sel.deleteIfExpanded())182 return false;183 }184 if (evt.keyCode==WYMeditor.KEY.HOME) {185 // if cursorToStart won't work, the cursor won't be set to start186 // if you press home-key187 sel.cursorToStart(sel.container);188 return false;189 }190 if (evt.keyCode==WYMeditor.KEY.END)191 {192 // if cursorToEnd won't work, the cursor won't be set to the end193 // if you press end-key194 sel.cursorToEnd(sel.container);195 return false;196 }197 */198 199 168 if(evt.ctrlKey){ 200 169 if(evt.keyCode == 66){ … … 308 277 }; 309 278 310 /********** SELECTION API **********/311 312 WYMeditor.WymSelMozilla = function(wym) {313 this._wym = wym;314 };315 316 WYMeditor.WymSelMozilla.prototype = {317 getSelection: function() {318 var _sel = this._wym._iframe.contentWindow.getSelection();319 // NOTE v.mische can startNode/endNote be phantom nodes?320 this.startNode = _sel.getRangeAt(0).startContainer;321 this.endNode = _sel.getRangeAt(0).endContainer;322 this.startOffset = _sel.getRangeAt(0).startOffset;323 this.endOffset = _sel.getRangeAt(0).endOffset;324 this.isCollapsed = _sel.isCollapsed;325 this.original = _sel;326 this.container = jQuery(this.startNode).parentsOrSelf(327 WYMeditor.MAIN_CONTAINERS.join(","))[0];328 329 return this;330 },331 332 cursorToStart: function(jqexpr) {333 if (jqexpr.nodeType == WYMeditor.NODE.TEXT)334 jqexpr = jqexpr.parentNode;335 336 var firstTextNode = jQuery(jqexpr)[0];337 338 while (firstTextNode.nodeType!=WYMeditor.NODE.TEXT) {339 if (!firstTextNode.hasChildNodes())340 break;341 firstTextNode = firstTextNode.firstChild;342 }343 344 if (WYMeditor.isPhantomNode(firstTextNode))345 firstTextNode = firstTextNode.nextSibling;346 347 // e.g. an <img/>348 if (firstTextNode.nodeType == WYMeditor.NODE.ELEMENT)349 this.original.collapse(firstTextNode.parentNode, 0);350 else351 this.original.collapse(firstTextNode, 0);352 },353 354 cursorToEnd: function(jqexpr) {355 if (jqexpr.nodeType == WYMeditor.NODE.TEXT)356 jqexpr = jqexpr.parentNode;357 358 var lastTextNode = jQuery(jqexpr)[0];359 360 while (lastTextNode.nodeType!=WYMeditor.NODE.TEXT) {361 if (!lastTextNode.hasChildNodes())362 break;363 lastTextNode = lastTextNode.lastChild;364 }365 366 if (WYMeditor.isPhantomNode(lastTextNode))367 lastTextNode = lastTextNode.previousSibling;368 369 // e.g. an <img/>370 if (lastTextNode.nodeType == WYMeditor.NODE.ELEMENT)371 this.original.collapse(lastTextNode.parentNode,372 lastTextNode.parentNode.childNodes.length);373 else374 this.original.collapse(lastTextNode, lastTextNode.length);375 },376 377 deleteIfExpanded: function() {378 if(!this.original.isCollapsed) {379 this.original.deleteFromDocument();380 return true;381 }382 return false;383 }384 };385 386 trunk/src/wymeditor/jquery.wymeditor.opera.js
r485 r530 107 107 //'this' is the doc 108 108 var wym = WYMeditor.INSTANCES[this.title]; 109 110 // "start" Selection API 111 var sel = wym.selection.getSelection(); 112 113 /* 114 // some small tests for the Selection API 115 var containers = WYMeditor.MAIN_CONTAINERS.join(","); 116 if (sel.isAtStart(containers)) 117 alert("isAtStart: "+sel.startNode.parentNode.nodeName); 118 if (sel.isAtEnd(containers)) 119 alert("isAtEnd: "+sel.endNode.parentNode.nodeName); 120 if (evt.keyCode==WYMeditor.KEY.DELETE) { 121 // if deleteIfExpanded wouldn't work, no selected text would be 122 // deleted if you press del-key 123 if (sel.deleteIfExpanded()) 124 return false; 125 } 126 if (evt.keyCode==WYMeditor.KEY.HOME) { 127 // if cursorToStart won't work, the cursor won't be set to start 128 // if you press home-key 129 sel.cursorToStart(sel.container); 130 return false; 131 } 132 if (evt.keyCode==WYMeditor.KEY.END) 133 { 134 // if cursorToEnd won't work, the cursor won't be set to the end 135 // if you press end-key 136 sel.cursorToEnd(sel.container); 137 return false; 138 } 139 */ 140 109 var sel = wym._iframe.contentWindow.getSelection(); 110 startNode = sel.getRangeAt(0).startContainer; 141 111 142 112 //Get a P instead of no container 143 if(!sel.container 113 if(!jQuery(startNode).parentsOrSelf( 114 WYMeditor.MAIN_CONTAINERS.join(","))[0] 144 115 && evt.keyCode != WYMeditor.KEY.ENTER 145 116 && evt.keyCode != WYMeditor.KEY.LEFT … … 166 137 }; 167 138 168 /********** SELECTION API **********/169 170 WYMeditor.WymSelOpera = function(wym) {171 this._wym = wym;172 };173 174 WYMeditor.WymSelOpera.prototype = {175 getSelection: function() {176 var _sel = this._wym._iframe.contentWindow.getSelection();177 // NOTE v.mische can startNode/endNote be phantom nodes?178 this.startNode = _sel.getRangeAt(0).startContainer;179 this.endNode = _sel.getRangeAt(0).endContainer;180 this.startOffset = _sel.getRangeAt(0).startOffset;181 this.endOffset = _sel.getRangeAt(0).endOffset;182 this.isCollapsed = _sel.isCollapsed;183 this.original = _sel;184 this.container = jQuery(this.startNode).parentsOrSelf(185 WYMeditor.MAIN_CONTAINERS.join(","))[0];186 187 return this;188 },189 190 cursorToStart: function(jqexpr) {191 if (jqexpr.nodeType == WYMeditor.NODE.TEXT)192 jqexpr = jqexpr.parentNode;193 194 var firstTextNode = jQuery(jqexpr)[0];195 196 while (firstTextNode.nodeType!=WYMeditor.NODE.TEXT) {197 if (!firstTextNode.hasChildNodes())198 break;199 firstTextNode = firstTextNode.firstChild;200 }201 202 if (WYMeditor.isPhantomNode(firstTextNode))203 firstTextNode = firstTextNode.nextSibling;204 205 // e.g. an <img/>206 if (firstTextNode.nodeType == WYMeditor.NODE.ELEMENT)207 this.original.collapse(firstTextNode.parentNode, 0);208 else209 this.original.collapse(firstTextNode, 0);210 },211 212 cursorToEnd: function(jqexpr) {213 if (jqexpr.nodeType == WYMeditor.NODE.TEXT)214 jqexpr = jqexpr.parentNode;215 216 var lastTextNode = jQuery(jqexpr)[0];217 218 while (lastTextNode.nodeType!=WYMeditor.NODE.TEXT) {219 if (!lastTextNode.hasChildNodes())220 break;221 lastTextNode = lastTextNode.lastChild;222 }223 224 if (WYMeditor.isPhantomNode(lastTextNode))225 lastTextNode = lastTextNode.previousSibling;226 227 // e.g. an <img/>228 if (lastTextNode.nodeType == WYMeditor.NODE.ELEMENT)229 this.original.collapse(lastTextNode.parentNode,230 lastTextNode.parentNode.childNodes.length);231 else232 this.original.collapse(lastTextNode, lastTextNode.length);233 },234 235 deleteIfExpanded: function() {236 if(!this.original.isCollapsed) {237 this.original.deleteFromDocument();238 return true;239 }240 return false;241 }242 };243 244 trunk/src/wymeditor/jquery.wymeditor.safari.js
r518 r530 146 146 var wym = WYMeditor.INSTANCES[this.title]; 147 147 148 // "start" Selection API149 //var sel = wym.selection.getSelection();150 151 /*152 // some small tests for the Selection API153 var containers = WYMeditor.MAIN_CONTAINERS.join(",");154 if (sel.isAtStart(containers))155 alert("isAtStart: "+sel.startNode.parentNode.nodeName);156 if (sel.isAtEnd(containers))157 alert("isAtEnd: "+sel.endNode.parentNode.nodeName);158 if (evt.keyCode==WYMeditor.KEY.DELETE) {159 // if deleteIfExpanded wouldn't work, no selected text would be160 // deleted if you press del-key161 if (sel.deleteIfExpanded())162 return false;163 }164 if (evt.keyCode==WYMeditor.KEY.HOME) {165 // if cursorToStart won't work, the cursor won't be set to start166 // if you press home-key167 sel.cursorToStart(sel.container);168 return false;169 }170 if (evt.keyCode==WYMeditor.KEY.END)171 {172 // if cursorToEnd won't work, the cursor won't be set to the end173 // if you press end-key174 sel.cursorToEnd(sel.container);175 return false;176 }177 */178 179 148 if(evt.ctrlKey){ 180 149 if(evt.keyCode == 66){ … … 294 263 }; 295 264 296 /********** SELECTION API **********/297 298 WYMeditor.WymSelSafari = function(wym) {299 this._wym = wym;300 };301 302 WYMeditor.WymSelSafari.prototype = {303 getSelection: function() {304 var _sel = this._wym._iframe.contentWindow.getSelection();305 // NOTE v.mische can startNode/endNote be phantom nodes?306 this.startNode = _sel.getRangeAt(0).startContainer;307 this.endNode = _sel.getRangeAt(0).endContainer;308 this.startOffset = _sel.getRangeAt(0).startOffset;309 this.endOffset = _sel.getRangeAt(0).endOffset;310 this.isCollapsed = _sel.isCollapsed;311 this.original = _sel;312 this.container = jQuery(this.startNode).parentsOrSelf(313 WYMeditor.MAIN_CONTAINERS.join(","))[0];314 315 return this;316 },317 318 cursorToStart: function(jqexpr) {319 if (jqexpr.nodeType == WYMeditor.NODE.TEXT)320 jqexpr = jqexpr.parentNode;321 322 var firstTextNode = jQuery(jqexpr)[0];323 324 while (firstTextNode.nodeType!=WYMeditor.NODE.TEXT) {325 if (!firstTextNode.hasChildNodes())326 break;327 firstTextNode = firstTextNode.firstChild;328 }329 330 if (WYMeditor.isPhantomNode(firstTextNode))331 firstTextNode = firstTextNode.nextSibling;332 333 // e.g. an <img/>334 if (firstTextNode.nodeType == WYMeditor.NODE.ELEMENT)335 this.original.collapse(firstTextNode.parentNode, 0);336 else337 this.original.collapse(firstTextNode, 0);338 },339 340 cursorToEnd: function(jqexpr) {341 if (jqexpr.nodeType == WYMeditor.NODE.TEXT)342 jqexpr = jqexpr.parentNode;343 344 var lastTextNode = jQuery(jqexpr)[0];345 346 while (lastTextNode.nodeType!=WYMeditor.NODE.TEXT) {347 if (!lastTextNode.hasChildNodes())348 break;349 lastTextNode = lastTextNode.lastChild;350 }351 352 if (WYMeditor.isPhantomNode(lastTextNode))353 lastTextNode = lastTextNode.previousSibling;354 355 // e.g. an <img/>356 if (lastTextNode.nodeType == WYMeditor.NODE.ELEMENT)357 this.original.collapse(lastTextNode.parentNode,358 lastTextNode.parentNode.childNodes.length);359 else360 this.original.collapse(lastTextNode, lastTextNode.length);361 },362 363 deleteIfExpanded: function() {364 if(!this.original.isCollapsed) {365 this.original.deleteFromDocument();366 return true;367 }368 return false;369 }370 };371 372