diff --git a/README.md b/README.md index 78d1cb9..7c6a4e2 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,11 @@ Please see the plugin site http://zipper.github.io/jquery.collapsable/ ## Changelog +### 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 + ### 2.0.1 -- renamed option `grouped` to more recognizable ``accordion` +- renamed option ~~`grouped`~~ to more recognizable `accordion` - changed default `fx` value to `null` for no effect used - changed order of executing `fx` function and class assigning so it doesn't interfere with jQuery effects - default value of `extLinks.selector` to empty string `''` diff --git a/bower.json b/bower.json index 01afcbf..68f3223 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "jquery.collapsable", "description": "jQuery plugin for collapsable boxes", - "version": "2.0.1", + "version": "2.0.2", "main": "dist/jquery.collapsable.js", "authors": [ "Radek Šerý " ], "homepage": "http://zipper.github.io/jquery.collapsable/", diff --git a/dist/jquery.collapsable.js b/dist/jquery.collapsable.js index 51f0e72..6fd654f 100644 --- a/dist/jquery.collapsable.js +++ b/dist/jquery.collapsable.js @@ -6,11 +6,11 @@ * @copyright Copyright (c) 2014-2016 Radek Šerý * @license MIT * - * @version 2.0.1 + * @version 2.0.2 */ ;(function($) { - // @feature: díky předávání originalEvent do expand.collapsable (atd.) je možné použít e.originalEvent.preventDefault() místo defaults.preventDefault! cool, ne?! + // @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 @@ -20,7 +20,7 @@ control: '.ca-control', // CSS selector for control element box: '.ca-box', // CSS selector for hideable element (box) event: 'click', // event triggering the expand/collapse - preventDefault: true, // whether prevenDefault should be called when specified event occurs on control; even if false, e.originalEvent.preventDefault() may be used inside collapsable event handlers + preventDefault: true, // whether prevenDefault should be called when specified event occurs on control; even if false, e.collapsableEvent.preventDefault() may be used inside collapsable event handlers fx: null, // effect for expanding/collapsing, [ false | toggle | slide | fade | {Object} ] fxDuration: 0, // duration of the effect, affects delay between `expand.collapsable`(`collapse.collapsable`) and `expanded.collapsable` (`collapsed.collapsable`) evetns are triggered; default value is 500 when fx set to slide @@ -462,9 +462,9 @@ this.$controlLink = this.$control.find('.ca-link').addBack('.ca-link'); - // originalEvent contains arguments passed when trigger is called, used for passing event that triggered opening (eg. extLink click) - this.$controlLink.on(opts.event + '.collapsable', function(event, originalEvent) { - var passEvent = originalEvent ? originalEvent : event; + // collapsableEvent contains arguments passed when trigger is called, used for passing event that triggered opening (eg. extLink click) + this.$controlLink.on(opts.event + '.collapsable', function(event, collapsableEvent) { + var passEvent = collapsableEvent ? collapsableEvent : event; if (opts.preventDefault) { event.preventDefault(); } @@ -487,10 +487,10 @@ * Handling common parts of expanding and collapsing * @param {String} action - Either `expand` or `collapse` * @param {Object} data - Data passed to triggered event - * @param {Event} originalEvent - Event to be passed to event handlers + * @param {Event} collapsableEvent - Event to be passed to event handlers * @returns {boolean} */ - function handleExpandCollapse(action, originalEvent, data) { + function handleExpandCollapse(action, collapsableEvent, data) { var opts = this.parent.opts; var that = this; var trigger = 'expanded'; @@ -504,7 +504,7 @@ removeClass = opts.classNames.expanded; } - var event = $.Event(trigger + '.collapsable', { customData: data, originalEvent: originalEvent }); + var event = $.Event(trigger + '.collapsable', { customData: data, collapsableEvent: collapsableEvent }); this.isExpanded = action === 'expand'; @@ -543,62 +543,62 @@ /** * Expands single CollapsableItem; could be prevented by `preventDefault` called on `expand.collapsable` event - * @param {Object} originalEvent - Event passed to triggered event + * @param {Object} collapsableEvent - Event passed to triggered event * @param {Object} data - Data passed to triggered event * @param {Boolean} force - Forcing CollapsableItem to expand regardless on onExpand return value, should be used only on initilization (force open default expanded item when collapsableAll === false) * @returns {Boolean} - Returns if CollapsableItem has been expanded or not */ - CollapsableItem.prototype.expand = function(originalEvent, data, force) { + CollapsableItem.prototype.expand = function(collapsableEvent, data, force) { var opts = this.parent.opts; var expandedItem = this.parent.getExpanded(); // accordion -> max one expanded item this.parent.promiseOpen = true; // allows us to collapse expanded item even if there might be collapseAll === false option if (opts.accordion) { // before expanding, we have to collapse previously opened item, if accordion element hasn't collapsed, we can't continue - if (expandedItem.length && this.parent.items[expandedItem[0]].collapse(originalEvent, data, force) === false) { + if (expandedItem.length && this.parent.items[expandedItem[0]].collapse(collapsableEvent, data, force) === false) { this.parent.promiseOpen = false; return false; } } this.parent.promiseOpen = false; - var event = $.Event('expand.collapsable', { customData: data, originalEvent: originalEvent }); + var event = $.Event('expand.collapsable', { customData: data, collapsableEvent: collapsableEvent }); this.$collapsable.trigger(event); if (event.isDefaultPrevented() && ! force) { // collapsableAll === false && accordion === true -> if the box has not opened, we must make sure something is opened, therefore we force-open previously opened box (opts.accordion is true means we tried to collapse something), simulating it has never closed in first place if (! opts.collapsableAll && opts.accordion) { - this.parent.items[expandedItem[0]].expand(originalEvent, data, true); + this.parent.items[expandedItem[0]].expand(collapsableEvent, data, true); } return false; } - return handleExpandCollapse.call(this, 'expand', originalEvent) + return handleExpandCollapse.call(this, 'expand', collapsableEvent) }; /** * Collapses single CollapsableItem; could be prevented by `preventDefault` called on `collapse.collapsable` event - * @param {Object} originalEvent - Event passed to triggered event + * @param {Object} collapsableEvent - Event passed to triggered event * @param {Object} data - Data passed to triggered event * @param {Boolean} force - Forcing CollapsableItem to collapse regardless on onCollapse return value * @returns {Boolean} - Returns if CollapsableItem has been collapsed or not */ - CollapsableItem.prototype.collapse = function(originalEvent, data, force) { + CollapsableItem.prototype.collapse = function(collapsableEvent, data, force) { var opts = this.parent.opts; // if we can't collapse all, we are not promised to open something and there is only one opened box, then we can't continue if (! opts.collapsableAll && ! this.parent.promiseOpen && this.parent.getExpanded().length < 2) { return false; } - var event = $.Event('collapse.collapsable', { customData: data, originalEvent: originalEvent }); + var event = $.Event('collapse.collapsable', { customData: data, collapsableEvent: collapsableEvent }); this.$collapsable.trigger(event); if (event.isDefaultPrevented() && !force) { return false; } - return handleExpandCollapse.call(this, 'collapse', originalEvent); + return handleExpandCollapse.call(this, 'collapse', collapsableEvent); }; diff --git a/dist/jquery.collapsable.min.js b/dist/jquery.collapsable.min.js index ca9dbf0..9c06f23 100644 --- a/dist/jquery.collapsable.min.js +++ b/dist/jquery.collapsable.min.js @@ -1,2 +1,2 @@ -/*! jQuery Collapsable 2.0.1 | MIT | Radek Šerý, http://zipper.github.io/jquery.collapsable/ */ -!function(a){function b(){return"ca-uid-"+l++}function c(b,c){var d=[];this.each(function(){var e=a(this).data("collapsable");if(e){var f=e.parent.uid;-1===d.indexOf(f)&&(d.push(f),e.parent[b](c))}})}function d(){var b=this.opts;(this.$extLinks=a(b.extLinks.selector).filter("a")).length&&this.$extLinks.on("click.collapsable",function(c){b.extLinks.preventDefault&&c.preventDefault();var d=a(a(this).attr("href")).data("collapsable");d&&d.$controlLink.first().trigger(b.event+".collapsable",c)})}function e(){var b=window.location.href,c=b.search(/#/),d=-1,e=-1,f=a(a.map(this.items,function(a){return a.$collapsable.get()}));if(-1===c||(b=b.substring(c+1),e=f.index(a("#"+b)),-1===e||(this.items[e].defaultExpanded=!0,!this.opts.accordion))){if(this.opts.accordion){if(d=f.index(a("."+this.opts.classNames.defaultExpanded)),-1!==d)return void(this.items[d].defaultExpanded=!0)}else{var g=this;f.each(function(b){a(this).hasClass(g.opts.classNames.defaultExpanded)&&(d=b,g.items[b].defaultExpanded=!0)})}-1!==e||-1!==d||this.opts.collapsableAll||(this.items[0].defaultExpanded=!0)}}function f(){var b=a.Event("init.collapsable"),c=this.opts,d=this.items,e=c.fx;c.fx&&(c.fx="toggle");for(var f=d.length,g=!c.collapsableAll,h=0;f>h;h++)d[h].defaultExpanded?(d[h].expand(b,null,g),g=!1):d[h].collapse(b,null,!0);c.fx=e}function g(){var a=this.opts;"slide"!==a.fx&&"fade"!==a.fx||(a.fxDuration=a.fxDuration||500),"slide"===a.fx?a.fx={expand:"slideDown",collapse:"slideUp"}:"fade"===this.opts.fx&&(a.fx={expand:"fadeIn",collapse:"fadeOut"})}function h(){var c=this;c.id||(c.id=b(),c.$collapsable.attr("id",this.id));var d=c.$box.attr("id")||c.id+"-ca-box";c.$box.attr("id",d).data("ca-pre-init-style",c.$box.attr("style")),c.$control.each(function(){var b,e=a(this);e.is("a")?b=e:(b=e.find("a")).length||(e.wrapInner(''),b=e.find("a")),b.addClass("ca-link"),b.attr("aria-controls",d)})}function i(b,c,d){var e=this.parent.opts,f=this,g="expanded",h=e.classNames.expanded,i=e.classNames.collapsed;"collapse"===b&&(g="collapsed",h=e.classNames.collapsed,i=e.classNames.expanded);var j=a.Event(g+".collapsable",{customData:d,originalEvent:c});return this.isExpanded="expand"===b,this.parent.$extLinks.filter('[href="#'+this.id+'"]')["expand"===b?"addClass":"removeClass"](e.classNames.extLinkActive),this.$controlLink.attr("aria-expanded","expand"===b),this.$box.attr("aria-hidden","expand"!==b),e.fx&&"object"==typeof e.fx?this.$box[e.fx[b]](e.fxDuration,function(){f.$collapsable.trigger(j)}):("toggle"===e.fx&&this.$box["expand"===b?"show":"hide"](),setTimeout(function(){f.$collapsable.trigger(j)},e.fxDuration)),this.$collapsable.removeClass(i).addClass(h),!0}var j={control:".ca-control",box:".ca-box",event:"click",preventDefault:!0,fx:null,fxDuration:0,accordion:!1,collapsableAll:!0,extLinks:{selector:"",preventDefault:!1},classNames:{expanded:"ca-expanded",collapsed:"ca-collapsed",defaultExpanded:"ca-default-expanded",extLinkActive:"ca-ext-active"}},k={init:function(a){return new m(this,a)},expandAll:function(a){c.call(this,"expandAll",a)},collapseAll:function(a){c.call(this,"collapseAll",a)},destroy:function(a){c.call(this,"destroy",a)}},l=0,m=function(c,h){this.opts=a.extend(!0,{},a.fn.collapsable.defaults,h),this.items=[];var i=this;return this.uid=b(),this.promiseOpen=!1,d.call(this),g.call(this),c.each(function(){var a=new n(i,this);a.$box.length&&a.$control.length&&i.items.push(a)}),e.call(this),f.call(this),this};m.prototype.getExpanded=function(){for(var a=[],b=this.items.length,c=0;b>c;c++)this.items[c].isExpanded&&a.push(c);return a},m.prototype.expandAll=function(b){if(!this.opts.accordion||!this.getExpanded().length)for(var c=a.Event("expandAll.collapsable"),d=this.items.length,e=0;d>e;e++)if(!this.items[e].isExpanded){var f=this.items[e].expand(c,b);if(this.opts.accordion&&f)break}},m.prototype.collapseAll=function(b){for(var c=a.Event("collapseAll.collapsable"),d=this.getExpanded(),e=d.length,f=0;e>f;f++)this.items[d[f]].collapse(c,b)},m.prototype.destroy=function(){for(var b=this.opts,c=this.items.length,d=0;c>d;d++){var e=this.items[d];e.$collapsable.removeClass(b.classNames.collapsed+" "+b.classNames.expanded).removeData("collapsable"),e.$control.find("[data-ca-created]").each(function(){a(this).parent().html(a(this).html())}),e.$control.find(".ca-link").addBack(".ca-link").off(b.event+".collapsable").removeClass("ca-link").removeAttr("aria-controls").removeAttr("aria-expanded");var f=e.$box.data("ca-pre-init-style")||"";e.$box.attr("style",f).removeData("ca-pre-init-style").removeAttr("aria-hidden"),e.$collapsable.trigger("destroy.collapsable")}this.$extLinks.off("click.collapsable")};var n=function(b,c){if(this.parent=b,this.$collapsable=a(c),this.id=this.$collapsable.attr("id"),this.$control=this.$collapsable.find(b.opts.control),this.$box=this.$collapsable.find(b.opts.box),0!=this.$control.length&&0!=this.$box.length){var d=this,e=this.parent.opts;return h.call(this),this.$controlLink=this.$control.find(".ca-link").addBack(".ca-link"),this.$controlLink.on(e.event+".collapsable",function(a,b){var c=b?b:a;e.preventDefault&&a.preventDefault(),d.isExpanded?d.collapse(c):d.expand(c)}),this.$collapsable.data("collapsable",this),this}};n.prototype.expand=function(b,c,d){var e=this.parent.opts,f=this.parent.getExpanded();if(this.parent.promiseOpen=!0,e.accordion&&f.length&&this.parent.items[f[0]].collapse(b,c,d)===!1)return this.parent.promiseOpen=!1,!1;this.parent.promiseOpen=!1;var g=a.Event("expand.collapsable",{customData:c,originalEvent:b});return this.$collapsable.trigger(g),g.isDefaultPrevented()&&!d?(!e.collapsableAll&&e.accordion&&this.parent.items[f[0]].expand(b,c,!0),!1):i.call(this,"expand",b)},n.prototype.collapse=function(b,c,d){var e=this.parent.opts;if(!e.collapsableAll&&!this.parent.promiseOpen&&this.parent.getExpanded().length<2)return!1;var f=a.Event("collapse.collapsable",{customData:c,originalEvent:b});return this.$collapsable.trigger(f),f.isDefaultPrevented()&&!d?!1:i.call(this,"collapse",b)},a.fn.collapsable=function(b){return k[b]?k[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?void a.error("Method "+b+" does not exist on jQuery.collapsable"):(k.init.apply(this,arguments),this)},a.fn.collapsable.defaults=j}(jQuery); \ No newline at end of file +/*! jQuery Collapsable 2.0.2 | MIT | Radek Šerý, http://zipper.github.io/jquery.collapsable/ */ +!function(a){function b(){return"ca-uid-"+l++}function c(b,c){var d=[];this.each(function(){var e=a(this).data("collapsable");if(e){var f=e.parent.uid;-1===d.indexOf(f)&&(d.push(f),e.parent[b](c))}})}function d(){var b=this.opts;(this.$extLinks=a(b.extLinks.selector).filter("a")).length&&this.$extLinks.on("click.collapsable",function(c){b.extLinks.preventDefault&&c.preventDefault();var d=a(a(this).attr("href")).data("collapsable");d&&d.$controlLink.first().trigger(b.event+".collapsable",c)})}function e(){var b=window.location.href,c=b.search(/#/),d=-1,e=-1,f=a(a.map(this.items,function(a){return a.$collapsable.get()}));if(-1===c||(b=b.substring(c+1),e=f.index(a("#"+b)),-1===e||(this.items[e].defaultExpanded=!0,!this.opts.accordion))){if(this.opts.accordion){if(d=f.index(a("."+this.opts.classNames.defaultExpanded)),-1!==d)return void(this.items[d].defaultExpanded=!0)}else{var g=this;f.each(function(b){a(this).hasClass(g.opts.classNames.defaultExpanded)&&(d=b,g.items[b].defaultExpanded=!0)})}-1!==e||-1!==d||this.opts.collapsableAll||(this.items[0].defaultExpanded=!0)}}function f(){var b=a.Event("init.collapsable"),c=this.opts,d=this.items,e=c.fx;c.fx&&(c.fx="toggle");for(var f=d.length,g=!c.collapsableAll,h=0;f>h;h++)d[h].defaultExpanded?(d[h].expand(b,null,g),g=!1):d[h].collapse(b,null,!0);c.fx=e}function g(){var a=this.opts;"slide"!==a.fx&&"fade"!==a.fx||(a.fxDuration=a.fxDuration||500),"slide"===a.fx?a.fx={expand:"slideDown",collapse:"slideUp"}:"fade"===this.opts.fx&&(a.fx={expand:"fadeIn",collapse:"fadeOut"})}function h(){var c=this;c.id||(c.id=b(),c.$collapsable.attr("id",this.id));var d=c.$box.attr("id")||c.id+"-ca-box";c.$box.attr("id",d).data("ca-pre-init-style",c.$box.attr("style")),c.$control.each(function(){var b,e=a(this);e.is("a")?b=e:(b=e.find("a")).length||(e.wrapInner(''),b=e.find("a")),b.addClass("ca-link"),b.attr("aria-controls",d)})}function i(b,c,d){var e=this.parent.opts,f=this,g="expanded",h=e.classNames.expanded,i=e.classNames.collapsed;"collapse"===b&&(g="collapsed",h=e.classNames.collapsed,i=e.classNames.expanded);var j=a.Event(g+".collapsable",{customData:d,collapsableEvent:c});return this.isExpanded="expand"===b,this.parent.$extLinks.filter('[href="#'+this.id+'"]')["expand"===b?"addClass":"removeClass"](e.classNames.extLinkActive),this.$controlLink.attr("aria-expanded","expand"===b),this.$box.attr("aria-hidden","expand"!==b),e.fx&&"object"==typeof e.fx?this.$box[e.fx[b]](e.fxDuration,function(){f.$collapsable.trigger(j)}):("toggle"===e.fx&&this.$box["expand"===b?"show":"hide"](),setTimeout(function(){f.$collapsable.trigger(j)},e.fxDuration)),this.$collapsable.removeClass(i).addClass(h),!0}var j={control:".ca-control",box:".ca-box",event:"click",preventDefault:!0,fx:null,fxDuration:0,accordion:!1,collapsableAll:!0,extLinks:{selector:"",preventDefault:!1},classNames:{expanded:"ca-expanded",collapsed:"ca-collapsed",defaultExpanded:"ca-default-expanded",extLinkActive:"ca-ext-active"}},k={init:function(a){return new m(this,a)},expandAll:function(a){c.call(this,"expandAll",a)},collapseAll:function(a){c.call(this,"collapseAll",a)},destroy:function(a){c.call(this,"destroy",a)}},l=0,m=function(c,h){this.opts=a.extend(!0,{},a.fn.collapsable.defaults,h),this.items=[];var i=this;return this.uid=b(),this.promiseOpen=!1,d.call(this),g.call(this),c.each(function(){var a=new n(i,this);a.$box.length&&a.$control.length&&i.items.push(a)}),e.call(this),f.call(this),this};m.prototype.getExpanded=function(){for(var a=[],b=this.items.length,c=0;b>c;c++)this.items[c].isExpanded&&a.push(c);return a},m.prototype.expandAll=function(b){if(!this.opts.accordion||!this.getExpanded().length)for(var c=a.Event("expandAll.collapsable"),d=this.items.length,e=0;d>e;e++)if(!this.items[e].isExpanded){var f=this.items[e].expand(c,b);if(this.opts.accordion&&f)break}},m.prototype.collapseAll=function(b){for(var c=a.Event("collapseAll.collapsable"),d=this.getExpanded(),e=d.length,f=0;e>f;f++)this.items[d[f]].collapse(c,b)},m.prototype.destroy=function(){for(var b=this.opts,c=this.items.length,d=0;c>d;d++){var e=this.items[d];e.$collapsable.removeClass(b.classNames.collapsed+" "+b.classNames.expanded).removeData("collapsable"),e.$control.find("[data-ca-created]").each(function(){a(this).parent().html(a(this).html())}),e.$control.find(".ca-link").addBack(".ca-link").off(b.event+".collapsable").removeClass("ca-link").removeAttr("aria-controls").removeAttr("aria-expanded");var f=e.$box.data("ca-pre-init-style")||"";e.$box.attr("style",f).removeData("ca-pre-init-style").removeAttr("aria-hidden"),e.$collapsable.trigger("destroy.collapsable")}this.$extLinks.off("click.collapsable")};var n=function(b,c){if(this.parent=b,this.$collapsable=a(c),this.id=this.$collapsable.attr("id"),this.$control=this.$collapsable.find(b.opts.control),this.$box=this.$collapsable.find(b.opts.box),0!=this.$control.length&&0!=this.$box.length){var d=this,e=this.parent.opts;return h.call(this),this.$controlLink=this.$control.find(".ca-link").addBack(".ca-link"),this.$controlLink.on(e.event+".collapsable",function(a,b){var c=b?b:a;e.preventDefault&&a.preventDefault(),d.isExpanded?d.collapse(c):d.expand(c)}),this.$collapsable.data("collapsable",this),this}};n.prototype.expand=function(b,c,d){var e=this.parent.opts,f=this.parent.getExpanded();if(this.parent.promiseOpen=!0,e.accordion&&f.length&&this.parent.items[f[0]].collapse(b,c,d)===!1)return this.parent.promiseOpen=!1,!1;this.parent.promiseOpen=!1;var g=a.Event("expand.collapsable",{customData:c,collapsableEvent:b});return this.$collapsable.trigger(g),g.isDefaultPrevented()&&!d?(!e.collapsableAll&&e.accordion&&this.parent.items[f[0]].expand(b,c,!0),!1):i.call(this,"expand",b)},n.prototype.collapse=function(b,c,d){var e=this.parent.opts;if(!e.collapsableAll&&!this.parent.promiseOpen&&this.parent.getExpanded().length<2)return!1;var f=a.Event("collapse.collapsable",{customData:c,collapsableEvent:b});return this.$collapsable.trigger(f),f.isDefaultPrevented()&&!d?!1:i.call(this,"collapse",b)},a.fn.collapsable=function(b){return k[b]?k[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?void a.error("Method "+b+" does not exist on jQuery.collapsable"):(k.init.apply(this,arguments),this)},a.fn.collapsable.defaults=j}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 1ea4130..4e7b15f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery.collapsable", "title": "jQuery Collapsable", "description": "jQuery plugin for collapsable boxes", - "version": "2.0.1", + "version": "2.0.2", "author": { "name": "Radek Šerý", "email": "radek.sery@gmail.com" diff --git a/src/jquery.collapsable.js b/src/jquery.collapsable.js index 22e7220..7b94c0c 100644 --- a/src/jquery.collapsable.js +++ b/src/jquery.collapsable.js @@ -3,7 +3,7 @@ */ ;(function($) { - // @feature: díky předávání originalEvent do expand.collapsable (atd.) je možné použít e.originalEvent.preventDefault() místo defaults.preventDefault! cool, ne?! + // @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 @@ -13,7 +13,7 @@ control: '.ca-control', // CSS selector for control element box: '.ca-box', // CSS selector for hideable element (box) event: 'click', // event triggering the expand/collapse - preventDefault: true, // whether prevenDefault should be called when specified event occurs on control; even if false, e.originalEvent.preventDefault() may be used inside collapsable event handlers + preventDefault: true, // whether prevenDefault should be called when specified event occurs on control; even if false, e.collapsableEvent.preventDefault() may be used inside collapsable event handlers fx: null, // effect for expanding/collapsing, [ false | toggle | slide | fade | {Object} ] fxDuration: 0, // duration of the effect, affects delay between `expand.collapsable`(`collapse.collapsable`) and `expanded.collapsable` (`collapsed.collapsable`) evetns are triggered; default value is 500 when fx set to slide @@ -455,9 +455,9 @@ this.$controlLink = this.$control.find('.ca-link').addBack('.ca-link'); - // originalEvent contains arguments passed when trigger is called, used for passing event that triggered opening (eg. extLink click) - this.$controlLink.on(opts.event + '.collapsable', function(event, originalEvent) { - var passEvent = originalEvent ? originalEvent : event; + // collapsableEvent contains arguments passed when trigger is called, used for passing event that triggered opening (eg. extLink click) + this.$controlLink.on(opts.event + '.collapsable', function(event, collapsableEvent) { + var passEvent = collapsableEvent ? collapsableEvent : event; if (opts.preventDefault) { event.preventDefault(); } @@ -480,10 +480,10 @@ * Handling common parts of expanding and collapsing * @param {String} action - Either `expand` or `collapse` * @param {Object} data - Data passed to triggered event - * @param {Event} originalEvent - Event to be passed to event handlers + * @param {Event} collapsableEvent - Event to be passed to event handlers * @returns {boolean} */ - function handleExpandCollapse(action, originalEvent, data) { + function handleExpandCollapse(action, collapsableEvent, data) { var opts = this.parent.opts; var that = this; var trigger = 'expanded'; @@ -497,7 +497,7 @@ removeClass = opts.classNames.expanded; } - var event = $.Event(trigger + '.collapsable', { customData: data, originalEvent: originalEvent }); + var event = $.Event(trigger + '.collapsable', { customData: data, collapsableEvent: collapsableEvent }); this.isExpanded = action === 'expand'; @@ -536,62 +536,62 @@ /** * Expands single CollapsableItem; could be prevented by `preventDefault` called on `expand.collapsable` event - * @param {Object} originalEvent - Event passed to triggered event + * @param {Object} collapsableEvent - Event passed to triggered event * @param {Object} data - Data passed to triggered event * @param {Boolean} force - Forcing CollapsableItem to expand regardless on onExpand return value, should be used only on initilization (force open default expanded item when collapsableAll === false) * @returns {Boolean} - Returns if CollapsableItem has been expanded or not */ - CollapsableItem.prototype.expand = function(originalEvent, data, force) { + CollapsableItem.prototype.expand = function(collapsableEvent, data, force) { var opts = this.parent.opts; var expandedItem = this.parent.getExpanded(); // accordion -> max one expanded item this.parent.promiseOpen = true; // allows us to collapse expanded item even if there might be collapseAll === false option if (opts.accordion) { // before expanding, we have to collapse previously opened item, if accordion element hasn't collapsed, we can't continue - if (expandedItem.length && this.parent.items[expandedItem[0]].collapse(originalEvent, data, force) === false) { + if (expandedItem.length && this.parent.items[expandedItem[0]].collapse(collapsableEvent, data, force) === false) { this.parent.promiseOpen = false; return false; } } this.parent.promiseOpen = false; - var event = $.Event('expand.collapsable', { customData: data, originalEvent: originalEvent }); + var event = $.Event('expand.collapsable', { customData: data, collapsableEvent: collapsableEvent }); this.$collapsable.trigger(event); if (event.isDefaultPrevented() && ! force) { // collapsableAll === false && accordion === true -> if the box has not opened, we must make sure something is opened, therefore we force-open previously opened box (opts.accordion is true means we tried to collapse something), simulating it has never closed in first place if (! opts.collapsableAll && opts.accordion) { - this.parent.items[expandedItem[0]].expand(originalEvent, data, true); + this.parent.items[expandedItem[0]].expand(collapsableEvent, data, true); } return false; } - return handleExpandCollapse.call(this, 'expand', originalEvent) + return handleExpandCollapse.call(this, 'expand', collapsableEvent) }; /** * Collapses single CollapsableItem; could be prevented by `preventDefault` called on `collapse.collapsable` event - * @param {Object} originalEvent - Event passed to triggered event + * @param {Object} collapsableEvent - Event passed to triggered event * @param {Object} data - Data passed to triggered event * @param {Boolean} force - Forcing CollapsableItem to collapse regardless on onCollapse return value * @returns {Boolean} - Returns if CollapsableItem has been collapsed or not */ - CollapsableItem.prototype.collapse = function(originalEvent, data, force) { + CollapsableItem.prototype.collapse = function(collapsableEvent, data, force) { var opts = this.parent.opts; // if we can't collapse all, we are not promised to open something and there is only one opened box, then we can't continue if (! opts.collapsableAll && ! this.parent.promiseOpen && this.parent.getExpanded().length < 2) { return false; } - var event = $.Event('collapse.collapsable', { customData: data, originalEvent: originalEvent }); + var event = $.Event('collapse.collapsable', { customData: data, collapsableEvent: collapsableEvent }); this.$collapsable.trigger(event); if (event.isDefaultPrevented() && !force) { return false; } - return handleExpandCollapse.call(this, 'collapse', originalEvent); + return handleExpandCollapse.call(this, 'collapse', collapsableEvent); };