Skip to content

Commit

Permalink
- fixed JS error when called on empty jQuery object with `collapsable…
Browse files Browse the repository at this point in the history
…All: false` set - fixes #7

- items are properly collapsed on initialization when combination of `collapsableAll` and `accordion` is used - fixes #8
  • Loading branch information
zipper committed Apr 16, 2016
1 parent 46f9909 commit def0682
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Please see the plugin site http://zipper.github.io/jquery.collapsable/

## Changelog

### 2.0.3
- fixed JS error when called on empty jQuery object with `collapsableAll: false` set - fixes #7
- items are properly collapsed on initialization when combination of `collapsableAll` and `accordion` is used - fixes #8

### 2.0.2
- renamed property ~~`originalEvent`~~ to `collapsableEvent`, so `preventDefault` called on `expand.collapsable`/`collapse.collapsable` event doesn't prevent that custom event as well

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquery.collapsable",
"description": "jQuery plugin for collapsable boxes",
"version": "2.0.2",
"version": "2.0.3",
"main": "dist/jquery.collapsable.js",
"authors": [ "Radek Šerý <radek.sery@gmail.com>" ],
"homepage": "http://zipper.github.io/jquery.collapsable/",
Expand Down
18 changes: 18 additions & 0 deletions dist/ie8-compat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
if (! Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/) {
var len = this.length >>> 0;

var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;

for (; from < len; from++) {
if (from in this && this[from] === elt)
return from;
}
return -1;
};
}
16 changes: 11 additions & 5 deletions dist/jquery.collapsable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
* @copyright Copyright (c) 2014-2016 Radek Šerý
* @license MIT
*
* @version 2.0.2
* @version 2.0.3
*/
;(function($) {

// @feature: díky předávání collapsableEvent do expand.collapsable (atd.) je možné použít e.collapsableEvent.preventDefault() místo defaults.preventDefault! cool, ne?!

/**
* Collapsable defaults
* @type {{control: string, box: string, event: string, fx: boolean, fxDuration: number, accordion: boolean, collapsableAll: boolean, preventDefault: boolean, extLinks: {selector: null, preventDefault: boolean, activeClass: string}, classNames: {expanded: string, collapsed: string, defaultExpanded: string}}}
Expand Down Expand Up @@ -264,6 +262,10 @@
* @constructor
*/
var Collapsable = function ($boxSet, options) {
if ($boxSet.length === 0) {
return null;
}

this.opts = $.extend(true, {}, $.fn.collapsable.defaults, options);
this.items = [];

Expand Down Expand Up @@ -452,8 +454,12 @@
this.$control = this.$collapsable.find(parent.opts.control);
this.$box = this.$collapsable.find(parent.opts.box);

if (this.$control.length == 0 || this.$box.length == 0)
return;
if (this.$control.length == 0 || this.$box.length == 0) {
return null;
}

// on initialization, we assume the item is expanded until it's actually collapsed
this.isExpanded = true;

var that = this;
var opts = this.parent.opts; // shortcut
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.collapsable.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jquery.collapsable",
"title": "jQuery Collapsable",
"description": "jQuery plugin for collapsable boxes",
"version": "2.0.2",
"version": "2.0.3",
"author": {
"name": "Radek Šerý",
"email": "radek.sery@gmail.com"
Expand Down
14 changes: 10 additions & 4 deletions src/jquery.collapsable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
;(function($) {

// @feature: díky předávání collapsableEvent do expand.collapsable (atd.) je možné použít e.collapsableEvent.preventDefault() místo defaults.preventDefault! cool, ne?!

/**
* Collapsable defaults
* @type {{control: string, box: string, event: string, fx: boolean, fxDuration: number, accordion: boolean, collapsableAll: boolean, preventDefault: boolean, extLinks: {selector: null, preventDefault: boolean, activeClass: string}, classNames: {expanded: string, collapsed: string, defaultExpanded: string}}}
Expand Down Expand Up @@ -257,6 +255,10 @@
* @constructor
*/
var Collapsable = function ($boxSet, options) {
if ($boxSet.length === 0) {
return null;
}

this.opts = $.extend(true, {}, $.fn.collapsable.defaults, options);
this.items = [];

Expand Down Expand Up @@ -445,8 +447,12 @@
this.$control = this.$collapsable.find(parent.opts.control);
this.$box = this.$collapsable.find(parent.opts.box);

if (this.$control.length == 0 || this.$box.length == 0)
return;
if (this.$control.length == 0 || this.$box.length == 0) {
return null;
}

// on initialization, we assume the item is expanded until it's actually collapsed
this.isExpanded = true;

var that = this;
var opts = this.parent.opts; // shortcut
Expand Down

0 comments on commit def0682

Please sign in to comment.