File size: 1,922 Bytes
2fcec7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | /**
* Created by dfitzgerald on 8/21/15.
*/
(function($){
$.widget('djf604.MaterialSidebar', {
options: {
toggleSelector: ''
},
/* Define instance variables */
$sidebarContainer: null,
$sidebarOverlay: null,
/* Constructor */
_create: function(){
var widget = this;
widget.$sidebarContainer = widget.element;
widget.$sidebarOverlay = $('<div>').addClass('sidebar-overlay').click(function(){
$(this).removeClass('active');
widget.$sidebarContainer.removeClass('open');
});
widget.$sidebarOverlay.appendTo($('body'));
/* Match dropdown elements to targets */
widget.updateTargets();
/* Attach toggle handle */
$(widget.options.toggleSelector).click(function(){
console.log('opened');
widget.open();
});
},
open: function(){
var widget = this;
widget.$sidebarContainer.toggleClass('open');
if ((widget.$sidebarContainer.hasClass('sidebar-fixed-left')
|| widget.$sidebarContainer.hasClass('sidebar-fixed-right'))
&& widget.$sidebarContainer.hasClass('open')) {
widget.$sidebarOverlay.addClass('active');
} else {
widget.$sidebarOverlay.removeClass('active');
}
console.log('workied');
},
updateTargets: function(){
var widget = this;
/* Match dropdown elements to targets */
widget.$sidebarContainer.find('[data-target]').each(function(){
if($(this).data('targetAttached') == 'attached') return;
var targetId = $(this).data('target');
//console.log('target is: ' + targetId);
$(this).click(function(){
$(targetId).stop(true, true).slideToggle();
});
$(this).data('targetAttached', 'attached');
});
}
});
})(jQuery); |