11/*!
2- * Materialize v0.96.0 (http://materializecss.com)
2+ * Materialize v0.96.1 (http://materializecss.com)
33 * Copyright 2014-2015 Materialize
44 * MIT License (https://raw.githubusercontent.com/Dogfalo/materialize/master/LICENSE)
55 */
@@ -252,7 +252,7 @@ jQuery.extend( jQuery.easing,
252252 } ;
253253 } ) ( Hammer . Manager . prototype . emit ) ;
254254} ) ) ;
255- ; var Materialize = { } ;
255+ ; Materialize = { } ;
256256
257257// Unique ID
258258Materialize . guid = ( function ( ) {
@@ -354,16 +354,44 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
354354 }
355355 }
356356
357+ /**
358+ * Check if object is children of panel header
359+ * @param {Object } object Jquery object
360+ * @return {Boolean } true if it is children
361+ */
362+ function isChildrenOfPanelHeader ( object ) {
363+
364+ var panelHeader = getPanelHeader ( object ) ;
365+
366+ return panelHeader . length > 0 ;
367+ }
368+
369+ /**
370+ * Get panel header from a children element
371+ * @param {Object } object Jquery object
372+ * @return {Object } panel header object
373+ */
374+ function getPanelHeader ( object ) {
375+
376+ return object . closest ( 'li > .collapsible-header' ) ;
377+ }
378+
357379 /***** End Helper Functions *****/
358380
359381
360382
361383 if ( options . accordion || collapsible_type == "accordion" || collapsible_type == undefined ) { // Handle Accordion
362384 // Add click handler to only direct collapsible header children
363- $this . find ( '> li > .collapsible-header' ) . on ( 'click.collapse' , function ( e ) {
364- var header = $ ( e . target ) ;
365- header . toggleClass ( 'active' ) ;
366- accordionOpen ( header ) ;
385+ $panel_headers = $this . find ( '> li > .collapsible-header' ) ;
386+ $panel_headers . on ( 'click.collapse' , function ( e ) {
387+ var element = $ ( e . target ) ;
388+
389+ if ( isChildrenOfPanelHeader ( element ) ) {
390+ element = getPanelHeader ( element ) ;
391+ }
392+
393+ element . toggleClass ( 'active' ) ;
394+ accordionOpen ( element ) ;
367395 } ) ;
368396 // Open first active
369397 accordionOpen ( $panel_headers . filter ( '.active' ) . first ( ) ) ;
@@ -372,9 +400,12 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
372400 $panel_headers . each ( function ( ) {
373401 // Add click handler to only direct collapsible header children
374402 $ ( this ) . on ( 'click.collapse' , function ( e ) {
375- var header = $ ( e . target ) ;
376- header . toggleClass ( 'active' ) ;
377- expandableOpen ( header ) ;
403+ var element = $ ( e . target ) ;
404+ if ( isChildrenOfPanelHeader ( element ) ) {
405+ element = getPanelHeader ( element ) ;
406+ }
407+ element . toggleClass ( 'active' ) ;
408+ expandableOpen ( element ) ;
378409 } ) ;
379410 // Open any bodies that have the active class
380411 if ( $ ( this ) . hasClass ( 'active' ) ) {
@@ -434,15 +465,7 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
434465 updateOptions ( ) ;
435466
436467 // Attach dropdown to its activator
437- if ( origin . hasClass ( 'select-dropdown' ) ) {
438- origin . after ( activates )
439- }
440- else {
441- origin . append ( activates ) ;
442- }
443-
444-
445-
468+ origin . after ( activates ) ;
446469
447470 /*
448471 Helper function to position and resize dropdown.
@@ -452,6 +475,9 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
452475 // Check html data attributes
453476 updateOptions ( ) ;
454477
478+ // Set Dropdown state
479+ activates . addClass ( 'active' ) ;
480+
455481 // Constrain width
456482 if ( options . constrain_width == true ) {
457483 activates . css ( 'width' , origin . outerWidth ( ) ) ;
@@ -463,7 +489,6 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
463489
464490 // Handle edge alignment
465491 var offsetLeft = origin . offset ( ) . left ;
466-
467492 var width_difference = 0 ;
468493 var gutter_spacing = options . gutter ;
469494
@@ -472,23 +497,15 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
472497 width_difference = origin . innerWidth ( ) - activates . innerWidth ( ) ;
473498 gutter_spacing = gutter_spacing * - 1 ;
474499 }
475- // If fixed placement
476- if ( Materialize . elementOrParentIsFixed ( origin [ 0 ] ) ) {
477- activates . css ( {
478- top : 0 + offset ,
479- left : 0 + width_difference + gutter_spacing
480- } ) ;
481- }
482- // If relative placement
483- else {
484500
485- activates . css ( {
486- position : 'absolute' ,
487- top : 0 + offset ,
488- left : 0 + width_difference + gutter_spacing
489- } ) ;
501+ // Position dropdown
502+ activates . css ( {
503+ position : 'absolute' ,
504+ top : origin . position ( ) . top + offset ,
505+ left : origin . position ( ) . left + width_difference + gutter_spacing
506+ } ) ;
507+
490508
491- }
492509
493510 // Show dropdown
494511 activates . stop ( true , true ) . css ( 'opacity' , 0 )
@@ -501,59 +518,62 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
501518 }
502519 } )
503520 . animate ( { opacity : 1 } , { queue : false , duration : options . inDuration , easing : 'easeOutSine' } ) ;
504-
505-
506521 }
507522
508-
509523 function hideDropdown ( ) {
510524 activates . fadeOut ( options . outDuration ) ;
525+ activates . removeClass ( 'active' ) ;
511526 }
512527
513- activates . on ( 'hover' , function ( e ) {
514- e . stopPropagation ( ) ;
515- } ) ;
516-
517528 // Hover
518529 if ( options . hover ) {
530+ var open = false ;
519531 origin . unbind ( 'click.' + origin . attr ( 'id' ) ) ;
520532 // Hover handler to show dropdown
521533 origin . on ( 'mouseenter' , function ( e ) { // Mouse over
522- placeDropdown ( ) ;
534+ if ( open === false ) {
535+ placeDropdown ( ) ;
536+ open = true
537+ }
538+ } ) ;
539+ origin . on ( 'mouseleave' , function ( e ) {
540+ // If hover on origin then to something other than dropdown content, then close
541+ if ( ! $ ( e . toElement ) . closest ( '.dropdown-content' ) . is ( activates ) ) {
542+ activates . stop ( true , true ) ;
543+ hideDropdown ( ) ;
544+ open = false ;
545+ }
523546 } ) ;
524547
525- origin . on ( 'mouseleave' , function ( e ) { // Mouse out
526- activates . stop ( true , true ) ;
527- hideDropdown ( ) ;
548+ activates . on ( 'mouseleave' , function ( e ) { // Mouse out
549+ if ( ! $ ( e . toElement ) . closest ( '.dropdown-button' ) . is ( origin ) ) {
550+ activates . stop ( true , true ) ;
551+ hideDropdown ( ) ;
552+ open = false ;
553+ }
528554 } ) ;
529555
530556 // Click
531557 } else {
532- var open = false ;
533558
534559 // Click handler to show dropdown
535560 origin . unbind ( 'click.' + origin . attr ( 'id' ) ) ;
536561 origin . bind ( 'click.' + origin . attr ( 'id' ) , function ( e ) {
537- // Handles case for select plugin
538- if ( origin . hasClass ( 'select-dropdown' ) ) {
539- return false ;
540- }
562+
541563 if ( origin [ 0 ] == e . currentTarget && ( $ ( e . target ) . closest ( '.dropdown-content' ) . length === 0 ) ) {
542564 e . preventDefault ( ) ; // Prevents button click from moving window
543565 placeDropdown ( ) ;
544- open = true ;
545566
546567 }
547568 // If origin is clicked and menu is open, close menu
548569 else {
549- if ( open === true ) {
570+ if ( origin . hasClass ( 'active' ) ) {
550571 hideDropdown ( ) ;
551572 $ ( document ) . unbind ( 'click.' + activates . attr ( 'id' ) ) ;
552- open = false ;
553573 }
554574 }
555575 // If menu open, add click close handler to document
556- if ( open === true ) {
576+ if ( activates . hasClass ( 'active' ) ) {
557577 $ ( document ) . bind ( 'click.' + activates . attr ( 'id' ) , function ( e ) {
558578 if ( ! activates . is ( e . target ) && ! origin . is ( e . target ) && ( ! origin . find ( e . target ) . length > 0 ) ) {
559579 hideDropdown ( ) ;
@@ -2295,7 +2315,7 @@ $(document).ready(function(){
22952315
22962316// offset - 200 allows elements near bottom of page to scroll
22972317
2298- $ ( 'html, body' ) . animate ( { scrollTop : offset - 200 } , { duration : 400 , easing : 'easeOutCubic' } ) ;
2318+ $ ( 'html, body' ) . animate ( { scrollTop : offset - 200 } , { duration : 400 , queue : false , easing : 'easeOutCubic' } ) ;
22992319
23002320 } ) ;
23012321 } ) ;
0 commit comments