Skip to content

Commit

Permalink
A few fixes around win.doc references:
Browse files Browse the repository at this point in the history
1. Standardize on this._sCall() interface to access selection API.   Also looked at passing window parameter to each selection method, or creating a Selection class that's attached to a window on creation... but just did the simple thing for now.   OTOH the range API takes a window parameter.

2. remove unneeded win.withGlobal(), win.withDoc() calls

3. misc cleanup

Refs #15216 !strict.
  • Loading branch information
wkeese committed Apr 24, 2012
1 parent 0f2cd98 commit b02d51c
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 364 deletions.
319 changes: 151 additions & 168 deletions _editor/RichText.js

Large diffs are not rendered by default.

159 changes: 77 additions & 82 deletions _editor/plugins/EnterKeyHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ define([
"dojo/keys", // keys.ENTER
"dojo/_base/lang",
"dojo/sniff", // has("ie") has("mozilla") has("webkit")
"dojo/_base/window", // win.global win.withGlobal
"dojo/_base/window", // win.withGlobal
"dojo/window", // winUtils.scrollIntoView
"../_Plugin",
"../RichText",
"../range",
"../selection"
], function(declare, domConstruct, event, keys, lang, has, win, winUtils, _Plugin, RichText, rangeapi, selectionapi){

"../selection",
"../../_base/focus"
], function(declare, domConstruct, event, keys, lang, has, win, winUtils, _Plugin, RichText, rangeapi, selectionapi,
baseFocus){
/*=====
var _Plugin = dijit._editor._Plugin;
=====*/
Expand Down Expand Up @@ -159,13 +160,13 @@ return declare("dijit._editor.plugins.EnterKeyHandling", _Plugin, {
// tags:
// private
if(this._checkListLater){
if(win.withGlobal(this.editor.window, 'isCollapsed', dijit)){
var liparent=win.withGlobal(this.editor.window, 'getAncestorElement', selectionapi, ['LI']);
if(win.withGlobal(this.editor.window, 'isCollapsed', baseFocus)){
var liparent = this.editor._sCall('getAncestorElement', ['LI']);
if(!liparent){
// circulate the undo detection code by calling RichText::execCommand directly
RichText.prototype.execCommand.call(this.editor, 'formatblock',this.blockNodeForEnter);
// set the innerHTML of the new block node
var block = win.withGlobal(this.editor.window, 'getAncestorElement', selectionapi, [this.blockNodeForEnter]);
var block = this.editor._sCall('getAncestorElement', this.blockNodeForEnter);
if(block){
block.innerHTML=this.bogusHtmlContent;
if(has("ie")){
Expand Down Expand Up @@ -224,7 +225,7 @@ return declare("dijit._editor.plugins.EnterKeyHandling", _Plugin, {

var selection, range, newrange, startNode, endNode, brNode, doc=this.editor.document,br,rs,txt;
if(e.shiftKey){ // shift+enter always generates <br>
var parent = win.withGlobal(this.editor.window, "getParentElement", selectionapi);
var parent = this.editor._sCall('getParentElement');
var header = rangeapi.getAncestor(parent,this.blockNodes);
if(header){
if(header.tagName == 'LI'){
Expand Down Expand Up @@ -257,23 +258,21 @@ return declare("dijit._editor.plugins.EnterKeyHandling", _Plugin, {
if(rs && rs.nodeType == 3){
// Text node, we have to split it.
txt = rs.nodeValue;
win.withGlobal(this.editor.window, function(){
startNode = doc.createTextNode(txt.substring(0, range.startOffset));
endNode = doc.createTextNode(txt.substring(range.startOffset));
brNode = doc.createElement("br");
startNode = doc.createTextNode(txt.substring(0, range.startOffset));
endNode = doc.createTextNode(txt.substring(range.startOffset));
brNode = doc.createElement("br");

if(endNode.nodeValue == "" && has("webkit")){
endNode = doc.createTextNode('\xA0')
}
domConstruct.place(startNode, rs, "after");
domConstruct.place(brNode, startNode, "after");
domConstruct.place(endNode, brNode, "after");
domConstruct.destroy(rs);
newrange = rangeapi.create();
newrange.setStart(endNode,0);
selection.removeAllRanges();
selection.addRange(newrange);
});
if(endNode.nodeValue == "" && has("webkit")){
endNode = doc.createTextNode('\xA0')
}
domConstruct.place(startNode, rs, "after");
domConstruct.place(brNode, startNode, "after");
domConstruct.place(endNode, brNode, "after");
domConstruct.destroy(rs);
newrange = rangeapi.create(this.editor.window);
newrange.setStart(endNode,0);
selection.removeAllRanges();
selection.addRange(newrange);
return false;
}
return true; // let browser handle
Expand All @@ -291,68 +290,64 @@ return declare("dijit._editor.plugins.EnterKeyHandling", _Plugin, {
rs = range.startContainer;
if(rs && rs.nodeType == 3){
// Text node, we have to split it.
win.withGlobal(this.editor.window, lang.hitch(this, function(){
var endEmpty = false;

var offset = range.startOffset;
if(rs.length < offset){
//We are not splitting the right node, try to locate the correct one
ret = this._adjustNodeAndOffset(rs, offset);
rs = ret.node;
offset = ret.offset;
}
txt = rs.nodeValue;

startNode = doc.createTextNode(txt.substring(0, offset));
endNode = doc.createTextNode(txt.substring(offset));
brNode = doc.createElement("br");

if(!endNode.length){
endNode = doc.createTextNode('\xA0');
endEmpty = true;
}

if(startNode.length){
domConstruct.place(startNode, rs, "after");
}else{
startNode = rs;
}
domConstruct.place(brNode, startNode, "after");
domConstruct.place(endNode, brNode, "after");
domConstruct.destroy(rs);
newrange = rangeapi.create();
newrange.setStart(endNode,0);
newrange.setEnd(endNode, endNode.length);
selection.removeAllRanges();
selection.addRange(newrange);
if(endEmpty && !has("webkit")){
selectionapi.remove();
}else{
selectionapi.collapse(true);
}
}));
var endEmpty = false;

var offset = range.startOffset;
if(rs.length < offset){
//We are not splitting the right node, try to locate the correct one
ret = this._adjustNodeAndOffset(rs, offset);
rs = ret.node;
offset = ret.offset;
}
txt = rs.nodeValue;

startNode = doc.createTextNode(txt.substring(0, offset));
endNode = doc.createTextNode(txt.substring(offset));
brNode = doc.createElement("br");

if(!endNode.length){
endNode = doc.createTextNode('\xA0');
endEmpty = true;
}

if(startNode.length){
domConstruct.place(startNode, rs, "after");
}else{
startNode = rs;
}
domConstruct.place(brNode, startNode, "after");
domConstruct.place(endNode, brNode, "after");
domConstruct.destroy(rs);
newrange = rangeapi.create(this.editor.window);
newrange.setStart(endNode,0);
newrange.setEnd(endNode, endNode.length);
selection.removeAllRanges();
selection.addRange(newrange);
if(endEmpty && !has("webkit")){
selectionapi.remove();
}else{
selectionapi.collapse(true);
}
}else{
var targetNode;
if(range.startOffset >= 0){
targetNode = rs.childNodes[range.startOffset];
}
win.withGlobal(this.editor.window, lang.hitch(this, function(){
var brNode = doc.createElement("br");
var endNode = doc.createTextNode('\xA0');
if(!targetNode){
rs.appendChild(brNode);
rs.appendChild(endNode);
}else{
domConstruct.place(brNode, targetNode, "before");
domConstruct.place(endNode, brNode, "after");
}
newrange = rangeapi.create(win.global);
newrange.setStart(endNode,0);
newrange.setEnd(endNode, endNode.length);
selection.removeAllRanges();
selection.addRange(newrange);
selectionapi.collapse(true);
}));
var brNode = doc.createElement("br");
var endNode = doc.createTextNode('\xA0');
if(!targetNode){
rs.appendChild(brNode);
rs.appendChild(endNode);
}else{
domConstruct.place(brNode, targetNode, "before");
domConstruct.place(endNode, brNode, "after");
}
newrange = rangeapi.create(this.editor.window);
newrange.setStart(endNode,0);
newrange.setEnd(endNode, endNode.length);
selection.removeAllRanges();
selection.addRange(newrange);
selectionapi.collapse(true);
}
}
}else{
Expand Down Expand Up @@ -404,7 +399,7 @@ return declare("dijit._editor.plugins.EnterKeyHandling", _Plugin, {
}catch(e2){ /*squelch FF3 exception bug when editor content is a single BR*/ }
// get the newly created block node
// FIXME
block = {blockNode:win.withGlobal(this.editor.window, "getAncestorElement", selectionapi, [this.blockNodeForEnter]),
block = {blockNode: this.editor._sCall('getAncestorElement', this.blockNodeForEnter),
blockContainer: this.editor.editNode};
if(block.blockNode){
if(block.blockNode != this.editor.editNode &&
Expand Down
16 changes: 6 additions & 10 deletions _editor/plugins/FontChoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ define([
"dojo/i18n", // i18n.getLocalization
"dojo/_base/lang", // lang.delegate lang.hitch lang.isString
"dojo/store/Memory", // MemoryStore
"dojo/_base/window", // win.withGlobal
"../../registry", // registry.getUniqueId
"../../_Widget",
"../../_TemplatedMixin",
Expand All @@ -15,7 +14,7 @@ define([
"../range",
"../selection",
"dojo/i18n!../nls/FontChoice"
], function(array, declare, domConstruct, i18n, lang, MemoryStore, win,
], function(array, declare, domConstruct, i18n, lang, MemoryStore,
registry, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, FilteringSelect, _Plugin, rangeapi, selectionapi){

/*=====
Expand Down Expand Up @@ -328,7 +327,7 @@ var _FormatBlockDropDown = declare("dijit._editor.plugins._FormatBlockDropDown",
for(i = 0; i < node.childNodes.length; i++){
var c = node.childNodes[i];
if(c.nodeType == 1){
if(win.withGlobal(editor.window, "inSelection", selectionapi, [c])){
if(editor._sCall("inSelection", [c])){
var tag = c.tagName? c.tagName.toLowerCase(): "";
if(array.indexOf(this.values, tag) !== -1){
ary.push(c);
Expand Down Expand Up @@ -379,7 +378,7 @@ var _FormatBlockDropDown = declare("dijit._editor.plugins._FormatBlockDropDown",
}else{
// Probably a multi select, so we have to process it. Whee.
node = start;
while(win.withGlobal(editor.window, "inSelection", selectionapi, [node])){
while(editor._sCall("inSelection", [node])){
if(node.nodeType == 1){
tag = node.tagName? node.tagName.toLowerCase(): "";
if(array.indexOf(this.values, tag) !== -1){
Expand Down Expand Up @@ -416,12 +415,9 @@ var _FormatBlockDropDown = declare("dijit._editor.plugins._FormatBlockDropDown",
}else{
// Everyone else works fine this way, a paste-over and is native
// undo friendly.
win.withGlobal(editor.window,
"selectElementChildren", selectionapi, [node]);
var html = win.withGlobal(editor.window,
"getSelectedHtml", selectionapi, [null]);
win.withGlobal(editor.window,
"selectElement", selectionapi, [node]);
editor._sCall("selectElementChildren", [node])
var html = editor._sCall("getSelectedHtml", [])
editor._sCall("selectElement", [node])
editor.execCommand("inserthtml", html||"");
}
}
Expand Down
Loading

0 comments on commit b02d51c

Please sign in to comment.