Skip to content

Commit

Permalink
upd accordion: switch to live binding for heading clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
olton committed Jul 11, 2014
1 parent b643b33 commit be62906
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 29 deletions.
Binary file added docs/fonts/OpenSans-Bold.woff
Binary file not shown.
Binary file added docs/fonts/OpenSans-Light.woff
Binary file not shown.
Binary file added docs/fonts/OpenSans.woff
Binary file not shown.
Binary file added docs/fonts/PTSerif-Caption.woff
Binary file not shown.
6 changes: 3 additions & 3 deletions docs/js/metro.min.js

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

Binary file added fonts/OpenSans-Bold.woff
Binary file not shown.
Binary file added fonts/OpenSans-Light.woff
Binary file not shown.
Binary file added fonts/OpenSans.woff
Binary file not shown.
Binary file added fonts/PTSerif-Caption.woff
Binary file not shown.
60 changes: 37 additions & 23 deletions js/metro-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,62 @@

if (element.data('closeany') != undefined) this.options.closeAny = element.data('closeany');

this._frames = element.children(".accordion-frame");

this.init();
},

init: function(){
var that = this;

this._frames.each(function(){
that.element.on('click', '.accordion-frame > .heading', function(e){
e.preventDefault();
e.stopPropagation();

if ($(this).attr('disabled') || $(this).data('action') == 'none') return;

if (that.options.closeAny) that._closeFrames();

var frame = $(this).parent(), content = frame.children('.content');
console.log(this);

if ($(content).is(":hidden")) {
$(content).slideDown();
$(this).removeClass("collapsed");
that._trigger("frame", e, {frame: frame});
that.options.open(frame);
} else {
$(content).slideUp();
$(this).addClass("collapsed");
}
that.options.action(frame);
});

var frames = this.element.children('.accordion-frame');


frames.each(function(){
var frame = this,
a = $(this).children(".heading"),
content = $(this).children(".content");

if ($(a).hasClass("active") && !$(a).attr('disabled') && $(a).data('action') != 'none') {
if ($(frame).hasClass("active") && !$(frame).attr('disabled') && $(frame).data('action') != 'none') {
$(content).show();
$(a).removeClass("collapsed");
} else {
$(a).addClass("collapsed");
}

a.on('click', function(e){
e.preventDefault();
if ($(this).attr('disabled') || $(this).data('action') == 'none') return;

if (that.options.closeAny) that._closeFrames();

if ($(content).is(":hidden")) {
$(content).slideDown();
$(this).removeClass("collapsed");
that._trigger("frame", e, {frame: frame});
that.options.open(frame);
} else {
$(content).slideUp();
$(this).addClass("collapsed");
}
that.options.action(frame);
});
});


},

_closeFrames: function(){
this._frames.children(".content").slideUp().parent().children('.heading').addClass("collapsed");
var frames = this.element.children('.accordion-frame');
$.each(frames, function(){
var frame = $(this);
frame.children('.heading').addClass('collapsed');
frame.children('.content').slideUp();
});
//this._frames.children(".content").slideUp().parent().children('.heading').addClass("collapsed");
},

_destroy: function(){},
Expand Down
6 changes: 3 additions & 3 deletions min/metro.min.js

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

0 comments on commit be62906

Please sign in to comment.