|
9 | 9 | *
|
10 | 10 | * @package rcSwitcher
|
11 | 11 | * @name rcSwitcher
|
12 |
| - * @version 4.0 < 29 Sep 2016 > |
| 12 | + * @version 4.1 < 18 Feb 2017 > |
| 13 | + * @changes 4.1 - Add feature that input shold only have on switcher |
| 14 | + * - Add rcSwitcher Object on input as property |
| 15 | + * - Add attribute 'data-has-rcswitcher="1"' on input to mark that input has rcswitcher |
| 16 | + * - Enhance Auto Stick |
13 | 17 | * @author ahmed saad <a7mad.sa3d.2014@gmail.com><ahmedfadlshaker@gmail.com>
|
14 | 18 | * @copyright ahmed saad april 2015
|
15 | 19 | * @link http://plus.google.com/+AhmedSaadGmail
|
|
34 | 38 | $blob: $( '<span>', {'class': 'sblob'} ),
|
35 | 39 |
|
36 | 40 | // Allowed Themes
|
37 |
| - themes: [ 'light', 'modern', 'dark', 'flat' ], |
| 41 | + themes: [ 'light', 'modern', 'dark', 'flat', 'yellowish-green' ], |
38 | 42 |
|
39 | 43 | };
|
40 | 44 |
|
|
64 | 68 | switcherP.$this.each( function( i, input )
|
65 | 69 | {
|
66 | 70 | // console.log( $input.type );
|
| 71 | + if( input.hasOwnProperty( 'rcSwitcher' ) ) |
| 72 | + { |
| 73 | + console.warn( 'already has instance' ); |
| 74 | + return; |
| 75 | + } |
| 76 | + |
67 | 77 | this.makeSwitcher( $( input ), switcherP, options );
|
68 | 78 | }.bind( this ) );
|
69 | 79 |
|
|
198 | 208 | // Add to switchers collections
|
199 | 209 | switcherP.$switchers = switcherP.$switchers.add( data.$switcher );
|
200 | 210 |
|
| 211 | + // Store In Element Input JS |
| 212 | + $input[0].rcSwitcher = data; |
| 213 | + |
| 214 | + // Add attribute to mark this input that it has rcswitcher |
| 215 | + $input.attr( 'data-has-rcswitcher', 1 ); |
| 216 | + |
201 | 217 | // Update input type length
|
202 | 218 | cat.length++;
|
203 | 219 |
|
|
308 | 324 | var margin = parentAW - options.width;
|
309 | 325 |
|
310 | 326 | // remove border width if exists
|
311 |
| - margin -= ( options.theme == 'dark' ) ? 0 : 2; |
| 327 | + switch( options.theme ) |
| 328 | + { |
| 329 | + case 'dark': |
| 330 | + margin -= 2; |
| 331 | + break; |
| 332 | + |
| 333 | + case 'yellowish-green': |
| 334 | + margin -= 4; |
| 335 | + break; |
| 336 | + } |
| 337 | + |
312 | 338 |
|
313 | 339 | // Left OR Right margin
|
314 | 340 | if( switcherP.cssValues.dir == 'rtl' )
|
|
471 | 497 | {
|
472 | 498 | --family.disabled;
|
473 | 499 | ++family.enabled;
|
474 |
| - // If Checked, Disable All Group |
475 | 500 | if( family.enabled - family.disabled >= 2 )
|
476 | 501 | family.switchable = true;
|
477 | 502 |
|
|
509 | 534 | data.$input.prop( 'checked', false );
|
510 | 535 |
|
511 | 536 | // Fire Event and pass data object to event handler
|
512 |
| - data.$input.trigger( 'turnoff.rcSwitcher', data ); |
513 |
| - data.$input.trigger( 'toggle.rcSwitcher', [ data, 'turnoff' ] ); |
514 |
| - |
| 537 | + // Wait Transition 500ms Time |
| 538 | + setTimeout( function(){ |
| 539 | + data.$input.trigger( 'turnoff.rcSwitcher', data ); |
| 540 | + data.$input.trigger( 'toggle.rcSwitcher', [ data, 'turnoff' ] ); |
| 541 | + }, 500 ); |
515 | 542 | },
|
516 | 543 |
|
517 | 544 |
|
|
540 | 567 | if( !outsideChange )
|
541 | 568 | data.$input.prop( 'checked', true );
|
542 | 569 |
|
543 |
| - data.$input.trigger( 'turnon.rcSwitcher', data ); |
544 |
| - data.$input.trigger( 'toggle.rcSwitcher', [ data, 'turnon' ] ); |
| 570 | + // Wait Transition 500ms Time |
| 571 | + setTimeout( function(){ |
| 572 | + data.$input.trigger( 'turnon.rcSwitcher', data ); |
| 573 | + data.$input.trigger( 'toggle.rcSwitcher', [ data, 'turnon' ] ); |
| 574 | + }, 500 ); |
| 575 | + |
545 | 576 |
|
546 | 577 | },
|
547 | 578 |
|
|
565 | 596 |
|
566 | 597 |
|
567 | 598 | // On Click on switchers
|
568 |
| - switcherP.$switchers.on( 'click', function( e ){ |
569 |
| - // $switcher.on( 'click', function( e ){ |
570 |
| - |
571 |
| - // console.log( e.currentTarget ); |
| 599 | + switcherP.$switchers.on( 'click', function( e ) |
| 600 | + { |
572 | 601 | var obj = {};
|
573 | 602 |
|
574 | 603 | obj.type = e.currentTarget.getAttribute( 'input-type' );
|
575 | 604 | obj.name = e.currentTarget.getAttribute( 'input-name' );
|
576 | 605 | obj.value = e.currentTarget.getAttribute( 'input-value' );
|
577 | 606 |
|
578 |
| - // obj.type = $switcher.attr( 'input-type' ); |
579 |
| - // obj.name = $switcher.attr( 'input-name' ); |
580 |
| - // obj.value = $switcher.attr( 'input-value' ); |
581 |
| - |
582 | 607 | // Toggle
|
583 | 608 | this.toggle( obj, switcherP );
|
584 | 609 |
|
|
628 | 653 | // Filter this
|
629 | 654 | // Get Only Checkbox and Radio inputs only
|
630 | 655 |
|
631 |
| - switcherP.$this = this.filter( 'input[type=checkbox], input[type=radio]' ); |
| 656 | + switcherP.$this = this.filter( 'input[type=checkbox], input[type=radio]' ).not( '[data-has-rcswitcher]' ); |
632 | 657 |
|
633 | 658 | // Stop if we havenot any checkboxs or radios
|
634 | 659 | if( switcherP.$this.length == 0 )
|
635 |
| - return; |
| 660 | + return this; |
636 | 661 |
|
637 | 662 | switcherP.cssValues.dir = window.getComputedStyle( switcherP.$this[0], null ).direction || 'ltr';
|
638 | 663 |
|
|
672 | 697 | // Start
|
673 | 698 | switcherM.start( switcherP, options );
|
674 | 699 |
|
675 |
| - |
676 | 700 | // Return selected jquery object to allow chaining
|
677 | 701 | return this;
|
678 | 702 |
|
|
0 commit comments