leanQuery

A jQuery based library

by edgardleal

HTML

<div style='border : solid 1px;'></div>

CSS

.x{
    background : blue;
    height : 27px;
}

.s{
    box-shadow : 3px 3px 3px inset;
}

JavaScript

(function(window, undefined){
   function log(text){
      if(window.console && window.console.log)   
          window.console.log(text);
   }             
    var $ = window.$;
    $ = function(selector){
        return new $.fn.init(selector);
    }
    $.fn = $.prototype = {
        selector : "",
        element : null,
        length : 0,
        constructor : $,
        css : function(obj, value){
           if($.fn.length==0) return $.fn;
            var old = $.fn.element.style.cssText;
           if(!value && !obj) 
               return $.fn.element.style.cssText;
            else if(typeof value==="string" && typeof obj==="string")
                $.fn.element.style.cssText = 
                    ((old.length>0&&old.indexOf(';')!=(old.length-1))?
                     ';':'') + (obj+':'+value);
            return $.fn;
        },
        addClass : function(className){
           if($.fn.length==0) return $.fn;
           var old = $.fn.element.className.trim();
                if(old.indexOf(className)>0)
                    return this;                
                $.fn.element.className = 
                    (old!==""?old + " ":"") + className; 
           return $.fn;
        },
        init : function(selector){
            $.fn.selector = selector;
            $.fn.element = document.querySelector(selector);
            $.fn.length=$.fn.element!=null?1:0;                        
            return $.fn;
        } ,
        get : function(index){
           if($.fn.length==0) return $.fn;
           if(!index)
               return $.fn.element;
        },
        text : function(value){
            if($.fn.length==0) return "";
            if(!value)
                return $.fn.element.innerText;
            else
                $.fn.element.innerText = value;
            return $.fn;
        },
        html : function(value){
            if($.fn.length==0) return "";
            if(!value)
                return $.fn.element.innerHTML;
     ...