/*
* toJSONObject function is used to convert a JSON string into an object literal
*/
function toJSONObject(s){
return s ? eval("(" + s + ")") : null;
}
window["Susa"]["toJSONObject"] = toJSONObject;
/*
* Three functions for reading, writing and deleting cookies
* sName: the name of the cookie;
* sValue; value of cookie;
* oExpires: the validity time of cookies;
* sPath:cookie path;
* sDomain:cookie domain
* bSecure:Safety Sign
*/
function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure){
var oCookie = sName + "=" + encodeURIComponent(sValue);
if (oExpires)
oCookie = "; expires=" + ();
if (sPath)
oCookie = "; path=" + sPath;
if (sDomain)
oCookie = "; domain=" + sDomain;
if (bSecure)
oCookie = "; secure";
= oCookie;
}
function getCookie(sName){
var re = "(?:;)?" + sName + "=([^;]*);?";
var oRe = new RegExp(re);
if (()) {
return decodeURIComponent(RegExp["$1"]);
}
else {
return null;
}
}
//Because the information set by the setCookie is the same as the information required by the deleteCookit, you can directly use the setCookie and pass it in a past invalid time (here is 1970/1/1)
function deleteCookie(sName, sPath, sDomain){ //Original
exp = FRI,02-Jan-1970 00:00:00 GMT ;
= sName + "=" + encodeURIComponent(sName) + "; expires=FRI,02-Jan-1970 00:00:00 GMT";
}
window["Susa"][ setCookie ] = setCookie;
window["Susa"][ getCookie ] = getCookie;
window["Susa"][ deleteCookie ] = deleteCookie;
/*
* Two helper functions that determine the x and y positions of the entire document
*/
function pageX(elem){
elem = transformLabelID(elem); // Ensure that elem is a DOM node element
// Check if it is located in the root element
return ? //If you can continue to get the previous element, increase the current offset and continue to recurse upwards
+ pageX() : ;
}
function pageY(elem){
elem = transformLabelID(elem);
return ? + pageX() : ;
}
window["Susa"]["pageX"] = pageX;
window["Susa"]["pageY"] = pageY;
/*
* Two functions that determine the position of an element relative to the father
*/
function parentX(elem){
elem = transformLabelID(elem); // Ensure that elem is a DOM node element
//If offsetParent is the parent element of the element, then return offsetLeft. Otherwise, you need to find the parent of the element relative to the entire page position and calculate the difference between them
return == ? : pageX(elem) - pageX();
}
function parentY(elem){
elem = transformLabelID(elem);
return == ? : pageY(elem) - pageY();
}
window["Susa"]["parentX"] = parentX;
window["Susa"]["parentY"] = parentY;
/*
* Get the helper function of the CSS position of the element, which is only meaningful when the CSS attribute position of the element is set to absolute or relative.
*/
function posX(elem){
elem = transformLabelID(elem);
return parseInt(getStyle(elem, "left")); //Get the value of the left attribute of the element
}
function posY(elem){
elem = transformLabelID(elem);
return parseInt(getStyle(elem, "top")); //Get the value of the top attribute of the element
}
window["Susa"]["posX"] = posX;
window["Susa"]["posY"] = posY;
/*
* A pair of functions that set the x and y positions of the element (irrelevant to the current position) will only make sense when the element's CSS attribute position is set to absolute or relative.
*/
function setX(elem, pos){
elem = transformLabelID(elem);
= pos + "px"; //Set the element's left attribute using pixels
}
function setY(elem, pos){
elem = transformLabelID(elem);
= pos + "px"; //Set the top attribute of the element using pixels
}
window["Susa"]["setX"] = setX;
window["Susa"]["setY"] = setY;
/*
* A pair of functions that adjust the distance between the element and the current position is only meaningful when the element's CSS attribute position is set to absolute or relative.
*/
function addX(elem, pos){
elem = transformLabelID(elem);
setX(elem, posX(elem) + pos); // Add pos to the original left attribute value
}
function addY(elem, pos){
elem = transformLabelID(elem);
setY(elem, posY(elem) + pos); //Add pos on the original top attribute value
}
window["Susa"]["addX"] = addX;
window["Susa"]["addY"] = addY;
/*
* Get the current height and width of the element
*/
function getHeight(elem){
return parseInt(getStyle(elem, "height"));
}
function getWidth(elem){
return parseInt(getStyle(elem, "width"));
}
/*
* Even if hidden, two functions can be obtained separately for its potential full height and width.
* Note: If hidden, that is, display is none, and the height attribute is not set, NAN will be returned.
*/
function fullHeight(elem){
elem = transformLabelID(elem);
//If the element is displayed, then use offsetHeight to get the height, or use getHeight()
if (getStyle(elem, display ) != none ) {
return || getStyle(elem, height );
}
// Otherwise, the element with display as none must be processed, so reset its css attribute to get more accurate readings
var old = resetCSS(elem, {
display: ,
visibility: hidden ,
position: absolute
});
// Use clientHeight to find the complete height of the element. If it does not take effect, use the getHeight function
var h = || getHeight(elem);
//Finally restore the original properties of css
restoreCSS(elem, old);
// and return to full height
return h;
}
function fullWidth(elem){
elem = transformLabelID(elem);
if (getStyle(elem, display ) != none ) {
return || getStyle(elem, width );
}
var old = resetCSS(elem, {
display: ,
visibility: hidden ,
position: absolute
});
var w = || getStyle(elem, width );
restoreCSS(elem, old);
return w;
}
//Two auxiliary functions
function resetCSS(elem, prop){
var old = {}; //Record old attribute values
for (var i in prop) {
old[i] = [i];
[i] = prop[i];
}
return old;
}
function restoreCSS(elem, prop){
for (var i in prop) { //Restore css attribute value
[i] = prop[i];
}
}
window["Susa"]["fullHeight"] = fullHeight;
window["Susa"]["fullWidth"] = fullWidth;
/*
* A set of functions that use CSS' display attribute to switch element visibility
*/
function hide(elem){
elem = transformLabelID(elem);
var curDisplay = getStyle(elem, display );
if (curDisplay != "none") {
elem.$oldDisplay = curDisplay; //Record its display status
= none ;
}
}
function show(elem){
elem = transformLabelID(elem);
//Set the original value of the display attribute. If the original value is not recorded, use block
= elem.$oldDisplay || block ;
}
window["Susa"]["hide"] = hide;
window["Susa"]["show"] = show;
/*
* A function that adjusts the transparency of an element. Level from 0-100, 0 means complete transparency, 100 means the opposite.
*/
function setOpacity(elem, level){
elem = transformLabelID(elem);
if () { // Set Alpha filter in IE
= alpha(opacity= + level + ) ;
}
else { //W3C's opacity attribute
= level / 100;
}
}
window["Susa"]["setOpacity"] = setOpacity;
/*
* By gradually displaying hidden elements functions by increasing and decreasing heights in a short time, you can customize the speed. The larger the speed, the slower the increase.
*/
function slideDown(elem, speed){
speed = speed || 100;
elem = transformLabelID(elem);
var h = fullHeight(elem); //Find the full potential height of the element
= "0px"; //The height starts to slide from 0
//alert();return;
restoreCSS(elem, elem.$old || null); //Restore the border style of the original CSS
show(elem); //Show the element first
for (var i = 0; i <= speed; i += 5) {
(function(){
var pos = i;
setTimeout(function(){
= (pos / speed) * h + "px";
}, (pos + 1) * 10);
})();
}
}
function slideUp(elem, speed){ //(Original)
speed = speed || 100;
elem = transformLabelID(elem);
var h = fullHeight(elem);
show(elem);
for (var i = 100; i >= 0; i -= 5) {
(function(){
var pos = i;
setTimeout(function(){
= (pos / speed) * h + "px";
}, (100 - pos + 1) * 10); // Pay attention to the time setting
})();
}
elem.$old = resetCSS(elem, {
border: "none"
}); //If the DOM element contains the border attribute, remove the border
}
window["Susa"]["slideDown"] = slideDown;
window["Susa"][ slideUp ] = slideUp;
/*
* By increasing and decreasing transparency in a short time, you can customize the speed. The larger the speed, the slower the increase
*/
function fadeIn(elem, speed){
speed = speed || 5;
elem = transformLabelID(elem);
setOpacity(elem, 0); //Start with 0 transparency
show(elem); //Show the element first
for (var i = 0; i <= 100; i += speed) {
(function(){
var pos = i;
setTimeout(function(){
setOpacity(elem, pos);
}, (pos + 1) * 10);
})();
}
}
function fadeOut(elem, speed){ //(Original)
elem = transformLabelID(elem);
speed = speed || 1;
setOpacity(elem, 100);
show(elem);
for (var i = 100; i >= 0; i -= speed) {
(function(){
var pos = i;
setTimeout(function(){
setOpacity(elem, pos);
}, (100 - pos + 1) * 10); // Pay attention to the time setting
})();
}
//hide(elem);
}
window["Susa"]["fadeIn"] = fadeIn;
window["Susa"]["fadeOut"] = fadeOut;
/*
* Used to get the current position of the mouse relative to the entire page
*/
function getX(e){
e = e || ;
return || + ;
}
function getY(e){
e = e || ;
return || + ;
}
window["Susa"]["getX"] = getX;
window["Susa"]["getY"] = getY;
/*
* Check whether a required field has been modified, including check boxes and radio boxes
*/
function required(elem){
if ( == checkbox || == "radio") {
return getInputsByName().numChecked;
}
else {
return > 0 && != ;
}
}
function getInputsByName(name){
var results = []; //Array of matching input elements
= 0; //Traces the number of selected elements
var input = ( input );
for (var i = 0; i < ; i++) {
if (input[i].name == name) {
(input[i]);
if (input[i].checked) { //If selected, increase the value of numChecked
++; // Pay attention to this usage
}
}
}
return results;
}
window["Susa"]["required"] = required;
/*
* imgToggle function is used to switch between two situations of moving the mouse to a picture (original)
*/
function imgToggle(elem, url){
elem = transformLabelID(elem);
= function(){
= ;
= url;
};
= function(){
= ;
};
}
window["Susa"]["imgToggle"] = imgToggle;
/*
* textToggle function is used to switch the mouse to move to a text two situations (original)
*/
function textToggle(elem, prop){
elem = transformLabelID(elem);
= function(){
for (var o in prop) {
elem["style"][o] = prop[o]; //Set the style attribute value
}
};
= function(){
for (var o in prop) {
elem["style"][o] = null;
}
}
}
window["Susa"]["textToggle"] = textToggle;
/*
* You can set the css attribute setCSS function of several HTML tags at the same time (original)
*/
function setCSS(ids, props){
for (var i = 0, len = ; i < len; i++) {
for (var o in props) {
(ids[i]).style[o] = props[o];
}
}
}
})();
// Methods to extend String
/*
* A function that repeats a string, such as: a.repeat(5), will return aaaaa
*/
if (!) {
= function(l){
return new Array(l + 1).join(this); //Note the meaning of the array
}
}
/*
* Delete the spaces before and after the string
*/
if (!) {
= function(){
return (/^\s+|\s+$/g, ); //Learn the syntax of candidates for regularity
}
}
/*
* serialize function traversals all members of this object and organizes their values into a string output
*/
function serialize(){
var output = [];
for (o in this) {
(o + ":" + this[o]);
}
return (",");
}
/*
* DOM object that detects when the DOM is loaded and code is executed (original)
*/
var DOM = {
done: false,
clearID: 0,
fn: [], //Initialize the parameter set of the function
ready: function(){ //Initialize the function
for (var i = 0; i < ; i++) {
if (typeof arguments[i] == function ) {
(arguments[i]);
}
else {
continue;
}
}
if () { //If the loading is completed, execute all function parameters of the initialization function
for (var i = 0; i < ; i++) {
[i]();
}
= false;
}
else {
();
}
},
Interval: function(){ //Repeat call to the check function
= (, 20);
},
check: function(){ //Check whether it loaded successfully
if () {
clearInterval();
();
}
else {
if ( && document && && ) {
= true;
}
}
}
};
Previous page12Read the full text