Skip to content

Commit

Permalink
Removing dependency on win.doc global-ish variable:
Browse files Browse the repository at this point in the history
- Each widget has a document determined at creation time, usually implied by srcNodeRef.ownerDocument but also specifiable explicitly.    Save that in this.ownerDocument, and for convenience also record the associated <body> node in this.ownerDocumentBody.    Maybe this.ownerDocument should be called this.doc instead,  but I thought that might be confusing with Editor.document.

- In widgets, use this.ownerDocument instead of win.doc, and this.ownerDocumentBody  instead of win.body().

- Since domConstruct.create() doesn't take a document parameter, either pass in a refNode (which implies the document), or avoid using domConstruct.create().   Could also have wrapped the domConstruct.create() calls with win.withDoc(), or used domConstruct.toDom().

- Miscellaneous fixes to widgets.

- Make dojo/_base/window::body() take an optional document parameter.

Editor not yet converted.

Refs #15216 !strict.



git-svn-id: http://svn.dojotoolkit.org/src/dijit/trunk@28401 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
wkeese committed Apr 21, 2012
1 parent d70bd7c commit 4934a4a
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 100 deletions.
5 changes: 2 additions & 3 deletions CalendarLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ define([
"dojo/_base/lang", // lang.getObject, lang.hitch
"dojo/sniff", // has("ie") has("webkit")
"dojo/string", // string.substitute
"dojo/_base/window", // win.doc.createTextNode
"./_WidgetBase",
"./_TemplatedMixin",
"dojo/text!./templates/Calendar.html",
"./hccss" // not used directly, but sets CSS class on <body>
], function(array, declare, cldrSupplemental, date, locale, stamp, dom, domClass, event, lang, has, string, win,
], function(array, declare, cldrSupplemental, date, locale, stamp, dom, domClass, event, lang, has, string,
_WidgetBase, _TemplatedMixin, template){

/*=====
Expand Down Expand Up @@ -170,7 +169,7 @@ define([
while(node.firstChild){
node.removeChild(node.firstChild);
}
node.appendChild(win.doc.createTextNode(text));
node.appendChild(node.ownerDocument.createTextNode(text));
},

_populateGrid: function(){
Expand Down
15 changes: 9 additions & 6 deletions Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ define([
"dojo/on",
"dojo/ready",
"dojo/sniff", // has("ie") has("opera") has("dijit-legacy-requires")
"dojo/_base/window", // win.body
"dojo/window", // winUtils.getBox
"dojo/dnd/Moveable", // Moveable
"dojo/dnd/TimedMoveable", // TimedMoveable
Expand All @@ -33,7 +32,7 @@ define([
"./main", // for back-compat, exporting dijit._underlay (remove in 2.0)
"dojo/i18n!./nls/common"
], function(require, array, connect, declare, Deferred,
dom, domClass, domGeometry, domStyle, event, fx, i18n, keys, lang, on, ready, has, win, winUtils,
dom, domClass, domGeometry, domStyle, event, fx, i18n, keys, lang, on, ready, has, winUtils,
Moveable, TimedMoveable, focus, manager, _Widget, _TemplatedMixin, _CssStateMixin, _FormMixin, _DialogMixin,
DialogUnderlay, ContentPane, template, dijit){

Expand Down Expand Up @@ -169,7 +168,7 @@ define([
display: "none",
position:"absolute"
});
win.body().appendChild(this.domNode);
this.ownerDocumentBody.appendChild(this.domNode);

this.inherited(arguments);

Expand Down Expand Up @@ -228,7 +227,8 @@ define([

this.underlayAttrs = {
dialogId: this.id,
"class": array.map(this["class"].split(/\s/), function(s){ return s+"_underlay"; }).join(" ")
"class": array.map(this["class"].split(/\s/), function(s){ return s+"_underlay"; }).join(" "),
ownerDocument: this.ownerDocument
};
},

Expand Down Expand Up @@ -296,7 +296,7 @@ define([
// in the viewport has been determined (by dragging, for instance),
// center the node. Otherwise, use the Dialog's stored relative offset,
// and position the node to top: left: values based on the viewport.
if(!domClass.contains(win.body(), "dojoMove")){ // don't do anything if called during auto-scroll
if(!domClass.contains(this.ownerDocumentBody, "dojoMove")){ // don't do anything if called during auto-scroll
var node = this.domNode,
viewport = winUtils.getBox(),
p = this._relativePosition,
Expand Down Expand Up @@ -381,7 +381,10 @@ define([
this._fadeOutDeferred.cancel();
}

this._modalconnects.push(on(window, "scroll", lang.hitch(this, "resize")));
// Recenter Dialog if user scrolls browser. Connecting to document doesn't work on IE, need to use window.
var win = this.ownerDocument.defaultView || this.ownerDocument.parentWindow;
this._modalconnects.push(on(win, "scroll", lang.hitch(this, "resize")));

this._modalconnects.push(on(this.domNode, connect._keypress, lang.hitch(this, "_onKey")));

domStyle.set(this.domNode, {
Expand Down
5 changes: 2 additions & 3 deletions DialogUnderlay.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
define([
"dojo/_base/declare", // declare
"dojo/dom-attr", // domAttr.set
"dojo/_base/window", // win.body
"dojo/window", // winUtils.getBox
"./_Widget",
"./_TemplatedMixin",
"./BackgroundIframe"
], function(declare, domAttr, win, winUtils, _Widget, _TemplatedMixin, BackgroundIframe){
], function(declare, domAttr, winUtils, _Widget, _TemplatedMixin, BackgroundIframe){

/*=====
var _Widget = dijit._Widget;
Expand Down Expand Up @@ -60,7 +59,7 @@ define([
postCreate: function(){
// summary:
// Append the underlay to the body
win.body().appendChild(this.domNode);
this.ownerDocumentBody.appendChild(this.domNode);
},

layout: function(){
Expand Down
9 changes: 4 additions & 5 deletions Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ return declare("dijit.Menu", DropDownMenu, {

postCreate: function(){
if(this.contextMenuForWindow){
this.bindDomNode(win.body());
this.bindDomNode(this.ownerDocumentBody);
}else{
// TODO: should have _setTargetNodeIds() method to handle initialization and a possible
// later set('targetNodeIds', ...) call. There's also a problem that targetNodeIds[]
Expand Down Expand Up @@ -118,7 +118,7 @@ return declare("dijit.Menu", DropDownMenu, {
bindDomNode: function(/*String|DomNode*/ node){
// summary:
// Attach menu to given node
node = dom.byId(node);
node = dom.byId(node, this.ownerDocument);

var cn; // Connect node

Expand All @@ -129,10 +129,9 @@ return declare("dijit.Menu", DropDownMenu, {
window = this._iframeContentWindow(iframe);
cn = win.withGlobal(window, win.body);
}else{

// To capture these events at the top level, attach to <html>, not <body>.
// Otherwise right-click context menu just doesn't work.
cn = (node == win.body() ? win.doc.documentElement : node);
cn = (node == win.body(this.ownerDocument) ? this.ownerDocument.documentElement : node);
}


Expand Down Expand Up @@ -203,7 +202,7 @@ return declare("dijit.Menu", DropDownMenu, {

var node;
try{
node = dom.byId(nodeName);
node = dom.byId(nodeName, this.ownerDocument);
}catch(e){
// On IE the dom.byId() call will get an exception if the attach point was
// the <body> node of an <iframe> that has since been reloaded (and thus the
Expand Down
5 changes: 2 additions & 3 deletions PopupMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ define([
"dojo/_base/declare", // declare
"dojo/dom-style", // domStyle.set
"dojo/query", // query
"dojo/_base/window", // win.body
"./registry", // registry.byNode
"./MenuItem",
"./hccss"
], function(declare, domStyle, query, win, registry, MenuItem){
], function(declare, domStyle, query, registry, MenuItem){

/*=====
var MenuItem = dijit.MenuItem;
Expand Down Expand Up @@ -55,7 +54,7 @@ define([
var node = query("[widgetId]", this.dropDownContainer)[0];
this.popup = registry.byNode(node);
}
win.body().appendChild(this.popup.domNode);
this.ownerDocumentBody.appendChild(this.popup.domNode);
this.popup.startup();

this.popup.domNode.style.display="none";
Expand Down
7 changes: 3 additions & 4 deletions Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ define([
"dojo/mouse",
"dojo/on",
"dojo/sniff", // has("ie")
"dojo/_base/window", // win.body
"./_base/manager", // manager.defaultDuration
"./place",
"./_Widget",
"./_TemplatedMixin",
"./BackgroundIframe",
"dojo/text!./templates/Tooltip.html",
"./main" // sets dijit.showTooltip etc. for back-compat
], function(array, declare, fx, dom, domClass, domGeometry, domStyle, lang, mouse, on, has, win,
], function(array, declare, fx, dom, domClass, domGeometry, domStyle, lang, mouse, on, has,
manager, place, _Widget, _TemplatedMixin, BackgroundIframe, template, dijit){

/*=====
Expand Down Expand Up @@ -57,7 +56,7 @@ define([
templateString: template,

postCreate: function(){
win.body().appendChild(this.domNode);
this.ownerDocumentBody.appendChild(this.domNode);

this.bgIframe = new BackgroundIframe(this.domNode);

Expand Down Expand Up @@ -348,7 +347,7 @@ define([

// Make array of id's to connect to, excluding entries for nodes that don't exist yet, see startup()
this._connectIds = array.filter(lang.isArrayLike(newId) ? newId : (newId ? [newId] : []),
function(id){ return dom.byId(id); });
function(id){ return dom.byId(id, this.ownerDocument); }, this);

// Make connections
this._connections = array.map(this._connectIds, function(id){
Expand Down
5 changes: 2 additions & 3 deletions _HasDropDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ define([
"dojo/keys", // keys.DOWN_ARROW keys.ENTER keys.ESCAPE
"dojo/_base/lang", // lang.hitch lang.isFunction
"dojo/touch",
"dojo/_base/window", // win.doc
"dojo/window", // winUtils.getBox
"./registry", // registry.byNode()
"./focus",
"./popup",
"./_FocusMixin"
], function(declare, Deferred, event,dom, domAttr, domClass, domGeometry, domStyle, has, keys, lang, touch,
win, winUtils, registry, focus, popup, _FocusMixin){
winUtils, registry, focus, popup, _FocusMixin){

/*=====
var _FocusMixin = dijit._FocusMixin;
Expand Down Expand Up @@ -112,7 +111,7 @@ define([
// 3. user defined onMouseDown handler fires
e.preventDefault();

this._docHandler = this.connect(win.doc, touch.release, "_onDropDownMouseUp");
this._docHandler = this.connect(this.ownerDocument, touch.release, "_onDropDownMouseUp");

this.toggleDropDown();
},
Expand Down
4 changes: 1 addition & 3 deletions _PaletteMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ return declare("dijit._PaletteMixin", [_CssStateMixin], {
tabIndex: "-1",
title: titles[value],
role: "gridcell"
});
}, rowNode);

// prepare cell inner structure
cellObject.fillCell(cellNode, url);

domConstruct.place(cellNode, rowNode);

cellNode.idx = this._cells.length;

// save cell info into _cells
Expand Down
18 changes: 10 additions & 8 deletions _TemplatedMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ define([
"dojo/_base/declare", // declare
"dojo/dom-construct", // domConstruct.destroy, domConstruct.toDom
"dojo/sniff", // has("ie")
"dojo/_base/unload", // unload.addOnWindowUnload
"dojo/_base/window" // win.doc
], function(lang, touch, _WidgetBase, string, cache, array, declare, domConstruct, has, unload, win) {
"dojo/_base/unload" // unload.addOnWindowUnload
], function(lang, touch, _WidgetBase, string, cache, array, declare, domConstruct, has, unload) {

/*=====
var _WidgetBase = dijit._WidgetBase;
Expand Down Expand Up @@ -104,11 +103,11 @@ define([
// Lookup cached version of template, and download to cache if it
// isn't there already. Returns either a DomNode or a string, depending on
// whether or not the template contains ${foo} replacement parameters.
var cached = _TemplatedMixin.getCachedTemplate(this.templateString, this._skipNodeCache);
var cached = _TemplatedMixin.getCachedTemplate(this.templateString, this._skipNodeCache, this.ownerDocument);

var node;
if(lang.isString(cached)){
node = domConstruct.toDom(this._stringRepl(cached));
node = domConstruct.toDom(this._stringRepl(cached), this.doc);
if(node.nodeType != 1){
// Flag common problems such as templates with multiple top level nodes (nodeType == 11)
throw new Error("Invalid template: " + cached);
Expand Down Expand Up @@ -237,14 +236,16 @@ define([
// key is templateString; object is either string or DOM tree
_TemplatedMixin._templateCache = {};

_TemplatedMixin.getCachedTemplate = function(templateString, alwaysUseString){
_TemplatedMixin.getCachedTemplate = function(templateString, alwaysUseString, doc){
// summary:
// Static method to get a template based on the templatePath or
// templateString key
// templateString: String
// The template
// alwaysUseString: Boolean
// Don't cache the DOM tree for this template, even if it doesn't have any variables
// doc: Document?
// The target document. Defaults to document global if unspecified.
// returns: Mixed
// Either string (if there are ${} variables that need to be replaced) or just
// a DOM tree (if the node can be cloned directly)
Expand All @@ -255,8 +256,9 @@ define([
var cached = tmplts[key];
if(cached){
try{
// if the cached value is an innerHTML string (no ownerDocument) or a DOM tree created within the current document, then use the current cached value
if(!cached.ownerDocument || cached.ownerDocument == win.doc){
// if the cached value is an innerHTML string (no ownerDocument) or a DOM tree created within the
// current document, then use the current cached value
if(!cached.ownerDocument || cached.ownerDocument == (doc || document)){
// string or node of the same document
return cached;
}
Expand Down
3 changes: 2 additions & 1 deletion _TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ define([
return null;
}

var div = domConstruct.create("div", {"class": this.baseClass+"Item"});
var div = this.ownerDocument.createElement("div");
div.className = this.baseClass+"Item";
div.date = date;
div.idx = index;
domConstruct.create('div',{
Expand Down
19 changes: 14 additions & 5 deletions _WidgetBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define([
"dojo/dom", // dom.byId
"dojo/dom-attr", // domAttr.set domAttr.remove
"dojo/dom-class", // domClass.add domClass.replace
"dojo/dom-construct", // domConstruct.create domConstruct.destroy domConstruct.place
"dojo/dom-construct", // domConstruct.destroy domConstruct.place
"dojo/dom-geometry", // isBodyLtr
"dojo/dom-style", // domStyle.set, domStyle.get
"dojo/has",
Expand All @@ -18,7 +18,7 @@ define([
"dojo/ready",
"dojo/Stateful", // Stateful
"dojo/topic",
"dojo/_base/window", // win.doc.createTextNode
"dojo/_base/window", // win.doc, win.body()
"./registry" // registry.getUniqueId(), registry.findWidgets()
], function(require, array, aspect, config, connect, declare,
dom, domAttr, domClass, domConstruct, domGeometry, domStyle, has, kernel,
Expand Down Expand Up @@ -212,6 +212,11 @@ return declare("dijit._WidgetBase", Stateful, {
containerNode: null,

/*=====
// ownerDocument: [const] Document?
// The document this widget belongs to. If not specified to constructor, will default to
// srcNodeRef.ownerDocument, or if no sourceRef specified, then to dojo/_base/window::doc
ownerDocument: null,
// _started: Boolean
// startup() has completed.
_started: false,
Expand Down Expand Up @@ -327,6 +332,10 @@ return declare("dijit._WidgetBase", Stateful, {
}
}

// The document and <body> node this widget is associated with
this.ownerDocument = this.ownerDocument || (this.srcNodeRef ? this.srcNodeRef.ownerDocument : win.doc);
this.ownerDocumentBody = win.body(this.ownerDocument);

registry.add(this);

this.buildRendering();
Expand Down Expand Up @@ -436,7 +445,7 @@ return declare("dijit._WidgetBase", Stateful, {

if(!this.domNode){
// Create root node if it wasn't created by _Templated
this.domNode = this.srcNodeRef || domConstruct.create('div');
this.domNode = this.srcNodeRef || this.ownerDocument.createElement("div");
}

// baseClass is a single class name or occasionally a space-separated list of names.
Expand Down Expand Up @@ -664,7 +673,7 @@ return declare("dijit._WidgetBase", Stateful, {
break;
case "innerText":
mapNode.innerHTML = "";
mapNode.appendChild(win.doc.createTextNode(value));
mapNode.appendChild(this.ownerDocument.createTextNode(value));
break;
case "innerHTML":
mapNode.innerHTML = value;
Expand Down Expand Up @@ -1043,7 +1052,7 @@ return declare("dijit._WidgetBase", Stateful, {
// refWidget.domNode otherwise ("after"/"before"/"replace"). (But not supported officially, see #14946.)
var ref = refWidget ?
(refWidget.containerNode && !/after|before|replace/.test(position||"") ?
refWidget.containerNode : refWidget.domNode) : reference;
refWidget.containerNode : refWidget.domNode) : dom.byId(reference, this.ownerDocument);
domConstruct.place(this.domNode, ref, position);

// Start this iff it has a parent widget that's already started.
Expand Down
7 changes: 5 additions & 2 deletions _base/popup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
define([
"dojo/dom-class", // domClass.contains
"dojo/_base/window",
"../popup",
"../BackgroundIframe" // just loading for back-compat, in case client code is referencing it
], function(domClass, popup){
], function(domClass, win, popup){

// module:
// dijit/_base/popup
Expand All @@ -19,7 +20,9 @@ popup._createWrapper = function(widget){
_popupWrapper: (widget.parentNode && domClass.contains(widget.parentNode, "dijitPopup")) ?
widget.parentNode : null,
domNode: widget,
destroy: function(){}
destroy: function(){},
ownerDocument: widget.ownerDocument,
ownerDocumentBody: win.body(widget.ownerDocument)
};
}
return origCreateWrapper.call(this, widget);
Expand Down
Loading

0 comments on commit 4934a4a

Please sign in to comment.