PageSourceSearch

http://www.akb48matomemory.com/jquery.exflexfixed-0.3.0.js

js akb48matomemory.com collected 2026-09-26 02:20:21 UTC 5,526 bytes, 202 lines download raw bytes

1/*
2 * 	Ex Flex Fixed 0.3.0 - jQuery plugin
3 *	written by Cyokodog	
4 *
5 *	Copyright (c) 2012 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	$.ex = $.ex || {};
15
16	var API = function(api){
17		var api = $(api),api0 = api[0];
18		for(var name in api0)
19			(function(name){
20				if($.isFunction( api0[name] ))
21					api[ name ] = (/^get[^a-z]/.test(name) || /^is[^a-z]/.test(name)) ?
22						function(){
23							return api0[name].apply(api0,arguments);
24						} : 
25						function(){
26							var arg = arguments;
27							api.each(function(idx){
28								var apix = api[idx];
29								apix[name].apply(apix,arg);
30							})
31							return api;
32						}
33			})(name);
34		return api;
35	}
36
37	$.ex.flexFixed = function(idx , targets , option){
38		var o = this,
39		c = o.config = $.extend({} , $.ex.flexFixed.defaults , option);
40		c.targets = targets;
41		c.target = c.targets.eq(idx);
42		c.index = idx;
43		c._win = $(window);
44
45		c._orgMarginTop = parseInt(c.target.css('margin-top'))||0;
46		c._orgMarginBottom = parseInt(c.target.css('margin-bottom'))||0;
47		c._orgMarginLeft = parseInt(c.target.css('margin-left'))||0;
48		c._orgMarginRight = parseInt(c.target.css('margin-right'))||0;
49
50		c.container = $(c.container);
51		c.fixedHeaderHeight = c.fixedHeader ? $(c.fixedHeader).outerHeight() : 0 ;
52		if(!(c.zIndex == null)) c.target.css('z-index',c.zIndex);
53
54		if(c.watchPosition == 'auto' && c.windowResizeAdjust == 'auto'){
55			c.watchPosition = false;
56		}
57		else
58		if(c.watchPosition == true && c.windowResizeAdjust == 'auto'){
59			c.windowResizeAdjust = false;
60		}
61
62		c.target.css({
63			position : 'fixed'
64		});
65		o._makeCloneBox(c.target);
66		o.adjustPosition();
67
68		c._win.scroll(function(){
69			o.adjustScrollPosition();
70		});
71
72		if(c.windowResizeAdjust){
73			c._win.resize(function(){
74				o.adjustPosition();
75			});
76		}
77
78		if(c.windowResizeAdjust){
79			c._win.resize(function(){
80				if(c._resizeTimer) clearTimeout(c._resizeTimer);
81				c._resizeTimer = setTimeout(function(){
82					o.adjustPosition();
83				},c.windowResizeDelay);
84			});
85		}
86
87		if(c.watchPosition){
88			var watch = function(){
89				setTimeout(function(){
90					o.adjustPosition();
91					c.watchCallback.call(o,o);
92					watch();
93				},c.watchDelay);
94			}
95			watch();
96		}
97
98	}
99	$.extend($.ex.flexFixed.prototype, {
100		_getMarginHeight : function(target){
101			var o = this, c = o.config;
102			return target.outerHeight() +
103				+ (parseInt(target.css('margin-top'))||0)
104				+ (parseInt(target.css('margin-bottom'))||0)
105			;
106		},
107		_adjustCloneSize : function(target){
108			var o = this, c = o.config;
109			c.cloneBox.css({
110				height : target.outerHeight(),
111				'margin-top' : parseInt(target.css('margin-top'))||0,
112				'margin-bottom' : parseInt(target.css('margin-bottom'))||0,
113				'margin-left' : parseInt(target.css('margin-left'))||0,
114				'margin-right' : parseInt(target.css('margin-right'))||0,
115				'padding-left' : (parseInt(target.css('border-left-width'))||0) + (parseInt(target.css('padding-left'))||0),
116				'padding-right' : (parseInt(target.css('border-right-width'))||0) + (parseInt(target.css('padding-right'))||0)
117			});
118		},
119		_makeCloneBox : function(target){
120			var o = this, c = o.config;
121			c.cloneBox = $('<div/>');
122			target.before(c.cloneBox);
123			o._adjustCloneSize(target);
124 		},
125		adjustPosition : function(){
126			var o = this, c = o.config;
127			c.containerOffset = c.container.offset();
128			if(c.width != 'auto'){
129				if(c.cloneBox.width() != c.width){
130					c.cloneBox.width(c.width);
131				}
132			}
133			c.target.css({
134				width : c.cloneBox.width()
135			});
136			o._adjustCloneSize(c.target);
137			c._fixedOffset = c.cloneBox.offset();
138			o.adjustScrollPosition();
139		},
140		adjustScrollPosition : function(){
141			var o = this, c = o.config;
142			var targetTotalHeight = c.target.outerHeight() + c._orgMarginTop + c._orgMarginBottom;
143			var winMinuseTargetGapHeight = c._win.height() - targetTotalHeight;
144			var top = c._fixedOffset.top - c._orgMarginTop - c._win.scrollTop()
145			c._nowFixed = false;
146
147
148			if(top - c.fixedHeaderHeight < 0){
149				if(!c._fromTop)	top = 0;
150				if(top - c.fixedHeaderHeight < winMinuseTargetGapHeight){
151					c._nowFixed = true;
152					if(winMinuseTargetGapHeight > 0){
153						top = c.fixedHeaderHeight;
154					}
155					else {
156						top = winMinuseTargetGapHeight;
157					}
158				}
159			}
160			else {
161				c._fromTop = true;
162			}
163			var containerBottom = c.containerOffset.top + c.container.outerHeight() - c._win.scrollTop();
164			var targetBottom = top + c.target.outerHeight() + c._orgMarginTop + c._orgMarginBottom;
165			var overBottom = targetBottom - containerBottom;
166			if(overBottom > 0){
167				c._nowFixed = false;
168				c._fromTop = false;
169				top = top - overBottom;
170			}
171			c.target.css({
172				top : top,
173				left : c._fixedOffset.left - c._win.scrollLeft() - c._orgMarginLeft
174			});
175
176		}
177	});
178	$.ex.flexFixed.defaults = {
179		api : false,
180		watchPosition : 'auto',
181		watchDelay : 500,
182		watchCallback : function(api){},
183		container : null,
184		fixedHeader : null,
185		zIndex : null,
186		width : 'auto',
187		windowResizeAdjust : 'auto',
188		windowResizeDelay : 100
189	}
190	$.fn.exFlexFixed = function(option){
191		var targets = this,api = [];
192		targets.each(function(idx) {
193			var target = targets.eq(idx);
194			var obj = target.data('ex-flex-fixed') || new $.ex.flexFixed( idx , targets , option);
195			api.push(obj);
196			target.data('ex-flex-fixed',obj);
197		});
198		return option && option.api ? API(api) : targets;
199	}
200	$.ex.flexFixed.version = '0.3.0';
201})(jQuery);
202

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.