1/* 2* jQuery.splitter.js - two-pane splitter window plugin 3* 4* version 1.51 (2009/01/09) 5* 6* Dual licensed under the MIT and GPL licenses: 7* http://www.opensource.org/licenses/mit-license.php 8* http://www.gnu.org/licenses/gpl.html 9*/ 10 11/** 12* The splitter() plugin implements a two-pane resizable splitter window. 13* The selected elements in the jQuery object are converted to a splitter; 14* each selected element should have two child elements, used for the panes 15* of the splitter. The plugin adds a third child element for the splitbar. 16* 17* For more details see: http://methvin.com/splitter/ 18* 19* 20* @example $('#MySplitter').splitter(); 21* @desc Create a vertical splitter with default settings 22* 23* @example $('#MySplitter').splitter({type: 'h', accessKey: 'M'}); 24* @desc Create a horizontal splitter resizable via Alt+Shift+M 25* 26* @name splitter 27* @type jQuery 28* @param Object options Options for the splitter (not required) 29* @cat Plugins/Splitter 30* @return jQuery 31* @author Dave Methvin ([email protected]) 32*/ 33;(function($){ 34 35$.fn.splitter = function(args){ 36 args = args || {}; 37 return this.each(function() { 38 var zombie; // left-behind splitbar for outline resizes 39 function startSplitMouse(evt) { 40 if ( opts.outline ) 41 zombie = zombie || bar.clone(false).insertAfter(A); 42 panes.css("-webkit-user-select", "none"); // Safari selects A/B text on a move 43 bar.addClass(opts.activeClass); 44 $('<div class="splitterMask"></div>').insertAfter(bar); 45 A._posSplit = A[0][opts.pxSplit] - evt[opts.eventPos]; 46 $(document) 47 .bind("mousemove", doSplitMouse) 48 .bind("mouseup", endSplitMouse); 49 } 50 function doSplitMouse(evt) { 51 var newPos = A._posSplit+evt[opts.eventPos]; 52 if ( opts.outline ) { 53 newPos = Math.max(0, Math.min(newPos, splitter._DA - bar._DA)); 54 bar.css(opts.origin, newPos); 55 } else 56 resplit(newPos); 57 } 58 function endSplitMouse(evt) { 59 $('div.splitterMask').remove(); 60 bar.removeClass(opts.activeClass); 61 var newPos = A._posSplit+evt[opts.eventPos]; 62 if ( opts.outline ) { 63 zombie.remove(); zombie = null; 64 resplit(newPos); 65 } 66 panes.css("-webkit-user-select", "text"); // let Safari select text again 67 $(document) 68 .unbind("mousemove", doSplitMouse) 69 .unbind("mouseup", endSplitMouse); 70 } 71 function resplit(newPos) {
72 // Constrain new splitbar position to fit pane size limits 73 newPos = Math.max(A._min, splitter._DA - B._max, 74 Math.min(newPos, A._max, splitter._DA - bar._DA - B._min)); 75 // Resize/position the two panes 76 bar._DA = bar[0][opts.pxSplit]; // bar size may change during dock 77 78 var posOffset = bar.is(':visible') ? bar._DA - 1 : 0; 79 80 bar.css(opts.origin, newPos - posOffset).css(opts.fixed, splitter._DF); 81 A.css(opts.origin, 0).css(opts.split, newPos).css(opts.fixed, splitter._DF); 82 B.css(opts.origin, newPos + bar._DA - posOffset) 83 .css(opts.split, splitter._DA-bar._DA-newPos).css(opts.fixed, splitter._DF); 84 // IE fires resize for us; all others pay cash 85 if ( !IE_10_AND_BELOW ) 86 panes.trigger("resize"); 87 } 88 function dimSum(jq, dims) { 89 // Opera returns -1 for missing min/max width, turn into 0 90 var sum = 0; 91 for ( var i=1; i < arguments.length; i++ ) 92 sum += Math.max(parseInt(jq.css(arguments[i])) || 0, 0); 93 return sum; 94 } 95 96 // Determine settings based on incoming opts, element classes, and defaults 97 var vh = (args.splitHorizontal? 'h' : args.splitVertical? 'v' : args.type) || 'v'; 98 var opts = $.extend({ 99 activeClass: 'active', // class name for active splitter 100 pxPerKey: 8, // splitter px moved per keypress 101 tabIndex: 0, // tab order indicator 102 accessKey: '' // accessKey for splitbar 103 },{ 104 v: { // Vertical splitters: 105 keyLeft: 39, keyRight: 37, cursor: "col-resize", 106 splitbarClass: "vsplitbar", outlineClass: "voutline", 107 type: 'v', eventPos: "pageX", origin: "left",
108 split: "width", pxSplit: "offsetWidth", side1: "Left", side2: "Right", 109 fixed: "height", pxFixed: "offsetHeight", side3: "Top", side4: "Bottom" 110 }, 111 h: { // Horizontal splitters: 112 keyTop: 40, keyBottom: 38, cursor: "row-resize", 113 splitbarClass: "hsplitbar", outlineClass: "houtline", 114 type: 'h', eventPos: "pageY", origin: "top", 115 split: "height", pxSplit: "offsetHeight", side1: "Top", side2: "Bottom", 116 fixed: "width", pxFixed: "offsetWidth", side3: "Left", side4: "Right" 117 } 118 }[vh], args); 119 120 // Create jQuery object closures for splitter and both panes 121 var splitter = $(this).css({position: "relative"}); 122 var panes = $(">*", splitter[0]).css({ 123 position: "absolute", // positioned inside splitter container 124 "z-index": "1", // splitbar is positioned above 125 "-moz-outline-style": "none" // don't show dotted outline 126 }); 127 var A = $(panes[0]); // left or top 128 var B = $(panes[1]); // right or bottom 129 130 // Focuser element, provides keyboard support; title is shown by Opera accessKeys 131 var focuser = $('<a href="javascript:void(0)"></a>') 132 .attr({accessKey: opts.accessKey, tabIndex: opts.tabIndex, title: opts.splitbarClass}) 133 .bind($.browser.opera?"click":"focus", function(){ this.focus(); bar.addClass(opts.activeClass) }) 134 .bind("keydown", function(e){ 135 var key = e.which || e.keyCode; 136 var dir = key==opts["key"+opts.side1]? 1 : key==opts["key"+opts.side2]? -1 : 0; 137 if ( dir ) 138 resplit(A[0][opts.pxSplit]+dir*opts.pxPerKey, false); 139 }) 140 .bind("blur", function(){ bar.removeClass(opts.activeClass) }); 141 142 // Splitbar element, can be already in the doc or we create one 143 var bar = $(panes[2] || '<div></div>') 144 .insertAfter(A).css("z-index", "100").append(focuser) 145 .attr({"class": opts.splitbarClass, unselectable: "on"}) 146 .css({position: "absolute", "user-select": "none", "-webkit-user-select": "none", 147 "-khtml-user-select": "none", "-moz-user-select": "none", "top": "0px"}) 148 .bind("mousedown", startSplitMouse); 149 // Use our cursor unless the style specifies a non-default cursor 150 if ( /^(auto|default|)$/.test(bar.css("cursor")) ) 151 bar.css("cursor", opts.cursor); 152 153 // Cache several dimensions for speed, rather than re-querying constantly 154 bar._DA = bar[0][opts.pxSplit]; 155 splitter._PBF = $.boxModel? dimSum(splitter, "border"+opts.side3+"Width", "border"+opts.side4+"Width") : 0; 156 splitter._PBA = $.boxModel? dimSum(splitter, "border"+opts.side1+"Width", "border"+opts.side2+"Width") : 0; 157 A._pane = opts.side1; 158 B._pane = opts.side2; 159 $.each([A,B], function(){ 160 this._min = opts["min"+this._pane] || dimSum(this, "min-"+opts.split); 161 this._max = opts["max"+this._pane] || dimSum(this, "max-"+opts.split) || 9999; 162 this._init = opts["size"+this._pane]===true ? 163 parseInt($.curCSS(this[0],opts.split)) : opts["size"+this._pane]; 164 }); 165 166 // Determine initial position, get from cookie if specified 167 var initPos = A._init; 168 if ( !isNaN(B._init) ) // recalc initial B size as an offset from the top or left side 169 initPos = splitter[0][opts.pxSplit] - splitter._PBA - B._init - bar._DA; 170 if ( opts.cookie ) { 171 if ( !$.cookie ) 172 alert('jQuery.splitter(): jQuery cookie plugin required'); 173 var ckpos = parseInt($.cookie(opts.cookie)); 174 if ( !isNaN(ckpos) ) 175 initPos = ckpos; 176 $(window).bind("unload", function(){ 177 var state = String(bar.css(opts.origin)); // current location of splitbar 178 $.cookie(opts.cookie, state, {expires: opts.cookieExpires || 365, 179 path: opts.cookiePath || document.location.pathname}); 180 }); 181 } 182 if ( isNaN(initPos) ) // King Solomon's algorithm
183 initPos = Math.round((splitter[0][opts.pxSplit] - splitter._PBA - bar._DA)/2); 184 185 // Resize event propagation and splitter sizing 186 if ( opts.anchorToWindow ) { 187 // Account for margin or border on the splitter container and enforce min height 188 splitter._hadjust = dimSum(splitter, "borderTopWidth", "borderBottomWidth", "marginBottom"); 189 splitter._hmin = Math.max(dimSum(splitter, "minHeight"), 20); 190 $(window).bind("resize", function(){ 191 var top = splitter.offset().top; 192 var wh = $(window).height(); 193 splitter.css("height", Math.max(wh-top-splitter._hadjust, splitter._hmin)+"px"); 194 if ( !IE_10_AND_BELOW ) splitter.trigger("resize"); 195 }).trigger("resize"); 196 } 197 else if ( opts.resizeToWidth && !IE_10_AND_BELOW ) 198 $(window).bind("resize", function(){ 199 splitter.trigger("resize"); 200 }); 201 202 // Resize event handler; triggered immediately to set initial position 203 splitter.bind("resize", function(e, size){ 204 // Custom events bubble in jQuery 1.3; don't Yo Dawg 205 if ( e.target != this ) return; 206 // Determine new width/height of splitter container 207 splitter._DF = splitter[0][opts.pxFixed] - splitter._PBF; 208 splitter._DA = splitter[0][opts.pxSplit] - splitter._PBA; 209 // Bail if splitter isn't visible or content isn't there yet 210 if ( splitter._DF <= 0 || splitter._DA <= 0 ) return; 211 // Re-divvy the adjustable dimension; maintain size of the preferred pane 212 resplit(!isNaN(size)? size : (!(opts.sizeRight||opts.sizeBottom)? A[0][opts.pxSplit] : 213 splitter._DA-B[0][opts.pxSplit]-bar._DA)); 214 }).trigger("resize" , [initPos]); 215 }); 216}; 217 218})(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.