The way to encapsulate the jquery classes and plug-ins into SEAJS modules

Source: Internet
Author: User

  This article mainly introduces the jquery class, Plug-ins packaged into Seajs module method, the need for friends can refer to the following

Note: The SEAJS version used in this article is 2.1.11, the module     code to encapsulate jquery into Seajs is as follows: Define (function () {     //place jquery code here Just put in your favorite jquery version.       return $.noconflict (); });     Calling Method: This introduction can be used as before with the jquery     code as follows: Define (function (Require, exports, module) {    var $ = require ('./js/jquery ');         //$ (document). Ready (function () {     //  $ ("tr"). wyhinterlaced ({ "Odd": "Red", "even": "Blue"});      //  $ ("tr"). Wyhhover ();    //})});   II, to encapsulate the jquery class into Seajs module   code as follows: Define (function (Require, exports, module) {      var $ = require ( ".. /js/jquery ");         var weekday = new Array (7)     Weekday[0] = "Monday";     WEEKDAY[1] = "Tuesday";     WEEKDAY[2] = "Wednesday";     WEEKDAY[3] = "Thursday";     WEEKDAY[4] = "Friday";     WEEKDAY[5] = "Saturday";     WEEKDAY[6] = "Sunday";        function GetType (ARG) {        var today = new Date ();       &NBS P var year = Today.getfullyear ();         var month = Today.getmonth () + 1;         var td = Today.getdate ();         var d = weekday[today.getday ()-1];         var h = today.gethours ();         var m = today.getminutes ();         var s = today.getseconds ();         switch (ARG) {            Case 1:  //2013-09-09 09:31:56 & nbsp              -return year + "-" + month + "-" + TD + " " + H + ":" + M + ":" + S; Break             Case 2:  //2013-09-09 (Monday) 09:31:56           &NB Sp     return year + "-" + month + "-" + TD + "(" + D + ")" + H + ":" + M + ":" + S; Break   &NBSP         Case 3:  //09-09-2013 09:31:56                 RE Turn month + "-" + TD + "-" + year + " " + H + ":" + M + ":" + S; Break             Case 4:  //09-09-2013 Monday 09:31:56           &NBSP ;     Return month + "-" + TD + "-" + Year + "(" + D + ")" + H + ":" + M + ":" + S; Break             Case 5:  //2013 Year September 09 09:31 sec                 return year + "years" + month + "month" + TD + "Day  " + H + "time" + M + "min" + S + "seconds"; Break             Case 6:  //2013 year September 09 Monday 09:31 sec           &NB Sp     return year + "years" + month + "month" + TD + "Day   (" + D + ")  " + H + "time" + M + "min" + S + "SEC"; Break        }    ;      /********************************   //Function name: GetTime    /* Parameters: values (including cosmetic floating-point types can be, floating-point type will do rounding, if not the number,     The function will return with the default time format! Time style has 15 "1-15 is valid time style     exceeds or less than will take default style style 1" medium)    /* feature   get current system time customizable format     ********** /       function  gettime (ARG) {    & nbsp   if (!isnan (ARG)) {            var num = Math.Round (ARG);               if (num < 7 && num > 0) {                Retu RN GetType (num);                         else {        & nbsp       var str;                 VAR str2;                 switch (num) {              &N Bsp    Case 0:return GetType (1); Break                     Case 7:str = GetType (2); Return Str.replace (/week/, ""); Break                     Case 8:str = GetType (1); Return Str.replace (/-/, "/"). Replace (/-/, "/"); Break                     Case 9:str = GetType (2); Return Str.replace (/-/, "/"). Replace (/-/, "/");                     Case 10:str = GetType (2); str2 = str.replace (/-/, "/"). Replace (/-/, "/"); Return Str2.replace (/week/, ""); Break                     Case 11:str = GetType (4); Return Str.replace (/week/, ""); Break                     Case 12:str = GetType (3); Return Str.replace (/-/, "/"). Replace (/-/, "/"); Break                     Case 13:STR = GetType (4); Return Str.replace (/-/, "/"). Replace (/-/, "/");                     Case 14:str = GetType (4); str2 = str.replace (/-/, "/"). Replace (/-/, "/"); Return Str2.replace (/week/, ""); Break                     Case 15:str = GetType (6); Return Str.replace (/week/, "");                     Default:return GetType (1); Break                            }                 else {            return GetType (1);     &N Bsp  }    };        /* Get the current number of systems/     function getyear () {        var today = new Date ();         return today.getfullyear ();    };     &NBSP  /* Get the current number of months of the system/      function getmonth () {        var today = new Date (); &nbsp ;       return Today.getmonth () + 1;    };    /* Get the current days of the system/      function getday () {        var today = new Date ();         return today.getdate ();    };    /* Get the system's current hour/   function GetHours () {        var today = new Date ();         return today.gethours ();    };    /* Get the system's current minutes/     function Getminute () {        var today = new Date () ;           return today.getminutes ();    };    /* Get the system's current number of seconds/     function Getsecond () {        var today = new Date () ;         return today.getseconds ();    };         /************************************************************     * Function name: Timesubmillisecond     * Parameters: Endtime (end time) starttime (start time)     * Features: Get two-time millisecond difference, must write a parameter the second parameter (starting time) can     * Not write default is the system current time     ************************************************************/    function   Timesubmillisecond (Endtime, starttime) {        var end = new Date (endtime). GetTime ();         if (!endtime) {            return-1         &N Bsp     if (!starttime) {            start = new Date () GetTime ();     &NBS P           else {            start = new Date (starttime). GetTime ( );        }         if (Start > End) {            return-1;        } &NBsp       Else {            return end-start;         &N Bsp  };    /************************************************************     * Function name: Timesubnormal   & nbsp * Parameters: Endtime (end time) starttime (start time)     * Function: Get two time difference, must write a parameter the second parameter (start time) can     * Not write default is the system current time   & nbsp /        function   Timesubnormal (Endtime, starttime) {        var end = new Date (endtime). GetTime ();     &NBSP ;   VAR start;         if (!starttime) {            start = new Date () GetTime (); &nbs P      }         else {            start = new Date (start Time). GetTime ();        }         if (Start > End) {            return-1;        }         else {            var alltime = e Nd-start;             var seconds = alltime/1000;             var minutes = Math.floor (SECONDS/60);             var hours = Math.floor (MINUTES/60);             var days = Math.floor (HOURS/24);             var cday = days;             var chour = hours% 24;             var cminute = minutes% 60;             var csecond = math.floor (seconds% 60);             var str = "";             if (Cday > 0) {                STR + = Cday + "Days";            }   &nbsp         if (Chour > 0) {                STR + chour + "H ";                         if (Cminute > 0) {                STR + + Cminute + "minutes";                         if (Csecond > 0) {                STR + + Csecond + "seconds";                         return str;        }    ;         exports. GetTime = GetTime;     exports. getyear = getyear;     exports. GetMonth = getmonth;     exports. Getday = getday;       exports. GetHours = GetHours;     exports. Getminute = Getminute;     exports. Getsecond = Getsecond;     exports. TimesubmillIsecond = Timesubmillisecond;     exports. Timesubnormal = Timesubnormal;  })     Calling method:   code is as follows: Define (function (Require, exports, module) {    var $ = require ('./js /jquery ');     var a=require ('./js/time ');       Alert (A.gettime (3)); });   III, to encapsulate the jquery plugin into SEAJS module, the following is an example of encapsulating a plug-in of jquery into a module   code as follows: Define (function (require, exports, moudles) {  & nbsp return function (jquery) {        (function ($) {             //to Current line highlighting   $.fn.wyhhover = function (options) {//options often have many arguments with this representation.           var defaultval = {       backcolor: ' #ccc ',     & nbsp  };            var obj = $.extend (defaultval, Options);             return This.each (function () {            var tab Object = $ (this); Get current object              var oldbgcolor = tabobject.css ("Background-color"); Gets the background color of the current object               tabobject.hover (//) define a hover method.             function () {tabobject.css ("Background-color", obj). BackColor);},             function () {tabobject.css ("Background-color", Oldbgcolor);});        });        }      //make odd and even rows different colors         $.fn.wyhinterlaced = function (o ptions) {//options often use this notation to have many parameters.           var defaultval = {       odd: ' #DDEDFB ',     &NBS P    even: ' #fff ',        };            var obj = $.extend (defaultval, Options);             return This.each (function () {            var tab Object = $ (this); Gets the current object &nbSp            if (Tabobject.index ()%2==0)            {  &NBS P           TABOBJECT.CSS ("Background-color", obj.odd);            }else            {        &NBS P    TABOBJECT.CSS ("Background-color", Obj.even);            }        });        }        }) (jquery);    }  })     Invoke method: Invoke plug-in using shared mode the     code is as follows: Define (function (Require, exports, module) {& nbsp   var $ = require ('./js/jquery ');     require ('./js/jquery_tr ') ($);//Shared to jquery       $ (document). Ready (function () {        $ ("tr"). wyhinterlaced ({"Odd": "Red", "even": "Blue"});         $ ("tr"). Wyhhover ();    })});  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.