1// jQuery Pseudo 2// URL: http://plugins.jquery.com/pseudo 3// Source: http://github.com/makesites/jquery-pseudo 4// 5// Initiated by [Makis Tracend](http://github.com/tracend) 6// Distributed by [Makesites.org](http://makesites.org) 7// Released under the [MIT license](http://makesites.org/licenses/MIT) 8 9(function (lib) { 10 11 //"use strict"; 12 13 if (typeof define === 'function' && define.amd) { 14 // AMD. Register as an anonymous module. 15 var deps = ['jquery']; 16 define(deps, lib); // give the module a name 17 } else if ( typeof module === "object" && module && typeof module.exports === "object" ){ 18 // Expose as module.exports in loaders that implement CommonJS module pattern. 19 module.exports = lib; 20 } else { 21 // Browser globals 22 var Query = window.jQuery; // not supporting other query engines || window.Zepto || window.vQuery; 23 lib(Query); 24 } 25}(function ( $ ){ 26 27// main data container 28var styles = {}; 29 30 31$.fn.pseudo = function( element, prop, value ) { 32 // variables 33 var el = this[0]; 34 var id = "pseudo-styles"; 35 var changed = false; 36 var className = ""; 37 var sheet = document.getElementById(id) || document.createElement('style'); 38 var head = document.head || document.getElementsByTagName('head')[0]; 39 sheet.id = id; 40 41 var has_pseudo_class = ( this.attr('class') && this.attr('class').indexOf('pseudo-style') > -1 ); 42 if( has_pseudo_class ){ 43 var classes = this.attr('class'); 44 // remove classes before 45 className = classes.substr( classes.indexOf('pseudo-style') ); 46 // remove classes after 47 className = classes.substr( classes.indexOf(' ')+1 ); 48 // add / update existing style... 49 var selector = className +":"+ element; 50 var attributes = {}; 51 attributes[prop] = value; 52 // fallback for the first time... 53 if( !styles[ selector ] ) styles[ selector ] = {}; 54 // check if the styles have changed 55 if( styles[ selector ] == attributes ){ 56 // do nothing... 57 } else { 58 styles[ selector ] = $.extend({}, styles[ selector ], attributes); 59 changed = true; 60 } 61 } else { 62 // generate a new class name 63 var className = "pseudo-style" + UID.getNew(); 64 el.className += ( ( el.className == "" ) ? "" : " ")+ className; 65 changed = true; // by definition if we're adding a new class we have a change... 66 } 67 68 // if the styles hasn't changed, save a cycle 69 if( !changed ) return this; 70 // compile stylesheet 71 var output = ""; 72 for( var target in styles ){ 73 var css = ""; 74 for( var key in styles[target] ){ 75 css += key +":"+ styles[target][key] +";"; 76 } 77 output += " ."+ target +" {"+ css +" }"; 78 } 79 sheet.innerHTML = output; 80 // append stylesheet 81 head.appendChild(sheet); 82 83 return this; 84 85}; 86 87// If there is a window object, that at least has a document property 88if( typeof window === "object" && typeof window.document === "object" ){ 89 // save in the global namespace (not needed?) 90 window.jQuery = $; 91} 92 93 94// Helpers 95var UID = { 96 _current: 0, 97 getNew: function(){ 98 this._current++; 99 return this._current; 100 } 101}; 102 103 104}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.