星期四, 11月 11, 2010

引用google libraries

  1. Google Libraries API - Developer's Guide
    還挺多的

    Available Libraries
    Chrome Frame
    Dojo
    Ext Core
    jQuery
    jQuery UI
    MooTools
    Prototype
    script_aculo_us
    SWFObject
    Yahoo! User Interface Library (YUI)
    WebFont Loader

    用法也很簡單,像jquery就先到該文件下找"path",再放入src就好啦
    <!-- jquery -->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>

    <!-- jquery ui -->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>


  2. dynamically load jquery if 'jQuery' does not exist
    function initJQuery() {
       //if the jQuery object isn't available
       if (typeof(jQuery) == 'undefined') {
         if (typeof initJQuery.jQueryScriptOutputted == 'undefined') {
           //only output the script once..
           initJQuery.jQueryScriptOutputted = true;
           //output the script (load it from google api)
           document.write("");
         }   
         setTimeout("initJQuery()", 50);
       } else {
         (function($){ // CLOSURE -> save to use $
            $.fn.foo = function(input) {
            alert("foo:" + input) ;
          } ;
         })(jQuery) ;
       }

       window.onload = function() {
       $('body').foo("bar") ; // won't necessarily fire if jQuery loads after   document load
      }
    }
    initJQuery();

沒有留言: