]> source.dussan.org Git - jquery.git/commitdiff
Started work on new attr plugin - will provide a ton of accessors for common styles...
authorJohn Resig <jeresig@gmail.com>
Sun, 9 Apr 2006 04:04:52 +0000 (04:04 +0000)
committerJohn Resig <jeresig@gmail.com>
Sun, 9 Apr 2006 04:04:52 +0000 (04:04 +0000)
attr/attr.js [new file with mode: 0644]

diff --git a/attr/attr.js b/attr/attr.js
new file mode 100644 (file)
index 0000000..21331b6
--- /dev/null
@@ -0,0 +1,37 @@
+var pos = [
+  "height", "width", "top", "left", "bottom", "right",
+  "paddingTop", "paddingRight", "paddingBottom", "paddingLeft",
+  "marginTop", "marginRight", "marginBottom", "marginLeft",
+  "lineHeight", "maxWidth", "maxHeight", "minWidth", "minHeight",
+  "textIndent", "fontSize"
+];
+
+for ( var i = 0; i < pos.length; i++ ) {
+       (function(){
+               var o = pos[i];
+               $.fn[o] = function(a){
+                       return a ?
+                               this.css(o,a) :
+                               parseInt( this.css(o) );
+               };
+       })();
+}
+
+var posArg = [
+       "clientLeft", "clientTop", "clientWidth", "clientHeight",
+       "offsetLeft", "offsetTop", "offsetWidth", "offsetHeight",
+       "scrollLeft", "scrollTop", "scrollWidth", "scrollHeight"
+];
+
+for ( var i = 0; i < posArg.length; i++ ) {
+       (function(){
+               var o = posArg[i];
+               $.fn[o] = function(a){
+                       return a ? this.each(function(){
+                               this[o] = parseInt( a );
+                       }) : this.size() > 0 ?
+                               this.get(0)[o] :
+                               null;
+               };
+       })();
+}
\ No newline at end of file