"JavaScript Packaging Library" Prototype prototype release!

Source: Internet
Author: User
Tags tagname

/* Source author:  stone not Easy (Louis shi) contact information:  http://www.shibuyi.net============================================= ====================================================== Program name: javascript  Package Library  Prototype  version Iteration :  non-functional total: 14  features: 1.  implementation code concatenating 2. id / name / tagname /  class  node Get 3. class  selector Add with remove 4. css  rule Add and remove 5.  set with Get element inner text 6.  set with Get CSS7.   Implementation  click  Event *///  instantiation Entry function $ ()  {return new base ();}   Package Library construction Method Function base ()  {this.elements = [];}   Get ID element node base.prototype.getid = function  (ID)  {this.elements.push ( document.getElementById (ID)); return this;};/ /  gets the name element node base.prototype.getname = function  (name, position)  {if  (typeof  position !=  ' undefined ')  { //  local var nodes = $ (). Gettagname (' * ',  position) .elements;for  (VAr i = 0; i < nodes.length; i ++)  {if  (Nodes[i]. GetAttribute (' name ')  == name)  this.elements.push (Nodes[i]);}}  else { //  Global Var nodes = document.getelementsbyname (name);for  (var  i = 0; i < nodes.length; i ++)  {this.elements.push (Nodes[i]);}} return this;};/ /  Get tagName element node base.prototype.gettagname = function  (tagname, position)  {if   (typeof position !=  ' undefined ')  { //  local var nodes = $ (). GetId (position). Elements[0].getelementsbytagname (TagName);}  else { //  Global Var nodes = document.getelementsbytagname (tagName);} for  (var i = 0; i < nodes.length; i ++)  { This.elements.push (Nodes[i]);} return this;};/ /  gets the class element node base.prototype.getclass = function  (CLassname, position)  {if  (typeof position !=  ' undefined ')  { //  Local var nodes = $ (). Gettagname (' * ',  position). elements;}  else { //  Global var nodes = $ (). Gettagname (' * '). elements;} for  (var i = 0; i < nodes.length; i ++)  {if  (nodes[i ].classname == classname)  this.elements.push (Nodes[i]);} return this;};/ /  Gets and sets innerhtmlbase.prototype.html = function  (text)  {if  (typeof text  !=  ' undefined ')  { //  set for  (var i = 0; i <  this.elements.length; i ++)  {this.elements[i].innerhtml = text;}}  else { //  Get var html = [];for  (var i = 0; i  < this.elements.length; i ++)  {html.push (this.elements[i].innerhtml);} return html;} Return this;};/ /  Get and set cssbase.prototype.css = function  (Csskey, cssvalue)  {if  (typeof  cssValue !=  ' undefined '  | |  csskey instanceof array)  { //  set for  (var i = 0; i  < this.elements.length; i ++)  {if  (Csskey instanceof array)  { var _csskye, _cssvalue, _css;for  (var j = 0; j <  csskey.length; j ++)  {if  (Csskey[j].match (/([a-z]+) \s*=\s* ([\w#]+)/i)  != null)  { // [' color=red ',  ' Backgroundcolor = green ']_css = csskey[j].split (/ \s*=\s*/); _csskey = _css[0];_cssvalue = _css[1];this.elements[i].style[_csskey] =  _cssvalue;}}}  else {this.elements[i].style[csskey] = cssvalue;}}}  else { //  Get var css = [];for  (var i = 0; i < this.elements.length; i ++)  {if  (typeof window.getcomputedstyle  !=  ' undefined ')  { // w3ccss.push (window.getComputedStyle (this.elements[i], null ) [Csskey]);}  else if  (typeof this.elements[i].currentstyle !=  ' undefined ')  { //  ie 6/7/8css.push (This.elements[i].currentstyle[csskey]);}} Return css;} return this;};/ /  Detection class selector base.prototype.hasclass = function  (className)  {var results =  [];for  (var i = 0; i < this.elements.length; i ++)   {Results.push (!! This.elements[i].classname.match (New regexp (' (\\s|^) '  + className +  ' (\\s|$) '));} return results;};/ /  Add Class selector base.prototype.addclass = function  (className)  {var space =   "; Var results = this.hasclass (ClassName);for  (var i = 0; i < results.length; i ++)  {if  (!results[i])  {if  ( this.elements[i].classname !=  ')  space =  '   '; this.elements[i].classname +=  space + classname;}} return this;};/ /  Remove class selector base.prototype.removeclass = function  (className)  {var results  = this.hasclass (ClassName);for  (var i = 0; i < results.length;  i ++)  {if  (Results[i])  this.elements[i].classname = this.elements[i]. Classname.replace (New regexp (' (\\s|^) '  + className +  ' (\\s|$) '),  ');} return this;};/ /  Add Style rule rulebase.prototype.addrule = function  (rulename, ruletext, index,  Position)  {if  (typeof index ==  ' undefined ')  index = 0;if  (typeof  position ==  ' undefined ')  position = 0;var sheet = document.stylesheets[index];if  (typeof sheet !=  ' undefined ')  {if  (typeof sheet.insertrule !=  ' undefined ')  { // w3csheet.insertrule (rulename +  '  {'  + ruleText +  '} ',  position);}  else if  (sheet.addrule !=  ' undefined ')  { // ie 6/7/ 8sheet.addrule (rulename, ruletext, position);}} return this;};/ /  Remove style rules rulebase.prototype.removerule = function  (index, position)  {if  ( typeof index ==  ' undefined ')  index = 0;if  (typeof position ==   ' undefined ')  position = 0;var sheet = document.styleSheets[index];if  (typeof sheet !=  ' undefined ')  {if  (typeof sheet.deleterule !=  ' Undefined ')  { // w3csheet.deleterule (position);}  else if  (Typeof sheet.removerule !=  ' undefined ')  { // ie 6/7/8sheet.removerule (position);}} return this;};/ /  Mouse  click  Event base.prototype.click = function  (method)  {if  (method  instanceof function)  {for  (var i = 0; i <  this.elements.length; i ++)  {this.elements[i].onclick = method;}} return this;};


For Prototype prototype core source code and example of the demo, please move to the official website to download!

Thank you for your positive evaluation to give comments!

Website address: http://www.shibuyi.net

Cnblogs Blog: http://www.cnblogs.com/shibuyi/

CSDN Blog: http://blog.csdn.net/louis_shi/

Iteye Blog: http://shibuyi.iteye.com/


This article from "Stone Not Easy Mood Blog" blog, please be sure to keep this source http://shibuyi.blog.51cto.com/9460768/1562088

"JavaScript Packaging Library" Prototype prototype release!

Related Article

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.