Skip to content

Commit

Permalink
"collapsible" property can now also be "0" which works the same as wh…
Browse files Browse the repository at this point in the history
…en set to FALSE except that all tabs can be collapsed
  • Loading branch information
stefangabos committed Oct 13, 2017
1 parent 5cd4ed9 commit 6fc3ed9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -148,10 +148,10 @@ $(document).ready(function() {
</tr> </tr>
<tr> <tr>
<td valign="top"><code>collapsible</code></td> <td valign="top"><code>collapsible</code></td>
<td valign="top"><em>boolean</em></td> <td valign="top"><em>mixed</em></td>
<td valign="top">FALSE</td> <td valign="top">FALSE</td>
<td valign="top"> <td valign="top">
When set to TRUE it indicates that all tabs can be collapsed; if set to FALSE, an expanded tab can be collapsed only by expanding another tab. - when set to <code>TRUE</code> it indicates that all tabs can be collapsed<br>- if set to <code>FALSE</code>, an expanded tab can be collapsed only by expanding another tab<br>- if set to <code>0</code>, the behavior is the same when set to <code>FALSE</code> with the difference that an open tab can also be closed.
</td> </td>
</tr> </tr>
<tr> <tr>
Expand Down Expand Up @@ -194,17 +194,17 @@ $(document).ready(function() {
<td valign="top">0</td> <td valign="top">0</td>
<td valign="top"> <td valign="top">
The index (0 based) of the tab to be expanded by default.<br> The index (0 based) of the tab to be expanded by default.<br>
The value of this property can also be boolean FALSE, indicating that all tabs should be collapsed by default.<br> The value of this property can also be boolean <code>FALSE</code>, indicating that all tabs should be collapsed by default.<br>
If the value of the <strong>collapsible</strong> property is TRUE, the value of this property can also be boolean TRUE, indicating that all tabs should be expanded by default. In this case, you can also provide <em>an array</em> of indexes to be expanded by default. If the value of the <strong>collapsible</strong> property is <code>TRUE</code>, the value of this property can also be boolean <code>TRUE</code>, indicating that all tabs should be expanded by default. In this case, you can also provide <em>an array</em> of indexes to be expanded by default.
</td> </td>
</tr> </tr>
<tr> <tr>
<td valign="top"><code>toggle_on_mouseover</code></td> <td valign="top"><code>toggle_on_mouseover</code></td>
<td valign="top"><em>boolean</em></td> <td valign="top"><em>boolean</em></td>
<td valign="top">FALSE</td> <td valign="top">FALSE</td>
<td valign="top"> <td valign="top">
Set this to TRUE if tabs should be expanded when hovering the mouse over their associated <em>titles</em>.<br><br> Set this to <code>TRUE</code> if tabs should be expanded when hovering the mouse over their associated <em>titles</em>.<br><br>
<blockquote>If the <strong>collapsible</strong> property is TRUE, this property will always be considered as FALSE!</blockquote> <blockquote>If the <strong>collapsible</strong> property is <code>TRUE</code>, this property will always be considered as <code>FALSE</code>!</blockquote>
</td> </td>
</tr> </tr>
</tbody> </tbody>
Expand Down
2 changes: 1 addition & 1 deletion dist/zebra_accordion.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 deletions dist/zebra_accordion.src.js
Expand Up @@ -21,7 +21,7 @@
* Read more {@link https://github.com/stefangabos/Zebra_Accordion/ here} * Read more {@link https://github.com/stefangabos/Zebra_Accordion/ here}
* *
* @author Stefan Gabos <contact@stefangabos.ro> * @author Stefan Gabos <contact@stefangabos.ro>
* @version 1.2.8 (last revision: September 16, 2017) * @version 1.2.8 (last revision: October 13, 2017)
* @copyright (c) 2011 - 2017 Stefan Gabos * @copyright (c) 2011 - 2017 Stefan Gabos
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE
* @package Zebra_Accordion * @package Zebra_Accordion
Expand All @@ -39,10 +39,13 @@
// Default is TRUE // Default is TRUE


collapsible: false, // If set to TRUE, an open block can also be collapsed collapsible: false, // If set to TRUE, an open block can also be collapsed
// - in this case, all blocks can be collapsed; if set // - in this case, all blocks can be collapsed;
// to FALSE, an open block can be collapsed only by // if set to FALSE, an open block can be collapsed
// opening another block - in this case, only a single // only by opening another block - in this case, only
// block is open at any given moment; // a single block is open at any given moment;
// if set to 0, the behavior is the same when set to
// FALSE with the difference that an open tab can
// also be closed.
// //
// Default is FALSE // Default is FALSE


Expand Down Expand Up @@ -377,7 +380,8 @@


var block = blocks[index], // get the block's properties var block = blocks[index], // get the block's properties
$title = titles[index].element, // reference to the title element $title = titles[index].element, // reference to the title element
$block = block.element; // reference to the tab element $block = block.element, // reference to the tab element
collapsed_all = false;


// if any number of blocks can can be expanded/collapsed // if any number of blocks can can be expanded/collapsed
// and current block is already expanded, collapse it instead // and current block is already expanded, collapse it instead
Expand All @@ -389,8 +393,11 @@
// iterate through the tabs // iterate through the tabs
$titles.each(function(key) { $titles.each(function(key) {


// if we found an expanded tab but it is not the one we're trying to expand // if we found an expanded tab but it is not the one we're trying to expand or we're closing an opened tab when plugin.settings.collapsible === 0
if (titles[key].element.hasClass(plugin.settings.expanded_class) && key !== index) { if (titles[key].element.hasClass(plugin.settings.expanded_class) && (key !== index || plugin.settings.collapsible === 0)) {

// if we just collapsed all tabs when plugin.settings.collapsible === 0, set a flag
if (key === index && plugin.settings.collapsible === 0) collapsed_all = true;


// collapse it // collapse it
plugin.hide(key, noFx); plugin.hide(key, noFx);
Expand All @@ -402,6 +409,9 @@


}); });


// if we just collapsed all tabs when plugin.settings.collapsible === 0, don't go further
if (collapsed_all) return false;

// if a callback function needs to be called before expanding the tab // if a callback function needs to be called before expanding the tab
if (plugin.settings.onBeforeOpen && typeof plugin.settings.onBeforeOpen === 'function') if (plugin.settings.onBeforeOpen && typeof plugin.settings.onBeforeOpen === 'function')


Expand Down
26 changes: 18 additions & 8 deletions src/zebra_accordion.src.js
Expand Up @@ -21,7 +21,7 @@
* Read more {@link https://github.com/stefangabos/Zebra_Accordion/ here} * Read more {@link https://github.com/stefangabos/Zebra_Accordion/ here}
* *
* @author Stefan Gabos <contact@stefangabos.ro> * @author Stefan Gabos <contact@stefangabos.ro>
* @version 1.2.8 (last revision: September 16, 2017) * @version 1.2.8 (last revision: October 13, 2017)
* @copyright (c) 2011 - 2017 Stefan Gabos * @copyright (c) 2011 - 2017 Stefan Gabos
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE
* @package Zebra_Accordion * @package Zebra_Accordion
Expand All @@ -39,10 +39,13 @@
// Default is TRUE // Default is TRUE


collapsible: false, // If set to TRUE, an open block can also be collapsed collapsible: false, // If set to TRUE, an open block can also be collapsed
// - in this case, all blocks can be collapsed; if set // - in this case, all blocks can be collapsed;
// to FALSE, an open block can be collapsed only by // if set to FALSE, an open block can be collapsed
// opening another block - in this case, only a single // only by opening another block - in this case, only
// block is open at any given moment; // a single block is open at any given moment;
// if set to 0, the behavior is the same when set to
// FALSE with the difference that an open tab can
// also be closed.
// //
// Default is FALSE // Default is FALSE


Expand Down Expand Up @@ -377,7 +380,8 @@


var block = blocks[index], // get the block's properties var block = blocks[index], // get the block's properties
$title = titles[index].element, // reference to the title element $title = titles[index].element, // reference to the title element
$block = block.element; // reference to the tab element $block = block.element, // reference to the tab element
collapsed_all = false;


// if any number of blocks can can be expanded/collapsed // if any number of blocks can can be expanded/collapsed
// and current block is already expanded, collapse it instead // and current block is already expanded, collapse it instead
Expand All @@ -389,8 +393,11 @@
// iterate through the tabs // iterate through the tabs
$titles.each(function(key) { $titles.each(function(key) {


// if we found an expanded tab but it is not the one we're trying to expand // if we found an expanded tab but it is not the one we're trying to expand or we're closing an opened tab when plugin.settings.collapsible === 0
if (titles[key].element.hasClass(plugin.settings.expanded_class) && key !== index) { if (titles[key].element.hasClass(plugin.settings.expanded_class) && (key !== index || plugin.settings.collapsible === 0)) {

// if we just collapsed all tabs when plugin.settings.collapsible === 0, set a flag
if (key === index && plugin.settings.collapsible === 0) collapsed_all = true;


// collapse it // collapse it
plugin.hide(key, noFx); plugin.hide(key, noFx);
Expand All @@ -402,6 +409,9 @@


}); });


// if we just collapsed all tabs when plugin.settings.collapsible === 0, don't go further
if (collapsed_all) return false;

// if a callback function needs to be called before expanding the tab // if a callback function needs to be called before expanding the tab
if (plugin.settings.onBeforeOpen && typeof plugin.settings.onBeforeOpen === 'function') if (plugin.settings.onBeforeOpen && typeof plugin.settings.onBeforeOpen === 'function')


Expand Down

0 comments on commit 6fc3ed9

Please sign in to comment.