OSDN Git Service

WordPressテンプレート使用ショップデモデータ追加。
[magic3/magic3.git] / templates / shop-isle / assets / js / custom.js
1 (function($){
2
3         /* ---------------------------------------------- /*
4          * Preloader
5         /* ---------------------------------------------- */
6
7         $(window).load(function() {
8                 $('.loader').fadeOut();
9                 $('.page-loader').delay(350).fadeOut('slow');
10         });
11
12         $(document).ready(function() {
13
14                 /* ---------------------------------------------- /*
15                  * Initialization General Scripts for all pages
16                 /* ---------------------------------------------- */
17
18                 var homeSection = $('.home-section'),
19                         navbar      = $('.navbar-custom'),
20                         navHeight   = navbar.height(),
21                         width       = Math.max($(window).width(), window.innerWidth),
22                         mobileTest;
23
24                 if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
25                         mobileTest = true;
26                 }
27
28                 buildHomeSection(homeSection);
29                 navbarAnimation(navbar, homeSection, navHeight);
30                 navbarSubmenu(width);
31                 hoverDropdown(width, mobileTest);
32
33                 $(window).resize(function() {
34                         var width = Math.max($(window).width(), window.innerWidth);
35                         buildHomeSection(homeSection);
36                         hoverDropdown(width, mobileTest);
37                 });
38
39                 $(window).scroll(function() {
40                         effectsHomeSection(homeSection, this);
41                         navbarAnimation(navbar, homeSection, navHeight);
42                 });
43
44                 /* ---------------------------------------------- /*
45                  * Home section height
46                 /* ---------------------------------------------- */
47
48                 function buildHomeSection(homeSection) {
49                         if (homeSection.length > 0) {
50                                 if (homeSection.hasClass('home-full-height')) {
51                                         homeSection.height($(window).height());
52                                 } else {
53                                         if ( !homeSection.hasClass('home-slider-plugin') ) {
54                                                 homeSection.height($(window).height() * 0.85);
55                                         }
56                                 }
57                         } else {
58                                 if( $('body.home' ).length>0 && homeSection.length<1 ) {
59                                         //$('.main').css('margin-top', $('.navbar-custom').outerHeight() );
60                                 }
61                         }
62                 }
63
64                 /* ---------------------------------------------- /*
65                  * Home section effects
66                 /* ---------------------------------------------- */
67
68                 function effectsHomeSection(homeSection, scrollTopp) {
69                         if (homeSection.length > 0) {
70                                 var homeSHeight = homeSection.height();
71                                 var topScroll = $(document).scrollTop();
72                                 if ( ( homeSection.hasClass( 'home-parallax' ) ) && ( $( scrollTopp ).scrollTop() <= homeSHeight ) ) {
73                                         $( '.home-slider-overlay' ).css( 'opacity', ( 0.3 + 0.7 * topScroll / $(window).height() ) );
74                                 }
75                                 if (homeSection.hasClass('home-fade') && ($(scrollTopp).scrollTop() <= homeSHeight)) {
76                                         var caption = $('.caption-content');
77                                         caption.css('opacity', (1 - topScroll/homeSection.height() * 1));
78                                 }
79                         }
80                 }
81
82                 /* ---------------------------------------------- /*
83                  * Intro slider setup
84                 /* ---------------------------------------------- */
85
86                 if( $('.hero-slider').length > 0 ) {
87                         $('.hero-slider').flexslider( {
88                                 animation: 'fade',
89                                 animationSpeed: 1000,
90                                 animationLoop: true,
91                                 prevText: '',
92                                 nextText: '',
93                                 before: function(slider) {
94                                         $('.hs-caption').fadeOut().animate({top:'-80px'},{queue:false, easing: 'swing', duration: 700});
95                                         slider.slides.eq(slider.currentSlide).delay(500);
96                                         slider.slides.eq(slider.animatingTo).delay(500);
97                                 },
98                                 after: function() {
99                                         $('.hs-caption').fadeIn().animate({top:'0'},{queue:false, easing: 'swing', duration: 700});
100                                 },
101                                 useCSS: true
102                         });
103                 }
104
105                 /* ---------------------------------------------- /*
106                  * Youtube video background
107                 /* ---------------------------------------------- */
108
109                 $(function(){
110                         $('.video-player').mb_YTPlayer();
111                 });
112
113                 $('#video-play').click(function(event) {
114                         event.preventDefault();
115                         if ($(this).hasClass('fa-play')) {
116                                 $('.video-player').playYTP();
117                         } else {
118                                 $('.video-player').pauseYTP();
119                         }
120                         $(this).toggleClass('fa-play fa-pause');
121                         return false;
122                 });
123
124                 $('#video-volume').click(function(event) {
125                         event.preventDefault();
126                         $('.video-player').toggleVolume();
127                         $(this).toggleClass('fa-volume-off fa-volume-up');
128                         return false;
129                 });
130
131                 /* ---------------------------------------------- /*
132                  * Transparent navbar animation
133                 /* ---------------------------------------------- */
134
135                 function navbarAnimation(navbar, homeSection, navHeight) {
136
137                         var topScroll = $(window).scrollTop();
138                         if (navbar.length > 0 && homeSection.length > 0) {
139                                 if(topScroll >= navHeight) {
140                                         navbar.removeClass('navbar-transparent');
141                                 } else {
142                                         navbar.addClass('navbar-transparent');
143                                 }
144                         } else {
145                                 navbar.removeClass('navbar-transparent');
146                         }
147                 }
148
149                 /* ---------------------------------------------- /*
150                  * Navbar submenu
151                 /* ---------------------------------------------- */
152
153                 function navbarSubmenu(width) {
154                         if (width > 767) {
155                                 $('.navbar-custom .navbar-nav > li.menu-item-has-children').on('click mouseover', function() {
156                                         var MenuLeftOffset  = $('.sub-menu', $(this)).offset().left;
157                                         var Menu1LevelWidth = $('.sub-menu', $(this)).width();
158                                         if (width - MenuLeftOffset < Menu1LevelWidth * 2) {
159                                                 $(this).children('.sub-menu').addClass('leftauto');
160                                         } else {
161                                                 $(this).children('.sub-menu').removeClass('leftauto');
162                                         }
163                                         if ($('.menu-item-has-children', $(this)).length > 0) {
164                                                 var Menu2LevelWidth = $('.sub-menu', $(this)).width();
165                                                 if (width - MenuLeftOffset - Menu1LevelWidth < Menu2LevelWidth) {
166                                                         $(this).children('.sub-menu').addClass('left-side');
167                                                 } else {
168                                                         $(this).children('.sub-menu').removeClass('left-side');
169                                                 }
170                                         }
171                                 });
172                         }
173                 }
174
175                 /* ---------------------------------------------- /*
176                  * Navbar hover dropdown on desctop
177                 /* ---------------------------------------------- */
178
179                 function hoverDropdown(width, mobileTest) {
180                         if ((width > 767) && (mobileTest !== true)) {
181                                 $('.navbar-custom .navbar-nav > li, .navbar-custom li.dropdown > ul > li').removeClass('open');
182                                 var delay = 0;
183                                 var setTimeoutConst;
184                                 $('.navbar-custom .navbar-nav > li, .navbar-custom li > ul > li').hover(function() {
185                                         var $this = $(this);
186                                         setTimeoutConst = setTimeout(function() {
187                                                 $this.addClass('open');
188                                                 $this.find('.dropdown-toggle').addClass('disabled');
189                                         }, delay);
190                                 },
191                                 function() {
192                                         clearTimeout(setTimeoutConst);
193                                         $(this).removeClass('open');
194                                         $(this).find('.dropdown-toggle').removeClass('disabled');
195                                 });
196                         } else {
197                                 $('.navbar-custom .navbar-nav > li, .navbar-custom li > ul > li').unbind('mouseenter mouseleave');
198                                 $('.navbar-custom [data-toggle=dropdown]').not('.binded').addClass('binded').on('click', function(event) {
199                                         event.preventDefault();
200                                         event.stopPropagation();
201                                         $(this).parent().siblings().removeClass('open');
202                                         $(this).parent().siblings().find('[data-toggle=dropdown]').parent().removeClass('open');
203                                         $(this).parent().toggleClass('open');
204                                 });
205                         }
206                 }
207
208                 /* ---------------------------------------------- /*
209                  * Navbar collapse on click
210                 /* ---------------------------------------------- */
211
212                 $(document).on('click','.navbar-collapse.in',function(e) {
213             if( $(e.target).is('a') && $(e.target).attr('class') !== 'dropdown-toggle' && !$('body').hasClass('mega-menu-primary') ) {
214                                 $(this).collapse('hide');
215                         }
216                 });
217
218                 /* ---------------------------------------------- /*
219                  * Set sections backgrounds
220                 /* ---------------------------------------------- */
221
222                 var module = $('.home-section, .module, .module-small, .side-image');
223                 module.each(function() {
224                         if ($(this).attr('data-background')) {
225                                 $(this).css('background-image', 'url(' + $(this).attr('data-background') + ')');
226                         }
227                 });
228
229                 /* ---------------------------------------------- /*
230                  * Testimonials, Post sliders
231                 /* ---------------------------------------------- */
232
233                 if ($('.testimonials-slider').length > 0 ) {
234                         $('.testimonials-slider').flexslider( {
235                                 animation: 'slide',
236                                 smoothHeight: true,
237                         });
238                 }
239
240                 $('.post-images-slider').flexslider( {
241                         animation: 'slide',
242                         smoothHeight: true,
243                 });
244
245                 /* ---------------------------------------------- /*
246                  * Owl slider
247                 /* ---------------------------------------------- */
248
249                 $('.owl-carousel').each(function() {
250
251                         // Check items number
252                         var items;
253                         if ($(this).data('items') > 0) {
254                                 items = $(this).data('items');
255                         } else {
256                                 items = 4;
257                         }
258
259                         // Check pagination true/false
260                         var pagination;
261                         if (($(this).data('pagination') > 0) && ($(this).data('pagination') === true)) {
262                                 pagination = true;
263                         } else {
264                                 pagination = false;
265                         }
266
267                         // Check navigation true/false
268                         var navigation;
269                         if (($(this).data('navigation') > 0) && ($(this).data('navigation') === true)) {
270                                 navigation = true;
271                         } else {
272                                 navigation = false;
273                         }
274
275             // Check rtl true/false
276             var rtl;
277             if (($(this).data('rtl') > 0) && ($(this).data('rtl') === true)) {
278                 rtl = true;
279             } else {
280                 rtl = false;
281             }
282
283                         // Build carousel
284                         $(this).owlCarousel( {
285                 loop:true,
286                 autoplay:true,
287                 autoplayTimeout:5000,
288                 autoplayHoverPause:true,
289                 dots: pagination,
290                 dotsSpeed: 400,
291                 items: items,
292                 rtl: rtl,
293                 nav: false,
294                 navText: ['', ''],
295                                 responsiveClass:true,
296                                 responsive:{
297                                         0:{
298                                                 items:1,
299                                         },
300                                         600:{
301                                                 items:3,
302                                         },
303                                         1000:{
304                                                 items:5,
305                                         }
306                                 }
307                         });
308
309                 });
310
311                 /* ---------------------------------------------- /*
312                  * Video popup, Gallery
313                 /* ---------------------------------------------- */
314
315                 $('.video-pop-up').magnificPopup({
316                         type: 'iframe',
317                 });
318
319                 $('a.gallery').magnificPopup({
320                         type: 'image',
321                         gallery: {
322                                 enabled: true,
323                                 navigateByImgClick: true,
324                                 preload: [0,1]
325                         },
326                         image: {
327                                 titleSrc: 'title',
328                                 tError: 'The image could not be loaded.',
329                         }
330                 });
331
332                 /* ---------------------------------------------- /*
333                  * A jQuery plugin for fluid width video embeds
334                 /* ---------------------------------------------- */
335
336                 $('body').fitVids();
337
338                 /* ---------------------------------------------- /*
339                  * Open tabs by external link
340                 /* ---------------------------------------------- */
341
342                 $('.open-tab').click(function (e) {
343                         var pattern = /#.+/gi;
344                         var contentID = e.target.toString().match(pattern)[0];
345                         $('.nav-tabs a[href="' + contentID + '"]').tab('show');
346                 });
347
348                 /* ---------------------------------------------- /*
349                  * Scroll Animation
350                 /* ---------------------------------------------- */
351
352                 $('.section-scroll').bind('click', function(e) {
353                         var anchor = $(this);
354                         $('html, body').stop().animate({
355                                 scrollTop: $(anchor.attr('href')).offset().top - 50
356                         }, 1000);
357                         e.preventDefault();
358                 });
359
360                 /* ---------------------------------------------- /*
361                  * Scroll top
362                 /* ---------------------------------------------- */
363
364                 $(window).scroll(function() {
365                         if ($(this).scrollTop() > 100) {
366                                 $('.scroll-up').fadeIn();
367                         } else {
368                                 $('.scroll-up').fadeOut();
369                         }
370                 });
371
372                 $('a[href="#totop"]').click(function() {
373                         $('html, body').animate({ scrollTop: 0 }, 'slow');
374                         return false;
375                 });
376                 
377                 /* ---------------------------------------------- /*
378                  * Dropdown mennu on tablet
379                  /* ---------------------------------------------- */
380
381                 var $menuBtnChildren = $('.menu-item-has-children'),
382                         submenuOpenClass = 'open',
383                         $thisParent,
384                         $menuWrap = $('.header-menu-wrap');
385                 $menuBtnChildren.click(function(event){
386                         if( mobileTest && !$(this).hasClass(submenuOpenClass) && window.innerWidth > 767 ) {
387                                 $thisParent = $(this).parent('ul').parent('li');
388                                 if( $thisParent.hasClass(submenuOpenClass) ){
389                                         $thisParent.find('.'+submenuOpenClass).removeClass(submenuOpenClass);
390                                 } else {
391                                         $menuWrap.find('.'+submenuOpenClass).removeClass(submenuOpenClass);
392                                 }
393                                 $(this).addClass(submenuOpenClass);
394                                 event.stopPropagation();
395                                 return false;
396                         }
397                 });
398
399                 $('html,body,.main,.navbar-custom,.bottom-page-wrap').click(function(){
400                         $menuWrap.find('.'+submenuOpenClass).removeClass(submenuOpenClass);
401                 });
402
403         /* Visible arrow on mobile */
404                 if( mobileTest === true && $( '.flex-direction-nav' ).length>0 && $( 'ul.slides > li' ).length>1 ) {
405             $('.flex-direction-nav').addClass('visible-arrow');
406         }
407
408         });
409
410         $('#review_form form :input').each(function(index, elem) {
411                 var eId = $(elem).attr('id');
412                 var label = null;
413                 if (eId && (label = $(elem).parents('form').find('label[for='+eId+']')).length === 1) {
414                         $(elem).attr('placeholder', $(label).text());
415                         $(label).remove();
416                 }
417         });
418
419         $('#map').click(function(event){
420         $('.shop_isle_pro_map_overlay').css('display','none');
421         event.stopPropagation();
422     });
423     
424     $('html').click(function(){
425         $('.shop_isle_pro_map_overlay').css('display','block');
426     });
427
428         if(typeof $('.wr-megamenu-container') !== 'undefined') {
429                 $('.wr-megamenu-container').addClass('bg-tr');
430         }
431
432     var isMobile = {
433         Android: function() {
434             return navigator.userAgent.match(/Android/i);
435         },
436         BlackBerry: function() {
437             return navigator.userAgent.match(/BlackBerry/i);
438         },
439         iOS: function() {
440             return navigator.userAgent.match(/iPhone|iPad|iPod/i);
441         },
442         Opera: function() {
443             return navigator.userAgent.match(/Opera Mini/i);
444         },
445         Windows: function() {
446             return navigator.userAgent.match(/IEMobile/i);
447         },
448         any: function() {
449             return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
450         }
451     };
452     if( isMobile.iOS() ) {
453         $( '#ribbon' ).addClass( 'ribbon-ios' );
454     }
455
456         if( isMobile.Windows() && $( '.navbar-cart' ).length > 0 ) {
457                 $( '.navbar-header' ).css({
458                         'float': 'left',
459                         'padding-left': '100px',
460                         'margin-left': '-100px',
461                 });
462         }
463
464 })(jQuery);