Analysis of javascript Functions used in discuz [original] Page 1/2 _ javascript skills

Source: Internet
Author: User
The js used in discuz is very good in compatibility and practicability of multiple browsers. We recommend you read var lang = new Array ();
Var userAgent = navigator. userAgent. toLowerCase ();
Var is_opera = userAgent. indexOf ('Opera ')! =-1 & opera. version ();
Var is_moz = (navigator. product = 'gecko ') & userAgent. substr (userAgent. indexOf ('Firefox') + 8, 3 );
Var is_ie = (userAgent. indexOf ('msie ')! =-1 &&! Is_opera) & userAgent. substr (userAgent. indexOf ('msie ') + 5, 3 );

Function $ (id ){
Return document. getElementById (id );
}
// Define the push attribute of the array
Array. prototype. push = function (value ){
This [this. length] = value;
Return this. length;
}
// Select all functions in javascript
Function checkall (form, prefix, checkall ){
Var checkall = checkall? Checkall: 'chall ';
For (var I = 0; I <form. elements. length; I ++ ){
Var e = form. elements [I];
If (e. name & e. name! = Checkall &&(! Prefix | (prefix & e. name. match (prefix )))){
E. checked = form. elements [checkall]. checked;
}
}
}

Function doane (event ){
E = event? Event: window. event;
If (is_ie ){
E. returnValue = false;
E. cancelBubble = true;
} Else if (e ){
E. stopPropagation ();
E. preventDefault ();
}
}

Function fetchCheckbox (cbn ){
Return $ (cbn) & $ (cbn). checked = true? 1: 0;
}

Function getcookie (name ){
Var cookie_start = document. cookie. indexOf (name );
Var cookie_end = document. cookie. indexOf (";", cookie_start );
Return cookie_start =-1? '': Unescape (document. cookie. substring (cookie_start + name. length + 1, (cookie_end> cookie_start? Cookie_end: document. cookie. length )));
}

Function thumbImg (obj ){
Var zw = obj. width;
Var zh = obj. height;
If (is_ie & zw = 0 & zh = 0 ){
Var matches;
Re =/width = (["']?) (\ D +) (\ 1)/I;
Matches = re.exe c (obj. outerHTML );
Zw = matches [2];
Re =/height = (["']?) (\ D +) (\ 1)/I;
Matches = re.exe c (obj. outerHTML );
Zh = matches [2];
}
Obj. resized = true;
Obj. style. width = zw + 'px ';
Obj. style. height = 'auto ';
If (obj. offsetHeight> zh ){
Obj. style. height = zh + 'px ';
Obj. style. width = 'auto ';
}
If (is_ie ){
Var imgid = 'img _ '+ Math. random ();
Obj. id = imgid;
SetTimeout ('try {if ($ (\ ''+ imgid + '\'). offsetHeight> '+ zh +') {$ (\ ''+ imgid + '\'). style. height = \ ''+ zh + 'px \ '; $ (\'' + imgid + '\'). style. width = \ 'Auto \ '; }}catch (e) {}', 1000 );
}
Obj. onload = null;
}

Function imgzoom (obj ){}

Function in_array (needle, haystack ){
If (typeof needle = 'string' | typeof needle = 'number '){
For (var I in haystack ){
If (haystack [I] = needle ){
Return true;
}
}
}
Return false;
}

Function setcopy (text, alertmsg ){
If (is_ie ){
ClipboardData. setData ('text', Text );
Alert (alertmsg );
} Else if (prompt ('Press Ctrl + C Copy to clipboard', text )){
Alert (alertmsg );
}
}

Function isUndefined (variable ){
Return typeof variable = 'undefined '? True: false;
}

Function mb_strlen (str ){
Var len = 0;
For (var I = 0; I <str. length; I ++ ){
Len + = str. charCodeAt (I)

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.