1/* 2 * exResize 0.1.0 - jQuery plugin 3 * written by Cyokodog 4 * 5 * Copyright (c) 2010 Cyokodog (http://d.hatena.ne.jp/cyokodog/) 6 * Dual licensed under the MIT (MIT-LICENSE.txt) 7 * and GPL (GPL-LICENSE.txt) licenses. 8 * 9 * Built for jQuery library 10 * http://jquery.com 11 * 12 */ 13(function($){ 14 var API = function(api){ 15 var api = $(api),api0 = api[0]; 16 for(var name in api0) 17 (function(name){ 18 if($.isFunction( api0[name] )) 19 api[ name ] = (/^get[^a-z]/.test(name)) ? 20 function(){ 21 return api0[name].apply(api0,arguments); 22 } : 23 function(){ 24 var arg = arguments; 25 api.each(function(idx){ 26 var apix = api[idx]; 27 apix[name].apply(apix,arg); 28 }) 29 return api; 30 } 31 })(name); 32 return api; 33 } 34 35 $.ex = $.ex || {}; 36 $.ex.resize = function(idx , targets , option){ 37 if ($.isFunction(option)) { 38 option = {callback : option}; 39 } 40 var o = this, 41 c = o.config = $.extend({} , $.ex.resize.defaults , option); 42 c.targets = targets; 43 c.target = c.watchTarget = c.targets.eq(idx); 44 c.index = idx; 45 c.oldBrowser = $.browser.msie && ($.browser.version < 8.0 || !$.boxModel); 46 c.key = { height : '', width : ''}; 47 if (c.contentsWatch) { 48 o._createContentsWrapper(); 49 } 50 c.currentSize = c.newSize = o.getSize(); 51 if (c.resizeWatch) o._resizeWatch(); 52 } 53 $.extend($.ex.resize.prototype, { 54 _createContentsWrapper : function(){ 55 var o = this, c = o.config; 56 var style = c.oldBrowser ? 'zoom:1;display:inline' : 'display:inline-block'; 57 c.watchTarget = c.target.wrapInner('<div style="' + style + ';width:' + c.target.css('width') + '"/>').children(); 58 return o; 59 }, 60 _resizeWatch : function(){ 61 var o = this, c = o.config; 62 setTimeout(function(){ 63 if (c.contentsWatch) { 64 if (c.watchTarget.prev().size() > 0 || c.watchTarget.next().size() > 0 || c.watchTarget.parent().get(0) != c.target.get(0)) { 65 c.watchTarget.replaceWith(c.watchTarget.get(0).childNodes); 66 o._createContentsWrapper(); 67 } 68 } 69 if (o._isResize()) { 70 c.currentSize = c.newSize; 71 c.callback.call(c.watchTarget.get(0),o); 72 } 73 o._resizeWatch(); 74 },c.resizeWatch); 75 }, 76 _isResize : function () { 77 var o = this, c = o.config; 78 var ret = false;
79 c.newSize = o.getSize(); 80 for (var i in c.key) { 81 ret = ret || (c.newSize[i] != c.currentSize[i]); 82 } 83 return ret; 84 }, 85 getTargets : function(){ 86 return this.config.targets; 87 }, 88 getTarget : function(){ 89 return this.config.target; 90 }, 91 getSize : function () { 92 var o = this, c = o.config; 93 if (c.contentsWatch) c.watchTarget.css('width','auto'); 94 var ret = {}; 95 for (var i in c.key) { 96 ret[i] = c.watchTarget[i](); 97 } 98 if (c.contentsWatch) c.watchTarget.css('width',c.target.css('width')); 99 return ret; 100 } 101 }); 102 $.ex.resize.defaults = { 103 contentsWatch : false, 104 resizeWatch : 100, 105 callback : function(){} 106 } 107 $.fn.exResize = function(option){ 108 var targets = this,api = []; 109 targets.each(function(idx) { 110 var target = targets.eq(idx); 111 var obj = target.data('ex-resize') || new $.ex.resize( idx , targets , option); 112 api.push(obj); 113 target.data('ex-resize',obj); 114 }); 115 return option && option.api ? API(api) : targets; 116 } 117})(jQuery);
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.