1// SpryPanelSelector.js - version 0.6 - Spry Pre-Release 1.7 2// 3// Copyright (c) 2009. Adobe Systems Incorporated. 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are met: 8// 9// * Redistributions of source code must retain the above copyright notice, 10// this list of conditions and the following disclaimer. 11// * Redistributions in binary form must reproduce the above copyright notice, 12// this list of conditions and the following disclaimer in the documentation 13// and/or other materials provided with the distribution. 14// * Neither the name of Adobe Systems Incorporated nor the names of its 15// contributors may be used to endorse or promote products derived from this 16// software without specific prior written permission. 17// 18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28// POSSIBILITY OF SUCH DAMAGE. 29 30(function() { // BeginSpryComponent 31 32if (typeof Spry == "undefined" || !Spry.Widget || !Spry.Widget.Base) 33{ 34 alert("SpryPanelSelector.js requires SpryWidget.js!"); 35 return; 36} 37 38Spry.Widget.PanelSelector = function(elements, panel, opts) 39{ 40 Spry.Widget.Base.call(this); 41 42 this.buttons = Spry.$$(elements); 43 this.panel = panel; 44 this.disablePanelCallbacks = 0; 45 this.currentButton = null; 46 47 // Initialize the accordion object with the global defaults. 48 49 this.setOptions(this, Spry.Widget.PanelSelector.config); 50 51 // Override the defaults with any options passed into the constructor. 52 53 this.setOptions(this, opts); 54 55 if (typeof (this.defaultButton) == "number") 56 { 57 if (this.defaultButton < 0) 58 this.defaultButton = 0; 59 else 60 { 61 var count = this.getButtonCount(); 62 if (this.defaultButton >= count) 63 this.defaultButton = (count > 1) ? (count - 1) : 0; 64 } 65 66 } 67 this.attachBehaviors(); 68}; 69 70Spry.Widget.PanelSelector.config = { 71 event: "click", 72 defaultButton: 0, 73 selectionStopsSlideShow: true, 74 useHrefs: false, 75 selectedClass: "PanelSelectorButtonSelected", 76 unselectedClass: "PanelSelectorButtonUnselected", 77 downClass: "PanelSelectorButtonDown", 78 disabledClass: "PanelSelectorButtonDisabled", 79 hoverClass: "PanelSelectorButtonHover", 80 focusedClass: "PanelSelectorButtonFocused" 81}; 82 83Spry.Widget.PanelSelector.prototype = new Spry.Widget.Base(); 84Spry.Widget.PanelSelector.prototype.constructor = Spry.Widget.PanelSelector; 85 86Spry.Widget.PanelSelector.prototype.getPanelIDFromHREF = function(ele) 87{ 88 if (ele) 89 { 90 var href = ele.getAttribute("href"); 91 if (href != undefined && href.search(/^#\w/) != -1) 92 return href.replace(/.*#/, "#"); 93 } 94 return null; 95}; 96 97Spry.Widget.PanelSelector.prototype.getButtonCount = function() 98{ 99 return this.buttons.length; 100}; 101 102 103Spry.Widget.PanelSelector.prototype.getCurrentButton = function() 104{ 105 return this.currentButton; 106}; 107 108Spry.Widget.PanelSelector.prototype.getCurrentButtonIndex = function() 109{ 110 return this.elementToIndex(this.getCurrentButton()); 111}; 112 113 114Spry.Widget.PanelSelector.prototype.elementToIndex = function(ele) 115{ 116 var ea = this.buttons; 117 var n = ea.length; 118 for (var i = 0; i < n; i++) 119 if (ea[i] == ele) return i; 120 return -1; 121}; 122 123Spry.Widget.PanelSelector.prototype.indexToElement = function(eleOrIndex) 124{ 125 return (typeof eleOrIndex == "number") ? this.buttons[eleOrIndex] : eleOrIndex; 126};
127 128 129Spry.Widget.PanelSelector.prototype.enableButton = function(eleOrIndex) 130{ 131 var ele = this.indexToElement(eleOrIndex); 132 if (ele && ele.psButton) 133 ele.psButton.enable(); 134}; 135 136 137Spry.Widget.PanelSelector.prototype.disableButton = function(eleOrIndex) 138{ 139 var ele = this.indexToElement(eleOrIndex); 140 if (ele && ele.psButton) 141 ele.psButton.disable(); 142}; 143 144Spry.Widget.PanelSelector.prototype.focusButton = function(eleOrIndex) 145{ 146 var ele = this.indexToElement(eleOrIndex); 147 if (ele && ele.psButton) 148 ele.psButton.focus(); 149}; 150 151Spry.Widget.PanelSelector.prototype.selectButton = function(eleOrIndex, suppressPanelSync) 152{ 153 ++this.disablePanelCallbacks; 154 155 var buttons = this.buttons; 156 var ele = this.indexToElement(eleOrIndex); 157 158 for (var i = 0; i < buttons.length; i++) 159 { 160 var e = buttons[i]; 161 this.removeClassName(e, (e == ele) ? this.unselectedClass : this.selectedClass); 162 this.addClassName(e, (e == ele) ? this.selectedClass : this.unselectedClass); 163 } 164 165 this.currentButton = ele; 166 167 if (!suppressPanelSync && this.panel) 168 { 169 var href = this.useHrefs ? this.getPanelIDFromHREF(ele) : null; 170 this.panel.showPanel(href ? href : this.elementToIndex(ele)); 171 } 172 173 --this.disablePanelCallbacks; 174}; 175 176Spry.Widget.PanelSelector.prototype.selectPreviousButton = function() 177{ 178 var evt = new Spry.Widget.Event(this); 179 this.notifyObservers("onPrePanelSelectorSelectPreviousButton", evt); 180 if (!evt.performDefaultAction) 181 return; 182 183 var curIndex = this.getCurrentButtonIndex(); 184 this.handleActivate(((curIndex < 1) ? this.getButtonCount() : curIndex) - 1); 185 186 this.notifyObservers("onPostPanelSelectorSelectPreviousButton", evt); 187}; 188 189Spry.Widget.PanelSelector.prototype.selectNextButton = function() 190{ 191 var evt = new Spry.Widget.Event(this); 192 this.notifyObservers("onPrePanelSelectorSelectNextButton", evt); 193 if (!evt.performDefaultAction) 194 return; 195 196 this.handleActivate((this.getCurrentButtonIndex()+1) % this.getButtonCount()); 197 198 this.notifyObservers("onPostPanelSelectorSelectNextButton", evt); 199}; 200 201Spry.Widget.PanelSelector.prototype.selectFirstButton = function() 202{ 203 var evt = new Spry.Widget.Event(this); 204 this.notifyObservers("onPrePanelSelectorSelectFirstButton", evt); 205 if (!evt.performDefaultAction) 206 return; 207 208 this.handleActivate(0); 209 210 this.notifyObservers("onPostPanelSelectorSelectFirstButton", evt); 211}; 212 213Spry.Widget.PanelSelector.prototype.selectLastButton = function() 214{ 215 var evt = new Spry.Widget.Event(this); 216 this.notifyObservers("onPrePanelSelectorSelectLastButton", evt); 217 if (!evt.performDefaultAction) 218 return; 219 220 var count = this.getButtonCount(); 221 this.handleActivate(count > 0 ? count - 1 : 0); 222 223 this.notifyObservers("onPostPanelSelectorSelectLastButton", evt); 224}; 225 226Spry.Widget.PanelSelector.prototype.handleActivate = function(ele) 227{ 228 if (typeof ele == "string") 229 ele = document.getElementById(ele); 230 231 var evt = new Spry.Widget.Event(this, { target: ele, targetIndex: this.elementToIndex(ele) }); 232 this.notifyObservers("onPrePanelSelectorClick", evt); 233 if (!evt.performDefaultAction) 234 return; 235 236 if (this.selectionStopsSlideShow && this.panel) 237 this.panel.stop(); 238 239 this.selectButton(ele); 240 241 this.notifyObservers("onPostPanelSelectorClick", evt); 242}; 243 244Spry.Widget.PanelSelector.prototype.handlePanelChange = function(data) 245{ 246 if (this.disablePanelCallbacks) 247 return; 248 249 var panelEle = data.target; 250 var panelIndex = data.targetIndex; 251 252 if (!this.panel) 253 return; 254 255 var panelID = panelEle.id; 256 var btns = this.buttons; 257 var btn = btns[panelIndex]; 258 259 if (panelID) 260 { 261 // Search for the button to activate based on 262 // the panel's id. 263 264 for (var i = 0; !btn && i < btns.length; i++) 265 { 266 var b = btns[i]; 267 var id = this.getPanelIDFromHREF(b); 268 if (id == panelID) 269 { 270 btn = b; 271 break; 272 } 273 } 274 } 275 276 if (btn) 277 this.selectButton(btn, true); 278}; 279 280Spry.Widget.PanelSelector.prototype.attachButtonBehaviors = function(ele) 281{ 282 var self = this; 283 284 var activateFunc = function(e) { self.handleActivate(ele); return false; }; 285 286 ele.psButton = new Spry.Widget.Button(ele, { 287 onclick: activateFunc, 288 downClass: this.downClass, 289 hoverClass: this.hoverClass, 290 disabledClass: this.disabledClass, 291 focusedClass: this.focusedClass 292 }); 293 294 if (this.event != "click") 295 this.addEventListener(ele, this.event, activateFunc, false); 296};
297 298Spry.Widget.PanelSelector.prototype.attachBehaviors = function() 299{ 300 var self = this; 301 var buttons = this.buttons; 302 303 for (var i = 0; i < buttons.length; i++) 304 this.attachButtonBehaviors(buttons[i]); 305 306 if (this.panel) 307 this.panel.addObserver({ onPostShowPanel: function(n, data){ self.handlePanelChange(data); }}); 308 309 this.selectButton(this.defaultButton); 310}; 311 312})(); // EndSpryComponent
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.