1
1
/*!
2
- * Materialize v0.96.0 (http://materializecss.com)
2
+ * Materialize v0.96.1 (http://materializecss.com)
3
3
* Copyright 2014-2015 Materialize
4
4
* MIT License (https://raw.githubusercontent.com/Dogfalo/materialize/master/LICENSE)
5
5
*/
@@ -252,7 +252,7 @@ jQuery.extend( jQuery.easing,
252
252
} ;
253
253
} ) ( Hammer . Manager . prototype . emit ) ;
254
254
} ) ) ;
255
- ; var Materialize = { } ;
255
+ ; Materialize = { } ;
256
256
257
257
// Unique ID
258
258
Materialize . guid = ( function ( ) {
@@ -354,16 +354,44 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
354
354
}
355
355
}
356
356
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
+
357
379
/***** End Helper Functions *****/
358
380
359
381
360
382
361
383
if ( options . accordion || collapsible_type == "accordion" || collapsible_type == undefined ) { // Handle Accordion
362
384
// 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 ) ;
367
395
} ) ;
368
396
// Open first active
369
397
accordionOpen ( $panel_headers . filter ( '.active' ) . first ( ) ) ;
@@ -372,9 +400,12 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
372
400
$panel_headers . each ( function ( ) {
373
401
// Add click handler to only direct collapsible header children
374
402
$ ( 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 ) ;
378
409
} ) ;
379
410
// Open any bodies that have the active class
380
411
if ( $ ( this ) . hasClass ( 'active' ) ) {
@@ -434,15 +465,7 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
434
465
updateOptions ( ) ;
435
466
436
467
// 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 ) ;
446
469
447
470
/*
448
471
Helper function to position and resize dropdown.
@@ -452,6 +475,9 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
452
475
// Check html data attributes
453
476
updateOptions ( ) ;
454
477
478
+ // Set Dropdown state
479
+ activates . addClass ( 'active' ) ;
480
+
455
481
// Constrain width
456
482
if ( options . constrain_width == true ) {
457
483
activates . css ( 'width' , origin . outerWidth ( ) ) ;
@@ -463,7 +489,6 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
463
489
464
490
// Handle edge alignment
465
491
var offsetLeft = origin . offset ( ) . left ;
466
-
467
492
var width_difference = 0 ;
468
493
var gutter_spacing = options . gutter ;
469
494
@@ -472,23 +497,15 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
472
497
width_difference = origin . innerWidth ( ) - activates . innerWidth ( ) ;
473
498
gutter_spacing = gutter_spacing * - 1 ;
474
499
}
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 {
484
500
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
+
490
508
491
- }
492
509
493
510
// Show dropdown
494
511
activates . stop ( true , true ) . css ( 'opacity' , 0 )
@@ -501,59 +518,62 @@ if ($) { Vel = $.Velocity } else { Vel = Velocity};
501
518
}
502
519
} )
503
520
. animate ( { opacity : 1 } , { queue : false , duration : options . inDuration , easing : 'easeOutSine' } ) ;
504
-
505
-
506
521
}
507
522
508
-
509
523
function hideDropdown ( ) {
510
524
activates . fadeOut ( options . outDuration ) ;
525
+ activates . removeClass ( 'active' ) ;
511
526
}
512
527
513
- activates . on ( 'hover' , function ( e ) {
514
- e . stopPropagation ( ) ;
515
- } ) ;
516
-
517
528
// Hover
518
529
if ( options . hover ) {
530
+ var open = false ;
519
531
origin . unbind ( 'click.' + origin . attr ( 'id' ) ) ;
520
532
// Hover handler to show dropdown
521
533
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
+ }
523
546
} ) ;
524
547
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
+ }
528
554
} ) ;
529
555
530
556
// Click
531
557
} else {
532
- var open = false ;
533
558
534
559
// Click handler to show dropdown
535
560
origin . unbind ( 'click.' + origin . attr ( 'id' ) ) ;
536
561
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
+
541
563
if ( origin [ 0 ] == e . currentTarget && ( $ ( e . target ) . closest ( '.dropdown-content' ) . length === 0 ) ) {
542
564
e . preventDefault ( ) ; // Prevents button click from moving window
543
565
placeDropdown ( ) ;
544
- open = true ;
545
566
546
567
}
547
568
// If origin is clicked and menu is open, close menu
548
569
else {
549
- if ( open === true ) {
570
+ if ( origin . hasClass ( 'active' ) ) {
550
571
hideDropdown ( ) ;
551
572
$ ( document ) . unbind ( 'click.' + activates . attr ( 'id' ) ) ;
552
- open = false ;
553
573
}
554
574
}
555
575
// If menu open, add click close handler to document
556
- if ( open === true ) {
576
+ if ( activates . hasClass ( 'active' ) ) {
557
577
$ ( document ) . bind ( 'click.' + activates . attr ( 'id' ) , function ( e ) {
558
578
if ( ! activates . is ( e . target ) && ! origin . is ( e . target ) && ( ! origin . find ( e . target ) . length > 0 ) ) {
559
579
hideDropdown ( ) ;
@@ -2295,7 +2315,7 @@ $(document).ready(function(){
2295
2315
2296
2316
// offset - 200 allows elements near bottom of page to scroll
2297
2317
2298
- $ ( 'html, body' ) . animate ( { scrollTop : offset - 200 } , { duration : 400 , easing : 'easeOutCubic' } ) ;
2318
+ $ ( 'html, body' ) . animate ( { scrollTop : offset - 200 } , { duration : 400 , queue : false , easing : 'easeOutCubic' } ) ;
2299
2319
2300
2320
} ) ;
2301
2321
} ) ;
0 commit comments