1 /* 2 * JBoss, Home of Professional Open Source 3 * Copyright ${year}, Red Hat, Inc. and individual contributors 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 23 (function ($, rf) { 24 25 rf.ui = rf.ui || {}; 26 27 rf.ui.AccordionItem = rf.ui.TogglePanelItem.extendClass({ 28 // class name 29 name:"AccordionItem", 30 31 /** 32 * @class AccordionItem 33 * @name AccordionItem 34 * 35 * @constructor 36 * @param {String} componentId - component id 37 * @param {Hash} options - params 38 * */ 39 init : function (componentId, options) { 40 $super.constructor.call(this, componentId, options); 41 42 if (!this.disabled) { 43 rf.Event.bindById(this.id + ":header", "click", this.__onHeaderClick, this); 44 } 45 46 if (this.isSelected()) { 47 var item = this; 48 $(document).one("javascriptServiceComplete", function () { 49 item.__fitToHeight(item.getTogglePanel()); 50 }); 51 } 52 }, 53 54 /***************************** Public Methods ****************************************************************/ 55 56 __onHeaderClick : function (comp) { 57 this.getTogglePanel().switchToItem(this.getName()); 58 }, 59 60 /** 61 * @return {jQuery Object} 62 * */ 63 __header : function () { 64 return $(rf.getDomElement(this.id + ":header")); 65 }, 66 67 /** 68 * @return {jQuery Object} 69 * */ 70 __content : function () { 71 if (!this.__content_) { 72 this.__content_ = $(rf.getDomElement(this.id + ":content")); 73 } 74 return this.__content_; 75 }, 76 77 /** 78 * @private 79 * 80 * used in TogglePanel 81 * */ 82 __enter : function () { 83 var parentPanel = this.getTogglePanel(); 84 if (parentPanel.isKeepHeight) { 85 this.__content().hide(); // TODO ? 86 this.__fitToHeight(parentPanel); 87 } 88 89 this.__content().show(); 90 this.__header().addClass("rf-ac-itm-hdr-act").removeClass("rf-ac-itm-hdr-inact"); 91 92 return this.__fireEnter(); 93 }, 94 95 __fitToHeight : function (parentPanel) { 96 var h = parentPanel.getInnerHeight(); 97 98 var items = parentPanel.getItems(); 99 for (var i in items) { 100 h -= items[i].__header().outerHeight(); 101 } 102 103 this.__content().height(h - 20); // 20 it is padding top and bottom 104 }, 105 106 getHeight : function (recalculate) { 107 if (recalculate || !this.__height) { 108 this.__height = $(rf.getDomElement(this.id)).outerHeight(true) 109 } 110 111 return this.__height; 112 }, 113 114 /** 115 * @private 116 * 117 * used in TogglePanel 118 * */ 119 __leave : function () { 120 var continueProcess = this.__fireLeave(); 121 if (!continueProcess) { 122 return false; 123 } 124 125 this.__content().hide(); 126 this.__header().removeClass("rf-ac-itm-hdr-act").addClass("rf-ac-itm-hdr-inact"); 127 128 return true; 129 } 130 }); 131 132 // define super class link 133 var $super = rf.ui.AccordionItem.$super; 134 })(RichFaces.jQuery, RichFaces); 135