Dojo win.doc未定义

时间:2014-05-21 11:23:38

标签: javascript dojo

我必须从Dojo继承 Mover 类,因为如果不这样做,必须更改由于图形错误而导致的函数。

错误: win.doc 未定义

define(["dojo/_base/declare", "dojo/dnd/Mover",  "dojo/_base/event", "dojo/dom-geometry","dojo/window"],function(declare,Mover, event,domGeom,win){
    console.log("myMover");
        return declare([Mover],{
        onFirstMove: function(e){
        // summary:
        //      makes the node absolute; it is meant to be called only once.
        //      relative and absolutely positioned nodes are assumed to use pixel units
        var s = this.node.style, l, t, h = this.host;
        switch(s.position){
            case "relative":
            case "absolute":
                // assume that left and top values are in pixels already
                l = Math.round(parseFloat(s.left)) || 0;
                t = Math.round(parseFloat(s.top)) || 0;
                break;
            default:
                var m = domGeom.getMarginBox(this.node);
                s.position = "absolute";    // enforcing the absolute mode
                // event.pageX/pageY (which we used to generate the initial
                // margin box) includes padding and margin set on the body.
                // However, setting the node's position to absolute and then
                // doing domGeom.marginBox on it *doesn't* take that additional
                // space into account - so we need to subtract the combined
                // padding and margin.  We use getComputedStyle and
                // _getMarginBox/_getContentBox to avoid the extra lookup of
                // the computed style.
                var b = win.doc.body;                           // Firebug is telling me win.doc is undefined
                var bs = domStyle.getComputedStyle(b);
                var bm = domGeom.getMarginBox(b, bs);
                var bc = domGeom.getContentBox(b, bs);
                l = m.l - (bc.l - bm.l);
                t = m.t - (bc.t - bm.t);
                break;
        }
        this.marginBox.l = l - this.marginBox.l;
        this.marginBox.t = t - this.marginBox.t;
        if(h && h.onFirstMove){
            h.onFirstMove(this, e);
        }

        // Disconnect touch.move that call this function
        this.events.shift().remove();
    },
    });

});

有人能告诉我一个解决方案吗?

问候 月

1 个答案:

答案 0 :(得分:1)

dojo/window模块和dojo/_base/window模块之间存在差异。只有dojo/_base/window模块具有属性doc

例如:

require([ "dojo/_base/window", "dojo/window" ], function(win, win2) {
    var myDoc = win.doc; // Returns current document
    var myDoc2 = win2.doc; // Returns undefined
});