|
1 | 1 | /* |
2 | | -* iziModal | v1.3.2 |
| 2 | +* iziModal | v1.3.3 |
3 | 3 | * http://izimodal.marcelodolce.com |
4 | 4 | * by Marcelo Dolce. |
5 | 5 | */ |
|
72 | 72 | index: null, |
73 | 73 | ids: [] |
74 | 74 | }; |
| 75 | + this.$element.attr('aria-hidden', 'true'); |
| 76 | + |
75 | 77 | if(this.group.name === undefined && options.group !== ""){ |
76 | 78 | this.group.name = options.group; |
77 | 79 | this.$element.attr('data-'+PLUGIN_NAME+'-group', options.group); |
|
85 | 87 | if(this.$element.attr('data-'+PLUGIN_NAME+'-icon') !== undefined){ |
86 | 88 | options.icon = this.$element.attr('data-'+PLUGIN_NAME+'-icon'); |
87 | 89 | } |
| 90 | + if(this.$element.attr('data-'+PLUGIN_NAME+'-iconText') !== undefined){ |
| 91 | + options.iconText = this.$element.attr('data-'+PLUGIN_NAME+'-iconText'); |
| 92 | + } |
88 | 93 | if(this.options.loop === true){ |
89 | 94 | this.$element.attr('data-'+PLUGIN_NAME+'-loop', true); |
90 | 95 | } |
|
120 | 125 | this.$element.css('border-bottom', '3px solid ' + options.headerColor + ''); |
121 | 126 | this.$header.css('background', this.options.headerColor); |
122 | 127 | } |
123 | | - if (options.icon !== null) { |
124 | | - this.$header.prepend('<i class="'+PLUGIN_NAME+'-header-icon ' + options.icon + '"></i>'); |
125 | | - this.$header.find('.'+PLUGIN_NAME+'-header-icon').css('color', options.iconColor); |
126 | | - } |
| 128 | + if (options.icon !== null || options.iconText !== null){ |
| 129 | + |
| 130 | + this.$header.prepend('<i class="'+PLUGIN_NAME+'-header-icon"></i>'); |
| 131 | + |
| 132 | + if (options.icon !== null) { |
| 133 | + this.$header.find('.'+PLUGIN_NAME+'-header-icon').addClass(options.icon).css('color', options.iconColor); |
| 134 | + } |
| 135 | + if (options.iconText !== null){ |
| 136 | + this.$header.find('.'+PLUGIN_NAME+'-header-icon').html(options.iconText); |
| 137 | + } |
| 138 | + } |
127 | 139 | this.$element.css('overflow', 'hidden').prepend(this.$header); |
128 | 140 | } |
129 | 141 |
|
|
142 | 154 | } |
143 | 155 |
|
144 | 156 | if(options.theme !== ""){ |
145 | | - this.$element.addClass(options.theme); |
| 157 | + if(options.theme === "light"){ |
| 158 | + this.$element.addClass(PLUGIN_NAME+"-light"); |
| 159 | + } else { |
| 160 | + this.$element.addClass(options.theme); |
| 161 | + } |
146 | 162 | } |
147 | 163 |
|
148 | | - this.$element.addClass(PLUGIN_NAME); |
149 | | - |
150 | 164 | if(options.openFullscreen === true){ |
151 | 165 | this.isFullscreen = true; |
152 | 166 | this.$element.addClass('isFullscreen'); |
|
240 | 254 |
|
241 | 255 | // console.info('[ '+PLUGIN_NAME+' | '+that.id+' ] Opened.'); |
242 | 256 |
|
243 | | - that.$element.trigger(STATES.OPENED); |
244 | 257 | that.state = STATES.OPENED; |
| 258 | + that.$element.trigger(STATES.OPENED); |
| 259 | + |
245 | 260 | if (that.options.onOpened && typeof(that.options.onOpened) === "function") { |
246 | 261 | that.options.onOpened(that); |
247 | 262 | } |
|
299 | 314 |
|
300 | 315 | bindEvents(); |
301 | 316 |
|
302 | | - this.$element.trigger(STATES.OPENING); |
303 | | - this.state = STATES.OPENING; |
304 | 317 | this.setGroup(); |
| 318 | + this.state = STATES.OPENING; |
| 319 | + this.$element.trigger(STATES.OPENING); |
| 320 | + this.$element.attr('aria-hidden', 'false'); |
305 | 321 |
|
306 | 322 | // console.info('[ '+PLUGIN_NAME+' | '+this.id+' ] Opening...'); |
307 | 323 |
|
|
329 | 345 | } |
330 | 346 |
|
331 | 347 | if (this.options.bodyOverflow || isMobile){ |
332 | | - $(document.body).css('overflow', 'hidden'); |
| 348 | + $('html').addClass(PLUGIN_NAME+'-isOverflow'); |
333 | 349 | } |
334 | 350 |
|
335 | | - if (that.options.onOpening && typeof(that.options.onOpening) === "function") { |
336 | | - that.options.onOpening(this); |
| 351 | + if (this.options.onOpening && typeof(this.options.onOpening) === "function") { |
| 352 | + this.options.onOpening(this); |
337 | 353 | } |
338 | 354 | (function open(){ |
339 | 355 |
|
|
476 | 492 | })(); |
477 | 493 |
|
478 | 494 | (function setUrlHash(){ |
479 | | - if(that.options.history || isMobile){ |
| 495 | + if(that.options.history){ |
480 | 496 | var oldTitle = document.title; |
481 | 497 | document.title = oldTitle + " - " + that.options.title; |
482 | 498 | document.location.hash = that.id; |
|
505 | 521 | } |
506 | 522 |
|
507 | 523 | if (that.options.bodyOverflow || isMobile){ |
508 | | - $(document.body).css('overflow', 'initial'); |
| 524 | + $('html').removeClass(PLUGIN_NAME+'-isOverflow'); |
509 | 525 | } |
510 | 526 |
|
511 | | - $(document.body).removeClass(PLUGIN_NAME+'-attached'); |
| 527 | + $('html').removeClass(PLUGIN_NAME+'-isAttached'); |
512 | 528 |
|
513 | | - that.$element.trigger(STATES.CLOSED); |
514 | 529 | that.state = STATES.CLOSED; |
| 530 | + that.$element.trigger(STATES.CLOSED); |
515 | 531 |
|
516 | 532 | // console.info('[ '+PLUGIN_NAME+' | '+that.id+' ] Closed.'); |
517 | 533 |
|
|
530 | 546 |
|
531 | 547 | this.state = STATES.CLOSING; |
532 | 548 | this.$element.trigger(STATES.CLOSING); |
| 549 | + this.$element.attr('aria-hidden', 'true'); |
533 | 550 |
|
534 | 551 | // console.info('[ '+PLUGIN_NAME+' | '+this.id+' ] Closing...'); |
535 | 552 |
|
|
718 | 735 |
|
719 | 736 | setIcon: function(icon){ |
720 | 737 |
|
721 | | - if (this.options.icon !== null) { |
722 | | - this.$header.find('.'+PLUGIN_NAME+'-header-icon').attr('class', PLUGIN_NAME+'-header-icon ' + icon); |
723 | | - this.options.icon = icon; |
| 738 | + console.log(this.$header.find('.'+PLUGIN_NAME+'-header-icon').length); |
| 739 | + |
| 740 | + if( this.$header.find('.'+PLUGIN_NAME+'-header-icon').length === 0 ){ |
| 741 | + this.$header.prepend('<i class="'+PLUGIN_NAME+'-header-icon"></i>'); |
724 | 742 | } |
| 743 | + this.$header.find('.'+PLUGIN_NAME+'-header-icon').attr('class', PLUGIN_NAME+'-header-icon ' + icon); |
| 744 | + this.options.icon = icon; |
| 745 | + }, |
| 746 | + |
| 747 | + setIconText: function(iconText){ |
| 748 | + |
| 749 | + this.$header.find('.'+PLUGIN_NAME+'-header-icon').html(iconText); |
| 750 | + this.options.iconText = iconText; |
725 | 751 | }, |
726 | 752 |
|
727 | 753 | setHeaderColor: function(headerColor){ |
|
792 | 818 | // Se a altura da janela é menor que o modal com iframe |
793 | 819 | if(windowHeight < (this.options.iframeHeight + this.headerHeight) || this.isFullscreen === true){ |
794 | 820 |
|
795 | | - $(document.body).addClass(PLUGIN_NAME+'-attached'); |
| 821 | + $('html').addClass(PLUGIN_NAME+'-isAttached'); |
796 | 822 |
|
797 | 823 | this.$element.find('.'+PLUGIN_NAME+'-iframe').css({ |
798 | 824 | 'height': parseInt(windowHeight - this.headerHeight) + 'px', |
799 | 825 | }); |
800 | 826 |
|
801 | 827 | } else { |
802 | | - $(document.body).removeClass(PLUGIN_NAME+'-attached'); |
| 828 | + $('html').removeClass(PLUGIN_NAME+'-isAttached'); |
803 | 829 |
|
804 | 830 | this.$element.find('.'+PLUGIN_NAME+'-iframe').css({ |
805 | 831 | 'height': parseInt(this.options.iframeHeight) + 'px', |
|
809 | 835 | } else { |
810 | 836 |
|
811 | 837 | if (windowHeight > (contentHeight + this.headerHeight) && this.isFullscreen !== true) { |
812 | | - $(document.body).removeClass(PLUGIN_NAME+'-attached'); |
| 838 | + $('html').removeClass(PLUGIN_NAME+'-isAttached'); |
813 | 839 | this.$element.find('.'+PLUGIN_NAME+'-wrap').css({'height': 'auto'}); |
814 | 840 | } |
815 | 841 |
|
816 | 842 | // subistuido (contentHeight + this.headerHeight) por this.$element.innerHeight() |
817 | 843 | // Se o modal é maior que a altura da janela ou |
818 | 844 | if ((contentHeight + this.headerHeight) > windowHeight || this.$element.innerHeight() < contentHeight || this.isFullscreen === true) { |
819 | 845 |
|
820 | | - if( !$(document.body).hasClass(PLUGIN_NAME+'-attached') ){ |
821 | | - $(document.body).addClass(PLUGIN_NAME+'-attached'); |
| 846 | + if( !$('html').hasClass(PLUGIN_NAME+'-isAttached') ){ |
| 847 | + $('html').addClass(PLUGIN_NAME+'-isAttached'); |
822 | 848 | } |
823 | 849 |
|
824 | 850 | this.$element.find('.'+PLUGIN_NAME+'-wrap').css({ |
|
849 | 875 |
|
850 | 876 | $window.off('hashchange load').on('hashchange load', function(e) { |
851 | 877 |
|
| 878 | + var modalHash = document.location.hash; |
| 879 | + |
852 | 880 | if(autoOpenModal === 0){ |
853 | 881 |
|
854 | | - if(document.location.hash !== ""){ |
| 882 | + if(modalHash !== ""){ |
855 | 883 |
|
856 | 884 | $.each( $('.'+PLUGIN_NAME) , function(index, modal) { |
857 | 885 | var state = $(modal).iziModal('getState'); |
858 | 886 | if(state == 'opened' || state == 'opening'){ |
859 | 887 |
|
860 | | - if( "#" + $(modal).attr('id') !== document.location.hash){ |
| 888 | + if( "#" + $(modal).attr('id') !== modalHash){ |
861 | 889 | $(modal).iziModal('close'); |
862 | 890 | } |
863 | 891 | } |
864 | 892 | }); |
865 | 893 |
|
866 | | - setTimeout(function(){ |
867 | | - $(document.location.hash).iziModal("open"); |
868 | | - },200); |
| 894 | + var data = $(modalHash).data(); |
| 895 | + |
| 896 | + if(e.type === 'load'){ |
| 897 | + if(data.iziModal.options.autoOpen !== false){ |
| 898 | + $(modalHash).iziModal("open"); |
| 899 | + } |
| 900 | + } else { |
| 901 | + setTimeout(function(){ |
| 902 | + $(modalHash).iziModal("open"); |
| 903 | + },200); |
| 904 | + } |
869 | 905 |
|
870 | 906 | } else { |
871 | 907 |
|
|
933 | 969 |
|
934 | 970 | $.fn[PLUGIN_NAME] = function(option, args) { |
935 | 971 |
|
936 | | - var $this = $(this), |
937 | | - data = $this.data(PLUGIN_NAME), |
938 | | - options = $.extend({}, $.fn.iziModal.defaults, $this.data(), typeof option == 'object' && option); |
| 972 | + var objs = this; |
| 973 | + |
| 974 | + for (var i=0; i<objs.length; i++) { |
| 975 | + |
| 976 | + var $this = $(objs[i]); |
| 977 | + var data = $this.data(PLUGIN_NAME); |
| 978 | + var options = $.extend({}, $.fn[PLUGIN_NAME].defaults, $this.data(), typeof option == 'object' && option); |
939 | 979 |
|
940 | | - if (!data && (!option || typeof option == 'object')){ |
| 980 | + if (!data && (!option || typeof option == 'object')){ |
941 | 981 |
|
942 | | - $this.data(PLUGIN_NAME, (data = new iziModal(this, options))); |
943 | | - } |
944 | | - else if (typeof option == 'string' && typeof data != 'undefined'){ |
| 982 | + $this.data(PLUGIN_NAME, (data = new iziModal($this, options))); |
| 983 | + } |
| 984 | + else if (typeof option == 'string' && typeof data != 'undefined'){ |
945 | 985 |
|
946 | | - return data[option].apply(data, [].concat(args)); |
947 | | - } |
| 986 | + return data[option].apply(data, [].concat(args)); |
| 987 | + } |
| 988 | + if (options.autoOpen){ // Automatically open the modal if autoOpen setted true or ms |
948 | 989 |
|
949 | | - if (options.autoOpen){ // Automatically open the modal if autoOpen setted true |
| 990 | + if( !isNaN(parseInt(options.autoOpen)) ){ |
| 991 | + |
| 992 | + setTimeout(function(){ |
| 993 | + data.open(); |
| 994 | + }, options.autoOpen); |
950 | 995 |
|
951 | | - if( !isNaN(parseInt(options.autoOpen)) ){ |
952 | | - |
953 | | - setTimeout(function(){ |
| 996 | + } else if(options.autoOpen === true ) { |
954 | 997 | data.open(); |
955 | | - }, options.autoOpen); |
956 | | - |
957 | | - } else if(options.autoOpen === true ) { |
958 | | - data.open(); |
| 998 | + } |
| 999 | + autoOpenModal++; |
959 | 1000 | } |
960 | | - autoOpenModal++; |
961 | 1001 | } |
| 1002 | + |
962 | 1003 | return this; |
963 | 1004 | }; |
964 | 1005 |
|
|
968 | 1009 | headerColor: '#88A0B9', |
969 | 1010 | theme: '', // light |
970 | 1011 | attached: '', // bottom, top |
971 | | - icon: '', |
| 1012 | + icon: null, |
| 1013 | + iconText: null, |
972 | 1014 | iconColor: '', |
973 | 1015 | width: 600, |
974 | 1016 | padding: 0, |
|
0 commit comments