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

Source: Internet
Author: User
Tags extend getdate

Note: The SEAJS version used in this article is 2.1.1
A module that encapsulates jquery into Seajs

Copy Code code as follows:
Define (function () {

Here's a jquery code to put your favorite jquery version in.


return $.noconflict ();
});

Call Method:
So the introduction can use jquery as before

Copy Code code as follows:
Define (function (Require, exports, module) {
var $ = require ('./js/jquery ');

$ (document). Ready (function () {
$ ("tr"). wyhinterlaced ({"Odd": "Red", "even": "Blue"});
$ ("tr"). Wyhhover ();
// })
});


Second, the jquery class encapsulated into a SEAJS module
Copy Code 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 ();
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
Return year + "-" + month + "-" + TD + "" + H + ":" + M + ":" + S; Break
Case 2://2013-09-09 (Monday) 09:31:56
Return year + "-" + month + "-" + TD + "(" + D + ")" + H + ":" + M + ":" + S; Break
Case 3://09-09-2013 09:31:56
Return month + "-" + TD + "-" + year + "" + H + ":" + M + ":" + S; Break
Case 4://09-09-2013 Monday 09:31:56
Return month + "-" + TD + "-" + Year + "(" + D + ")" + H + ":" + M + ":" + S; Break
Case 5://September 09, 2013 09:31 sec 56
Return year + "years" + month + "month" + TD + "Day" + H + "time" + M + "min" + S + "second"; Break
Case 6://September 09, 2013 Monday 09:31 sec 56
Return year + "years" + month + "month" + TD + "Day (" + D + ")" + H + "" + M + "min" + S + "seconds"; Break
}
};

/*******************************************************
/* Function Name: GetTime
/* Parameters: Numeric values, including cosmetic floating-point types, and floating-point types are rounded, if not numbers,
The function will return with the default time format! Time style has 15 "1-15 is a valid time style
Exceeding or less than will be in the default style style 1 ")
/* feature to get the current system time customizable format
*******************************************************/

function GetTime (ARG) {
if (!isnan (ARG)) {
var num = Math.Round (ARG);

if (Num < 7 && num > 0) {
return GetType (num);
}
else {
var str;
var str2;
Switch (num) {
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);
}
};


    * Get the current number of years for the system */
     function getyear () {
         var today = new Date ();
        return today.getfullyear ();
   };


    * Get the current number of months for the system */
      function getmonth () {
         var today = new Date ();
        return Today.getmonth () + 1;;
   };
   /* Get the current number of days for 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 current number of seconds of the system * *
function Getsecond () {
var today = new Date ();
return Today.getseconds ();
};


/************************************************************
* Function Name: Timesubmillisecond
* Parameters: Endtime (end time) starttime (start time)
* Function: Gets two time millisecond level difference, must write a parameter the second parameter (starting time) can
* Do not write default is the system current time
************************************************************/
function Timesubmillisecond (Endtime, starttime) {
var end = new Date (endtime). GetTime ();
if (!endtime) {
return-1;
}
if (!starttime) {
start = new Date (). GetTime ();
}
else {
start = new Date (starttime). GetTime ();
}
if (Start > End) {
return-1;
}
else {
return end-start;
}
};
/************************************************************
* Function Name: timesubnormal
* Parameters: Endtime (end time) starttime (start time)
* Function: Get two time difference, must write a parameter the second parameter (starting time) can
* Do not write default is the system current time
************************************************************/

function Timesubnormal (Endtime, starttime) {
var end = new Date (endtime). GetTime ();
var start;
if (!starttime) {
start = new Date (). GetTime ();
}
else {
start = new Date (starttime). GetTime ();
}
if (Start > End) {
return-1;
}
else {
var alltime = End-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";
}
if (Chour > 0) {
STR + + Chour + "hour";
}
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;

})

Call Method:

Copy Code code as follows:
Define (function (Require, exports, module) {
var $ = require ('./js/jquery ');
var a=require ('./js/time ');

Alert (A.gettime (3));
});


third, the jquery plug-in packaging into a SEAJS module
Here's an example of encapsulating a plug-in of jquery into a module
Copy Code code as follows:
Define (function (require, exports, moudles) {
return function (jquery) {
(function ($) {
Highlight to Current line
$.fn.wyhhover = function (options) {//options often have many arguments with this representation.
var defaultval = {
BackColor: ' #ccc ',
};

var obj = $.extend (defaultval, Options);

Return This.each (function () {
var Tabobject = $ (this); Get current Object
var oldbgcolor = tabobject.css ("Background-color"); Gets the background color of the current object
Tabobject.hover (//) defines 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 (options) {//options often have many arguments with this representation.
var defaultval = {
Odd: ' #DDEDFB ',
Even: ' #fff ',
};

var obj = $.extend (defaultval, Options);

          return This.each (function () {
             var tabobject = $ (this); Gets the current object
           if (Tabobject.index ()%2==0)
            {
               tabobject.css ("Background-color", obj.odd);
          }else
            {
             Tabobject.css ("Background-color", Obj.even);
          }
       });
       }
       }) (jquery);
   }

})

Call Method:
Calling Plug-ins by using shared methods

Copy Code code as follows:
Define (function (Require, exports, module) {
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.