跳到主要內容

[快快樂樂教學] YUI2 in 3 使用方法,以calendar widget 為例

YUI2 in 3 使用方法,以calendar widget 為例。

使用方法
Y.use('yui2-calendar', function (Y) {    
    var YAHOO,
        _cal,
        id       = 'calContent',     //指定的id
        pageDate = '9/30/2010',     //設定起始日期, 格式均為,月/日/年
        minDate  = '1/1/2010',        //設定最小日期
        maxDate  = '12/30/2010';    //設定最大日期
        
    YAHOO = Y.YUI2;
    _cal = new YAHOO.widget.Calendar(
        '_cal', 
        id,
        {
            pagedate: pageDate,
            mindate: minDate,
            maxdate: maxDate
        }
    );
    
    //    可以設定多國語系
    _cal.cfg.setProperty("MONTHS_LONG",   ["Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]);
    _cal.cfg.setProperty("WEEKDAYS_SHORT", ["S", "M", "D", "M", "D", "F", "S"]);
    
    //    render 事件設定一定要在 render() 執行以前
    _cal.renderEvent.subscribe(_calendarRenderHandler, _cal, true);
    
    //    產生 calendar
    _cal.render();
    
    // 日期選取事件
    _cal.selectEvent.subscribe(_calendarSelectHandler, _cal, true);
    //    改變日期事件
    _cal.changePageEvent.subscribe(_calendarChangeHandler, _cal, true);
});

接下來解釋一下事件。(以下為YUI2 提供樂樂長的列表)

EventFires...Arguments
selectEvent...after a date is selected.Array of date fields representing the dates that were selected. Example: [ [2008,8,1],[2006,8,2] ]
beforeSelectEvent...when a date is selected, before processing the change.N/A
deselectEvent...after a date is deselected.Array of date fields representing the dates that were deselected. Example: [ [2008,8,1],[2006,8,2] ]
beforeDeselectEvent...when a date is deselected, before processing the change.N/A
renderEvent...after the Calendar is rendered.N/A
beforeRenderEvent...just before the Calendar is rendered.N/A
changePageEvent...when the Calendar navigates to a new month (page).The date prior to the Calendar changing pages, and the new date after changing pages
clearEvent...when the Calendar is cleared.N/A
resetEvent...when the Calendar is reset.N/A
beforeHideEvent...just before the Calendar is hidden. Returning false from a subscriber will prevent the Calendar from being hidden.N/A
hideEvent...after the Calendar is hidden.N/A
beforeShowEvent...just before the Calendar is shown. Returning false from a subscriber will stop the Calendar from being shown.N/A
showEvent...after the Calendar is shown.N/A
beforeShowNavEvent...just before the CalendarNavigator is shown. Returning false from a subscriber will stop the CalendarNavigator from being shown.N/A
showNavEvent...after the CalendarNavigator is shown.N/A
beforeHideNavEvent...just before the CalendarNavigator is hidden. Returning false from a subscriber will stop the CalendarNavigator from being hidden.N/A
hideNavEvent...after the CalendarNavigator is hidden.N/A


主要傳送的參數可以參考如下:

選取事件
/*以下為日期選取事件 (when click some date)*/
_calendarSelectHandler = function (type, args, obj) {
    conlose.log(type);    //    目前事件的行為{String}
    var dates = args[0],    //    日期型態物件
        date = dates[0];    //    取得日期資料
        
    conlose.log(date[0], date[1], date[2]);    //輸出資料為 year, month, day
};

切換月份事件
/**
  *    @parm type  {目前行為String}, 
  *          dates {前一頁和目前的日期array},
  *          obj   {calendar 物件}
  */
_calendarChangeHandler = function (typ, dates, obj) {
    var oldDate = new Date(dates[0]),    //前一頁的日期
        newDate = new Date(dates[1]);    //目前的日期
    console.log(newDate.getMonth());
};

calendar執行事件(當月份切換也會執行此事件)
_calendarRenderHandler = function (arg1, arg2, obj) {
    //    arg1, arg2, obj = cal <-指的就是calendar 本身
};

總結:
雖然說大部分事件都是沒有傳入任何參數,不過經過測試,通常第一個參數指的是目前執行的狀態(event status),第三個參數指行事曆物件本身(obj = cal)。

以上的是我自己嘗試的結果,當然還有其他nav, calendar group等強大功能還沒來得及測試,希望如果有心的人可以繼續補足。

留言

這個網誌中的熱門文章

[CSS] z-index 在不同瀏覽器繼承問題

今天會討論到這個課題,是因為要實做一個Popup dialog,所以我們希望的結果如下圖。 可是在IE7 卻發生了這樣的情況。 Popup不論怎麼設定z-index都無法浮在最上層,我們看一下html架構發生什麼事情。

[教學] 快快樂樂刪除CodeIgniter index.php

預設的CI網址預設都設定為index.php同一層級,因此所有的程式都必須指定index.php導向才能開始,例如 http://localhost/ci/index.php/welcome/test http://localhost/ci/welcome/test 本文將說明如何將惱人的index.php消除,還你一個漂亮的URL。 設定開始: 接下來說明如何使用rewrite方式將惱人的index.php去除。 rewrite不清楚的人,煩請先自行google 首先要先確定Apache的 mod_rewrite 有 開啟 ,如果沒有開啟請設定好之後重新啟動apache。 接著,在根目錄底下建立一個新檔案,檔名為 .htaccess ,裡面程式碼如下: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> 接著到 application/config/config.php ,開啟檔案修改 $config['index_page'] = ""; 注意: /index.php/$1 要根據你目錄,例如 http://localhost/index.php ,網站根目錄為 /ci/index.php 則要寫成 /ci/index.php/$1 接著至CI目錄下,尋找 config\config.php , 修改一下裡面的檔案,修改如下: $config['index_page'] = ""; 存檔後,如此一來大功告成。 參考資料 官方網站說明

[教學] Mojito 安裝與入門,install mojito for beginner.

mojito ,最近終於從 YDN 對外公開此專案,這個套件主要用於解決前端多重裝置及瀏覽器端的問題,後端服務採取 node.js ,因此使用上必定要先準備以下幾個元素 準備素材 c++ complier git Node.js > 0.4.x NPM > 1.0.x 安裝方式 git clone git://github.com/yahoo/mojito.git cd mojito/source sudo npm install -g . npm install . 以上四個簡單的步驟,就可以把 mojito module 完整安裝到服務器上,接著就可以開始進入 mojito 的世界 使用方式 mojito 提供了完整的 command line 給開發者使用,接著先建立一個基本 hello world 專案,跟著以下步驟完成第一個專案。首先建立一個 mojito application, mojito create app hello cd hello 切換到目錄之後,再接著建立自己的 mojit,這邊的 mojit 就像是一個應用(application)可能會包含許多個獨立網站體,擁有獨立架構的 MVC ,包含內部設定等,詳細資料可以參考官方的 說明 ,建立 mojit mojito create mojit HelloMojit 輸入指令後,會看到顯示結果如下, creating mojit called 'HelloMojit' (using "default" archetype) ✔ mojit: HelloMojit created! ✔ mojito done. 接著修改 application.json 這個 mojit 設定檔案,讓剛才新建立的 hellp application 指定底下有一個 mojit -> HelloMojit ,讓應用可以去執行 mojit controller ,修改如下, [ { "settings": [ "master" ], "appPort": 8666, "specs": { ...