咸鱼的翻身技术

JAVA/JAVASCRIPT

Dialog的position的一个fix

如果屏幕高度小于Dialog高度,Dialog的top会是负数,可以写一类继承dijit.Dialog 然后把fix写在里面
dojo.provide("company.Dialog");

dojo.require(
"dijit.Dialog");
/**
 * fix the same issue from the dijit.Dialog
 
*/
dojo.declare(
"company.Dialog", [dijit.Dialog],{
    
/**
     * @see dijit.Dialog#postCreate
     
*/
    postCreate: 
function() {
      
this.inherited(arguments);

      
this.connect(this"_position""_fixPosition");
    },

    
/**
     * fix the position while the dialog size is less than the browser screen
     
*/
    _fixPosition: 
function() {
        
var mb = dojo._getMarginSize(this.domNode),
            viewport 
= dojo.window.getBox();

        
if (viewport.h < mb.h) {
            
var top = dojo.style(this.domNode, 'top');
            
if (top < 0) {
                dojo.style(
this.domNode, {top: '0'});
            }
        }
    }

posted on 2011-07-28 10:42 hopesfish 阅读(401) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。