Created
August 20, 2015 00:55
-
-
Save fulv/38ab213eeac3b16adec6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// page init | |
jQuery(function(){ | |
initCustomForms(); | |
initTouchNav(); | |
initCarousel(); | |
initOpenClose(); | |
initAccordion(); | |
initMobileNav(); | |
initBackgroundResize(); | |
initSameHeight(); | |
initFitVids(); | |
jQuery('input, textarea').placeholder(); | |
}); | |
// initialize custom form elements | |
function initCustomForms() { | |
jcf.replaceAll(); | |
} | |
// scroll gallery init | |
function initCarousel() { | |
jQuery('div.carousel').scrollGallery({ | |
mask: 'div.mask', | |
slider: 'div.slideset', | |
slides: 'div.slide', | |
btnPrev: 'a.btn-prev', | |
btnNext: 'a.btn-next', | |
pagerLinks: '.pagination li', | |
stretchSlideToMask: true, | |
maskAutoSize: true, | |
autoRotation: false, | |
switchTime: 3000, | |
animSpeed: 500, | |
step: 1 | |
}); | |
} | |
// open-close init | |
function initOpenClose() { | |
jQuery('.advance-block').openClose({ | |
activeClass: 'active', | |
opener: '.search-opener', | |
slider: '.search-slide', | |
animSpeed: 400, | |
effect: 'slide' | |
}); | |
} | |
// accordion menu init | |
function initAccordion() { | |
jQuery('.accordion').slideAccordion({ | |
opener: 'a.opener', | |
slider: '.slide', | |
animSpeed: 300 | |
}); | |
} | |
// mobile menu init | |
function initMobileNav() { | |
jQuery('body').mobileNav({ | |
menuActiveClass: 'nav-active', | |
menuOpener: '.nav-opener' | |
}); | |
} | |
// stretch background to fill blocks | |
function initBackgroundResize() { | |
jQuery('.bg-stretch').each(function() { | |
ImageStretcher.add({ | |
container: this, | |
image: 'img' | |
}); | |
}); | |
} | |
// align blocks height | |
function initSameHeight() { | |
jQuery('div.columns-holder').sameHeight({ | |
elements: 'div.column', | |
multiLine: true, | |
biggestHeight: true | |
}); | |
} | |
// handle flexible video size | |
function initFitVids() { | |
jQuery('.video-area').fitVids(); | |
} | |
// handle dropdowns on mobile devices | |
function initTouchNav() { | |
jQuery('#nav').each(function(){ | |
new TouchNav({ | |
navBlock: this | |
}); | |
}); | |
} | |
/* | |
* jQuery Carousel plugin | |
*/ | |
;(function($){ | |
function ScrollGallery(options) { | |
this.options = $.extend({ | |
mask: 'div.mask', | |
slider: '>*', | |
slides: '>*', | |
activeClass:'active', | |
disabledClass:'disabled', | |
btnPrev: 'a.btn-prev', | |
btnNext: 'a.btn-next', | |
generatePagination: false, | |
pagerList: '<ul>', | |
pagerListItem: '<li><a href="#"></a></li>', | |
pagerListItemText: 'a', | |
pagerLinks: '.pagination li', | |
currentNumber: 'span.current-num', | |
totalNumber: 'span.total-num', | |
btnPlay: '.btn-play', | |
btnPause: '.btn-pause', | |
btnPlayPause: '.btn-play-pause', | |
galleryReadyClass: 'gallery-js-ready', | |
autorotationActiveClass: 'autorotation-active', | |
autorotationDisabledClass: 'autorotation-disabled', | |
stretchSlideToMask: false, | |
circularRotation: true, | |
disableWhileAnimating: false, | |
autoRotation: false, | |
pauseOnHover: isTouchDevice ? false : true, | |
maskAutoSize: false, | |
switchTime: 4000, | |
animSpeed: 600, | |
event:'click', | |
swipeThreshold: 15, | |
handleTouch: true, | |
vertical: false, | |
useTranslate3D: false, | |
step: false | |
}, options); | |
this.init(); | |
} | |
ScrollGallery.prototype = { | |
init: function() { | |
if(this.options.holder) { | |
this.findElements(); | |
this.attachEvents(); | |
this.refreshPosition(); | |
this.refreshState(true); | |
this.resumeRotation(); | |
this.makeCallback('onInit', this); | |
} | |
}, | |
findElements: function() { | |
// define dimensions proporties | |
this.fullSizeFunction = this.options.vertical ? 'outerHeight' : 'outerWidth'; | |
this.innerSizeFunction = this.options.vertical ? 'height' : 'width'; | |
this.slideSizeFunction = 'outerHeight'; | |
this.maskSizeProperty = 'height'; | |
this.animProperty = this.options.vertical ? 'marginTop' : 'marginLeft'; | |
// control elements | |
this.gallery = $(this.options.holder).addClass(this.options.galleryReadyClass); | |
this.mask = this.gallery.find(this.options.mask); | |
this.slider = this.mask.find(this.options.slider); | |
this.slides = this.slider.find(this.options.slides); | |
this.btnPrev = this.gallery.find(this.options.btnPrev); | |
this.btnNext = this.gallery.find(this.options.btnNext); | |
this.currentStep = 0; this.stepsCount = 0; | |
// get start index | |
if(this.options.step === false) { | |
var activeSlide = this.slides.filter('.'+this.options.activeClass); | |
if(activeSlide.length) { | |
this.currentStep = this.slides.index(activeSlide); | |
} | |
} | |
// calculate offsets | |
this.calculateOffsets(); | |
// create gallery pagination | |
if(typeof this.options.generatePagination === 'string') { | |
this.pagerLinks = $(); | |
this.buildPagination(); | |
} else { | |
this.pagerLinks = this.gallery.find(this.options.pagerLinks); | |
this.attachPaginationEvents(); | |
} | |
// autorotation control buttons | |
this.btnPlay = this.gallery.find(this.options.btnPlay); | |
this.btnPause = this.gallery.find(this.options.btnPause); | |
this.btnPlayPause = this.gallery.find(this.options.btnPlayPause); | |
// misc elements | |
this.curNum = this.gallery.find(this.options.currentNumber); | |
this.allNum = this.gallery.find(this.options.totalNumber); | |
}, | |
attachEvents: function() { | |
// bind handlers scope | |
var self = this; | |
this.bindHandlers(['onWindowResize']); | |
$(window).bind('load resize orientationchange', this.onWindowResize); | |
// previous and next button handlers | |
if(this.btnPrev.length) { | |
this.prevSlideHandler = function(e) { | |
e.preventDefault(); | |
self.prevSlide(); | |
}; | |
this.btnPrev.bind(this.options.event, this.prevSlideHandler); | |
} | |
if(this.btnNext.length) { | |
this.nextSlideHandler = function(e) { | |
e.preventDefault(); | |
self.nextSlide(); | |
}; | |
this.btnNext.bind(this.options.event, this.nextSlideHandler); | |
} | |
// pause on hover handling | |
if(this.options.pauseOnHover && !isTouchDevice) { | |
this.hoverHandler = function() { | |
if(self.options.autoRotation) { | |
self.galleryHover = true; | |
self.pauseRotation(); | |
} | |
}; | |
this.leaveHandler = function() { | |
if(self.options.autoRotation) { | |
self.galleryHover = false; | |
self.resumeRotation(); | |
} | |
}; | |
this.gallery.bind({mouseenter: this.hoverHandler, mouseleave: this.leaveHandler}); | |
} | |
// autorotation buttons handler | |
if(this.btnPlay.length) { | |
this.btnPlayHandler = function(e) { | |
e.preventDefault(); | |
self.startRotation(); | |
}; | |
this.btnPlay.bind(this.options.event, this.btnPlayHandler); | |
} | |
if(this.btnPause.length) { | |
this.btnPauseHandler = function(e) { | |
e.preventDefault(); | |
self.stopRotation(); | |
}; | |
this.btnPause.bind(this.options.event, this.btnPauseHandler); | |
} | |
if(this.btnPlayPause.length) { | |
this.btnPlayPauseHandler = function(e) { | |
e.preventDefault(); | |
if(!self.gallery.hasClass(self.options.autorotationActiveClass)) { | |
self.startRotation(); | |
} else { | |
self.stopRotation(); | |
} | |
}; | |
this.btnPlayPause.bind(this.options.event, this.btnPlayPauseHandler); | |
} | |
// enable hardware acceleration | |
if(isTouchDevice && this.options.useTranslate3D) { | |
this.slider.css({'-webkit-transform': 'translate3d(0px, 0px, 0px)'}); | |
} | |
// swipe event handling | |
if(isTouchDevice && this.options.handleTouch && window.Hammer && this.mask.length) { | |
this.swipeHandler = new Hammer.Manager(this.mask[0]); | |
this.swipeHandler.add(new Hammer.Pan({ | |
direction: self.options.vertical ? Hammer.DIRECTION_VERTICAL : Hammer.DIRECTION_HORIZONTAL, | |
threshold: self.options.swipeThreshold | |
})); | |
this.swipeHandler.on('panstart', function() { | |
if(self.galleryAnimating) { | |
self.swipeHandler.stop(); | |
} else { | |
self.pauseRotation(); | |
self.originalOffset = parseFloat(self.slider.css(self.animProperty)); | |
} | |
}).on('panmove', function(e) { | |
var tmpOffset = self.originalOffset + e[self.options.vertical ? 'deltaY' : 'deltaX']; | |
tmpOffset = Math.max(Math.min(0, tmpOffset), self.maxOffset); | |
self.slider.css(self.animProperty, tmpOffset); | |
}).on('panend', function(e) { | |
self.resumeRotation(); | |
if(e.distance > self.options.swipeThreshold) { | |
if(e.offsetDirection === Hammer.DIRECTION_RIGHT || e.offsetDirection === Hammer.DIRECTION_DOWN) { | |
self.nextSlide(); | |
} else { | |
self.prevSlide(); | |
} | |
} else { | |
self.switchSlide(); | |
} | |
}); | |
} | |
}, | |
onWindowResize: function() { | |
if(!this.galleryAnimating) { | |
this.calculateOffsets(); | |
this.refreshPosition(); | |
this.buildPagination(); | |
this.refreshState(); | |
this.resizeQueue = false; | |
} else { | |
this.resizeQueue = true; | |
} | |
}, | |
refreshPosition: function() { | |
this.currentStep = Math.min(this.currentStep, this.stepsCount - 1); | |
this.tmpProps = {}; | |
this.tmpProps[this.animProperty] = this.getStepOffset(); | |
this.slider.stop().css(this.tmpProps); | |
}, | |
calculateOffsets: function() { | |
var self = this, tmpOffset, tmpStep; | |
if(this.options.stretchSlideToMask) { | |
var tmpObj = {}; | |
tmpObj[this.innerSizeFunction] = this.mask[this.innerSizeFunction](); | |
this.slides.css(tmpObj); | |
} | |
this.maskSize = this.mask[this.innerSizeFunction](); | |
this.sumSize = this.getSumSize(); | |
this.maxOffset = this.maskSize - this.sumSize; | |
// vertical gallery with single size step custom behavior | |
if(this.options.vertical && this.options.maskAutoSize) { | |
this.options.step = 1; | |
this.stepsCount = this.slides.length; | |
this.stepOffsets = [0]; | |
tmpOffset = 0; | |
for(var i = 0; i < this.slides.length; i++) { | |
tmpOffset -= $(this.slides[i])[this.fullSizeFunction](true); | |
this.stepOffsets.push(tmpOffset); | |
} | |
this.maxOffset = tmpOffset; | |
return; | |
} | |
// scroll by slide size | |
if(typeof this.options.step === 'number' && this.options.step > 0) { | |
this.slideDimensions = []; | |
this.slides.each($.proxy(function(ind, obj){ | |
self.slideDimensions.push( $(obj)[self.fullSizeFunction](true) ); | |
},this)); | |
// calculate steps count | |
this.stepOffsets = [0]; | |
this.stepsCount = 1; | |
tmpOffset = tmpStep = 0; | |
while(tmpOffset > this.maxOffset) { | |
tmpOffset -= this.getSlideSize(tmpStep, tmpStep + this.options.step); | |
tmpStep += this.options.step; | |
this.stepOffsets.push(Math.max(tmpOffset, this.maxOffset)); | |
this.stepsCount++; | |
} | |
} | |
// scroll by mask size | |
else { | |
// define step size | |
this.stepSize = this.maskSize; | |
// calculate steps count | |
this.stepsCount = 1; | |
tmpOffset = 0; | |
while(tmpOffset > this.maxOffset) { | |
tmpOffset -= this.stepSize; | |
this.stepsCount++; | |
} | |
} | |
}, | |
getSumSize: function() { | |
var sum = 0; | |
this.slides.each($.proxy(function(ind, obj){ | |
sum += $(obj)[this.fullSizeFunction](true); | |
},this)); | |
this.slider.css(this.innerSizeFunction, sum); | |
return sum; | |
}, | |
getStepOffset: function(step) { | |
step = step || this.currentStep; | |
if(typeof this.options.step === 'number') { | |
return this.stepOffsets[this.currentStep]; | |
} else { | |
return Math.min(0, Math.max(-this.currentStep * this.stepSize, this.maxOffset)); | |
} | |
}, | |
getSlideSize: function(i1, i2) { | |
var sum = 0; | |
for(var i = i1; i < Math.min(i2, this.slideDimensions.length); i++) { | |
sum += this.slideDimensions[i]; | |
} | |
return sum; | |
}, | |
buildPagination: function() { | |
if(typeof this.options.generatePagination === 'string') { | |
if(!this.pagerHolder) { | |
this.pagerHolder = this.gallery.find(this.options.generatePagination); | |
} | |
if(this.pagerHolder.length && this.oldStepsCount != this.stepsCount) { | |
this.oldStepsCount = this.stepsCount; | |
this.pagerHolder.empty(); | |
this.pagerList = $(this.options.pagerList).appendTo(this.pagerHolder); | |
for(var i = 0; i < this.stepsCount; i++) { | |
$(this.options.pagerListItem).appendTo(this.pagerList).find(this.options.pagerListItemText).text(i+1); | |
} | |
this.pagerLinks = this.pagerList.children(); | |
this.attachPaginationEvents(); | |
} | |
} | |
}, | |
attachPaginationEvents: function() { | |
var self = this; | |
this.pagerLinksHandler = function(e) { | |
e.preventDefault(); | |
self.numSlide(self.pagerLinks.index(e.currentTarget)); | |
}; | |
this.pagerLinks.bind(this.options.event, this.pagerLinksHandler); | |
}, | |
prevSlide: function() { | |
if(!(this.options.disableWhileAnimating && this.galleryAnimating)) { | |
if(this.currentStep > 0) { | |
this.currentStep--; | |
this.switchSlide(); | |
} else if(this.options.circularRotation) { | |
this.currentStep = this.stepsCount - 1; | |
this.switchSlide(); | |
} | |
} | |
}, | |
nextSlide: function(fromAutoRotation) { | |
if(!(this.options.disableWhileAnimating && this.galleryAnimating)) { | |
if(this.currentStep < this.stepsCount - 1) { | |
this.currentStep++; | |
this.switchSlide(); | |
} else if(this.options.circularRotation || fromAutoRotation === true) { | |
this.currentStep = 0; | |
this.switchSlide(); | |
} | |
} | |
}, | |
numSlide: function(c) { | |
if(this.currentStep != c) { | |
this.currentStep = c; | |
this.switchSlide(); | |
} | |
}, | |
switchSlide: function() { | |
var self = this; | |
this.galleryAnimating = true; | |
this.tmpProps = {}; | |
this.tmpProps[this.animProperty] = this.getStepOffset(); | |
this.slider.stop().animate(this.tmpProps, {duration: this.options.animSpeed, complete: function(){ | |
// animation complete | |
self.galleryAnimating = false; | |
if(self.resizeQueue) { | |
self.onWindowResize(); | |
} | |
// onchange callback | |
self.makeCallback('onChange', self); | |
self.autoRotate(); | |
}}); | |
this.refreshState(); | |
// onchange callback | |
this.makeCallback('onBeforeChange', this); | |
}, | |
refreshState: function(initial) { | |
if(this.options.step === 1 || this.stepsCount === this.slides.length) { | |
this.slides.removeClass(this.options.activeClass).eq(this.currentStep).addClass(this.options.activeClass); | |
} | |
this.pagerLinks.removeClass(this.options.activeClass).eq(this.currentStep).addClass(this.options.activeClass); | |
this.curNum.html(this.currentStep+1); | |
this.allNum.html(this.stepsCount); | |
// initial refresh | |
if(this.options.maskAutoSize && typeof this.options.step === 'number') { | |
this.tmpProps = {}; | |
this.tmpProps[this.maskSizeProperty] = this.slides.eq(Math.min(this.currentStep,this.slides.length-1))[this.slideSizeFunction](true); | |
this.mask.stop()[initial ? 'css' : 'animate'](this.tmpProps); | |
} | |
// disabled state | |
if(!this.options.circularRotation) { | |
this.btnPrev.add(this.btnNext).removeClass(this.options.disabledClass); | |
if(this.currentStep === 0) this.btnPrev.addClass(this.options.disabledClass); | |
if(this.currentStep === this.stepsCount - 1) this.btnNext.addClass(this.options.disabledClass); | |
} | |
// add class if not enough slides | |
this.gallery.toggleClass('not-enough-slides', this.sumSize <= this.maskSize); | |
}, | |
startRotation: function() { | |
this.options.autoRotation = true; | |
this.galleryHover = false; | |
this.autoRotationStopped = false; | |
this.resumeRotation(); | |
}, | |
stopRotation: function() { | |
this.galleryHover = true; | |
this.autoRotationStopped = true; | |
this.pauseRotation(); | |
}, | |
pauseRotation: function() { | |
this.gallery.addClass(this.options.autorotationDisabledClass); | |
this.gallery.removeClass(this.options.autorotationActiveClass); | |
clearTimeout(this.timer); | |
}, | |
resumeRotation: function() { | |
if(!this.autoRotationStopped) { | |
this.gallery.addClass(this.options.autorotationActiveClass); | |
this.gallery.removeClass(this.options.autorotationDisabledClass); | |
this.autoRotate(); | |
} | |
}, | |
autoRotate: function() { | |
var self = this; | |
clearTimeout(this.timer); | |
if(this.options.autoRotation && !this.galleryHover && !this.autoRotationStopped) { | |
this.timer = setTimeout(function(){ | |
self.nextSlide(true); | |
}, this.options.switchTime); | |
} else { | |
this.pauseRotation(); | |
} | |
}, | |
bindHandlers: function(handlersList) { | |
var self = this; | |
$.each(handlersList, function(index, handler) { | |
var origHandler = self[handler]; | |
self[handler] = function() { | |
return origHandler.apply(self, arguments); | |
}; | |
}); | |
}, | |
makeCallback: function(name) { | |
if(typeof this.options[name] === 'function') { | |
var args = Array.prototype.slice.call(arguments); | |
args.shift(); | |
this.options[name].apply(this, args); | |
} | |
}, | |
destroy: function() { | |
// destroy handler | |
$(window).unbind('load resize orientationchange', this.onWindowResize); | |
this.btnPrev.unbind(this.options.event, this.prevSlideHandler); | |
this.btnNext.unbind(this.options.event, this.nextSlideHandler); | |
this.pagerLinks.unbind(this.options.event, this.pagerLinksHandler); | |
this.gallery.unbind('mouseenter', this.hoverHandler); | |
this.gallery.unbind('mouseleave', this.leaveHandler); | |
// autorotation buttons handlers | |
this.stopRotation(); | |
this.btnPlay.unbind(this.options.event, this.btnPlayHandler); | |
this.btnPause.unbind(this.options.event, this.btnPauseHandler); | |
this.btnPlayPause.unbind(this.options.event, this.btnPlayPauseHandler); | |
// destroy swipe handler | |
if(this.swipeHandler) { | |
this.swipeHandler.destroy(); | |
} | |
// remove inline styles, classes and pagination | |
var unneededClasses = [this.options.galleryReadyClass, this.options.autorotationActiveClass, this.options.autorotationDisabledClass]; | |
this.gallery.removeClass(unneededClasses.join(' ')); | |
this.slider.add(this.slides).removeAttr('style'); | |
if(typeof this.options.generatePagination === 'string') { | |
this.pagerHolder.empty(); | |
} | |
} | |
}; | |
// detect device type | |
var isTouchDevice = /Windows Phone/.test(navigator.userAgent) || ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch; | |
// jquery plugin | |
$.fn.scrollGallery = function(opt){ | |
return this.each(function(){ | |
$(this).data('ScrollGallery', new ScrollGallery($.extend(opt,{holder:this}))); | |
}); | |
}; | |
}(jQuery)); | |
/* | |
* jQuery Open/Close plugin | |
*/ | |
;(function($) { | |
function OpenClose(options) { | |
this.options = $.extend({ | |
addClassBeforeAnimation: true, | |
hideOnClickOutside: false, | |
activeClass:'active', | |
opener:'.opener', | |
slider:'.slide', | |
animSpeed: 400, | |
effect:'fade', | |
event:'click' | |
}, options); | |
this.init(); | |
} | |
OpenClose.prototype = { | |
init: function() { | |
if (this.options.holder) { | |
this.findElements(); | |
this.attachEvents(); | |
this.makeCallback('onInit', this); | |
} | |
}, | |
findElements: function() { | |
this.holder = $(this.options.holder); | |
this.opener = this.holder.find(this.options.opener); | |
this.slider = this.holder.find(this.options.slider); | |
}, | |
attachEvents: function() { | |
// add handler | |
var self = this; | |
this.eventHandler = function(e) { | |
e.preventDefault(); | |
if (self.slider.hasClass(slideHiddenClass)) { | |
self.showSlide(); | |
} else { | |
self.hideSlide(); | |
} | |
}; | |
self.opener.bind(self.options.event, this.eventHandler); | |
// hover mode handler | |
if (self.options.event === 'over') { | |
self.opener.bind('mouseenter', function() { | |
if (!self.holder.hasClass(self.options.activeClass)){ | |
self.showSlide(); | |
} | |
}); | |
self.holder.bind('mouseleave', function() { | |
self.hideSlide(); | |
}); | |
} | |
// outside click handler | |
self.outsideClickHandler = function(e) { | |
if (self.options.hideOnClickOutside) { | |
var target = $(e.target); | |
if (!target.is(self.holder) && !target.closest(self.holder).length) { | |
self.hideSlide(); | |
} | |
} | |
}; | |
// set initial styles | |
if (this.holder.hasClass(this.options.activeClass)) { | |
$(document).bind('click touchstart', self.outsideClickHandler); | |
} else { | |
this.slider.addClass(slideHiddenClass); | |
} | |
}, | |
showSlide: function() { | |
var self = this; | |
if (self.options.addClassBeforeAnimation) { | |
self.holder.addClass(self.options.activeClass); | |
} | |
self.slider.removeClass(slideHiddenClass); | |
$(document).bind('click touchstart', self.outsideClickHandler); | |
self.makeCallback('animStart', true); | |
toggleEffects[self.options.effect].show({ | |
box: self.slider, | |
speed: self.options.animSpeed, | |
complete: function() { | |
if (!self.options.addClassBeforeAnimation) { | |
self.holder.addClass(self.options.activeClass); | |
} | |
self.makeCallback('animEnd', true); | |
} | |
}); | |
}, | |
hideSlide: function() { | |
var self = this; | |
if (self.options.addClassBeforeAnimation) { | |
self.holder.removeClass(self.options.activeClass); | |
} | |
$(document).unbind('click touchstart', self.outsideClickHandler); | |
self.makeCallback('animStart', false); | |
toggleEffects[self.options.effect].hide({ | |
box: self.slider, | |
speed: self.options.animSpeed, | |
complete: function() { | |
if (!self.options.addClassBeforeAnimation) { | |
self.holder.removeClass(self.options.activeClass); | |
} | |
self.slider.addClass(slideHiddenClass); | |
self.makeCallback('animEnd', false); | |
} | |
}); | |
}, | |
destroy: function() { | |
this.slider.removeClass(slideHiddenClass).css({ display:'' }); | |
this.opener.unbind(this.options.event, this.eventHandler); | |
this.holder.removeClass(this.options.activeClass).removeData('OpenClose'); | |
$(document).unbind('click touchstart', this.outsideClickHandler); | |
}, | |
makeCallback: function(name) { | |
if (typeof this.options[name] === 'function') { | |
var args = Array.prototype.slice.call(arguments); | |
args.shift(); | |
this.options[name].apply(this, args); | |
} | |
} | |
}; | |
// add stylesheet for slide on DOMReady | |
var slideHiddenClass = 'js-slide-hidden'; | |
(function() { | |
var tabStyleSheet = $('<style type="text/css">')[0]; | |
var tabStyleRule = '.' + slideHiddenClass; | |
tabStyleRule += '{position:absolute !important;left:-9999px !important;top:-9999px !important;display:block !important}'; | |
if (tabStyleSheet.styleSheet) { | |
tabStyleSheet.styleSheet.cssText = tabStyleRule; | |
} else { | |
tabStyleSheet.appendChild(document.createTextNode(tabStyleRule)); | |
} | |
$('head').append(tabStyleSheet); | |
}()); | |
// animation effects | |
var toggleEffects = { | |
slide: { | |
show: function(o) { | |
o.box.stop(true).hide().slideDown(o.speed, o.complete); | |
}, | |
hide: function(o) { | |
o.box.stop(true).slideUp(o.speed, o.complete); | |
} | |
}, | |
fade: { | |
show: function(o) { | |
o.box.stop(true).hide().fadeIn(o.speed, o.complete); | |
}, | |
hide: function(o) { | |
o.box.stop(true).fadeOut(o.speed, o.complete); | |
} | |
}, | |
none: { | |
show: function(o) { | |
o.box.hide().show(0, o.complete); | |
}, | |
hide: function(o) { | |
o.box.hide(0, o.complete); | |
} | |
} | |
}; | |
// jQuery plugin interface | |
$.fn.openClose = function(opt) { | |
return this.each(function() { | |
jQuery(this).data('OpenClose', new OpenClose($.extend(opt, { holder: this }))); | |
}); | |
}; | |
}(jQuery)); | |
/* | |
* jQuery Accordion plugin | |
*/ | |
;(function($){ | |
$.fn.slideAccordion = function(opt){ | |
// default options | |
var options = $.extend({ | |
addClassBeforeAnimation: false, | |
allowClickWhenExpanded: false, | |
activeClass:'active', | |
opener:'.opener', | |
slider:'.slide', | |
animSpeed: 300, | |
collapsible:true, | |
event:'click' | |
},opt); | |
return this.each(function(){ | |
// options | |
var accordion = $(this); | |
var items = accordion.find(':has('+options.slider+')'); | |
items.each(function(){ | |
var item = $(this); | |
var opener = item.find(options.opener); | |
var slider = item.find(options.slider); | |
opener.bind(options.event, function(e){ | |
if(!slider.is(':animated')) { | |
if(item.hasClass(options.activeClass)) { | |
if(options.allowClickWhenExpanded) { | |
return; | |
} else if(options.collapsible) { | |
slider.slideUp(options.animSpeed, function(){ | |
hideSlide(slider); | |
item.removeClass(options.activeClass); | |
}); | |
} | |
} else { | |
// show active | |
var levelItems = item.siblings('.'+options.activeClass); | |
var sliderElements = levelItems.find(options.slider); | |
item.addClass(options.activeClass); | |
showSlide(slider).hide().slideDown(options.animSpeed); | |
// collapse others | |
sliderElements.slideUp(options.animSpeed, function(){ | |
levelItems.removeClass(options.activeClass); | |
hideSlide(sliderElements); | |
}); | |
} | |
} | |
e.preventDefault(); | |
}); | |
if(item.hasClass(options.activeClass)) showSlide(slider); else hideSlide(slider); | |
}); | |
}); | |
}; | |
// accordion slide visibility | |
var showSlide = function(slide) { | |
return slide.css({position:'', top: '', left: '', width: '' }); | |
}; | |
var hideSlide = function(slide) { | |
return slide.show().css({position:'absolute', top: -9999, left: -9999, width: slide.width() }); | |
}; | |
}(jQuery)); | |
/* | |
* Simple Mobile Navigation | |
*/ | |
;(function($) { | |
function MobileNav(options) { | |
this.options = $.extend({ | |
container: null, | |
hideOnClickOutside: false, | |
menuActiveClass: 'nav-active', | |
menuOpener: '.nav-opener', | |
menuDrop: '.nav-drop', | |
toggleEvent: 'click', | |
outsideClickEvent: 'click touchstart pointerdown MSPointerDown' | |
}, options); | |
this.initStructure(); | |
this.attachEvents(); | |
} | |
MobileNav.prototype = { | |
initStructure: function() { | |
this.page = $('html'); | |
this.container = $(this.options.container); | |
this.opener = this.container.find(this.options.menuOpener); | |
this.drop = this.container.find(this.options.menuDrop); | |
}, | |
attachEvents: function() { | |
var self = this; | |
if(activateResizeHandler) { | |
activateResizeHandler(); | |
activateResizeHandler = null; | |
} | |
this.outsideClickHandler = function(e) { | |
if(self.isOpened()) { | |
var target = $(e.target); | |
if(!target.closest(self.opener).length && !target.closest(self.drop).length) { | |
self.hide(); | |
} | |
} | |
}; | |
this.openerClickHandler = function(e) { | |
e.preventDefault(); | |
self.toggle(); | |
}; | |
this.opener.on(this.options.toggleEvent, this.openerClickHandler); | |
}, | |
isOpened: function() { | |
return this.container.hasClass(this.options.menuActiveClass); | |
}, | |
show: function() { | |
this.container.addClass(this.options.menuActiveClass); | |
if(this.options.hideOnClickOutside) { | |
this.page.on(this.options.outsideClickEvent, this.outsideClickHandler); | |
} | |
}, | |
hide: function() { | |
this.container.removeClass(this.options.menuActiveClass); | |
if(this.options.hideOnClickOutside) { | |
this.page.off(this.options.outsideClickEvent, this.outsideClickHandler); | |
} | |
}, | |
toggle: function() { | |
if(this.isOpened()) { | |
this.hide(); | |
} else { | |
this.show(); | |
} | |
}, | |
destroy: function() { | |
this.container.removeClass(this.options.menuActiveClass); | |
this.opener.off(this.options.toggleEvent, this.clickHandler); | |
this.page.off(this.options.outsideClickEvent, this.outsideClickHandler); | |
} | |
}; | |
var activateResizeHandler = function() { | |
var win = $(window), | |
doc = $('html'), | |
resizeClass = 'resize-active', | |
flag, timer; | |
var removeClassHandler = function() { | |
flag = false; | |
doc.removeClass(resizeClass); | |
}; | |
var resizeHandler = function() { | |
if(!flag) { | |
flag = true; | |
doc.addClass(resizeClass); | |
} | |
clearTimeout(timer); | |
timer = setTimeout(removeClassHandler, 500); | |
}; | |
win.on('resize orientationchange', resizeHandler); | |
}; | |
$.fn.mobileNav = function(options) { | |
return this.each(function() { | |
var params = $.extend({}, options, {container: this}), | |
instance = new MobileNav(params); | |
$.data(this, 'MobileNav', instance); | |
}); | |
}; | |
}(jQuery)); | |
/* | |
* jQuery SameHeight plugin | |
*/ | |
;(function($){ | |
$.fn.sameHeight = function(opt) { | |
var options = $.extend({ | |
skipClass: 'same-height-ignore', | |
leftEdgeClass: 'same-height-left', | |
rightEdgeClass: 'same-height-right', | |
elements: '>*', | |
flexible: false, | |
multiLine: false, | |
useMinHeight: false, | |
biggestHeight: false | |
},opt); | |
return this.each(function(){ | |
var holder = $(this), postResizeTimer, ignoreResize; | |
var elements = holder.find(options.elements).not('.' + options.skipClass); | |
if(!elements.length) return; | |
// resize handler | |
function doResize() { | |
elements.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', ''); | |
if(options.multiLine) { | |
// resize elements row by row | |
resizeElementsByRows(elements, options); | |
} else { | |
// resize elements by holder | |
resizeElements(elements, holder, options); | |
} | |
} | |
doResize(); | |
// handle flexible layout / font resize | |
var delayedResizeHandler = function() { | |
if(!ignoreResize) { | |
ignoreResize = true; | |
doResize(); | |
clearTimeout(postResizeTimer); | |
postResizeTimer = setTimeout(function() { | |
doResize(); | |
setTimeout(function(){ | |
ignoreResize = false; | |
}, 10); | |
}, 100); | |
} | |
}; | |
// handle flexible/responsive layout | |
if(options.flexible) { | |
$(window).bind('resize orientationchange fontresize', delayedResizeHandler); | |
} | |
// handle complete page load including images and fonts | |
$(window).bind('load', delayedResizeHandler); | |
}); | |
}; | |
// detect css min-height support | |
var supportMinHeight = typeof document.documentElement.style.maxHeight !== 'undefined'; | |
// get elements by rows | |
function resizeElementsByRows(boxes, options) { | |
var currentRow = $(), maxHeight, maxCalcHeight = 0, firstOffset = boxes.eq(0).offset().top; | |
boxes.each(function(ind){ | |
var curItem = $(this); | |
if(curItem.offset().top === firstOffset) { | |
currentRow = currentRow.add(this); | |
} else { | |
maxHeight = getMaxHeight(currentRow); | |
maxCalcHeight = Math.max(maxCalcHeight, resizeElements(currentRow, maxHeight, options)); | |
currentRow = curItem; | |
firstOffset = curItem.offset().top; | |
} | |
}); | |
if(currentRow.length) { | |
maxHeight = getMaxHeight(currentRow); | |
maxCalcHeight = Math.max(maxCalcHeight, resizeElements(currentRow, maxHeight, options)); | |
} | |
if(options.biggestHeight) { | |
boxes.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', maxCalcHeight); | |
} | |
} | |
// calculate max element height | |
function getMaxHeight(boxes) { | |
var maxHeight = 0; | |
boxes.each(function(){ | |
maxHeight = Math.max(maxHeight, $(this).outerHeight()); | |
}); | |
return maxHeight; | |
} | |
// resize helper function | |
function resizeElements(boxes, parent, options) { | |
var calcHeight; | |
var parentHeight = typeof parent === 'number' ? parent : parent.height(); | |
boxes.removeClass(options.leftEdgeClass).removeClass(options.rightEdgeClass).each(function(i){ | |
var element = $(this); | |
var depthDiffHeight = 0; | |
var isBorderBox = element.css('boxSizing') === 'border-box' || element.css('-moz-box-sizing') === 'border-box' || element.css('-webkit-box-sizing') === 'border-box'; | |
if(typeof parent !== 'number') { | |
element.parents().each(function(){ | |
var tmpParent = $(this); | |
if(parent.is(this)) { | |
return false; | |
} else { | |
depthDiffHeight += tmpParent.outerHeight() - tmpParent.height(); | |
} | |
}); | |
} | |
calcHeight = parentHeight - depthDiffHeight; | |
calcHeight -= isBorderBox ? 0 : element.outerHeight() - element.height(); | |
if(calcHeight > 0) { | |
element.css(options.useMinHeight && supportMinHeight ? 'minHeight' : 'height', calcHeight); | |
} | |
}); | |
boxes.filter(':first').addClass(options.leftEdgeClass); | |
boxes.filter(':last').addClass(options.rightEdgeClass); | |
return calcHeight; | |
} | |
}(jQuery)); | |
/* | |
* jQuery FontResize Event | |
*/ | |
jQuery.onFontResize = (function($) { | |
$(function() { | |
var randomID = 'font-resize-frame-' + Math.floor(Math.random() * 1000); | |
var resizeFrame = $('<iframe>').attr('id', randomID).addClass('font-resize-helper'); | |
// required styles | |
resizeFrame.css({ | |
width: '100em', | |
height: '10px', | |
position: 'absolute', | |
borderWidth: 0, | |
top: '-9999px', | |
left: '-9999px' | |
}).appendTo('body'); | |
// use native IE resize event if possible | |
if (window.attachEvent && !window.addEventListener) { | |
resizeFrame.bind('resize', function () { | |
$.onFontResize.trigger(resizeFrame[0].offsetWidth / 100); | |
}); | |
} | |
// use script inside the iframe to detect resize for other browsers | |
else { | |
var doc = resizeFrame[0].contentWindow.document; | |
doc.open(); | |
doc.write('<scri' + 'pt>window.onload = function(){var em = parent.jQuery("#' + randomID + '")[0];window.onresize = function(){if(parent.jQuery.onFontResize){parent.jQuery.onFontResize.trigger(em.offsetWidth / 100);}}};</scri' + 'pt>'); | |
doc.close(); | |
} | |
jQuery.onFontResize.initialSize = resizeFrame[0].offsetWidth / 100; | |
}); | |
return { | |
// public method, so it can be called from within the iframe | |
trigger: function (em) { | |
$(window).trigger("fontresize", [em]); | |
} | |
}; | |
}(jQuery)); | |
/*! http://mths.be/placeholder v2.0.7 by @mathias */ | |
;(function(window, document, $) { | |
// Opera Mini v7 doesn’t support placeholder although its DOM seems to indicate so | |
var isOperaMini = Object.prototype.toString.call(window.operamini) == '[object OperaMini]'; | |
var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini; | |
var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini; | |
var prototype = $.fn; | |
var valHooks = $.valHooks; | |
var propHooks = $.propHooks; | |
var hooks; | |
var placeholder; | |
if (isInputSupported && isTextareaSupported) { | |
placeholder = prototype.placeholder = function() { | |
return this; | |
}; | |
placeholder.input = placeholder.textarea = true; | |
} else { | |
placeholder = prototype.placeholder = function() { | |
var $this = this; | |
$this | |
.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]') | |
.not('.placeholder') | |
.bind({ | |
'focus.placeholder': clearPlaceholder, | |
'blur.placeholder': setPlaceholder | |
}) | |
.data('placeholder-enabled', true) | |
.trigger('blur.placeholder'); | |
return $this; | |
}; | |
placeholder.input = isInputSupported; | |
placeholder.textarea = isTextareaSupported; | |
hooks = { | |
'get': function(element) { | |
var $element = $(element); | |
var $passwordInput = $element.data('placeholder-password'); | |
if ($passwordInput) { | |
return $passwordInput[0].value; | |
} | |
return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value; | |
}, | |
'set': function(element, value) { | |
var $element = $(element); | |
var $passwordInput = $element.data('placeholder-password'); | |
if ($passwordInput) { | |
return $passwordInput[0].value = value; | |
} | |
if (!$element.data('placeholder-enabled')) { | |
return element.value = value; | |
} | |
if (value == '') { | |
element.value = value; | |
// Issue #56: Setting the placeholder causes problems if the element continues to have focus. | |
if (element != safeActiveElement()) { | |
// We can't use `triggerHandler` here because of dummy text/password inputs :( | |
setPlaceholder.call(element); | |
} | |
} else if ($element.hasClass('placeholder')) { | |
clearPlaceholder.call(element, true, value) || (element.value = value); | |
} else { | |
element.value = value; | |
} | |
// `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363 | |
return $element; | |
} | |
}; | |
if (!isInputSupported) { | |
valHooks.input = hooks; | |
propHooks.value = hooks; | |
} | |
if (!isTextareaSupported) { | |
valHooks.textarea = hooks; | |
propHooks.value = hooks; | |
} | |
$(function() { | |
// Look for forms | |
$(document).delegate('form', 'submit.placeholder', function() { | |
// Clear the placeholder values so they don't get submitted | |
var $inputs = $('.placeholder', this).each(clearPlaceholder); | |
setTimeout(function() { | |
$inputs.each(setPlaceholder); | |
}, 10); | |
}); | |
}); | |
// Clear placeholder values upon page reload | |
$(window).bind('beforeunload.placeholder', function() { | |
$('.placeholder').each(function() { | |
this.value = ''; | |
}); | |
}); | |
} | |
function args(elem) { | |
// Return an object of element attributes | |
var newAttrs = {}; | |
var rinlinejQuery = /^jQuery\d+$/; | |
$.each(elem.attributes, function(i, attr) { | |
if (attr.specified && !rinlinejQuery.test(attr.name)) { | |
newAttrs[attr.name] = attr.value; | |
} | |
}); | |
return newAttrs; | |
} | |
function clearPlaceholder(event, value) { | |
var input = this; | |
var $input = $(input); | |
if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) { | |
if ($input.data('placeholder-password')) { | |
$input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id')); | |
// If `clearPlaceholder` was called from `$.valHooks.input.set` | |
if (event === true) { | |
return $input[0].value = value; | |
} | |
$input.focus(); | |
} else { | |
input.value = ''; | |
$input.removeClass('placeholder'); | |
input == safeActiveElement() && input.select(); | |
} | |
} | |
} | |
function setPlaceholder() { | |
var $replacement; | |
var input = this; | |
var $input = $(input); | |
var id = this.id; | |
if (input.value == '') { | |
if (input.type == 'password') { | |
if (!$input.data('placeholder-textinput')) { | |
try { | |
$replacement = $input.clone().attr({ 'type': 'text' }); | |
} catch(e) { | |
$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' })); | |
} | |
$replacement | |
.removeAttr('name') | |
.data({ | |
'placeholder-password': $input, | |
'placeholder-id': id | |
}) | |
.bind('focus.placeholder', clearPlaceholder); | |
$input | |
.data({ | |
'placeholder-textinput': $replacement, | |
'placeholder-id': id | |
}) | |
.before($replacement); | |
} | |
$input = $input.removeAttr('id').hide().prev().attr('id', id).show(); | |
// Note: `$input[0] != input` now! | |
} | |
$input.addClass('placeholder'); | |
$input[0].value = $input.attr('placeholder'); | |
} else { | |
$input.removeClass('placeholder'); | |
} | |
} | |
function safeActiveElement() { | |
// Avoid IE9 `document.activeElement` of death | |
// https://github.com/mathiasbynens/jquery-placeholder/pull/99 | |
try { | |
return document.activeElement; | |
} catch (err) {} | |
} | |
}(this, document, jQuery)); | |
/*! | |
* JavaScript Custom Forms | |
* | |
* Copyright 2014-2015 PSD2HTML - http://psd2html.com/jcf | |
* Released under the MIT license (LICENSE.txt) | |
* | |
* Version: 1.1.3 | |
*/ | |
;(function(root, factory) { | |
'use strict'; | |
if (typeof define === 'function' && define.amd) { | |
define(['jquery'], factory); | |
} else if (typeof exports === 'object') { | |
module.exports = factory(require('jquery')); | |
} else { | |
root.jcf = factory(jQuery); | |
} | |
}(this, function($) { | |
'use strict'; | |
// define version | |
var version = '1.1.3'; | |
// private variables | |
var customInstances = []; | |
// default global options | |
var commonOptions = { | |
optionsKey: 'jcf', | |
dataKey: 'jcf-instance', | |
rtlClass: 'jcf-rtl', | |
focusClass: 'jcf-focus', | |
pressedClass: 'jcf-pressed', | |
disabledClass: 'jcf-disabled', | |
hiddenClass: 'jcf-hidden', | |
resetAppearanceClass: 'jcf-reset-appearance', | |
unselectableClass: 'jcf-unselectable' | |
}; | |
// detect device type | |
var isTouchDevice = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch, | |
isWinPhoneDevice = /Windows Phone/.test(navigator.userAgent); | |
commonOptions.isMobileDevice = !!(isTouchDevice || isWinPhoneDevice); | |
// create global stylesheet if custom forms are used | |
var createStyleSheet = function() { | |
var styleTag = $('<style>').appendTo('head'), | |
styleSheet = styleTag.prop('sheet') || styleTag.prop('styleSheet'); | |
// crossbrowser style handling | |
var addCSSRule = function(selector, rules, index) { | |
if (styleSheet.insertRule) { | |
styleSheet.insertRule(selector + '{' + rules + '}', index); | |
} else { | |
styleSheet.addRule(selector, rules, index); | |
} | |
}; | |
// add special rules | |
addCSSRule('.' + commonOptions.hiddenClass, 'position:absolute !important;left:-9999px !important;height:1px !important;width:1px !important;margin:0 !important;border-width:0 !important;-webkit-appearance:none;-moz-appearance:none;appearance:none'); | |
addCSSRule('.' + commonOptions.rtlClass + ' .' + commonOptions.hiddenClass, 'right:-9999px !important; left: auto !important'); | |
addCSSRule('.' + commonOptions.unselectableClass, '-webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; -webkit-tap-highlight-color: rgba(0,0,0,0);'); | |
addCSSRule('.' + commonOptions.resetAppearanceClass, 'background: none; border: none; -webkit-appearance: none; appearance: none; opacity: 0; filter: alpha(opacity=0);'); | |
// detect rtl pages | |
var html = $('html'), body = $('body'); | |
if (html.css('direction') === 'rtl' || body.css('direction') === 'rtl') { | |
html.addClass(commonOptions.rtlClass); | |
} | |
// handle form reset event | |
html.on('reset', function() { | |
setTimeout(function() { | |
api.refreshAll(); | |
}, 0); | |
}); | |
// mark stylesheet as created | |
commonOptions.styleSheetCreated = true; | |
}; | |
// simplified pointer events handler | |
(function() { | |
var pointerEventsSupported = navigator.pointerEnabled || navigator.msPointerEnabled, | |
touchEventsSupported = ('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch, | |
eventList, eventMap = {}, eventPrefix = 'jcf-'; | |
// detect events to attach | |
if (pointerEventsSupported) { | |
eventList = { | |
pointerover: navigator.pointerEnabled ? 'pointerover' : 'MSPointerOver', | |
pointerdown: navigator.pointerEnabled ? 'pointerdown' : 'MSPointerDown', | |
pointermove: navigator.pointerEnabled ? 'pointermove' : 'MSPointerMove', | |
pointerup: navigator.pointerEnabled ? 'pointerup' : 'MSPointerUp' | |
}; | |
} else { | |
eventList = { | |
pointerover: 'mouseover', | |
pointerdown: 'mousedown' + (touchEventsSupported ? ' touchstart' : ''), | |
pointermove: 'mousemove' + (touchEventsSupported ? ' touchmove' : ''), | |
pointerup: 'mouseup' + (touchEventsSupported ? ' touchend' : '') | |
}; | |
} | |
// create event map | |
$.each(eventList, function(targetEventName, fakeEventList) { | |
$.each(fakeEventList.split(' '), function(index, fakeEventName) { | |
eventMap[fakeEventName] = targetEventName; | |
}); | |
}); | |
// jQuery event hooks | |
$.each(eventList, function(eventName, eventHandlers) { | |
eventHandlers = eventHandlers.split(' '); | |
$.event.special[eventPrefix + eventName] = { | |
setup: function() { | |
var self = this; | |
$.each(eventHandlers, function(index, fallbackEvent) { | |
if (self.addEventListener) self.addEventListener(fallbackEvent, fixEvent, false); | |
else self['on' + fallbackEvent] = fixEvent; | |
}); | |
}, | |
teardown: function() { | |
var self = this; | |
$.each(eventHandlers, function(index, fallbackEvent) { | |
if (self.addEventListener) self.removeEventListener(fallbackEvent, fixEvent, false); | |
else self['on' + fallbackEvent] = null; | |
}); | |
} | |
}; | |
}); | |
// check that mouse event are not simulated by mobile browsers | |
var lastTouch = null; | |
var mouseEventSimulated = function(e) { | |
var dx = Math.abs(e.pageX - lastTouch.x), | |
dy = Math.abs(e.pageY - lastTouch.y), | |
rangeDistance = 25; | |
if (dx <= rangeDistance && dy <= rangeDistance) { | |
return true; | |
} | |
}; | |
// normalize event | |
var fixEvent = function(e) { | |
var origEvent = e || window.event, | |
touchEventData = null, | |
targetEventName = eventMap[origEvent.type]; | |
e = $.event.fix(origEvent); | |
e.type = eventPrefix + targetEventName; | |
if (origEvent.pointerType) { | |
switch (origEvent.pointerType) { | |
case 2: e.pointerType = 'touch'; break; | |
case 3: e.pointerType = 'pen'; break; | |
case 4: e.pointerType = 'mouse'; break; | |
default: e.pointerType = origEvent.pointerType; | |
} | |
} else { | |
e.pointerType = origEvent.type.substr(0, 5); // "mouse" or "touch" word length | |
} | |
if (!e.pageX && !e.pageY) { | |
touchEventData = origEvent.changedTouches ? origEvent.changedTouches[0] : origEvent; | |
e.pageX = touchEventData.pageX; | |
e.pageY = touchEventData.pageY; | |
} | |
if (origEvent.type === 'touchend') { | |
lastTouch = { x: e.pageX, y: e.pageY }; | |
} | |
if (e.pointerType === 'mouse' && lastTouch && mouseEventSimulated(e)) { | |
return; | |
} else { | |
return ($.event.dispatch || $.event.handle).call(this, e); | |
} | |
}; | |
}()); | |
// custom mousewheel/trackpad handler | |
(function() { | |
var wheelEvents = ('onwheel' in document || document.documentMode >= 9 ? 'wheel' : 'mousewheel DOMMouseScroll').split(' '), | |
shimEventName = 'jcf-mousewheel'; | |
$.event.special[shimEventName] = { | |
setup: function() { | |
var self = this; | |
$.each(wheelEvents, function(index, fallbackEvent) { | |
if (self.addEventListener) self.addEventListener(fallbackEvent, fixEvent, false); | |
else self['on' + fallbackEvent] = fixEvent; | |
}); | |
}, | |
teardown: function() { | |
var self = this; | |
$.each(wheelEvents, function(index, fallbackEvent) { | |
if (self.addEventListener) self.removeEventListener(fallbackEvent, fixEvent, false); | |
else self['on' + fallbackEvent] = null; | |
}); | |
} | |
}; | |
var fixEvent = function(e) { | |
var origEvent = e || window.event; | |
e = $.event.fix(origEvent); | |
e.type = shimEventName; | |
// old wheel events handler | |
if ('detail' in origEvent) { e.deltaY = -origEvent.detail; } | |
if ('wheelDelta' in origEvent) { e.deltaY = -origEvent.wheelDelta; } | |
if ('wheelDeltaY' in origEvent) { e.deltaY = -origEvent.wheelDeltaY; } | |
if ('wheelDeltaX' in origEvent) { e.deltaX = -origEvent.wheelDeltaX; } | |
// modern wheel event handler | |
if ('deltaY' in origEvent) { | |
e.deltaY = origEvent.deltaY; | |
} | |
if ('deltaX' in origEvent) { | |
e.deltaX = origEvent.deltaX; | |
} | |
// handle deltaMode for mouse wheel | |
e.delta = e.deltaY || e.deltaX; | |
if (origEvent.deltaMode === 1) { | |
var lineHeight = 16; | |
e.delta *= lineHeight; | |
e.deltaY *= lineHeight; | |
e.deltaX *= lineHeight; | |
} | |
return ($.event.dispatch || $.event.handle).call(this, e); | |
}; | |
}()); | |
// extra module methods | |
var moduleMixin = { | |
// provide function for firing native events | |
fireNativeEvent: function(elements, eventName) { | |
$(elements).each(function() { | |
var element = this, eventObject; | |
if (element.dispatchEvent) { | |
eventObject = document.createEvent('HTMLEvents'); | |
eventObject.initEvent(eventName, true, true); | |
element.dispatchEvent(eventObject); | |
} else if (document.createEventObject) { | |
eventObject = document.createEventObject(); | |
eventObject.target = element; | |
element.fireEvent('on' + eventName, eventObject); | |
} | |
}); | |
}, | |
// bind event handlers for module instance (functions beggining with "on") | |
bindHandlers: function() { | |
var self = this; | |
$.each(self, function(propName, propValue) { | |
if (propName.indexOf('on') === 0 && $.isFunction(propValue)) { | |
// dont use $.proxy here because it doesn't create unique handler | |
self[propName] = function() { | |
return propValue.apply(self, arguments); | |
}; | |
} | |
}); | |
} | |
}; | |
// public API | |
var api = { | |
version: version, | |
modules: {}, | |
getOptions: function() { | |
return $.extend({}, commonOptions); | |
}, | |
setOptions: function(moduleName, moduleOptions) { | |
if (arguments.length > 1) { | |
// set module options | |
if (this.modules[moduleName]) { | |
$.extend(this.modules[moduleName].prototype.options, moduleOptions); | |
} | |
} else { | |
// set common options | |
$.extend(commonOptions, moduleName); | |
} | |
}, | |
addModule: function(proto) { | |
// add module to list | |
var Module = function(options) { | |
// save instance to collection | |
if (!options.element.data(commonOptions.dataKey)) { | |
options.element.data(commonOptions.dataKey, this); | |
} | |
customInstances.push(this); | |
// save options | |
this.options = $.extend({}, commonOptions, this.options, getInlineOptions(options.element), options); | |
// bind event handlers to instance | |
this.bindHandlers(); | |
// call constructor | |
this.init.apply(this, arguments); | |
}; | |
// parse options from HTML attribute | |
var getInlineOptions = function(element) { | |
var dataOptions = element.data(commonOptions.optionsKey), | |
attrOptions = element.attr(commonOptions.optionsKey); | |
if (dataOptions) { | |
return dataOptions; | |
} else if (attrOptions) { | |
try { | |
return $.parseJSON(attrOptions); | |
} catch (e) { | |
// ignore invalid attributes | |
} | |
} | |
}; | |
// set proto as prototype for new module | |
Module.prototype = proto; | |
// add mixin methods to module proto | |
$.extend(proto, moduleMixin); | |
if (proto.plugins) { | |
$.each(proto.plugins, function(pluginName, plugin) { | |
$.extend(plugin.prototype, moduleMixin); | |
}); | |
} | |
// override destroy method | |
var originalDestroy = Module.prototype.destroy; | |
Module.prototype.destroy = function() { | |
this.options.element.removeData(this.options.dataKey); | |
for (var i = customInstances.length - 1; i >= 0; i--) { | |
if (customInstances[i] === this) { | |
customInstances.splice(i, 1); | |
break; | |
} | |
} | |
if (originalDestroy) { | |
originalDestroy.apply(this, arguments); | |
} | |
}; | |
// save module to list | |
this.modules[proto.name] = Module; | |
}, | |
getInstance: function(element) { | |
return $(element).data(commonOptions.dataKey); | |
}, | |
replace: function(elements, moduleName, customOptions) { | |
var self = this, | |
instance; | |
if (!commonOptions.styleSheetCreated) { | |
createStyleSheet(); | |
} | |
$(elements).each(function() { | |
var moduleOptions, | |
element = $(this); | |
instance = element.data(commonOptions.dataKey); | |
if (instance) { | |
instance.refresh(); | |
} else { | |
if (!moduleName) { | |
$.each(self.modules, function(currentModuleName, module) { | |
if (module.prototype.matchElement.call(module.prototype, element)) { | |
moduleName = currentModuleName; | |
return false; | |
} | |
}); | |
} | |
if (moduleName) { | |
moduleOptions = $.extend({ element: element }, customOptions); | |
instance = new self.modules[moduleName](moduleOptions); | |
} | |
} | |
}); | |
return instance; | |
}, | |
refresh: function(elements) { | |
$(elements).each(function() { | |
var instance = $(this).data(commonOptions.dataKey); | |
if (instance) { | |
instance.refresh(); | |
} | |
}); | |
}, | |
destroy: function(elements) { | |
$(elements).each(function() { | |
var instance = $(this).data(commonOptions.dataKey); | |
if (instance) { | |
instance.destroy(); | |
} | |
}); | |
}, | |
replaceAll: function(context) { | |
var self = this; | |
$.each(this.modules, function(moduleName, module) { | |
$(module.prototype.selector, context).each(function() { | |
if (this.className.indexOf('jcf-ignore') < 0) { | |
self.replace(this, moduleName); | |
} | |
}); | |
}); | |
}, | |
refreshAll: function(context) { | |
if (context) { | |
$.each(this.modules, function(moduleName, module) { | |
$(module.prototype.selector, context).each(function() { | |
var instance = $(this).data(commonOptions.dataKey); | |
if (instance) { | |
instance.refresh(); | |
} | |
}); | |
}); | |
} else { | |
for (var i = customInstances.length - 1; i >= 0; i--) { | |
customInstances[i].refresh(); | |
} | |
} | |
}, | |
destroyAll: function(context) { | |
if (context) { | |
$.each(this.modules, function(moduleName, module) { | |
$(module.prototype.selector, context).each(function(index, element) { | |
var instance = $(element).data(commonOptions.dataKey); | |
if (instance) { | |
instance.destroy(); | |
} | |
}); | |
}); | |
} else { | |
while (customInstances.length) { | |
customInstances[0].destroy(); | |
} | |
} | |
} | |
}; | |
// always export API to the global window object | |
window.jcf = api; | |
return api; | |
})); | |
/*! | |
* JavaScript Custom Forms : Checkbox Module | |
* | |
* Copyright 2014-2015 PSD2HTML - http://psd2html.com/jcf | |
* Released under the MIT license (LICENSE.txt) | |
* | |
* Version: 1.1.3 | |
*/ | |
;(function($) { | |
'use strict'; | |
jcf.addModule({ | |
name: 'Checkbox', | |
selector: 'input[type="checkbox"]', | |
options: { | |
wrapNative: true, | |
checkedClass: 'jcf-checked', | |
uncheckedClass: 'jcf-unchecked', | |
labelActiveClass: 'jcf-label-active', | |
fakeStructure: '<span class="jcf-checkbox"><span></span></span>' | |
}, | |
matchElement: function(element) { | |
return element.is(':checkbox'); | |
}, | |
init: function() { | |
this.initStructure(); | |
this.attachEvents(); | |
this.refresh(); | |
}, | |
initStructure: function() { | |
// prepare structure | |
this.doc = $(document); | |
this.realElement = $(this.options.element); | |
this.fakeElement = $(this.options.fakeStructure).insertAfter(this.realElement); | |
this.labelElement = this.getLabelFor(); | |
if (this.options.wrapNative) { | |
// wrap native checkbox inside fake block | |
this.realElement.appendTo(this.fakeElement).css({ | |
position: 'absolute', | |
height: '100%', | |
width: '100%', | |
opacity: 0, | |
margin: 0 | |
}); | |
} else { | |
// just hide native checkbox | |
this.realElement.addClass(this.options.hiddenClass); | |
} | |
}, | |
attachEvents: function() { | |
// add event handlers | |
this.realElement.on({ | |
focus: this.onFocus, | |
click: this.onRealClick | |
}); | |
this.fakeElement.on('click', this.onFakeClick); | |
this.fakeElement.on('jcf-pointerdown', this.onPress); | |
}, | |
onRealClick: function(e) { | |
// just redraw fake element (setTimeout handles click that might be prevented) | |
var self = this; | |
this.savedEventObject = e; | |
setTimeout(function() { | |
self.refresh(); | |
}, 0); | |
}, | |
onFakeClick: function(e) { | |
// skip event if clicked on real element inside wrapper | |
if (this.options.wrapNative && this.realElement.is(e.target)) { | |
return; | |
} | |
// toggle checked class | |
if (!this.realElement.is(':disabled')) { | |
delete this.savedEventObject; | |
this.stateChecked = this.realElement.prop('checked'); | |
this.realElement.prop('checked', !this.stateChecked); | |
this.fireNativeEvent(this.realElement, 'click'); | |
if (this.savedEventObject && this.savedEventObject.isDefaultPrevented()) { | |
this.realElement.prop('checked', this.stateChecked); | |
} else { | |
this.fireNativeEvent(this.realElement, 'change'); | |
} | |
delete this.savedEventObject; | |
} | |
}, | |
onFocus: function() { | |
if (!this.pressedFlag || !this.focusedFlag) { | |
this.focusedFlag = true; | |
this.fakeElement.addClass(this.options.focusClass); | |
this.realElement.on('blur', this.onBlur); | |
} | |
}, | |
onBlur: function() { | |
if (!this.pressedFlag) { | |
this.focusedFlag = false; | |
this.fakeElement.removeClass(this.options.focusClass); | |
this.realElement.off('blur', this.onBlur); | |
} | |
}, | |
onPress: function(e) { | |
if (!this.focusedFlag && e.pointerType === 'mouse') { | |
this.realElement.focus(); | |
} | |
this.pressedFlag = true; | |
this.fakeElement.addClass(this.options.pressedClass); | |
this.doc.on('jcf-pointerup', this.onRelease); | |
}, | |
onRelease: function(e) { | |
if (this.focusedFlag && e.pointerType === 'mouse') { | |
this.realElement.focus(); | |
} | |
this.pressedFlag = false; | |
this.fakeElement.removeClass(this.options.pressedClass); | |
this.doc.off('jcf-pointerup', this.onRelease); | |
}, | |
getLabelFor: function() { | |
var parentLabel = this.realElement.closest('label'), | |
elementId = this.realElement.prop('id'); | |
if (!parentLabel.length && elementId) { | |
parentLabel = $('label[for="' + elementId + '"]'); | |
} | |
return parentLabel.length ? parentLabel : null; | |
}, | |
refresh: function() { | |
// redraw custom checkbox | |
var isChecked = this.realElement.is(':checked'), | |
isDisabled = this.realElement.is(':disabled'); | |
this.fakeElement.toggleClass(this.options.checkedClass, isChecked) | |
.toggleClass(this.options.uncheckedClass, !isChecked) | |
.toggleClass(this.options.disabledClass, isDisabled); | |
if (this.labelElement) { | |
this.labelElement.toggleClass(this.options.labelActiveClass, isChecked); | |
} | |
}, | |
destroy: function() { | |
// restore structure | |
if (this.options.wrapNative) { | |
this.realElement.insertBefore(this.fakeElement).css({ | |
position: '', | |
width: '', | |
height: '', | |
opacity: '', | |
margin: '' | |
}); | |
} else { | |
this.realElement.removeClass(this.options.hiddenClass); | |
} | |
// removing element will also remove its event handlers | |
this.fakeElement.off('jcf-pointerdown', this.onPress); | |
this.fakeElement.remove(); | |
// remove other event handlers | |
this.doc.off('jcf-pointerup', this.onRelease); | |
this.realElement.off({ | |
focus: this.onFocus, | |
click: this.onRealClick | |
}); | |
} | |
}); | |
}(jQuery)); | |
/* | |
* Image Stretch module | |
*/ | |
var ImageStretcher = { | |
getDimensions: function(data) { | |
// calculate element coords to fit in mask | |
var ratio = data.imageRatio || (data.imageWidth / data.imageHeight), | |
slideWidth = data.maskWidth, | |
slideHeight = slideWidth / ratio; | |
if(slideHeight < data.maskHeight) { | |
slideHeight = data.maskHeight; | |
slideWidth = slideHeight * ratio; | |
} | |
return { | |
width: slideWidth, | |
height: slideHeight, | |
top: (data.maskHeight - slideHeight) / 2, | |
left: (data.maskWidth - slideWidth) / 2 | |
}; | |
}, | |
getRatio: function(image) { | |
if(image.prop('naturalWidth')) { | |
return image.prop('naturalWidth') / image.prop('naturalHeight'); | |
} else { | |
var img = new Image(); | |
img.src = image.prop('src'); | |
return img.width / img.height; | |
} | |
}, | |
imageLoaded: function(image, callback) { | |
var self = this; | |
var loadHandler = function() { | |
callback.call(self); | |
}; | |
if(image.prop('complete')) { | |
loadHandler(); | |
} else { | |
image.one('load', loadHandler); | |
} | |
}, | |
resizeHandler: function() { | |
var self = this; | |
jQuery.each(this.imgList, function(index, item) { | |
if(item.image.prop('complete')) { | |
self.resizeImage(item.image, item.container); | |
} | |
}); | |
}, | |
resizeImage: function(image, container) { | |
this.imageLoaded(image, function() { | |
var styles = this.getDimensions({ | |
imageRatio: this.getRatio(image), | |
maskWidth: container.width(), | |
maskHeight: container.height() | |
}); | |
image.css({ | |
width: styles.width, | |
height: styles.height, | |
marginTop: styles.top, | |
marginLeft: styles.left | |
}); | |
}); | |
}, | |
add: function(options) { | |
var container = jQuery(options.container ? options.container : window), | |
image = typeof options.image === 'string' ? container.find(options.image) : jQuery(options.image); | |
// resize image | |
this.resizeImage(image, container); | |
// add resize handler once if needed | |
if(!this.win) { | |
this.resizeHandler = jQuery.proxy(this.resizeHandler, this); | |
this.imgList = []; | |
this.win = jQuery(window); | |
this.win.on('resize orientationchange', this.resizeHandler); | |
} | |
// store item in collection | |
this.imgList.push({ | |
container: container, | |
image: image | |
}); | |
} | |
}; | |
// navigation accesibility module | |
function TouchNav(opt) { | |
this.options = { | |
hoverClass: 'hover', | |
menuItems: 'li', | |
menuOpener: 'a', | |
menuDrop: 'ul', | |
navBlock: null | |
}; | |
for(var p in opt) { | |
if(opt.hasOwnProperty(p)) { | |
this.options[p] = opt[p]; | |
} | |
} | |
this.init(); | |
} | |
TouchNav.isActiveOn = function(elem) { | |
return elem && elem.touchNavActive; | |
}; | |
TouchNav.prototype = { | |
init: function() { | |
if(typeof this.options.navBlock === 'string') { | |
this.menu = document.getElementById(this.options.navBlock); | |
} else if(typeof this.options.navBlock === 'object') { | |
this.menu = this.options.navBlock; | |
} | |
if(this.menu) { | |
this.addEvents(); | |
} | |
}, | |
addEvents: function() { | |
// attach event handlers | |
var self = this; | |
var touchEvent = (navigator.pointerEnabled && 'pointerdown') || (navigator.msPointerEnabled && 'MSPointerDown') || (this.isTouchDevice && 'touchstart'); | |
this.menuItems = lib.queryElementsBySelector(this.options.menuItems, this.menu); | |
var initMenuItem = function(item) { | |
var currentDrop = lib.queryElementsBySelector(self.options.menuDrop, item)[0], | |
currentOpener = lib.queryElementsBySelector(self.options.menuOpener, item)[0]; | |
// only for touch input devices | |
if( currentDrop && currentOpener && (self.isTouchDevice || self.isPointerDevice) ) { | |
lib.event.add(currentOpener, 'click', lib.bind(self.clickHandler, self)); | |
lib.event.add(currentOpener, 'mousedown', lib.bind(self.mousedownHandler, self)); | |
lib.event.add(currentOpener, touchEvent, function(e){ | |
if( !self.isTouchPointerEvent(e) ) { | |
self.preventCurrentClick = false; | |
return; | |
} | |
self.touchFlag = true; | |
self.currentItem = item; | |
self.currentLink = currentOpener; | |
self.pressHandler.apply(self, arguments); | |
}); | |
} | |
// for desktop computers and touch devices | |
jQuery(item).bind('mouseenter', function(){ | |
if(!self.touchFlag) { | |
self.currentItem = item; | |
self.mouseoverHandler(); | |
} | |
}); | |
jQuery(item).bind('mouseleave', function(){ | |
if(!self.touchFlag) { | |
self.currentItem = item; | |
self.mouseoutHandler(); | |
} | |
}); | |
item.touchNavActive = true; | |
}; | |
// addd handlers for all menu items | |
for(var i = 0; i < this.menuItems.length; i++) { | |
initMenuItem(self.menuItems[i]); | |
} | |
// hide dropdowns when clicking outside navigation | |
if(this.isTouchDevice || this.isPointerDevice) { | |
lib.event.add(document.documentElement, 'mousedown', lib.bind(this.clickOutsideHandler, this)); | |
lib.event.add(document.documentElement, touchEvent, lib.bind(this.clickOutsideHandler, this)); | |
} | |
}, | |
mousedownHandler: function(e) { | |
if(this.touchFlag) { | |
e.preventDefault(); | |
this.touchFlag = false; | |
this.preventCurrentClick = false; | |
} | |
}, | |
mouseoverHandler: function() { | |
lib.addClass(this.currentItem, this.options.hoverClass); | |
jQuery(this.currentItem).trigger('itemhover'); | |
}, | |
mouseoutHandler: function() { | |
lib.removeClass(this.currentItem, this.options.hoverClass); | |
jQuery(this.currentItem).trigger('itemleave'); | |
}, | |
hideActiveDropdown: function() { | |
for(var i = 0; i < this.menuItems.length; i++) { | |
if(lib.hasClass(this.menuItems[i], this.options.hoverClass)) { | |
lib.removeClass(this.menuItems[i], this.options.hoverClass); | |
jQuery(this.menuItems[i]).trigger('itemleave'); | |
} | |
} | |
this.activeParent = null; | |
}, | |
pressHandler: function(e) { | |
// hide previous drop (if active) | |
if(this.currentItem !== this.activeParent) { | |
if(this.activeParent && this.currentItem.parentNode === this.activeParent.parentNode) { | |
lib.removeClass(this.activeParent, this.options.hoverClass); | |
} else if(!this.isParent(this.activeParent, this.currentLink)) { | |
this.hideActiveDropdown(); | |
} | |
} | |
// handle current drop | |
this.activeParent = this.currentItem; | |
if(lib.hasClass(this.currentItem, this.options.hoverClass)) { | |
this.preventCurrentClick = false; | |
} else { | |
e.preventDefault(); | |
this.preventCurrentClick = true; | |
lib.addClass(this.currentItem, this.options.hoverClass); | |
jQuery(this.currentItem).trigger('itemhover'); | |
} | |
}, | |
clickHandler: function(e) { | |
// prevent first click on link | |
if(this.preventCurrentClick) { | |
e.preventDefault(); | |
} | |
}, | |
clickOutsideHandler: function(event) { | |
var e = event.changedTouches ? event.changedTouches[0] : event; | |
if(this.activeParent && !this.isParent(this.menu, e.target)) { | |
this.hideActiveDropdown(); | |
this.touchFlag = false; | |
} | |
}, | |
isParent: function(parent, child) { | |
while(child.parentNode) { | |
if(child.parentNode == parent) { | |
return true; | |
} | |
child = child.parentNode; | |
} | |
return false; | |
}, | |
isTouchPointerEvent: function(e) { | |
return (e.type.indexOf('touch') > -1) || | |
(navigator.pointerEnabled && e.pointerType === 'touch') || | |
(navigator.msPointerEnabled && e.pointerType == e.MSPOINTER_TYPE_TOUCH); | |
}, | |
isPointerDevice: (function() { | |
return !!(navigator.pointerEnabled || navigator.msPointerEnabled); | |
}()), | |
isTouchDevice: (function() { | |
return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch); | |
}()) | |
}; | |
/* | |
* Utility module | |
*/ | |
lib = { | |
hasClass: function(el,cls) { | |
return el && el.className ? el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')) : false; | |
}, | |
addClass: function(el,cls) { | |
if (el && !this.hasClass(el,cls)) el.className += " "+cls; | |
}, | |
removeClass: function(el,cls) { | |
if (el && this.hasClass(el,cls)) {el.className=el.className.replace(new RegExp('(\\s|^)'+cls+'(\\s|$)'),' ');} | |
}, | |
extend: function(obj) { | |
for(var i = 1; i < arguments.length; i++) { | |
for(var p in arguments[i]) { | |
if(arguments[i].hasOwnProperty(p)) { | |
obj[p] = arguments[i][p]; | |
} | |
} | |
} | |
return obj; | |
}, | |
each: function(obj, callback) { | |
var property, len; | |
if(typeof obj.length === 'number') { | |
for(property = 0, len = obj.length; property < len; property++) { | |
if(callback.call(obj[property], property, obj[property]) === false) { | |
break; | |
} | |
} | |
} else { | |
for(property in obj) { | |
if(obj.hasOwnProperty(property)) { | |
if(callback.call(obj[property], property, obj[property]) === false) { | |
break; | |
} | |
} | |
} | |
} | |
}, | |
event: (function() { | |
var fixEvent = function(e) { | |
e = e || window.event; | |
if(e.isFixed) return e; else e.isFixed = true; | |
if(!e.target) e.target = e.srcElement; | |
e.preventDefault = e.preventDefault || function() {this.returnValue = false;}; | |
e.stopPropagation = e.stopPropagation || function() {this.cancelBubble = true;}; | |
return e; | |
}; | |
return { | |
add: function(elem, event, handler) { | |
if(!elem.events) { | |
elem.events = {}; | |
elem.handle = function(e) { | |
var ret, handlers = elem.events[e.type]; | |
e = fixEvent(e); | |
for(var i = 0, len = handlers.length; i < len; i++) { | |
if(handlers[i]) { | |
ret = handlers[i].call(elem, e); | |
if(ret === false) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
} | |
} | |
} | |
}; | |
} | |
if(!elem.events[event]) { | |
elem.events[event] = []; | |
if(elem.addEventListener) elem.addEventListener(event, elem.handle, false); | |
else if(elem.attachEvent) elem.attachEvent('on'+event, elem.handle); | |
} | |
elem.events[event].push(handler); | |
}, | |
remove: function(elem, event, handler) { | |
var handlers = elem.events[event]; | |
for(var i = handlers.length - 1; i >= 0; i--) { | |
if(handlers[i] === handler) { | |
handlers.splice(i,1); | |
} | |
} | |
if(!handlers.length) { | |
delete elem.events[event]; | |
if(elem.removeEventListener) elem.removeEventListener(event, elem.handle, false); | |
else if(elem.detachEvent) elem.detachEvent('on'+event, elem.handle); | |
} | |
} | |
}; | |
}()), | |
queryElementsBySelector: function(selector, scope) { | |
scope = scope || document; | |
if(!selector) return []; | |
if(selector === '>*') return scope.children; | |
if(typeof document.querySelectorAll === 'function') { | |
return scope.querySelectorAll(selector); | |
} | |
var selectors = selector.split(','); | |
var resultList = []; | |
for(var s = 0; s < selectors.length; s++) { | |
var currentContext = [scope || document]; | |
var tokens = selectors[s].replace(/^\s+/,'').replace(/\s+$/,'').split(' '); | |
for (var i = 0; i < tokens.length; i++) { | |
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,''); | |
if (token.indexOf('#') > -1) { | |
var bits = token.split('#'), tagName = bits[0], id = bits[1]; | |
var element = document.getElementById(id); | |
if (element && tagName && element.nodeName.toLowerCase() != tagName) { | |
return []; | |
} | |
currentContext = element ? [element] : []; | |
continue; | |
} | |
if (token.indexOf('.') > -1) { | |
var bits = token.split('.'), tagName = bits[0] || '*', className = bits[1], found = [], foundCount = 0; | |
for (var h = 0; h < currentContext.length; h++) { | |
var elements; | |
if (tagName == '*') { | |
elements = currentContext[h].getElementsByTagName('*'); | |
} else { | |
elements = currentContext[h].getElementsByTagName(tagName); | |
} | |
for (var j = 0; j < elements.length; j++) { | |
found[foundCount++] = elements[j]; | |
} | |
} | |
currentContext = []; | |
var currentContextIndex = 0; | |
for (var k = 0; k < found.length; k++) { | |
if (found[k].className && found[k].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'))) { | |
currentContext[currentContextIndex++] = found[k]; | |
} | |
} | |
continue; | |
} | |
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) { | |
var tagName = RegExp.$1 || '*', attrName = RegExp.$2, attrOperator = RegExp.$3, attrValue = RegExp.$4; | |
if(attrName.toLowerCase() == 'for' && this.browser.msie && this.browser.version < 8) { | |
attrName = 'htmlFor'; | |
} | |
var found = [], foundCount = 0; | |
for (var h = 0; h < currentContext.length; h++) { | |
var elements; | |
if (tagName == '*') { | |
elements = currentContext[h].getElementsByTagName('*'); | |
} else { | |
elements = currentContext[h].getElementsByTagName(tagName); | |
} | |
for (var j = 0; elements[j]; j++) { | |
found[foundCount++] = elements[j]; | |
} | |
} | |
currentContext = []; | |
var currentContextIndex = 0, checkFunction; | |
switch (attrOperator) { | |
case '=': checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue) }; break; | |
case '~': checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('(\\s|^)'+attrValue+'(\\s|$)'))) }; break; | |
case '|': checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))) }; break; | |
case '^': checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0) }; break; | |
case '$': checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length) }; break; | |
case '*': checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1) }; break; | |
default : checkFunction = function(e) { return e.getAttribute(attrName) }; | |
} | |
currentContext = []; | |
var currentContextIndex = 0; | |
for (var k = 0; k < found.length; k++) { | |
if (checkFunction(found[k])) { | |
currentContext[currentContextIndex++] = found[k]; | |
} | |
} | |
continue; | |
} | |
tagName = token; | |
var found = [], foundCount = 0; | |
for (var h = 0; h < currentContext.length; h++) { | |
var elements = currentContext[h].getElementsByTagName(tagName); | |
for (var j = 0; j < elements.length; j++) { | |
found[foundCount++] = elements[j]; | |
} | |
} | |
currentContext = found; | |
} | |
resultList = [].concat(resultList,currentContext); | |
} | |
return resultList; | |
}, | |
trim: function (str) { | |
return str.replace(/^\s+/, '').replace(/\s+$/, ''); | |
}, | |
bind: function(f, scope, forceArgs){ | |
return function() {return f.apply(scope, typeof forceArgs !== 'undefined' ? [forceArgs] : arguments);}; | |
} | |
}; | |
/*! Hammer.JS - v2.0.4 - 2014-09-28 | |
* http://hammerjs.github.io/ | |
* | |
* Copyright (c) 2014 Jorik Tangelder; | |
* Licensed under the MIT license */ | |
if(Object.create){!function(a,b,c,d){"use strict";function e(a,b,c){return setTimeout(k(a,c),b)}function f(a,b,c){return Array.isArray(a)?(g(a,c[b],c),!0):!1}function g(a,b,c){var e;if(a)if(a.forEach)a.forEach(b,c);else if(a.length!==d)for(e=0;e<a.length;)b.call(c,a[e],e,a),e++;else for(e in a)a.hasOwnProperty(e)&&b.call(c,a[e],e,a)}function h(a,b,c){for(var e=Object.keys(b),f=0;f<e.length;)(!c||c&&a[e[f]]===d)&&(a[e[f]]=b[e[f]]),f++;return a}function i(a,b){return h(a,b,!0)}function j(a,b,c){var d,e=b.prototype;d=a.prototype=Object.create(e),d.constructor=a,d._super=e,c&&h(d,c)}function k(a,b){return function(){return a.apply(b,arguments)}}function l(a,b){return typeof a==kb?a.apply(b?b[0]||d:d,b):a}function m(a,b){return a===d?b:a}function n(a,b,c){g(r(b),function(b){a.addEventListener(b,c,!1)})}function o(a,b,c){g(r(b),function(b){a.removeEventListener(b,c,!1)})}function p(a,b){for(;a;){if(a==b)return!0;a=a.parentNode}return!1}function q(a,b){return a.indexOf(b)>-1}function r(a){return a.trim().split(/\s+/g)}function s(a,b,c){if(a.indexOf&&!c)return a.indexOf(b);for(var d=0;d<a.length;){if(c&&a[d][c]==b||!c&&a[d]===b)return d;d++}return-1}function t(a){return Array.prototype.slice.call(a,0)}function u(a,b,c){for(var d=[],e=[],f=0;f<a.length;){var g=b?a[f][b]:a[f];s(e,g)<0&&d.push(a[f]),e[f]=g,f++}return c&&(d=b?d.sort(function(a,c){return a[b]>c[b]}):d.sort()),d}function v(a,b){for(var c,e,f=b[0].toUpperCase()+b.slice(1),g=0;g<ib.length;){if(c=ib[g],e=c?c+f:b,e in a)return e;g++}return d}function w(){return ob++}function x(a){var b=a.ownerDocument;return b.defaultView||b.parentWindow}function y(a,b){var c=this;this.manager=a,this.callback=b,this.element=a.element,this.target=a.options.inputTarget,this.domHandler=function(b){l(a.options.enable,[a])&&c.handler(b)},this.init()}function z(a){var b,c=a.options.inputClass;return new(b=c?c:rb?N:sb?Q:qb?S:M)(a,A)}function A(a,b,c){var d=c.pointers.length,e=c.changedPointers.length,f=b&yb&&d-e===0,g=b&(Ab|Bb)&&d-e===0;c.isFirst=!!f,c.isFinal=!!g,f&&(a.session={}),c.eventType=b,B(a,c),a.emit("hammer.input",c),a.recognize(c),a.session.prevInput=c}function B(a,b){var c=a.session,d=b.pointers,e=d.length;c.firstInput||(c.firstInput=E(b)),e>1&&!c.firstMultiple?c.firstMultiple=E(b):1===e&&(c.firstMultiple=!1);var f=c.firstInput,g=c.firstMultiple,h=g?g.center:f.center,i=b.center=F(d);b.timeStamp=nb(),b.deltaTime=b.timeStamp-f.timeStamp,b.angle=J(h,i),b.distance=I(h,i),C(c,b),b.offsetDirection=H(b.deltaX,b.deltaY),b.scale=g?L(g.pointers,d):1,b.rotation=g?K(g.pointers,d):0,D(c,b);var j=a.element;p(b.srcEvent.target,j)&&(j=b.srcEvent.target),b.target=j}function C(a,b){var c=b.center,d=a.offsetDelta||{},e=a.prevDelta||{},f=a.prevInput||{};(b.eventType===yb||f.eventType===Ab)&&(e=a.prevDelta={x:f.deltaX||0,y:f.deltaY||0},d=a.offsetDelta={x:c.x,y:c.y}),b.deltaX=e.x+(c.x-d.x),b.deltaY=e.y+(c.y-d.y)}function D(a,b){var c,e,f,g,h=a.lastInterval||b,i=b.timeStamp-h.timeStamp;if(b.eventType!=Bb&&(i>xb||h.velocity===d)){var j=h.deltaX-b.deltaX,k=h.deltaY-b.deltaY,l=G(i,j,k);e=l.x,f=l.y,c=mb(l.x)>mb(l.y)?l.x:l.y,g=H(j,k),a.lastInterval=b}else c=h.velocity,e=h.velocityX,f=h.velocityY,g=h.direction;b.velocity=c,b.velocityX=e,b.velocityY=f,b.direction=g}function E(a){for(var b=[],c=0;c<a.pointers.length;)b[c]={clientX:lb(a.pointers[c].clientX),clientY:lb(a.pointers[c].clientY)},c++;return{timeStamp:nb(),pointers:b,center:F(b),deltaX:a.deltaX,deltaY:a.deltaY}}function F(a){var b=a.length;if(1===b)return{x:lb(a[0].clientX),y:lb(a[0].clientY)};for(var c=0,d=0,e=0;b>e;)c+=a[e].clientX,d+=a[e].clientY,e++;return{x:lb(c/b),y:lb(d/b)}}function G(a,b,c){return{x:b/a||0,y:c/a||0}}function H(a,b){return a===b?Cb:mb(a)>=mb(b)?a>0?Db:Eb:b>0?Fb:Gb}function I(a,b,c){c||(c=Kb);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return Math.sqrt(d*d+e*e)}function J(a,b,c){c||(c=Kb);var d=b[c[0]]-a[c[0]],e=b[c[1]]-a[c[1]];return 180*Math.atan2(e,d)/Math.PI}function K(a,b){return J(b[1],b[0],Lb)-J(a[1],a[0],Lb)}function L(a,b){return I(b[0],b[1],Lb)/I(a[0],a[1],Lb)}function M(){this.evEl=Nb,this.evWin=Ob,this.allow=!0,this.pressed=!1,y.apply(this,arguments)}function N(){this.evEl=Rb,this.evWin=Sb,y.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}function O(){this.evTarget=Ub,this.evWin=Vb,this.started=!1,y.apply(this,arguments)}function P(a,b){var c=t(a.touches),d=t(a.changedTouches);return b&(Ab|Bb)&&(c=u(c.concat(d),"identifier",!0)),[c,d]}function Q(){this.evTarget=Xb,this.targetIds={},y.apply(this,arguments)}function R(a,b){var c=t(a.touches),d=this.targetIds;if(b&(yb|zb)&&1===c.length)return d[c[0].identifier]=!0,[c,c];var e,f,g=t(a.changedTouches),h=[],i=this.target;if(f=c.filter(function(a){return p(a.target,i)}),b===yb)for(e=0;e<f.length;)d[f[e].identifier]=!0,e++;for(e=0;e<g.length;)d[g[e].identifier]&&h.push(g[e]),b&(Ab|Bb)&&delete d[g[e].identifier],e++;return h.length?[u(f.concat(h),"identifier",!0),h]:void 0}function S(){y.apply(this,arguments);var a=k(this.handler,this);this.touch=new Q(this.manager,a),this.mouse=new M(this.manager,a)}function T(a,b){this.manager=a,this.set(b)}function U(a){if(q(a,bc))return bc;var b=q(a,cc),c=q(a,dc);return b&&c?cc+" "+dc:b||c?b?cc:dc:q(a,ac)?ac:_b}function V(a){this.id=w(),this.manager=null,this.options=i(a||{},this.defaults),this.options.enable=m(this.options.enable,!0),this.state=ec,this.simultaneous={},this.requireFail=[]}function W(a){return a&jc?"cancel":a&hc?"end":a&gc?"move":a&fc?"start":""}function X(a){return a==Gb?"down":a==Fb?"up":a==Db?"left":a==Eb?"right":""}function Y(a,b){var c=b.manager;return c?c.get(a):a}function Z(){V.apply(this,arguments)}function $(){Z.apply(this,arguments),this.pX=null,this.pY=null}function _(){Z.apply(this,arguments)}function ab(){V.apply(this,arguments),this._timer=null,this._input=null}function bb(){Z.apply(this,arguments)}function cb(){Z.apply(this,arguments)}function db(){V.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function eb(a,b){return b=b||{},b.recognizers=m(b.recognizers,eb.defaults.preset),new fb(a,b)}function fb(a,b){b=b||{},this.options=i(b,eb.defaults),this.options.inputTarget=this.options.inputTarget||a,this.handlers={},this.session={},this.recognizers=[],this.element=a,this.input=z(this),this.touchAction=new T(this,this.options.touchAction),gb(this,!0),g(b.recognizers,function(a){var b=this.add(new a[0](a[1]));a[2]&&b.recognizeWith(a[2]),a[3]&&b.requireFailure(a[3])},this)}function gb(a,b){var c=a.element;g(a.options.cssProps,function(a,d){c.style[v(c.style,d)]=b?a:""})}function hb(a,c){var d=b.createEvent("Event");d.initEvent(a,!0,!0),d.gesture=c,c.target.dispatchEvent(d)}var ib=["","webkit","moz","MS","ms","o"],jb=b.createElement("div"),kb="function",lb=Math.round,mb=Math.abs,nb=Date.now,ob=1,pb=/mobile|tablet|ip(ad|hone|od)|android/i,qb="ontouchstart"in a,rb=v(a,"PointerEvent")!==d,sb=qb&&pb.test(navigator.userAgent),tb="touch",ub="pen",vb="mouse",wb="kinect",xb=25,yb=1,zb=2,Ab=4,Bb=8,Cb=1,Db=2,Eb=4,Fb=8,Gb=16,Hb=Db|Eb,Ib=Fb|Gb,Jb=Hb|Ib,Kb=["x","y"],Lb=["clientX","clientY"];y.prototype={handler:function(){},init:function(){this.evEl&&n(this.element,this.evEl,this.domHandler),this.evTarget&&n(this.target,this.evTarget,this.domHandler),this.evWin&&n(x(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&o(this.element,this.evEl,this.domHandler),this.evTarget&&o(this.target,this.evTarget,this.domHandler),this.evWin&&o(x(this.element),this.evWin,this.domHandler)}};var Mb={mousedown:yb,mousemove:zb,mouseup:Ab},Nb="mousedown",Ob="mousemove mouseup";j(M,y,{handler:function(a){var b=Mb[a.type];b&yb&&0===a.button&&(this.pressed=!0),b&zb&&1!==a.which&&(b=Ab),this.pressed&&this.allow&&(b&Ab&&(this.pressed=!1),this.callback(this.manager,b,{pointers:[a],changedPointers:[a],pointerType:vb,srcEvent:a}))}});var Pb={pointerdown:yb,pointermove:zb,pointerup:Ab,pointercancel:Bb,pointerout:Bb},Qb={2:tb,3:ub,4:vb,5:wb},Rb="pointerdown",Sb="pointermove pointerup pointercancel";a.MSPointerEvent&&(Rb="MSPointerDown",Sb="MSPointerMove MSPointerUp MSPointerCancel"),j(N,y,{handler:function(a){var b=this.store,c=!1,d=a.type.toLowerCase().replace("ms",""),e=Pb[d],f=Qb[a.pointerType]||a.pointerType,g=f==tb,h=s(b,a.pointerId,"pointerId");e&yb&&(0===a.button||g)?0>h&&(b.push(a),h=b.length-1):e&(Ab|Bb)&&(c=!0),0>h||(b[h]=a,this.callback(this.manager,e,{pointers:b,changedPointers:[a],pointerType:f,srcEvent:a}),c&&b.splice(h,1))}});var Tb={touchstart:yb,touchmove:zb,touchend:Ab,touchcancel:Bb},Ub="touchstart",Vb="touchstart touchmove touchend touchcancel";j(O,y,{handler:function(a){var b=Tb[a.type];if(b===yb&&(this.started=!0),this.started){var c=P.call(this,a,b);b&(Ab|Bb)&&c[0].length-c[1].length===0&&(this.started=!1),this.callback(this.manager,b,{pointers:c[0],changedPointers:c[1],pointerType:tb,srcEvent:a})}}});var Wb={touchstart:yb,touchmove:zb,touchend:Ab,touchcancel:Bb},Xb="touchstart touchmove touchend touchcancel";j(Q,y,{handler:function(a){var b=Wb[a.type],c=R.call(this,a,b);c&&this.callback(this.manager,b,{pointers:c[0],changedPointers:c[1],pointerType:tb,srcEvent:a})}}),j(S,y,{handler:function(a,b,c){var d=c.pointerType==tb,e=c.pointerType==vb;if(d)this.mouse.allow=!1;else if(e&&!this.mouse.allow)return;b&(Ab|Bb)&&(this.mouse.allow=!0),this.callback(a,b,c)},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var Yb=v(jb.style,"touchAction"),Zb=Yb!==d,$b="compute",_b="auto",ac="manipulation",bc="none",cc="pan-x",dc="pan-y";T.prototype={set:function(a){a==$b&&(a=this.compute()),Zb&&(this.manager.element.style[Yb]=a),this.actions=a.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var a=[];return g(this.manager.recognizers,function(b){l(b.options.enable,[b])&&(a=a.concat(b.getTouchAction()))}),U(a.join(" "))},preventDefaults:function(a){if(!Zb){var b=a.srcEvent,c=a.offsetDirection;if(this.manager.session.prevented)return void b.preventDefault();var d=this.actions,e=q(d,bc),f=q(d,dc),g=q(d,cc);return e||f&&c&Hb||g&&c&Ib?this.preventSrc(b):void 0}},preventSrc:function(a){this.manager.session.prevented=!0,a.preventDefault()}};var ec=1,fc=2,gc=4,hc=8,ic=hc,jc=16,kc=32;V.prototype={defaults:{},set:function(a){return h(this.options,a),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(a){if(f(a,"recognizeWith",this))return this;var b=this.simultaneous;return a=Y(a,this),b[a.id]||(b[a.id]=a,a.recognizeWith(this)),this},dropRecognizeWith:function(a){return f(a,"dropRecognizeWith",this)?this:(a=Y(a,this),delete this.simultaneous[a.id],this)},requireFailure:function(a){if(f(a,"requireFailure",this))return this;var b=this.requireFail;return a=Y(a,this),-1===s(b,a)&&(b.push(a),a.requireFailure(this)),this},dropRequireFailure:function(a){if(f(a,"dropRequireFailure",this))return this;a=Y(a,this);var b=s(this.requireFail,a);return b>-1&&this.requireFail.splice(b,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(a){return!!this.simultaneous[a.id]},emit:function(a){function b(b){c.manager.emit(c.options.event+(b?W(d):""),a)}var c=this,d=this.state;hc>d&&b(!0),b(),d>=hc&&b(!0)},tryEmit:function(a){return this.canEmit()?this.emit(a):void(this.state=kc)},canEmit:function(){for(var a=0;a<this.requireFail.length;){if(!(this.requireFail[a].state&(kc|ec)))return!1;a++}return!0},recognize:function(a){var b=h({},a);return l(this.options.enable,[this,b])?(this.state&(ic|jc|kc)&&(this.state=ec),this.state=this.process(b),void(this.state&(fc|gc|hc|jc)&&this.tryEmit(b))):(this.reset(),void(this.state=kc))},process:function(){},getTouchAction:function(){},reset:function(){}},j(Z,V,{defaults:{pointers:1},attrTest:function(a){var b=this.options.pointers;return 0===b||a.pointers.length===b},process:function(a){var b=this.state,c=a.eventType,d=b&(fc|gc),e=this.attrTest(a);return d&&(c&Bb||!e)?b|jc:d||e?c&Ab?b|hc:b&fc?b|gc:fc:kc}}),j($,Z,{defaults:{event:"pan",threshold:10,pointers:1,direction:Jb},getTouchAction:function(){var a=this.options.direction,b=[];return a&Hb&&b.push(dc),a&Ib&&b.push(cc),b},directionTest:function(a){var b=this.options,c=!0,d=a.distance,e=a.direction,f=a.deltaX,g=a.deltaY;return e&b.direction||(b.direction&Hb?(e=0===f?Cb:0>f?Db:Eb,c=f!=this.pX,d=Math.abs(a.deltaX)):(e=0===g?Cb:0>g?Fb:Gb,c=g!=this.pY,d=Math.abs(a.deltaY))),a.direction=e,c&&d>b.threshold&&e&b.direction},attrTest:function(a){return Z.prototype.attrTest.call(this,a)&&(this.state&fc||!(this.state&fc)&&this.directionTest(a))},emit:function(a){this.pX=a.deltaX,this.pY=a.deltaY;var b=X(a.direction);b&&this.manager.emit(this.options.event+b,a),this._super.emit.call(this,a)}}),j(_,Z,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[bc]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.scale-1)>this.options.threshold||this.state&fc)},emit:function(a){if(this._super.emit.call(this,a),1!==a.scale){var b=a.scale<1?"in":"out";this.manager.emit(this.options.event+b,a)}}}),j(ab,V,{defaults:{event:"press",pointers:1,time:500,threshold:5},getTouchAction:function(){return[_b]},process:function(a){var b=this.options,c=a.pointers.length===b.pointers,d=a.distance<b.threshold,f=a.deltaTime>b.time;if(this._input=a,!d||!c||a.eventType&(Ab|Bb)&&!f)this.reset();else if(a.eventType&yb)this.reset(),this._timer=e(function(){this.state=ic,this.tryEmit()},b.time,this);else if(a.eventType&Ab)return ic;return kc},reset:function(){clearTimeout(this._timer)},emit:function(a){this.state===ic&&(a&&a.eventType&Ab?this.manager.emit(this.options.event+"up",a):(this._input.timeStamp=nb(),this.manager.emit(this.options.event,this._input)))}}),j(bb,Z,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[bc]},attrTest:function(a){return this._super.attrTest.call(this,a)&&(Math.abs(a.rotation)>this.options.threshold||this.state&fc)}}),j(cb,Z,{defaults:{event:"swipe",threshold:10,velocity:.65,direction:Hb|Ib,pointers:1},getTouchAction:function(){return $.prototype.getTouchAction.call(this)},attrTest:function(a){var b,c=this.options.direction;return c&(Hb|Ib)?b=a.velocity:c&Hb?b=a.velocityX:c&Ib&&(b=a.velocityY),this._super.attrTest.call(this,a)&&c&a.direction&&a.distance>this.options.threshold&&mb(b)>this.options.velocity&&a.eventType&Ab},emit:function(a){var b=X(a.direction);b&&this.manager.emit(this.options.event+b,a),this.manager.emit(this.options.event,a)}}),j(db,V,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:2,posThreshold:10},getTouchAction:function(){return[ac]},process:function(a){var b=this.options,c=a.pointers.length===b.pointers,d=a.distance<b.threshold,f=a.deltaTime<b.time;if(this.reset(),a.eventType&yb&&0===this.count)return this.failTimeout();if(d&&f&&c){if(a.eventType!=Ab)return this.failTimeout();var g=this.pTime?a.timeStamp-this.pTime<b.interval:!0,h=!this.pCenter||I(this.pCenter,a.center)<b.posThreshold;this.pTime=a.timeStamp,this.pCenter=a.center,h&&g?this.count+=1:this.count=1,this._input=a;var i=this.count%b.taps;if(0===i)return this.hasRequireFailures()?(this._timer=e(function(){this.state=ic,this.tryEmit()},b.interval,this),fc):ic}return kc},failTimeout:function(){return this._timer=e(function(){this.state=kc},this.options.interval,this),kc},reset:function(){clearTimeout(this._timer)},emit:function(){this.state==ic&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),eb.VERSION="2.0.4",eb.defaults={domEvents:!1,touchAction:$b,enable:!0,inputTarget:null,inputClass:null,preset:[[bb,{enable:!1}],[_,{enable:!1},["rotate"]],[cb,{direction:Hb}],[$,{direction:Hb},["swipe"]],[db],[db,{event:"doubletap",taps:2},["tap"]],[ab]],cssProps:{userSelect:"none",touchSelect:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};var lc=1,mc=2;fb.prototype={set:function(a){return h(this.options,a),a.touchAction&&this.touchAction.update(),a.inputTarget&&(this.input.destroy(),this.input.target=a.inputTarget,this.input.init()),this},stop:function(a){this.session.stopped=a?mc:lc},recognize:function(a){var b=this.session;if(!b.stopped){this.touchAction.preventDefaults(a);var c,d=this.recognizers,e=b.curRecognizer;(!e||e&&e.state&ic)&&(e=b.curRecognizer=null);for(var f=0;f<d.length;)c=d[f],b.stopped===mc||e&&c!=e&&!c.canRecognizeWith(e)?c.reset():c.recognize(a),!e&&c.state&(fc|gc|hc)&&(e=b.curRecognizer=c),f++}},get:function(a){if(a instanceof V)return a;for(var b=this.recognizers,c=0;c<b.length;c++)if(b[c].options.event==a)return b[c];return null},add:function(a){if(f(a,"add",this))return this;var b=this.get(a.options.event);return b&&this.remove(b),this.recognizers.push(a),a.manager=this,this.touchAction.update(),a},remove:function(a){if(f(a,"remove",this))return this;var b=this.recognizers;return a=this.get(a),b.splice(s(b,a),1),this.touchAction.update(),this},on:function(a,b){var c=this.handlers;return g(r(a),function(a){c[a]=c[a]||[],c[a].push(b)}),this},off:function(a,b){var c=this.handlers;return g(r(a),function(a){b?c[a].splice(s(c[a],b),1):delete c[a]}),this},emit:function(a,b){this.options.domEvents&&hb(a,b);var c=this.handlers[a]&&this.handlers[a].slice();if(c&&c.length){b.type=a,b.preventDefault=function(){b.srcEvent.preventDefault()};for(var d=0;d<c.length;)c[d](b),d++}},destroy:function(){this.element&&gb(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},h(eb,{INPUT_START:yb,INPUT_MOVE:zb,INPUT_END:Ab,INPUT_CANCEL:Bb,STATE_POSSIBLE:ec,STATE_BEGAN:fc,STATE_CHANGED:gc,STATE_ENDED:hc,STATE_RECOGNIZED:ic,STATE_CANCELLED:jc,STATE_FAILED:kc,DIRECTION_NONE:Cb,DIRECTION_LEFT:Db,DIRECTION_RIGHT:Eb,DIRECTION_UP:Fb,DIRECTION_DOWN:Gb,DIRECTION_HORIZONTAL:Hb,DIRECTION_VERTICAL:Ib,DIRECTION_ALL:Jb,Manager:fb,Input:y,TouchAction:T,TouchInput:Q,MouseInput:M,PointerEventInput:N,TouchMouseInput:S,SingleTouchInput:O,Recognizer:V,AttrRecognizer:Z,Tap:db,Pan:$,Swipe:cb,Pinch:_,Rotate:bb,Press:ab,on:n,off:o,each:g,merge:i,extend:h,inherit:j,bindFn:k,prefixed:v}),typeof define==kb&&define.amd?define(function(){return eb}):"undefined"!=typeof module&&module.exports?module.exports=eb:a[c]=eb}(window,document,"Hammer");} | |
/*! | |
* FitVids 1.0.3 | |
* | |
* Copyright 2013, Chris Coyier - http://css-tricks.com + Dave Rupert - http://daverupert.com | |
* Credit to Thierry Koblentz - http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/ | |
* Released under the WTFPL license - http://sam.zoy.org/wtfpl/ | |
* | |
* Date: Thu Sept 01 18:00:00 2011 -0500 | |
*/ | |
;(function(a){a.fn.fitVids=function(b){var c={customSelector:null};if(!document.getElementById("fit-vids-style")){var f=document.createElement("div"),d=document.getElementsByTagName("base")[0]||document.getElementsByTagName("script")[0],e="­<style>.fluid-width-video-wrapper{width:100%;position:relative;padding:0;}.fluid-width-video-wrapper iframe,.fluid-width-video-wrapper object,.fluid-width-video-wrapper embed {position:absolute;top:0;left:0;width:100%;height:100%;}</style>";f.className="fit-vids-style";f.id="fit-vids-style";f.style.display="none";f.innerHTML=e;d.parentNode.insertBefore(f,d)}if(b){a.extend(c,b)}return this.each(function(){var g=["iframe[src*='player.vimeo.com']","iframe[src*='youtube.com']","iframe[src*='youtube-nocookie.com']","iframe[src*='kickstarter.com'][src*='video.html']","object","embed"];if(c.customSelector){g.push(c.customSelector)}var h=a(this).find(g.join(","));h=h.not("object object");h.each(function(){var m=a(this);if(this.tagName.toLowerCase()==="embed"&&m.parent("object").length||m.parent(".fluid-width-video-wrapper").length){return}var i=(this.tagName.toLowerCase()==="object"||(m.attr("height")&&!isNaN(parseInt(m.attr("height"),10))))?parseInt(m.attr("height"),10):m.height(),j=!isNaN(parseInt(m.attr("width"),10))?parseInt(m.attr("width"),10):m.width(),k=i/j;if(!m.attr("id")){var l="fitvid"+Math.floor(Math.random()*999999);m.attr("id",l)}m.wrap('<div class="fluid-width-video-wrapper"></div>').parent(".fluid-width-video-wrapper").css("padding-top",(k*100)+"%");m.removeAttr("height").removeAttr("width")})})}})(window.jQuery||window.Zepto); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment