2010-11-17 109 views
0

我正在消除在JavaScript中的全局變量在我的Rails /視圖/ show.html.erb使用的Javascript Onready函數調用的命名空間功能

,我使用的JavaScript是

var App = {}; 
App.UserSnapShot = function() { 
    var _body, _detailEl, _selectedLinkEl; 

    var _init = function() { 
    _body = $$("body")[0]; 

    $$(".user-link").each(function (el) { 
     el.observe("mouseover", function (event) { 
     _selectedLinkEl = el; 
     _detailEl = event.element().next(); 
     _detailEl.show(); 
     _body.observe("mouseover", _bodyMouseOverFunction); 
     }); 
    }); 
    }; 

    var _bodyMouseOverFunction = function (event) { 
    if (event.element() != _selectedLinkEl && 
     event.element() != _detailEl && 
     !event.element().ancestors().include(_detailEl)) { 
     _detailEl.hide(); 
     _body.stopObserving("mouseover", _bodyMouseOverFunction); 
    } 
    }; 

    return { 
    init: function() { 
     _init(); 
    } 
    }; 
}(); 

我需要調用我的函數App.UserSnapShot.init();通過onready函數的相同..,以便得到這個工作.. 我怎樣才能在這裏添加onReady函數。

請給一些建議

+0

所有這些問題! AAAAAAHHHHHHHH !!!!! – 2010-11-17 06:00:35

+1

@jacob爲私人變化,我給了_variablename – useranon 2010-11-17 06:06:43

+0

你是什麼意思''同樣的'''''''''''''''''''''請詳細解釋你想要什麼。 – galambalazs 2010-11-17 08:52:44

回答

2

您的意思是?

App.onReady = function() { 
    App.UserSnapShot.init(); 
}; 

document.observe("dom:loaded", App.onReady); 
-1

使用jQuery ...

$(文件)。就緒(函數(){// 代碼插入到文檔加載運行這裏 });

+0

'$$(「body」)'他顯然使用Prototype ... – galambalazs 2010-11-17 08:45:26

相關問題