/home/arranoyd/gazehome/wp-content/themes/uncode/library/js/plugins.js
/* ----------------------------------------------------------
* Plugins
* ---------------------------------------------------------- */
(function(window, $) {
'use strict';
var counter = 0,
$headCache = $('head'),
oldBigText = window.BigText,
oldjQueryMethod = $.fn.bigtext,
BigText = {
DEBUG_MODE: false,
DEFAULT_MIN_FONT_SIZE_PX: null,
DEFAULT_MAX_FONT_SIZE_PX: 528,
GLOBAL_STYLE_ID: 'bigtext-style',
STYLE_ID: 'bigtext-id',
LINE_CLASS_PREFIX: 'bigtext-line',
EXEMPT_CLASS: 'bigtext-exempt',
noConflict: function(restore)
{
if(restore) {
$.fn.bigtext = oldjQueryMethod;
window.BigText = oldBigText;
}
return BigText;
},
supports: {
wholeNumberFontSizeOnly: (function() {
if( !( 'getComputedStyle' in window ) ) {
return true;
}
var test = $('<div/>').css({
position: 'absolute',
'font-size': '14.1px'
}).insertBefore( $('script').eq(0) ),
computedStyle = window.getComputedStyle( test[0], null );
var ret = computedStyle && computedStyle.getPropertyValue( 'font-size' ) === '14px';
test.remove();
return ret;
})()
},
init: function() {
if(!$('#'+BigText.GLOBAL_STYLE_ID).length) {
$headCache.append(BigText.generateStyleTag(BigText.GLOBAL_STYLE_ID, ['.bigtext * { white-space: nowrap; } .bigtext > * { display: block; }',
'.bigtext .' + BigText.EXEMPT_CLASS + ', .bigtext .' + BigText.EXEMPT_CLASS + ' * { white-space: normal; }']));
}
},
bindResize: function(eventName, resizeFunction) {
var timeoutId;
$(window).unbind(eventName).bind(eventName, function() {
if( timeoutId ) {
clearTimeout( timeoutId );
}
timeoutId = setTimeout( resizeFunction, 300 );
});
},
getStyleId: function(id)
{
return BigText.STYLE_ID + '-' + id;
},
generateStyleTag: function(id, css)
{
return $('<style>' + css.join('\n') + '</style>').attr('id', id);
},
clearCss: function(id)
{
var styleId = BigText.getStyleId(id);
$('#' + styleId).remove();
},
generateCss: function(id, linesFontSizes, lineWordSpacings, minFontSizes)
{
var css = [];
BigText.clearCss(id);
for(var j=0, k=linesFontSizes.length; j<k; j++) {
css.push('#' + id + ' .' + BigText.LINE_CLASS_PREFIX + j + ' {' +
(minFontSizes[j] ? ' white-space: normal;' : '') +
(linesFontSizes[j] ? ' font-size: ' + linesFontSizes[j] + 'px;' : '') +
(lineWordSpacings[j] ? ' word-spacing: ' + lineWordSpacings[j] + 'px;' : '') +
'}');
}
return BigText.generateStyleTag(BigText.getStyleId(id), css);
},
jQueryMethod: function(options)
{
BigText.init();
options = $.extend({
minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
childSelector: '',
resize: true
}, options || {});
this.each(function()
{
var $t = $(this).addClass('bigtext'),
maxWidth = $t.width(),
id = $t.attr('id'),
$children = options.childSelector ? $t.find( options.childSelector ) : $t.children();
if(!id) {
id = 'bigtext-id' + (counter++);
$t.attr('id', id);
}
if(options.resize) {
BigText.bindResize('resize.bigtext-event-' + id, function()
{
// TODO only call this if the width has changed.
BigText.jQueryMethod.call($('#' + id), options);
});
}
BigText.clearCss(id);
$children.addClass(function(lineNumber, className)
{
// remove existing line classes.
return [className.replace(new RegExp('\\b' + BigText.LINE_CLASS_PREFIX + '\\d+\\b'), ''),
BigText.LINE_CLASS_PREFIX + lineNumber].join(' ');
});
var sizes = calculateSizes($t, $children, maxWidth, options.maxfontsize, options.minfontsize);
$headCache.append(BigText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
});
return this.trigger('bigtext:complete');
}
};
function testLineDimensions($line, maxWidth, property, size, interval, units, previousWidth)
{
var width;
previousWidth = typeof previousWidth === 'number' ? previousWidth : 0;
$line.css(property, size + units);
width = $line.width();
if(width >= maxWidth) {
$line.css(property, '');
if(width === maxWidth) {
return {
match: 'exact',
size: parseFloat((parseFloat(size) - 0.1).toFixed(3))
};
}
// Since this is an estimate, we calculate how far over the width we went with the new value.
// If this is word-spacing (our last resort guess) and the over is less than the under, we keep the higher value.
// Otherwise, we revert to the underestimate.
var under = maxWidth - previousWidth,
over = width - maxWidth;
return {
match: 'estimate',
size: parseFloat((parseFloat(size) - (property === 'word-spacing' && previousWidth && ( over < under ) ? 0 : interval)).toFixed(3))
};
}
return width;
}
function calculateSizes($t, $children, maxWidth, maxFontSize, minFontSize)
{
var $c = $t.clone(true)
.addClass('bigtext-cloned')
.css({
fontFamily: $t.css('font-family'),
textTransform: $t.css('text-transform'),
wordSpacing: $t.css('word-spacing'),
letterSpacing: $t.css('letter-spacing'),
position: 'absolute',
left: BigText.DEBUG_MODE ? 0 : -9999,
top: BigText.DEBUG_MODE ? 0 : -9999
})
.appendTo(document.body);
// font-size isn't the only thing we can modify, we can also mess with:
// word-spacing and letter-spacing. WebKit does not respect subpixel
// letter-spacing, word-spacing, or font-size.
// TODO try -webkit-transform: scale() as a workaround.
var fontSizes = [],
wordSpacings = [],
minFontSizes = [],
ratios = [];
$children.css('float', 'left').each(function() {
var $line = $(this),
// TODO replace 8, 4 with a proportional size to the calculated font-size.
intervals = BigText.supports.wholeNumberFontSizeOnly ? [8, 4, 1] : [8, 4, 1, 0.1],
lineMax,
newFontSize;
if($line.hasClass(BigText.EXEMPT_CLASS)) {
fontSizes.push(null);
ratios.push(null);
minFontSizes.push(false);
return;
}
// TODO we can cache this ratio?
var autoGuessSubtraction = 32, // font size in px
currentFontSize = parseFloat($line.css('font-size')),
ratio = ( $line.width() / currentFontSize ).toFixed(6);
newFontSize = parseInt( maxWidth / ratio, 10 ) - autoGuessSubtraction;
outer: for(var m=0, n=intervals.length; m<n; m++) {
inner: for(var j=1, k=10; j<=k; j++) {
if(newFontSize + j*intervals[m] > maxFontSize) {
newFontSize = maxFontSize;
break outer;
}
lineMax = testLineDimensions($line, maxWidth, 'font-size', newFontSize + j*intervals[m], intervals[m], 'px', lineMax);
if(typeof lineMax !== 'number') {
newFontSize = lineMax.size;
if(lineMax.match === 'exact') {
break outer;
}
break inner;
}
}
}
ratios.push(maxWidth / newFontSize);
if(newFontSize > maxFontSize) {
fontSizes.push(maxFontSize);
minFontSizes.push(false);
} else if(!!minFontSize && newFontSize < minFontSize) {
fontSizes.push(minFontSize);
minFontSizes.push(true);
} else {
fontSizes.push(newFontSize);
minFontSizes.push(false);
}
}).each(function(lineNumber) {
var $line = $(this),
wordSpacing = 0,
interval = 1,
maxWordSpacing;
if($line.hasClass(BigText.EXEMPT_CLASS)) {
wordSpacings.push(null);
return;
}
// must re-use font-size, even though it was removed above.
$line.css('font-size', fontSizes[lineNumber] + 'px');
for(var m=1, n=3; m<n; m+=interval) {
maxWordSpacing = testLineDimensions($line, maxWidth, 'word-spacing', m, interval, 'px', maxWordSpacing);
if(typeof maxWordSpacing !== 'number') {
wordSpacing = maxWordSpacing.size;
break;
}
}
$line.css('font-size', '');
wordSpacings.push(wordSpacing);
}).removeAttr('style');
if( !BigText.DEBUG_MODE ) {
$c.remove();
} else {
$c.css({
'background-color': 'rgba(255,255,255,.4)'
});
}
return {
fontSizes: fontSizes,
wordSpacings: wordSpacings,
ratios: ratios,
minFontSizes: minFontSizes
};
}
$.fn.bigtext = BigText.jQueryMethod;
window.BigText = BigText;
})(this, jQuery);
/*!
* Isotope PACKAGED v2.2.2
*
* Licensed GPLv3 for open source use
* or Isotope Commercial License for commercial use
*
* http://isotope.metafizzy.co
* Copyright 2015 Metafizzy
*/
/**
* Bridget makes jQuery widgets
* v1.1.0
* MIT license
*/
( function( window ) {
// -------------------------- utils -------------------------- //
var slice = Array.prototype.slice;
function noop() {}
// -------------------------- definition -------------------------- //
function defineBridget( $ ) {
// bail if no jQuery
if ( !$ ) {
return;
}
// -------------------------- addOptionMethod -------------------------- //
/**
* adds option method -> $().plugin('option', {...})
* @param {Function} PluginClass - constructor class
*/
function addOptionMethod( PluginClass ) {
// don't overwrite original option method
if ( PluginClass.prototype.option ) {
return;
}
// option setter
PluginClass.prototype.option = function( opts ) {
// bail out if not an object
if ( !$.isPlainObject( opts ) ){
return;
}
this.options = $.extend( true, this.options, opts );
};
}
// -------------------------- plugin bridge -------------------------- //
// helper function for logging errors
// $.error breaks jQuery chaining
var logError = typeof console === 'undefined' ? noop :
function( message ) {
console.error( message );
};
/**
* jQuery plugin bridge, access methods like $elem.plugin('method')
* @param {String} namespace - plugin name
* @param {Function} PluginClass - constructor class
*/
function bridge( namespace, PluginClass ) {
// add to jQuery fn namespace
$.fn[ namespace ] = function( options ) {
if ( typeof options === 'string' ) {
// call plugin method when first argument is a string
// get arguments for method
var args = slice.call( arguments, 1 );
for ( var i=0, len = this.length; i < len; i++ ) {
var elem = this[i];
var instance = $.data( elem, namespace );
if ( !instance ) {
logError( "cannot call methods on " + namespace + " prior to initialization; " +
"attempted to call '" + options + "'" );
continue;
}
if ( !$.isFunction( instance[options] ) || options.charAt(0) === '_' ) {
logError( "no such method '" + options + "' for " + namespace + " instance" );
continue;
}
// trigger method with arguments
var returnValue = instance[ options ].apply( instance, args );
// break look and return first value if provided
if ( returnValue !== undefined ) {
return returnValue;
}
}
// return this if no return value
return this;
} else {
return this.each( function() {
var instance = $.data( this, namespace );
if ( instance ) {
// apply options & init
instance.option( options );
instance._init();
} else {
// initialize new instance
instance = new PluginClass( this, options );
$.data( this, namespace, instance );
}
});
}
};
}
// -------------------------- bridget -------------------------- //
/**
* converts a Prototypical class into a proper jQuery plugin
* the class must have a ._init method
* @param {String} namespace - plugin name, used in $().pluginName
* @param {Function} PluginClass - constructor class
*/
$.bridget = function( namespace, PluginClass ) {
addOptionMethod( PluginClass );
bridge( namespace, PluginClass );
};
return $.bridget;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'jquery-bridget/jquery.bridget',[ 'jquery' ], defineBridget );
} else if ( typeof exports === 'object' ) {
defineBridget( require('jquery') );
} else {
// get jquery from browser global
defineBridget( window.jQuery );
}
})( window );
/*!
* eventie v1.0.6
* event binding helper
* eventie.bind( elem, 'click', myFn )
* eventie.unbind( elem, 'click', myFn )
* MIT license
*/
/*jshint browser: true, undef: true, unused: true */
/*global define: false, module: false */
( function( window ) {
var docElem = document.documentElement;
var bind = function() {};
function getIEEvent( obj ) {
var event = window.event;
// add event.target
event.target = event.target || event.srcElement || obj;
return event;
}
if ( docElem.addEventListener ) {
bind = function( obj, type, fn ) {
obj.addEventListener( type, fn, false );
};
} else if ( docElem.attachEvent ) {
bind = function( obj, type, fn ) {
obj[ type + fn ] = fn.handleEvent ?
function() {
var event = getIEEvent( obj );
fn.handleEvent.call( fn, event );
} :
function() {
var event = getIEEvent( obj );
fn.call( obj, event );
};
obj.attachEvent( "on" + type, obj[ type + fn ] );
};
}
var unbind = function() {};
if ( docElem.removeEventListener ) {
unbind = function( obj, type, fn ) {
obj.removeEventListener( type, fn, false );
};
} else if ( docElem.detachEvent ) {
unbind = function( obj, type, fn ) {
obj.detachEvent( "on" + type, obj[ type + fn ] );
try {
delete obj[ type + fn ];
} catch ( err ) {
// can't delete window object properties
obj[ type + fn ] = undefined;
}
};
}
var eventie = {
bind: bind,
unbind: unbind
};
// ----- module definition ----- //
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'eventie/eventie',eventie );
} else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = eventie;
} else {
// browser global
window.eventie = eventie;
}
})( window );
/*!
* EventEmitter v4.2.11 - git.io/ee
* Unlicense - http://unlicense.org/
* Oliver Caldwell - http://oli.me.uk/
* @preserve
*/
;(function () {
'use strict';
/**
* Class for managing events.
* Can be extended to provide event functionality in other classes.
*
* @class EventEmitter Manages event registering and emitting.
*/
function EventEmitter() {}
// Shortcuts to improve speed and size
var proto = EventEmitter.prototype;
var exports = this;
var originalGlobalValue = exports.EventEmitter;
/**
* Finds the index of the listener for the event in its storage array.
*
* @param {Function[]} listeners Array of listeners to search through.
* @param {Function} listener Method to look for.
* @return {Number} Index of the specified listener, -1 if not found
* @api private
*/
function indexOfListener(listeners, listener) {
var i = listeners.length;
while (i--) {
if (listeners[i].listener === listener) {
return i;
}
}
return -1;
}
/**
* Alias a method while keeping the context correct, to allow for overwriting of target method.
*
* @param {String} name The name of the target method.
* @return {Function} The aliased method
* @api private
*/
function alias(name) {
return function aliasClosure() {
return this[name].apply(this, arguments);
};
}
/**
* Returns the listener array for the specified event.
* Will initialise the event object and listener arrays if required.
* Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
* Each property in the object response is an array of listener functions.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Function[]|Object} All listener functions for the event.
*/
proto.getListeners = function getListeners(evt) {
var events = this._getEvents();
var response;
var key;
// Return a concatenated array of all matching events if
// the selector is a regular expression.
if (evt instanceof RegExp) {
response = {};
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
response[key] = events[key];
}
}
}
else {
response = events[evt] || (events[evt] = []);
}
return response;
};
/**
* Takes a list of listener objects and flattens it into a list of listener functions.
*
* @param {Object[]} listeners Raw listener objects.
* @return {Function[]} Just the listener functions.
*/
proto.flattenListeners = function flattenListeners(listeners) {
var flatListeners = [];
var i;
for (i = 0; i < listeners.length; i += 1) {
flatListeners.push(listeners[i].listener);
}
return flatListeners;
};
/**
* Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Object} All listener functions for an event in an object.
*/
proto.getListenersAsObject = function getListenersAsObject(evt) {
var listeners = this.getListeners(evt);
var response;
if (listeners instanceof Array) {
response = {};
response[evt] = listeners;
}
return response || listeners;
};
/**
* Adds a listener function to the specified event.
* The listener will not be added if it is a duplicate.
* If the listener returns true then it will be removed after it is called.
* If you pass a regular expression as the event name then the listener will be added to all events that match it.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListener = function addListener(evt, listener) {
var listeners = this.getListenersAsObject(evt);
var listenerIsWrapped = typeof listener === 'object';
var key;
for (key in listeners) {
if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
listeners[key].push(listenerIsWrapped ? listener : {
listener: listener,
once: false
});
}
}
return this;
};
/**
* Alias of addListener
*/
proto.on = alias('addListener');
/**
* Semi-alias of addListener. It will add a listener that will be
* automatically removed after its first execution.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addOnceListener = function addOnceListener(evt, listener) {
return this.addListener(evt, {
listener: listener,
once: true
});
};
/**
* Alias of addOnceListener.
*/
proto.once = alias('addOnceListener');
/**
* Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
* You need to tell it what event names should be matched by a regex.
*
* @param {String} evt Name of the event to create.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvent = function defineEvent(evt) {
this.getListeners(evt);
return this;
};
/**
* Uses defineEvent to define multiple events.
*
* @param {String[]} evts An array of event names to define.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvents = function defineEvents(evts) {
for (var i = 0; i < evts.length; i += 1) {
this.defineEvent(evts[i]);
}
return this;
};
/**
* Removes a listener function from the specified event.
* When passed a regular expression as the event name, it will remove the listener from all events that match it.
*
* @param {String|RegExp} evt Name of the event to remove the listener from.
* @param {Function} listener Method to remove from the event.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListener = function removeListener(evt, listener) {
var listeners = this.getListenersAsObject(evt);
var index;
var key;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
index = indexOfListener(listeners[key], listener);
if (index !== -1) {
listeners[key].splice(index, 1);
}
}
}
return this;
};
/**
* Alias of removeListener
*/
proto.off = alias('removeListener');
/**
* Adds listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
* You can also pass it a regular expression to add the array of listeners to all events that match it.
* Yeah, this function does quite a bit. That's probably a bad thing.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListeners = function addListeners(evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(false, evt, listeners);
};
/**
* Removes listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be removed.
* You can also pass it a regular expression to remove the listeners from all events that match it.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListeners = function removeListeners(evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(true, evt, listeners);
};
/**
* Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
* The first argument will determine if the listeners are removed (true) or added (false).
* If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be added/removed.
* You can also pass it a regular expression to manipulate the listeners of all events that match it.
*
* @param {Boolean} remove True if you want to remove listeners, false if you want to add.
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add/remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
var i;
var value;
var single = remove ? this.removeListener : this.addListener;
var multiple = remove ? this.removeListeners : this.addListeners;
// If evt is an object then pass each of its properties to this method
if (typeof evt === 'object' && !(evt instanceof RegExp)) {
for (i in evt) {
if (evt.hasOwnProperty(i) && (value = evt[i])) {
// Pass the single listener straight through to the singular method
if (typeof value === 'function') {
single.call(this, i, value);
}
else {
// Otherwise pass back to the multiple function
multiple.call(this, i, value);
}
}
}
}
else {
// So evt must be a string
// And listeners must be an array of listeners
// Loop over it and pass each one to the multiple method
i = listeners.length;
while (i--) {
single.call(this, evt, listeners[i]);
}
}
return this;
};
/**
* Removes all listeners from a specified event.
* If you do not specify an event then all listeners will be removed.
* That means every event will be emptied.
* You can also pass a regex to remove all events that match it.
*
* @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeEvent = function removeEvent(evt) {
var type = typeof evt;
var events = this._getEvents();
var key;
// Remove different things depending on the state of evt
if (type === 'string') {
// Remove all listeners for the specified event
delete events[evt];
}
else if (evt instanceof RegExp) {
// Remove all events matching the regex.
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
delete events[key];
}
}
}
else {
// Remove all listeners in all events
delete this._events;
}
return this;
};
/**
* Alias of removeEvent.
*
* Added to mirror the node API.
*/
proto.removeAllListeners = alias('removeEvent');
/**
* Emits an event of your choice.
* When emitted, every listener attached to that event will be executed.
* If you pass the optional argument array then those arguments will be passed to every listener upon execution.
* Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
* So they will not arrive within the array on the other side, they will be separate.
* You can also pass a regular expression to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {Array} [args] Optional array of arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emitEvent = function emitEvent(evt, args) {
var listeners = this.getListenersAsObject(evt);
var listener;
var i;
var key;
var response;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
i = listeners[key].length;
while (i--) {
// If the listener returns true then it shall be removed from the event
// The function is executed either with a basic call or an apply if there is an args array
listener = listeners[key][i];
if (listener.once === true) {
this.removeListener(evt, listener.listener);
}
response = listener.listener.apply(this, args || []);
if (response === this._getOnceReturnValue()) {
this.removeListener(evt, listener.listener);
}
}
}
}
return this;
};
/**
* Alias of emitEvent
*/
proto.trigger = alias('emitEvent');
/**
* Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
* As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {...*} Optional additional arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emit = function emit(evt) {
var args = Array.prototype.slice.call(arguments, 1);
return this.emitEvent(evt, args);
};
/**
* Sets the current value to check against when executing listeners. If a
* listeners return value matches the one set here then it will be removed
* after execution. This value defaults to true.
*
* @param {*} value The new value to check for when executing listeners.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.setOnceReturnValue = function setOnceReturnValue(value) {
this._onceReturnValue = value;
return this;
};
/**
* Fetches the current value to check against when executing listeners. If
* the listeners return value matches this one then it should be removed
* automatically. It will return true by default.
*
* @return {*|Boolean} The current value to check for or the default, true.
* @api private
*/
proto._getOnceReturnValue = function _getOnceReturnValue() {
if (this.hasOwnProperty('_onceReturnValue')) {
return this._onceReturnValue;
}
else {
return true;
}
};
/**
* Fetches the events object and creates one if required.
*
* @return {Object} The events storage object.
* @api private
*/
proto._getEvents = function _getEvents() {
return this._events || (this._events = {});
};
/**
* Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
*
* @return {Function} Non conflicting EventEmitter class.
*/
EventEmitter.noConflict = function noConflict() {
exports.EventEmitter = originalGlobalValue;
return EventEmitter;
};
// Expose the class either via AMD, CommonJS or the global object
if (typeof define === 'function' && define.amd) {
define('eventEmitter/EventEmitter',[],function () {
return EventEmitter;
});
}
else if (typeof module === 'object' && module.exports){
module.exports = EventEmitter;
}
else {
exports.EventEmitter = EventEmitter;
}
}.call(this));
/*!
* getStyleProperty v1.0.4
* original by kangax
* http://perfectionkills.com/feature-testing-css-properties/
* MIT license
*/
/*jshint browser: true, strict: true, undef: true */
/*global define: false, exports: false, module: false */
( function( window ) {
var prefixes = 'Webkit Moz ms Ms O'.split(' ');
var docElemStyle = document.documentElement.style;
function getStyleProperty( propName ) {
if ( !propName ) {
return;
}
// test standard property first
if ( typeof docElemStyle[ propName ] === 'string' ) {
return propName;
}
// capitalize
propName = propName.charAt(0).toUpperCase() + propName.slice(1);
// test vendor specific properties
var prefixed;
for ( var i=0, len = prefixes.length; i < len; i++ ) {
prefixed = prefixes[i] + propName;
if ( typeof docElemStyle[ prefixed ] === 'string' ) {
return prefixed;
}
}
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'get-style-property/get-style-property',[],function() {
return getStyleProperty;
});
} else if ( typeof exports === 'object' ) {
// CommonJS for Component
module.exports = getStyleProperty;
} else {
// browser global
window.getStyleProperty = getStyleProperty;
}
})( window );
/*!
* getSize v1.2.2
* measure size of elements
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, exports: false, require: false, module: false, console: false */
( function( window, undefined ) {
// -------------------------- helpers -------------------------- //
// get a number from a string, not a percentage
function getStyleSize( value ) {
var num = parseFloat( value );
// not a percent like '100%', and a number
var isValid = value.indexOf('%') === -1 && !isNaN( num );
return isValid && num;
}
function noop() {}
var logError = typeof console === 'undefined' ? noop :
function( message ) {
console.error( message );
};
// -------------------------- measurements -------------------------- //
var measurements = [
'paddingLeft',
'paddingRight',
'paddingTop',
'paddingBottom',
'marginLeft',
'marginRight',
'marginTop',
'marginBottom',
'borderLeftWidth',
'borderRightWidth',
'borderTopWidth',
'borderBottomWidth'
];
function getZeroSize() {
var size = {
width: 0,
height: 0,
innerWidth: 0,
innerHeight: 0,
outerWidth: 0,
outerHeight: 0
};
for ( var i=0, len = measurements.length; i < len; i++ ) {
var measurement = measurements[i];
size[ measurement ] = 0;
}
return size;
}
function defineGetSize( getStyleProperty ) {
// -------------------------- setup -------------------------- //
var isSetup = false;
var getStyle, boxSizingProp, isBoxSizeOuter;
/**
* setup vars and functions
* do it on initial getSize(), rather than on script load
* For Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=548397
*/
function setup() {
// setup once
if ( isSetup ) {
return;
}
isSetup = true;
var getComputedStyle = window.getComputedStyle;
getStyle = ( function() {
var getStyleFn = getComputedStyle ?
function( elem ) {
return getComputedStyle( elem, null );
} :
function( elem ) {
return elem.currentStyle;
};
return function getStyle( elem ) {
var style = getStyleFn( elem );
if ( !style ) {
logError( 'Style returned ' + style +
'. Are you running this code in a hidden iframe on Firefox? ' +
'See http://bit.ly/getsizebug1' );
}
return style;
};
})();
// -------------------------- box sizing -------------------------- //
boxSizingProp = getStyleProperty('boxSizing');
/**
* WebKit measures the outer-width on style.width on border-box elems
* IE & Firefox measures the inner-width
*/
if ( boxSizingProp ) {
var div = document.createElement('div');
div.style.width = '200px';
div.style.padding = '1px 2px 3px 4px';
div.style.borderStyle = 'solid';
div.style.borderWidth = '1px 2px 3px 4px';
div.style[ boxSizingProp ] = 'border-box';
var body = document.body || document.documentElement;
body.appendChild( div );
var style = getStyle( div );
isBoxSizeOuter = getStyleSize( style.width ) === 200;
body.removeChild( div );
}
}
// -------------------------- getSize -------------------------- //
function getSize( elem ) {
setup();
// use querySeletor if elem is string
if ( typeof elem === 'string' ) {
elem = document.querySelector( elem );
}
// do not proceed on non-objects
if ( !elem || typeof elem !== 'object' || !elem.nodeType ) {
return;
}
var style = getStyle( elem );
// if hidden, everything is 0
if ( style.display === 'none' ) {
return getZeroSize();
}
var size = {};
size.width = elem.offsetWidth;
size.height = elem.offsetHeight;
var isBorderBox = size.isBorderBox = !!( boxSizingProp &&
style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' );
// get all measurements
for ( var i=0, len = measurements.length; i < len; i++ ) {
var measurement = measurements[i];
var value = style[ measurement ];
value = mungeNonPixel( elem, value );
var num = parseFloat( value );
// any 'auto', 'medium' value will be 0
size[ measurement ] = !isNaN( num ) ? num : 0;
}
var paddingWidth = size.paddingLeft + size.paddingRight;
var paddingHeight = size.paddingTop + size.paddingBottom;
var marginWidth = size.marginLeft + size.marginRight;
var marginHeight = size.marginTop + size.marginBottom;
var borderWidth = size.borderLeftWidth + size.borderRightWidth;
var borderHeight = size.borderTopWidth + size.borderBottomWidth;
var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
// overwrite width and height if we can get it from style
var styleWidth = getStyleSize( style.width );
if ( styleWidth !== false ) {
size.width = styleWidth +
// add padding and border unless it's already including it
( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
}
var styleHeight = getStyleSize( style.height );
if ( styleHeight !== false ) {
size.height = styleHeight +
// add padding and border unless it's already including it
( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
}
size.innerWidth = size.width - ( paddingWidth + borderWidth );
size.innerHeight = size.height - ( paddingHeight + borderHeight );
size.outerWidth = size.width + marginWidth;
size.outerHeight = size.height + marginHeight;
return size;
}
// IE8 returns percent values, not pixels
// taken from jQuery's curCSS
function mungeNonPixel( elem, value ) {
// IE8 and has percent value
if ( window.getComputedStyle || value.indexOf('%') === -1 ) {
return value;
}
var style = elem.style;
// Remember the original values
var left = style.left;
var rs = elem.runtimeStyle;
var rsLeft = rs && rs.left;
// Put in the new values to get a computed value out
if ( rsLeft ) {
rs.left = elem.currentStyle.left;
}
style.left = value;
value = style.pixelLeft;
// Revert the changed values
style.left = left;
if ( rsLeft ) {
rs.left = rsLeft;
}
return value;
}
return getSize;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD for RequireJS
define( 'get-size/get-size',[ 'get-style-property/get-style-property' ], defineGetSize );
} else if ( typeof exports === 'object' ) {
// CommonJS for Component
module.exports = defineGetSize( require('desandro-get-style-property') );
} else {
// browser global
window.getSize = defineGetSize( window.getStyleProperty );
}
})( window );
/*!
* docReady v1.0.4
* Cross browser DOMContentLoaded event emitter
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true*/
/*global define: false, require: false, module: false */
( function( window ) {
var document = window.document;
// collection of functions to be triggered on ready
var queue = [];
function docReady( fn ) {
// throw out non-functions
if ( typeof fn !== 'function' ) {
return;
}
if ( docReady.isReady ) {
// ready now, hit it
fn();
} else {
// queue function when ready
queue.push( fn );
}
}
docReady.isReady = false;
// triggered on various doc ready events
function onReady( event ) {
// bail if already triggered or IE8 document is not ready just yet
var isIE8NotReady = event.type === 'readystatechange' && document.readyState !== 'complete';
if ( docReady.isReady || isIE8NotReady ) {
return;
}
trigger();
}
function trigger() {
docReady.isReady = true;
// process queue
for ( var i=0, len = queue.length; i < len; i++ ) {
var fn = queue[i];
fn();
}
}
function defineDocReady( eventie ) {
// trigger ready if page is ready
if ( document.readyState === 'complete' ) {
trigger();
} else {
// listen for events
eventie.bind( document, 'DOMContentLoaded', onReady );
eventie.bind( document, 'readystatechange', onReady );
eventie.bind( window, 'load', onReady );
}
return docReady;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'doc-ready/doc-ready',[ 'eventie/eventie' ], defineDocReady );
} else if ( typeof exports === 'object' ) {
module.exports = defineDocReady( require('eventie') );
} else {
// browser global
window.docReady = defineDocReady( window.eventie );
}
})( window );
/**
* matchesSelector v1.0.3
* matchesSelector( element, '.selector' )
* MIT license
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
/*global define: false, module: false */
( function( ElemProto ) {
'use strict';
var matchesMethod = ( function() {
// check for the standard method name first
if ( ElemProto.matches ) {
return 'matches';
}
// check un-prefixed
if ( ElemProto.matchesSelector ) {
return 'matchesSelector';
}
// check vendor prefixes
var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
for ( var i=0, len = prefixes.length; i < len; i++ ) {
var prefix = prefixes[i];
var method = prefix + 'MatchesSelector';
if ( ElemProto[ method ] ) {
return method;
}
}
})();
// ----- match ----- //
function match( elem, selector ) {
return elem[ matchesMethod ]( selector );
}
// ----- appendToFragment ----- //
function checkParent( elem ) {
// not needed if already has parent
if ( elem.parentNode ) {
return;
}
var fragment = document.createDocumentFragment();
fragment.appendChild( elem );
}
// ----- query ----- //
// fall back to using QSA
// thx @jonathantneal https://gist.github.com/3062955
function query( elem, selector ) {
// append to fragment if no parent
checkParent( elem );
// match elem with all selected elems of parent
var elems = elem.parentNode.querySelectorAll( selector );
for ( var i=0, len = elems.length; i < len; i++ ) {
// return true if match
if ( elems[i] === elem ) {
return true;
}
}
// otherwise return false
return false;
}
// ----- matchChild ----- //
function matchChild( elem, selector ) {
checkParent( elem );
return match( elem, selector );
}
// ----- matchesSelector ----- //
var matchesSelector;
if ( matchesMethod ) {
// IE9 supports matchesSelector, but doesn't work on orphaned elems
// check for that
var div = document.createElement('div');
var supportsOrphans = match( div, 'div' );
matchesSelector = supportsOrphans ? match : matchChild;
} else {
matchesSelector = query;
}
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'matches-selector/matches-selector',[],function() {
return matchesSelector;
});
} else if ( typeof exports === 'object' ) {
module.exports = matchesSelector;
}
else {
// browser global
window.matchesSelector = matchesSelector;
}
})( Element.prototype );
/**
* Fizzy UI utils v1.0.1
* MIT license
*/
/*jshint browser: true, undef: true, unused: true, strict: true */
( function( window, factory ) {
/*global define: false, module: false, require: false */
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'fizzy-ui-utils/utils',[
'doc-ready/doc-ready',
'matches-selector/matches-selector'
], function( docReady, matchesSelector ) {
return factory( window, docReady, matchesSelector );
});
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
require('doc-ready'),
require('desandro-matches-selector')
);
} else {
// browser global
window.fizzyUIUtils = factory(
window,
window.docReady,
window.matchesSelector
);
}
}( window, function factory( window, docReady, matchesSelector ) {
var utils = {};
// ----- extend ----- //
// extends objects
utils.extend = function( a, b ) {
for ( var prop in b ) {
a[ prop ] = b[ prop ];
}
return a;
};
// ----- modulo ----- //
utils.modulo = function( num, div ) {
return ( ( num % div ) + div ) % div;
};
// ----- isArray ----- //
var objToString = Object.prototype.toString;
utils.isArray = function( obj ) {
return objToString.call( obj ) == '[object Array]';
};
// ----- makeArray ----- //
// turn element or nodeList into an array
utils.makeArray = function( obj ) {
var ary = [];
if ( utils.isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( obj && typeof obj.length == 'number' ) {
// convert nodeList to array
for ( var i=0, len = obj.length; i < len; i++ ) {
ary.push( obj[i] );
}
} else {
// array of single index
ary.push( obj );
}
return ary;
};
// ----- indexOf ----- //
// index of helper cause IE8
utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) {
return ary.indexOf( obj );
} : function( ary, obj ) {
for ( var i=0, len = ary.length; i < len; i++ ) {
if ( ary[i] === obj ) {
return i;
}
}
return -1;
};
// ----- removeFrom ----- //
utils.removeFrom = function( ary, obj ) {
var index = utils.indexOf( ary, obj );
if ( index != -1 ) {
ary.splice( index, 1 );
}
};
// ----- isElement ----- //
// http://stackoverflow.com/a/384380/182183
utils.isElement = ( typeof HTMLElement == 'function' || typeof HTMLElement == 'object' ) ?
function isElementDOM2( obj ) {
return obj instanceof HTMLElement;
} :
function isElementQuirky( obj ) {
return obj && typeof obj == 'object' &&
obj.nodeType == 1 && typeof obj.nodeName == 'string';
};
// ----- setText ----- //
utils.setText = ( function() {
var setTextProperty;
function setText( elem, text ) {
// only check setTextProperty once
setTextProperty = setTextProperty || ( document.documentElement.textContent !== undefined ? 'textContent' : 'innerText' );
elem[ setTextProperty ] = text;
}
return setText;
})();
// ----- getParent ----- //
utils.getParent = function( elem, selector ) {
while ( elem != document.body ) {
elem = elem.parentNode;
if ( matchesSelector( elem, selector ) ) {
return elem;
}
}
};
// ----- getQueryElement ----- //
// use element as selector string
utils.getQueryElement = function( elem ) {
if ( typeof elem == 'string' ) {
return document.querySelector( elem );
}
return elem;
};
// ----- handleEvent ----- //
// enable .ontype to trigger from .addEventListener( elem, 'type' )
utils.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
// ----- filterFindElements ----- //
utils.filterFindElements = function( elems, selector ) {
// make array of elems
elems = utils.makeArray( elems );
var ffElems = [];
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
// check that elem is an actual element
// START UNCODE EDIT
// if ( !utils.isElement( elem ) ) {
if ( !utils.isElement( elem ) && !SiteParameters.is_frontend_editor ) {
// END UNCODE EDIT
continue;
}
// filter & find items if we have a selector
if ( selector ) {
// filter siblings
if ( matchesSelector( elem, selector ) ) {
ffElems.push( elem );
}
// find children
var childElems = elem.querySelectorAll( selector );
// concat childElems to filterFound array
for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
ffElems.push( childElems[j] );
}
} else {
ffElems.push( elem );
}
}
return ffElems;
};
// ----- debounceMethod ----- //
utils.debounceMethod = function( _class, methodName, threshold ) {
// original method
var method = _class.prototype[ methodName ];
var timeoutName = methodName + 'Timeout';
_class.prototype[ methodName ] = function() {
var timeout = this[ timeoutName ];
if ( timeout ) {
clearTimeout( timeout );
}
var args = arguments;
var _this = this;
this[ timeoutName ] = setTimeout( function() {
method.apply( _this, args );
delete _this[ timeoutName ];
}, threshold || 100 );
};
};
// ----- htmlInit ----- //
// http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
utils.toDashed = function( str ) {
return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
return $1 + '-' + $2;
}).toLowerCase();
};
var console = window.console;
/**
* allow user to initialize classes via .js-namespace class
* htmlInit( Widget, 'widgetName' )
* options are parsed from data-namespace-option attribute
*/
utils.htmlInit = function( WidgetClass, namespace ) {
docReady( function() {
var dashedNamespace = utils.toDashed( namespace );
var elems = document.querySelectorAll( '.js-' + dashedNamespace );
var dataAttr = 'data-' + dashedNamespace + '-options';
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
var attr = elem.getAttribute( dataAttr );
var options;
try {
options = attr && JSON.parse( attr );
} catch ( error ) {
// log error, do not initialize
if ( console ) {
console.error( 'Error parsing ' + dataAttr + ' on ' +
elem.nodeName.toLowerCase() + ( elem.id ? '#' + elem.id : '' ) + ': ' +
error );
}
continue;
}
// initialize
var instance = new WidgetClass( elem, options );
// make available via $().data('layoutname')
var jQuery = window.jQuery;
if ( jQuery ) {
jQuery.data( elem, namespace, instance );
}
}
});
};
// ----- ----- //
return utils;
}));
/**
* Outlayer Item
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'outlayer/item',[
'eventEmitter/EventEmitter',
'get-size/get-size',
'get-style-property/get-style-property',
'fizzy-ui-utils/utils'
],
function( EventEmitter, getSize, getStyleProperty, utils ) {
return factory( window, EventEmitter, getSize, getStyleProperty, utils );
}
);
} else if (typeof exports === 'object') {
// CommonJS
module.exports = factory(
window,
require('wolfy87-eventemitter'),
require('get-size'),
require('desandro-get-style-property'),
require('fizzy-ui-utils')
);
} else {
// browser global
window.Outlayer = {};
window.Outlayer.Item = factory(
window,
window.EventEmitter,
window.getSize,
window.getStyleProperty,
window.fizzyUIUtils
);
}
}( window, function factory( window, EventEmitter, getSize, getStyleProperty, utils ) {
'use strict';
// ----- helpers ----- //
var getComputedStyle = window.getComputedStyle;
var getStyle = getComputedStyle ?
function( elem ) {
return getComputedStyle( elem, null );
} :
function( elem ) {
return elem.currentStyle;
};
function isEmptyObj( obj ) {
for ( var prop in obj ) {
return false;
}
prop = null;
return true;
}
// -------------------------- CSS3 support -------------------------- //
var transitionProperty = getStyleProperty('transition');
var transformProperty = getStyleProperty('transform');
var supportsCSS3 = transitionProperty && transformProperty;
var is3d = !!getStyleProperty('perspective');
var transitionEndEvent = {
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'otransitionend',
transition: 'transitionend'
}[ transitionProperty ];
// properties that could have vendor prefix
var prefixableProperties = [
'transform',
'transition',
'transitionDuration',
'transitionProperty'
];
// cache all vendor properties
var vendorProperties = ( function() {
var cache = {};
for ( var i=0, len = prefixableProperties.length; i < len; i++ ) {
var prop = prefixableProperties[i];
var supportedProp = getStyleProperty( prop );
if ( supportedProp && supportedProp !== prop ) {
cache[ prop ] = supportedProp;
}
}
return cache;
})();
// -------------------------- Item -------------------------- //
function Item( element, layout ) {
if ( !element ) {
return;
}
this.element = element;
// parent layout class, i.e. Masonry, Isotope, or Packery
this.layout = layout;
this.position = {
x: 0,
y: 0
};
this._create();
}
// inherit EventEmitter
utils.extend( Item.prototype, EventEmitter.prototype );
Item.prototype._create = function() {
// transition objects
this._transn = {
ingProperties: {},
clean: {},
onEnd: {}
};
this.css({
position: 'absolute'
});
};
// trigger specified handler for event type
Item.prototype.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
Item.prototype.getSize = function() {
this.size = getSize( this.element );
};
/**
* apply CSS styles to element
* @param {Object} style
*/
Item.prototype.css = function( style ) {
var elemStyle = this.element.style;
for ( var prop in style ) {
// use vendor property if available
var supportedProp = vendorProperties[ prop ] || prop;
elemStyle[ supportedProp ] = style[ prop ];
}
};
// measure position, and sets it
Item.prototype.getPosition = function() {
var style = getStyle( this.element );
var layoutOptions = this.layout.options;
var isOriginLeft = layoutOptions.isOriginLeft;
var isOriginTop = layoutOptions.isOriginTop;
var xValue = style[ isOriginLeft ? 'left' : 'right' ];
var yValue = style[ isOriginTop ? 'top' : 'bottom' ];
// convert percent to pixels
var layoutSize = this.layout.size;
var x = xValue.indexOf('%') != -1 ?
( parseFloat( xValue ) / 100 ) * layoutSize.width : parseInt( xValue, 10 );
var y = yValue.indexOf('%') != -1 ?
( parseFloat( yValue ) / 100 ) * layoutSize.height : parseInt( yValue, 10 );
// clean up 'auto' or other non-integer values
x = isNaN( x ) ? 0 : x;
y = isNaN( y ) ? 0 : y;
// remove padding from measurement
x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight;
y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom;
this.position.x = x;
this.position.y = y;
};
// set settled position, apply padding
Item.prototype.layoutPosition = function() {
var layoutSize = this.layout.size;
var layoutOptions = this.layout.options;
var style = {};
// x
var xPadding = layoutOptions.isOriginLeft ? 'paddingLeft' : 'paddingRight';
var xProperty = layoutOptions.isOriginLeft ? 'left' : 'right';
var xResetProperty = layoutOptions.isOriginLeft ? 'right' : 'left';
var x = this.position.x + layoutSize[ xPadding ];
// set in percentage or pixels
style[ xProperty ] = this.getXValue( x );
// reset other property
style[ xResetProperty ] = '';
// y
var yPadding = layoutOptions.isOriginTop ? 'paddingTop' : 'paddingBottom';
var yProperty = layoutOptions.isOriginTop ? 'top' : 'bottom';
var yResetProperty = layoutOptions.isOriginTop ? 'bottom' : 'top';
var y = this.position.y + layoutSize[ yPadding ];
// set in percentage or pixels
style[ yProperty ] = this.getYValue( y );
// reset other property
style[ yResetProperty ] = '';
this.css( style );
this.emitEvent( 'layout', [ this ] );
};
Item.prototype.getXValue = function( x ) {
var layoutOptions = this.layout.options;
return layoutOptions.percentPosition && !layoutOptions.isHorizontal ?
( ( x / this.layout.size.width ) * 100 ) + '%' : x + 'px';
};
Item.prototype.getYValue = function( y ) {
var layoutOptions = this.layout.options;
return layoutOptions.percentPosition && layoutOptions.isHorizontal ?
( ( y / this.layout.size.height ) * 100 ) + '%' : y + 'px';
};
Item.prototype._transitionTo = function( x, y ) {
this.getPosition();
// get current x & y from top/left
var curX = this.position.x;
var curY = this.position.y;
var compareX = parseInt( x, 10 );
var compareY = parseInt( y, 10 );
var didNotMove = compareX === this.position.x && compareY === this.position.y;
// save end position
this.setPosition( x, y );
// if did not move and not transitioning, just go to layout
if ( didNotMove && !this.isTransitioning ) {
this.layoutPosition();
return;
}
var transX = x - curX;
var transY = y - curY;
var transitionStyle = {};
transitionStyle.transform = this.getTranslate( transX, transY );
this.transition({
to: transitionStyle,
onTransitionEnd: {
transform: this.layoutPosition
},
isCleaning: true
});
};
Item.prototype.getTranslate = function( x, y ) {
// flip cooridinates if origin on right or bottom
var layoutOptions = this.layout.options;
x = layoutOptions.isOriginLeft ? x : -x;
y = layoutOptions.isOriginTop ? y : -y;
if ( is3d ) {
return 'translate3d(' + x + 'px, ' + y + 'px, 0)';
}
return 'translate(' + x + 'px, ' + y + 'px)';
};
// non transition + transform support
Item.prototype.goTo = function( x, y ) {
this.setPosition( x, y );
this.layoutPosition();
};
// use transition and transforms if supported
Item.prototype.moveTo = supportsCSS3 ?
Item.prototype._transitionTo : Item.prototype.goTo;
Item.prototype.setPosition = function( x, y ) {
this.position.x = parseInt( x, 10 );
this.position.y = parseInt( y, 10 );
};
// ----- transition ----- //
/**
* @param {Object} style - CSS
* @param {Function} onTransitionEnd
*/
// non transition, just trigger callback
Item.prototype._nonTransition = function( args ) {
this.css( args.to );
if ( args.isCleaning ) {
this._removeStyles( args.to );
}
for ( var prop in args.onTransitionEnd ) {
args.onTransitionEnd[ prop ].call( this );
}
};
/**
* proper transition
* @param {Object} args - arguments
* @param {Object} to - style to transition to
* @param {Object} from - style to start transition from
* @param {Boolean} isCleaning - removes transition styles after transition
* @param {Function} onTransitionEnd - callback
*/
Item.prototype._transition = function( args ) {
// redirect to nonTransition if no transition duration
if ( !parseFloat( this.layout.options.transitionDuration ) ) {
this._nonTransition( args );
return;
}
var _transition = this._transn;
// keep track of onTransitionEnd callback by css property
for ( var prop in args.onTransitionEnd ) {
_transition.onEnd[ prop ] = args.onTransitionEnd[ prop ];
}
// keep track of properties that are transitioning
for ( prop in args.to ) {
_transition.ingProperties[ prop ] = true;
// keep track of properties to clean up when transition is done
if ( args.isCleaning ) {
_transition.clean[ prop ] = true;
}
}
// set from styles
if ( args.from ) {
this.css( args.from );
// force redraw. http://blog.alexmaccaw.com/css-transitions
var h = this.element.offsetHeight;
// hack for JSHint to hush about unused var
h = null;
}
// enable transition
this.enableTransition( args.to );
// set styles that are transitioning
this.css( args.to );
this.isTransitioning = true;
};
// dash before all cap letters, including first for
// WebkitTransform => -webkit-transform
function toDashedAll( str ) {
return str.replace( /([A-Z])/g, function( $1 ) {
return '-' + $1.toLowerCase();
});
}
var transitionProps = 'opacity,' +
toDashedAll( vendorProperties.transform || 'transform' );
Item.prototype.enableTransition = function(/* style */) {
// HACK changing transitionProperty during a transition
// will cause transition to jump
if ( this.isTransitioning ) {
return;
}
// make `transition: foo, bar, baz` from style object
// HACK un-comment this when enableTransition can work
// while a transition is happening
// var transitionValues = [];
// for ( var prop in style ) {
// // dash-ify camelCased properties like WebkitTransition
// prop = vendorProperties[ prop ] || prop;
// transitionValues.push( toDashedAll( prop ) );
// }
// enable transition styles
this.css({
transitionProperty: transitionProps,
transitionDuration: this.layout.options.transitionDuration
});
// listen for transition end event
this.element.addEventListener( transitionEndEvent, this, false );
};
Item.prototype.transition = Item.prototype[ transitionProperty ? '_transition' : '_nonTransition' ];
// ----- events ----- //
Item.prototype.onwebkitTransitionEnd = function( event ) {
this.ontransitionend( event );
};
Item.prototype.onotransitionend = function( event ) {
this.ontransitionend( event );
};
// properties that I munge to make my life easier
var dashedVendorProperties = {
'-webkit-transform': 'transform',
'-moz-transform': 'transform',
'-o-transform': 'transform'
};
Item.prototype.ontransitionend = function( event ) {
// disregard bubbled events from children
if ( event.target !== this.element ) {
return;
}
var _transition = this._transn;
// get property name of transitioned property, convert to prefix-free
var propertyName = dashedVendorProperties[ event.propertyName ] || event.propertyName;
// remove property that has completed transitioning
delete _transition.ingProperties[ propertyName ];
// check if any properties are still transitioning
if ( isEmptyObj( _transition.ingProperties ) ) {
// all properties have completed transitioning
this.disableTransition();
}
// clean style
if ( propertyName in _transition.clean ) {
// clean up style
this.element.style[ event.propertyName ] = '';
delete _transition.clean[ propertyName ];
}
// trigger onTransitionEnd callback
if ( propertyName in _transition.onEnd ) {
var onTransitionEnd = _transition.onEnd[ propertyName ];
onTransitionEnd.call( this );
delete _transition.onEnd[ propertyName ];
}
this.emitEvent( 'transitionEnd', [ this ] );
};
Item.prototype.disableTransition = function() {
this.removeTransitionStyles();
this.element.removeEventListener( transitionEndEvent, this, false );
this.isTransitioning = false;
};
/**
* removes style property from element
* @param {Object} style
**/
Item.prototype._removeStyles = function( style ) {
// clean up transition styles
var cleanStyle = {};
for ( var prop in style ) {
cleanStyle[ prop ] = '';
}
this.css( cleanStyle );
};
var cleanTransitionStyle = {
transitionProperty: '',
transitionDuration: ''
};
Item.prototype.removeTransitionStyles = function() {
// remove transition
this.css( cleanTransitionStyle );
};
// ----- show/hide/remove ----- //
// remove element from DOM
Item.prototype.removeElem = function() {
this.element.parentNode.removeChild( this.element );
// remove display: none
this.css({ display: '' });
this.emitEvent( 'remove', [ this ] );
};
Item.prototype.remove = function() {
// just remove element if no transition support or no transition
if ( !transitionProperty || !parseFloat( this.layout.options.transitionDuration ) ) {
this.removeElem();
return;
}
// start transition
var _this = this;
this.once( 'transitionEnd', function() {
_this.removeElem();
});
this.hide();
};
Item.prototype.reveal = function() {
delete this.isHidden;
// remove display: none
this.css({ display: '' });
var options = this.layout.options;
var onTransitionEnd = {};
var transitionEndProperty = this.getHideRevealTransitionEndProperty('visibleStyle');
onTransitionEnd[ transitionEndProperty ] = this.onRevealTransitionEnd;
this.transition({
from: options.hiddenStyle,
to: options.visibleStyle,
isCleaning: true,
onTransitionEnd: onTransitionEnd
});
};
Item.prototype.onRevealTransitionEnd = function() {
// check if still visible
// during transition, item may have been hidden
if ( !this.isHidden ) {
this.emitEvent('reveal');
}
};
/**
* get style property use for hide/reveal transition end
* @param {String} styleProperty - hiddenStyle/visibleStyle
* @returns {String}
*/
Item.prototype.getHideRevealTransitionEndProperty = function( styleProperty ) {
var optionStyle = this.layout.options[ styleProperty ];
// use opacity
if ( optionStyle.opacity ) {
return 'opacity';
}
// get first property
for ( var prop in optionStyle ) {
return prop;
}
};
Item.prototype.hide = function() {
// set flag
this.isHidden = true;
// remove display: none
this.css({ display: '' });
var options = this.layout.options;
var onTransitionEnd = {};
var transitionEndProperty = this.getHideRevealTransitionEndProperty('hiddenStyle');
onTransitionEnd[ transitionEndProperty ] = this.onHideTransitionEnd;
this.transition({
from: options.visibleStyle,
to: options.hiddenStyle,
// keep hidden stuff hidden
isCleaning: true,
onTransitionEnd: onTransitionEnd
});
};
Item.prototype.onHideTransitionEnd = function() {
// check if still hidden
// during transition, item may have been un-hidden
if ( this.isHidden ) {
this.css({ display: 'none' });
this.emitEvent('hide');
}
};
Item.prototype.destroy = function() {
this.css({
position: '',
left: '',
right: '',
top: '',
bottom: '',
transition: '',
transform: ''
});
};
return Item;
}));
/*!
* Outlayer v1.4.2
* the brains and guts of a layout library
* MIT license
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'outlayer/outlayer',[
'eventie/eventie',
'eventEmitter/EventEmitter',
'get-size/get-size',
'fizzy-ui-utils/utils',
'./item'
],
function( eventie, EventEmitter, getSize, utils, Item ) {
return factory( window, eventie, EventEmitter, getSize, utils, Item);
}
);
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
require('eventie'),
require('wolfy87-eventemitter'),
require('get-size'),
require('fizzy-ui-utils'),
require('./item')
);
} else {
// browser global
window.Outlayer = factory(
window,
window.eventie,
window.EventEmitter,
window.getSize,
window.fizzyUIUtils,
window.Outlayer.Item
);
}
}( window, function factory( window, eventie, EventEmitter, getSize, utils, Item ) {
'use strict';
// ----- vars ----- //
var console = window.console;
var jQuery = window.jQuery;
var noop = function() {};
// -------------------------- Outlayer -------------------------- //
// globally unique identifiers
var GUID = 0;
// internal store of all Outlayer intances
var instances = {};
/**
* @param {Element, String} element
* @param {Object} options
* @constructor
*/
function Outlayer( element, options ) {
var queryElement = utils.getQueryElement( element );
if ( !queryElement ) {
if ( console ) {
console.error( 'Bad element for ' + this.constructor.namespace +
': ' + ( queryElement || element ) );
}
return;
}
this.element = queryElement;
// add jQuery
if ( jQuery ) {
this.$element = jQuery( this.element );
}
// options
this.options = utils.extend( {}, this.constructor.defaults );
this.option( options );
// add id for Outlayer.getFromElement
var id = ++GUID;
this.element.outlayerGUID = id; // expando
instances[ id ] = this; // associate via id
// kick it off
this._create();
if ( this.options.isInitLayout ) {
this.layout();
}
}
// settings are for internal use only
Outlayer.namespace = 'outlayer';
Outlayer.Item = Item;
// default options
Outlayer.defaults = {
containerStyle: {
position: 'relative'
},
isInitLayout: true,
isOriginLeft: true,
isOriginTop: true,
isResizeBound: true,
isResizingContainer: true,
// item options
transitionDuration: '0.4s',
hiddenStyle: {
opacity: 0,
transform: 'scale(0.001)'
},
visibleStyle: {
opacity: 1,
transform: 'scale(1)'
}
};
// inherit EventEmitter
utils.extend( Outlayer.prototype, EventEmitter.prototype );
/**
* set options
* @param {Object} opts
*/
Outlayer.prototype.option = function( opts ) {
utils.extend( this.options, opts );
};
Outlayer.prototype._create = function() {
// get items from children
this.reloadItems();
// elements that affect layout, but are not laid out
this.stamps = [];
this.stamp( this.options.stamp );
// set container style
utils.extend( this.element.style, this.options.containerStyle );
// bind resize method
if ( this.options.isResizeBound ) {
this.bindResize();
}
};
// goes through all children again and gets bricks in proper order
Outlayer.prototype.reloadItems = function() {
// collection of item elements
this.items = this._itemize( this.element.children );
};
/**
* turn elements into Outlayer.Items to be used in layout
* @param {Array or NodeList or HTMLElement} elems
* @returns {Array} items - collection of new Outlayer Items
*/
Outlayer.prototype._itemize = function( elems ) {
var itemElems = this._filterFindItemElements( elems );
var Item = this.constructor.Item;
// create new Outlayer Items for collection
var items = [];
for ( var i=0, len = itemElems.length; i < len; i++ ) {
var elem = itemElems[i];
var item = new Item( elem, this );
items.push( item );
}
return items;
};
/**
* get item elements to be used in layout
* @param {Array or NodeList or HTMLElement} elems
* @returns {Array} items - item elements
*/
Outlayer.prototype._filterFindItemElements = function( elems ) {
return utils.filterFindElements( elems, this.options.itemSelector );
};
/**
* getter method for getting item elements
* @returns {Array} elems - collection of item elements
*/
Outlayer.prototype.getItemElements = function() {
var elems = [];
for ( var i=0, len = this.items.length; i < len; i++ ) {
elems.push( this.items[i].element );
}
return elems;
};
// ----- init & layout ----- //
/**
* lays out all items
*/
Outlayer.prototype.layout = function() {
this._resetLayout();
this._manageStamps();
// don't animate first layout
var isInstant = this.options.isLayoutInstant !== undefined ?
this.options.isLayoutInstant : !this._isLayoutInited;
this.layoutItems( this.items, isInstant );
// flag for initalized
this._isLayoutInited = true;
};
// _init is alias for layout
Outlayer.prototype._init = Outlayer.prototype.layout;
/**
* logic before any new layout
*/
Outlayer.prototype._resetLayout = function() {
this.getSize();
};
Outlayer.prototype.getSize = function() {
this.size = getSize( this.element );
};
/**
* get measurement from option, for columnWidth, rowHeight, gutter
* if option is String -> get element from selector string, & get size of element
* if option is Element -> get size of element
* else use option as a number
*
* @param {String} measurement
* @param {String} size - width or height
* @private
*/
Outlayer.prototype._getMeasurement = function( measurement, size ) {
var option = this.options[ measurement ];
var elem;
if ( !option ) {
// default to 0
this[ measurement ] = 0;
} else {
// use option as an element
if ( typeof option === 'string' ) {
elem = this.element.querySelector( option );
} else if ( utils.isElement( option ) ) {
elem = option;
}
// use size of element, if element
this[ measurement ] = elem ? getSize( elem )[ size ] : option;
}
};
/**
* layout a collection of item elements
* @api public
*/
Outlayer.prototype.layoutItems = function( items, isInstant ) {
items = this._getItemsForLayout( items );
this._layoutItems( items, isInstant );
this._postLayout();
};
/**
* get the items to be laid out
* you may want to skip over some items
* @param {Array} items
* @returns {Array} items
*/
Outlayer.prototype._getItemsForLayout = function( items ) {
var layoutItems = [];
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
if ( !item.isIgnored ) {
layoutItems.push( item );
}
}
return layoutItems;
};
/**
* layout items
* @param {Array} items
* @param {Boolean} isInstant
*/
Outlayer.prototype._layoutItems = function( items, isInstant ) {
this._emitCompleteOnItems( 'layout', items );
if ( !items || !items.length ) {
// no items, emit event with empty array
return;
}
var queue = [];
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
// get x/y object from method
var position = this._getItemLayoutPosition( item );
// enqueue
position.item = item;
position.isInstant = isInstant || item.isLayoutInstant;
queue.push( position );
}
this._processLayoutQueue( queue );
};
/**
* get item layout position
* @param {Outlayer.Item} item
* @returns {Object} x and y position
*/
Outlayer.prototype._getItemLayoutPosition = function( /* item */ ) {
return {
x: 0,
y: 0
};
};
/**
* iterate over array and position each item
* Reason being - separating this logic prevents 'layout invalidation'
* thx @paul_irish
* @param {Array} queue
*/
Outlayer.prototype._processLayoutQueue = function( queue ) {
for ( var i=0, len = queue.length; i < len; i++ ) {
var obj = queue[i];
this._positionItem( obj.item, obj.x, obj.y, obj.isInstant );
}
};
/**
* Sets position of item in DOM
* @param {Outlayer.Item} item
* @param {Number} x - horizontal position
* @param {Number} y - vertical position
* @param {Boolean} isInstant - disables transitions
*/
Outlayer.prototype._positionItem = function( item, x, y, isInstant ) {
if ( isInstant ) {
// if not transition, just set CSS
item.goTo( x, y );
} else {
item.moveTo( x, y );
}
};
/**
* Any logic you want to do after each layout,
* i.e. size the container
*/
Outlayer.prototype._postLayout = function() {
this.resizeContainer();
};
Outlayer.prototype.resizeContainer = function() {
if ( !this.options.isResizingContainer ) {
return;
}
var size = this._getContainerSize();
if ( size ) {
this._setContainerMeasure( size.width, true );
this._setContainerMeasure( size.height, false );
}
};
/**
* Sets width or height of container if returned
* @returns {Object} size
* @param {Number} width
* @param {Number} height
*/
Outlayer.prototype._getContainerSize = noop;
/**
* @param {Number} measure - size of width or height
* @param {Boolean} isWidth
*/
Outlayer.prototype._setContainerMeasure = function( measure, isWidth ) {
if ( measure === undefined ) {
return;
}
var elemSize = this.size;
// add padding and border width if border box
if ( elemSize.isBorderBox ) {
measure += isWidth ? elemSize.paddingLeft + elemSize.paddingRight +
elemSize.borderLeftWidth + elemSize.borderRightWidth :
elemSize.paddingBottom + elemSize.paddingTop +
elemSize.borderTopWidth + elemSize.borderBottomWidth;
}
measure = Math.max( measure, 0 );
this.element.style[ isWidth ? 'width' : 'height' ] = measure + 'px';
};
/**
* emit eventComplete on a collection of items events
* @param {String} eventName
* @param {Array} items - Outlayer.Items
*/
Outlayer.prototype._emitCompleteOnItems = function( eventName, items ) {
var _this = this;
function onComplete() {
_this.dispatchEvent( eventName + 'Complete', null, [ items ] );
}
var count = items.length;
if ( !items || !count ) {
onComplete();
return;
}
var doneCount = 0;
function tick() {
doneCount++;
if ( doneCount === count ) {
onComplete();
}
}
// bind callback
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
item.once( eventName, tick );
}
};
/**
* emits events via eventEmitter and jQuery events
* @param {String} type - name of event
* @param {Event} event - original event
* @param {Array} args - extra arguments
*/
Outlayer.prototype.dispatchEvent = function( type, event, args ) {
// add original event to arguments
var emitArgs = event ? [ event ].concat( args ) : args;
this.emitEvent( type, emitArgs );
if ( jQuery ) {
// set this.$element
this.$element = this.$element || jQuery( this.element );
if ( event ) {
// create jQuery event
var $event = jQuery.Event( event );
$event.type = type;
this.$element.trigger( $event, args );
} else {
// just trigger with type if no event available
this.$element.trigger( type, args );
}
}
};
// -------------------------- ignore & stamps -------------------------- //
/**
* keep item in collection, but do not lay it out
* ignored items do not get skipped in layout
* @param {Element} elem
*/
Outlayer.prototype.ignore = function( elem ) {
var item = this.getItem( elem );
if ( item ) {
item.isIgnored = true;
}
};
/**
* return item to layout collection
* @param {Element} elem
*/
Outlayer.prototype.unignore = function( elem ) {
var item = this.getItem( elem );
if ( item ) {
delete item.isIgnored;
}
};
/**
* adds elements to stamps
* @param {NodeList, Array, Element, or String} elems
*/
Outlayer.prototype.stamp = function( elems ) {
elems = this._find( elems );
if ( !elems ) {
return;
}
this.stamps = this.stamps.concat( elems );
// ignore
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
this.ignore( elem );
}
};
/**
* removes elements to stamps
* @param {NodeList, Array, or Element} elems
*/
Outlayer.prototype.unstamp = function( elems ) {
elems = this._find( elems );
if ( !elems ){
return;
}
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
// filter out removed stamp elements
utils.removeFrom( this.stamps, elem );
this.unignore( elem );
}
};
/**
* finds child elements
* @param {NodeList, Array, Element, or String} elems
* @returns {Array} elems
*/
Outlayer.prototype._find = function( elems ) {
if ( !elems ) {
return;
}
// if string, use argument as selector string
if ( typeof elems === 'string' ) {
elems = this.element.querySelectorAll( elems );
}
elems = utils.makeArray( elems );
return elems;
};
Outlayer.prototype._manageStamps = function() {
if ( !this.stamps || !this.stamps.length ) {
return;
}
this._getBoundingRect();
for ( var i=0, len = this.stamps.length; i < len; i++ ) {
var stamp = this.stamps[i];
this._manageStamp( stamp );
}
};
// update boundingLeft / Top
Outlayer.prototype._getBoundingRect = function() {
// get bounding rect for container element
var boundingRect = this.element.getBoundingClientRect();
var size = this.size;
this._boundingRect = {
left: boundingRect.left + size.paddingLeft + size.borderLeftWidth,
top: boundingRect.top + size.paddingTop + size.borderTopWidth,
right: boundingRect.right - ( size.paddingRight + size.borderRightWidth ),
bottom: boundingRect.bottom - ( size.paddingBottom + size.borderBottomWidth )
};
};
/**
* @param {Element} stamp
**/
Outlayer.prototype._manageStamp = noop;
/**
* get x/y position of element relative to container element
* @param {Element} elem
* @returns {Object} offset - has left, top, right, bottom
*/
Outlayer.prototype._getElementOffset = function( elem ) {
var boundingRect = elem.getBoundingClientRect();
var thisRect = this._boundingRect;
var size = getSize( elem );
var offset = {
left: boundingRect.left - thisRect.left - size.marginLeft,
top: boundingRect.top - thisRect.top - size.marginTop,
right: thisRect.right - boundingRect.right - size.marginRight,
bottom: thisRect.bottom - boundingRect.bottom - size.marginBottom
};
return offset;
};
// -------------------------- resize -------------------------- //
// enable event handlers for listeners
// i.e. resize -> onresize
Outlayer.prototype.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
/**
* Bind layout to window resizing
*/
Outlayer.prototype.bindResize = function() {
// bind just one listener
if ( this.isResizeBound ) {
return;
}
eventie.bind( window, 'resize', this );
this.isResizeBound = true;
};
/**
* Unbind layout to window resizing
*/
Outlayer.prototype.unbindResize = function() {
if ( this.isResizeBound ) {
eventie.unbind( window, 'resize', this );
}
this.isResizeBound = false;
};
// original debounce by John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
// this fires every resize
Outlayer.prototype.onresize = function() {
if ( this.resizeTimeout ) {
clearTimeout( this.resizeTimeout );
}
var _this = this;
function delayed() {
_this.resize();
delete _this.resizeTimeout;
}
this.resizeTimeout = setTimeout( delayed, 100 );
};
// debounced, layout on resize
Outlayer.prototype.resize = function() {
// don't trigger if size did not change
// or if resize was unbound. See #9
if ( !this.isResizeBound || !this.needsResizeLayout() ) {
return;
}
this.layout();
};
/**
* check if layout is needed post layout
* @returns Boolean
*/
Outlayer.prototype.needsResizeLayout = function() {
var size = getSize( this.element );
// check that this.size and size are there
// IE8 triggers resize on body size change, so they might not be
var hasSizes = this.size && size;
return hasSizes && size.innerWidth !== this.size.innerWidth;
};
// -------------------------- methods -------------------------- //
/**
* add items to Outlayer instance
* @param {Array or NodeList or Element} elems
* @returns {Array} items - Outlayer.Items
**/
Outlayer.prototype.addItems = function( elems ) {
var items = this._itemize( elems );
// add items to collection
if ( items.length ) {
this.items = this.items.concat( items );
}
return items;
};
/**
* Layout newly-appended item elements
* @param {Array or NodeList or Element} elems
*/
Outlayer.prototype.appended = function( elems ) {
var items = this.addItems( elems );
if ( !items.length ) {
return;
}
// layout and reveal just the new items
this.layoutItems( items, true );
this.reveal( items );
};
/**
* Layout prepended elements
* @param {Array or NodeList or Element} elems
*/
Outlayer.prototype.prepended = function( elems ) {
var items = this._itemize( elems );
if ( !items.length ) {
return;
}
// add items to beginning of collection
var previousItems = this.items.slice(0);
this.items = items.concat( previousItems );
// start new layout
this._resetLayout();
this._manageStamps();
// layout new stuff without transition
this.layoutItems( items, true );
this.reveal( items );
// layout previous items
this.layoutItems( previousItems );
};
/**
* reveal a collection of items
* @param {Array of Outlayer.Items} items
*/
Outlayer.prototype.reveal = function( items ) {
this._emitCompleteOnItems( 'reveal', items );
var len = items && items.length;
for ( var i=0; len && i < len; i++ ) {
var item = items[i];
item.reveal();
}
};
/**
* hide a collection of items
* @param {Array of Outlayer.Items} items
*/
Outlayer.prototype.hide = function( items ) {
this._emitCompleteOnItems( 'hide', items );
var len = items && items.length;
for ( var i=0; len && i < len; i++ ) {
var item = items[i];
item.hide();
}
};
/**
* reveal item elements
* @param {Array}, {Element}, {NodeList} items
*/
Outlayer.prototype.revealItemElements = function( elems ) {
var items = this.getItems( elems );
this.reveal( items );
};
/**
* hide item elements
* @param {Array}, {Element}, {NodeList} items
*/
Outlayer.prototype.hideItemElements = function( elems ) {
var items = this.getItems( elems );
this.hide( items );
};
/**
* get Outlayer.Item, given an Element
* @param {Element} elem
* @param {Function} callback
* @returns {Outlayer.Item} item
*/
Outlayer.prototype.getItem = function( elem ) {
// loop through items to get the one that matches
for ( var i=0, len = this.items.length; i < len; i++ ) {
var item = this.items[i];
if ( item.element === elem ) {
// return item
return item;
}
}
};
/**
* get collection of Outlayer.Items, given Elements
* @param {Array} elems
* @returns {Array} items - Outlayer.Items
*/
Outlayer.prototype.getItems = function( elems ) {
elems = utils.makeArray( elems );
var items = [];
for ( var i=0, len = elems.length; i < len; i++ ) {
var elem = elems[i];
var item = this.getItem( elem );
if ( item ) {
items.push( item );
}
}
return items;
};
/**
* remove element(s) from instance and DOM
* @param {Array or NodeList or Element} elems
*/
Outlayer.prototype.remove = function( elems ) {
var removeItems = this.getItems( elems );
this._emitCompleteOnItems( 'remove', removeItems );
// bail if no items to remove
if ( !removeItems || !removeItems.length ) {
return;
}
for ( var i=0, len = removeItems.length; i < len; i++ ) {
var item = removeItems[i];
item.remove();
// remove item from collection
utils.removeFrom( this.items, item );
}
};
// ----- destroy ----- //
// remove and disable Outlayer instance
Outlayer.prototype.destroy = function() {
// clean up dynamic styles
var style = this.element.style;
style.height = '';
style.position = '';
style.width = '';
// destroy items
for ( var i=0, len = this.items.length; i < len; i++ ) {
var item = this.items[i];
item.destroy();
}
this.unbindResize();
var id = this.element.outlayerGUID;
delete instances[ id ]; // remove reference to instance by id
delete this.element.outlayerGUID;
// remove data for jQuery
if ( jQuery ) {
jQuery.removeData( this.element, this.constructor.namespace );
}
};
// -------------------------- data -------------------------- //
/**
* get Outlayer instance from element
* @param {Element} elem
* @returns {Outlayer}
*/
Outlayer.data = function( elem ) {
elem = utils.getQueryElement( elem );
var id = elem && elem.outlayerGUID;
return id && instances[ id ];
};
// -------------------------- create Outlayer class -------------------------- //
/**
* create a layout class
* @param {String} namespace
*/
Outlayer.create = function( namespace, options ) {
// sub-class Outlayer
function Layout() {
Outlayer.apply( this, arguments );
}
// inherit Outlayer prototype, use Object.create if there
if ( Object.create ) {
Layout.prototype = Object.create( Outlayer.prototype );
} else {
utils.extend( Layout.prototype, Outlayer.prototype );
}
// set contructor, used for namespace and Item
Layout.prototype.constructor = Layout;
Layout.defaults = utils.extend( {}, Outlayer.defaults );
// apply new options
utils.extend( Layout.defaults, options );
// keep prototype.settings for backwards compatibility (Packery v1.2.0)
Layout.prototype.settings = {};
Layout.namespace = namespace;
Layout.data = Outlayer.data;
// sub-class Item
Layout.Item = function LayoutItem() {
Item.apply( this, arguments );
};
Layout.Item.prototype = new Item();
// -------------------------- declarative -------------------------- //
utils.htmlInit( Layout, namespace );
// -------------------------- jQuery bridge -------------------------- //
// make into jQuery plugin
if ( jQuery && jQuery.bridget ) {
jQuery.bridget( namespace, Layout );
}
return Layout;
};
// ----- fin ----- //
// back in global
Outlayer.Item = Item;
return Outlayer;
}));
/**
* Isotope Item
**/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/item',[
'outlayer/outlayer'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('outlayer')
);
} else {
// browser global
window.Isotope = window.Isotope || {};
window.Isotope.Item = factory(
window.Outlayer
);
}
}( window, function factory( Outlayer ) {
'use strict';
// -------------------------- Item -------------------------- //
// sub-class Outlayer Item
function Item() {
Outlayer.Item.apply( this, arguments );
}
Item.prototype = new Outlayer.Item();
Item.prototype._create = function() {
// assign id, used for original-order sorting
this.id = this.layout.itemGUID++;
Outlayer.Item.prototype._create.call( this );
this.sortData = {};
};
Item.prototype.updateSortData = function() {
if ( this.isIgnored ) {
return;
}
// default sorters
this.sortData.id = this.id;
// for backward compatibility
this.sortData['original-order'] = this.id;
this.sortData.random = Math.random();
// go thru getSortData obj and apply the sorters
var getSortData = this.layout.options.getSortData;
var sorters = this.layout._sorters;
for ( var key in getSortData ) {
var sorter = sorters[ key ];
this.sortData[ key ] = sorter( this.element, this );
}
};
var _destroy = Item.prototype.destroy;
Item.prototype.destroy = function() {
// call super
_destroy.apply( this, arguments );
// reset display, #741
this.css({
display: ''
});
};
return Item;
}));
/**
* Isotope LayoutMode
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-mode',[
'get-size/get-size',
'outlayer/outlayer'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('get-size'),
require('outlayer')
);
} else {
// browser global
window.Isotope = window.Isotope || {};
window.Isotope.LayoutMode = factory(
window.getSize,
window.Outlayer
);
}
}( window, function factory( getSize, Outlayer ) {
'use strict';
// layout mode class
function LayoutMode( isotope ) {
this.isotope = isotope;
// link properties
if ( isotope ) {
this.options = isotope.options[ this.namespace ];
this.element = isotope.element;
this.items = isotope.filteredItems;
this.size = isotope.size;
}
}
/**
* some methods should just defer to default Outlayer method
* and reference the Isotope instance as `this`
**/
( function() {
var facadeMethods = [
'_resetLayout',
'_getItemLayoutPosition',
'_manageStamp',
'_getContainerSize',
'_getElementOffset',
'needsResizeLayout'
];
for ( var i=0, len = facadeMethods.length; i < len; i++ ) {
var methodName = facadeMethods[i];
LayoutMode.prototype[ methodName ] = getOutlayerMethod( methodName );
}
function getOutlayerMethod( methodName ) {
return function() {
return Outlayer.prototype[ methodName ].apply( this.isotope, arguments );
};
}
})();
// ----- ----- //
// for horizontal layout modes, check vertical size
LayoutMode.prototype.needsVerticalResizeLayout = function() {
// don't trigger if size did not change
var size = getSize( this.isotope.element );
// check that this.size and size are there
// IE8 triggers resize on body size change, so they might not be
var hasSizes = this.isotope.size && size;
return hasSizes && size.innerHeight != this.isotope.size.innerHeight;
};
// ----- measurements ----- //
LayoutMode.prototype._getMeasurement = function() {
this.isotope._getMeasurement.apply( this, arguments );
};
LayoutMode.prototype.getColumnWidth = function() {
this.getSegmentSize( 'column', 'Width' );
};
LayoutMode.prototype.getRowHeight = function() {
this.getSegmentSize( 'row', 'Height' );
};
/**
* get columnWidth or rowHeight
* segment: 'column' or 'row'
* size 'Width' or 'Height'
**/
LayoutMode.prototype.getSegmentSize = function( segment, size ) {
var segmentName = segment + size;
var outerSize = 'outer' + size;
// columnWidth / outerWidth // rowHeight / outerHeight
this._getMeasurement( segmentName, outerSize );
// got rowHeight or columnWidth, we can chill
if ( this[ segmentName ] ) {
return;
}
// fall back to item of first element
var firstItemSize = this.getFirstItemSize();
this[ segmentName ] = firstItemSize && firstItemSize[ outerSize ] ||
// or size of container
this.isotope.size[ 'inner' + size ];
};
LayoutMode.prototype.getFirstItemSize = function() {
var firstItem = this.isotope.filteredItems[0];
return firstItem && firstItem.element && getSize( firstItem.element );
};
// ----- methods that should reference isotope ----- //
LayoutMode.prototype.layout = function() {
this.isotope.layout.apply( this.isotope, arguments );
};
LayoutMode.prototype.getSize = function() {
this.isotope.getSize();
this.size = this.isotope.size;
};
// -------------------------- create -------------------------- //
LayoutMode.modes = {};
LayoutMode.create = function( namespace, options ) {
function Mode() {
LayoutMode.apply( this, arguments );
}
Mode.prototype = new LayoutMode();
// default options
if ( options ) {
Mode.options = options;
}
Mode.prototype.namespace = namespace;
// register in Isotope
LayoutMode.modes[ namespace ] = Mode;
return Mode;
};
return LayoutMode;
}));
/*!
* Masonry v3.3.1
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
* by David DeSandro
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define === 'function' && define.amd ) {
// AMD
define( 'masonry/masonry',[
'outlayer/outlayer',
'get-size/get-size',
'fizzy-ui-utils/utils'
],
factory );
} else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = factory(
require('outlayer'),
require('get-size'),
require('fizzy-ui-utils')
);
} else {
// browser global
window.Masonry = factory(
window.Outlayer,
window.getSize,
window.fizzyUIUtils
);
}
}( window, function factory( Outlayer, getSize, utils ) {
// -------------------------- masonryDefinition -------------------------- //
// create an Outlayer layout class
var Masonry = Outlayer.create('masonry');
Masonry.prototype._resetLayout = function() {
this.getSize();
this._getMeasurement( 'columnWidth', 'outerWidth' );
this._getMeasurement( 'gutter', 'outerWidth' );
this.measureColumns();
// reset column Y
var i = this.cols;
this.colYs = [];
while (i--) {
this.colYs.push( 0 );
}
this.maxY = 0;
};
Masonry.prototype.measureColumns = function() {
this.getContainerWidth();
// if columnWidth is 0, default to outerWidth of first item
if ( !this.columnWidth ) {
var firstItem = this.items[0];
var firstItemElem = firstItem && firstItem.element;
// columnWidth fall back to item of first element
this.columnWidth = firstItemElem && getSize( firstItemElem ).outerWidth ||
// if first elem has no width, default to size of container
this.containerWidth;
}
var columnWidth = this.columnWidth += this.gutter;
// calculate columns
var containerWidth = this.containerWidth + this.gutter;
var cols = containerWidth / columnWidth;
// fix rounding errors, typically with gutters
var excess = columnWidth - containerWidth % columnWidth;
// if overshoot is less than a pixel, round up, otherwise floor it
var mathMethod = excess && excess < 1 ? 'round' : 'floor';
cols = Math[ mathMethod ]( cols );
this.cols = Math.max( cols, 1 );
};
Masonry.prototype.getContainerWidth = function() {
// container is parent if fit width
var container = this.options.isFitWidth ? this.element.parentNode : this.element;
// check that this.size and size are there
// IE8 triggers resize on body size change, so they might not be
var size = getSize( container );
this.containerWidth = size && size.innerWidth;
};
Masonry.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
// how many columns does this brick span
var remainder = item.size.outerWidth % this.columnWidth;
var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
// round if off by 1 pixel, otherwise use ceil
var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
colSpan = Math.min( colSpan, this.cols );
var colGroup = this._getColGroup( colSpan );
// get the minimum Y value from the columns
var minimumY = Math.min.apply( Math, colGroup );
var shortColIndex = utils.indexOf( colGroup, minimumY );
// position the brick
var position = {
x: this.columnWidth * shortColIndex,
y: minimumY
};
// apply setHeight to necessary columns
var setHeight = minimumY + item.size.outerHeight;
var setSpan = this.cols + 1 - colGroup.length;
for ( var i = 0; i < setSpan; i++ ) {
this.colYs[ shortColIndex + i ] = setHeight;
}
return position;
};
/**
* @param {Number} colSpan - number of columns the element spans
* @returns {Array} colGroup
*/
Masonry.prototype._getColGroup = function( colSpan ) {
if ( colSpan < 2 ) {
// if brick spans only one column, use all the column Ys
return this.colYs;
}
var colGroup = [];
// how many different places could this brick fit horizontally
var groupCount = this.cols + 1 - colSpan;
// for each group potential horizontal position
for ( var i = 0; i < groupCount; i++ ) {
// make an array of colY values for that one group
var groupColYs = this.colYs.slice( i, i + colSpan );
// and get the max value of the array
colGroup[i] = Math.max.apply( Math, groupColYs );
}
return colGroup;
};
Masonry.prototype._manageStamp = function( stamp ) {
var stampSize = getSize( stamp );
var offset = this._getElementOffset( stamp );
// get the columns that this stamp affects
var firstX = this.options.isOriginLeft ? offset.left : offset.right;
var lastX = firstX + stampSize.outerWidth;
var firstCol = Math.floor( firstX / this.columnWidth );
firstCol = Math.max( 0, firstCol );
var lastCol = Math.floor( lastX / this.columnWidth );
// lastCol should not go over if multiple of columnWidth #425
lastCol -= lastX % this.columnWidth ? 0 : 1;
lastCol = Math.min( this.cols - 1, lastCol );
// set colYs to bottom of the stamp
var stampMaxY = ( this.options.isOriginTop ? offset.top : offset.bottom ) +
stampSize.outerHeight;
for ( var i = firstCol; i <= lastCol; i++ ) {
this.colYs[i] = Math.max( stampMaxY, this.colYs[i] );
}
};
Masonry.prototype._getContainerSize = function() {
this.maxY = Math.max.apply( Math, this.colYs );
var size = {
height: this.maxY
};
if ( this.options.isFitWidth ) {
size.width = this._getContainerFitWidth();
}
return size;
};
Masonry.prototype._getContainerFitWidth = function() {
var unusedCols = 0;
// count unused columns
var i = this.cols;
while ( --i ) {
if ( this.colYs[i] !== 0 ) {
break;
}
unusedCols++;
}
// fit container to columns that have been used
return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
};
Masonry.prototype.needsResizeLayout = function() {
var previousWidth = this.containerWidth;
this.getContainerWidth();
return previousWidth !== this.containerWidth;
};
return Masonry;
}));
/*!
* Masonry layout mode
* sub-classes Masonry
* http://masonry.desandro.com
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-modes/masonry',[
'../layout-mode',
'masonry/masonry'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('../layout-mode'),
require('masonry-layout')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode,
window.Masonry
);
}
}( window, function factory( LayoutMode, Masonry ) {
'use strict';
// -------------------------- helpers -------------------------- //
// extend objects
function extend( a, b ) {
for ( var prop in b ) {
a[ prop ] = b[ prop ];
}
return a;
}
// -------------------------- masonryDefinition -------------------------- //
// create an Outlayer layout class
var MasonryMode = LayoutMode.create('masonry');
// save on to these methods
var _getElementOffset = MasonryMode.prototype._getElementOffset;
var layout = MasonryMode.prototype.layout;
var _getMeasurement = MasonryMode.prototype._getMeasurement;
// sub-class Masonry
extend( MasonryMode.prototype, Masonry.prototype );
// set back, as it was overwritten by Masonry
MasonryMode.prototype._getElementOffset = _getElementOffset;
MasonryMode.prototype.layout = layout;
MasonryMode.prototype._getMeasurement = _getMeasurement;
var measureColumns = MasonryMode.prototype.measureColumns;
MasonryMode.prototype.measureColumns = function() {
// set items, used if measuring first item
this.items = this.isotope.filteredItems;
measureColumns.call( this );
};
// HACK copy over isOriginLeft/Top options
var _manageStamp = MasonryMode.prototype._manageStamp;
MasonryMode.prototype._manageStamp = function() {
this.options.isOriginLeft = this.isotope.options.isOriginLeft;
this.options.isOriginTop = this.isotope.options.isOriginTop;
_manageStamp.apply( this, arguments );
};
return MasonryMode;
}));
/**
* fitRows layout mode
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-modes/fit-rows',[
'../layout-mode'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('../layout-mode')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode
);
}
}( window, function factory( LayoutMode ) {
'use strict';
var FitRows = LayoutMode.create('fitRows');
FitRows.prototype._resetLayout = function() {
this.x = 0;
this.y = 0;
this.maxY = 0;
this._getMeasurement( 'gutter', 'outerWidth' );
};
FitRows.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
var itemWidth = item.size.outerWidth + this.gutter;
// if this element cannot fit in the current row
var containerWidth = this.isotope.size.innerWidth + this.gutter;
if ( this.x !== 0 && itemWidth + this.x > containerWidth ) {
this.x = 0;
this.y = this.maxY;
}
var position = {
x: this.x,
y: this.y
};
this.maxY = Math.max( this.maxY, this.y + item.size.outerHeight );
this.x += itemWidth;
return position;
};
FitRows.prototype._getContainerSize = function() {
return { height: this.maxY };
};
return FitRows;
}));
/**
* vertical layout mode
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'isotope/js/layout-modes/vertical',[
'../layout-mode'
],
factory );
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
require('../layout-mode')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode
);
}
}( window, function factory( LayoutMode ) {
'use strict';
var Vertical = LayoutMode.create( 'vertical', {
horizontalAlignment: 0
});
Vertical.prototype._resetLayout = function() {
this.y = 0;
};
Vertical.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
var x = ( this.isotope.size.innerWidth - item.size.outerWidth ) *
this.options.horizontalAlignment;
var y = this.y;
this.y += item.size.outerHeight;
return { x: x, y: y };
};
Vertical.prototype._getContainerSize = function() {
return { height: this.y };
};
return Vertical;
}));
/*!
* Isotope v2.2.2
*
* Licensed GPLv3 for open source use
* or Isotope Commercial License for commercial use
*
* http://isotope.metafizzy.co
* Copyright 2015 Metafizzy
*/
( function( window, factory ) {
'use strict';
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( [
'outlayer/outlayer',
'get-size/get-size',
'matches-selector/matches-selector',
'fizzy-ui-utils/utils',
'isotope/js/item',
'isotope/js/layout-mode',
// include default layout modes
'isotope/js/layout-modes/masonry',
'isotope/js/layout-modes/fit-rows',
'isotope/js/layout-modes/vertical'
],
function( Outlayer, getSize, matchesSelector, utils, Item, LayoutMode ) {
return factory( window, Outlayer, getSize, matchesSelector, utils, Item, LayoutMode );
});
} else if ( typeof exports == 'object' ) {
// CommonJS
module.exports = factory(
window,
require('outlayer'),
require('get-size'),
require('desandro-matches-selector'),
require('fizzy-ui-utils'),
require('./item'),
require('./layout-mode'),
// include default layout modes
require('./layout-modes/masonry'),
require('./layout-modes/fit-rows'),
require('./layout-modes/vertical')
);
} else {
// browser global
window.Isotope = factory(
window,
window.Outlayer,
window.getSize,
window.matchesSelector,
window.fizzyUIUtils,
window.Isotope.Item,
window.Isotope.LayoutMode
);
}
}( window, function factory( window, Outlayer, getSize, matchesSelector, utils,
Item, LayoutMode ) {
// -------------------------- vars -------------------------- //
var jQuery = window.jQuery;
// -------------------------- helpers -------------------------- //
var trim = String.prototype.trim ?
function( str ) {
return str.trim();
} :
function( str ) {
return str.replace( /^\s+|\s+$/g, '' );
};
var docElem = document.documentElement;
var getText = docElem.textContent ?
function( elem ) {
return elem.textContent;
} :
function( elem ) {
return elem.innerText;
};
// -------------------------- isotopeDefinition -------------------------- //
// create an Outlayer layout class
var Isotope = Outlayer.create( 'isotope', {
layoutMode: "masonry",
isJQueryFiltering: true,
sortAscending: true
});
Isotope.Item = Item;
Isotope.LayoutMode = LayoutMode;
Isotope.prototype._create = function() {
this.itemGUID = 0;
// functions that sort items
this._sorters = {};
this._getSorters();
// call super
Outlayer.prototype._create.call( this );
// create layout modes
this.modes = {};
// start filteredItems with all items
this.filteredItems = this.items;
// keep of track of sortBys
this.sortHistory = [ 'original-order' ];
// create from registered layout modes
for ( var name in LayoutMode.modes ) {
this._initLayoutMode( name );
}
};
Isotope.prototype.reloadItems = function() {
// reset item ID counter
this.itemGUID = 0;
// call super
Outlayer.prototype.reloadItems.call( this );
};
Isotope.prototype._itemize = function() {
var items = Outlayer.prototype._itemize.apply( this, arguments );
// assign ID for original-order
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
item.id = this.itemGUID++;
}
this._updateItemsSortData( items );
return items;
};
// -------------------------- layout -------------------------- //
Isotope.prototype._initLayoutMode = function( name ) {
var Mode = LayoutMode.modes[ name ];
// set mode options
// HACK extend initial options, back-fill in default options
var initialOpts = this.options[ name ] || {};
this.options[ name ] = Mode.options ?
utils.extend( Mode.options, initialOpts ) : initialOpts;
// init layout mode instance
this.modes[ name ] = new Mode( this );
};
Isotope.prototype.layout = function() {
// if first time doing layout, do all magic
if ( !this._isLayoutInited && this.options.isInitLayout ) {
this.arrange();
return;
}
this._layout();
};
// private method to be used in layout() & magic()
Isotope.prototype._layout = function() {
// don't animate first layout
var isInstant = this._getIsInstant();
// layout flow
this._resetLayout();
this._manageStamps();
this.layoutItems( this.filteredItems, isInstant );
// flag for initalized
this._isLayoutInited = true;
};
// filter + sort + layout
Isotope.prototype.arrange = function( opts ) {
// set any options pass
this.option( opts );
this._getIsInstant();
// filter, sort, and layout
// filter
var filtered = this._filter( this.items );
this.filteredItems = filtered.matches;
var _this = this;
function hideReveal() {
_this.reveal( filtered.needReveal );
_this.hide( filtered.needHide );
}
this._bindArrangeComplete();
if ( this._isInstant ) {
this._noTransition( hideReveal );
} else {
hideReveal();
}
this._sort();
this._layout();
};
// alias to _init for main plugin method
Isotope.prototype._init = Isotope.prototype.arrange;
// HACK
// Don't animate/transition first layout
// Or don't animate/transition other layouts
Isotope.prototype._getIsInstant = function() {
var isInstant = this.options.isLayoutInstant !== undefined ?
this.options.isLayoutInstant : !this._isLayoutInited;
this._isInstant = isInstant;
return isInstant;
};
// listen for layoutComplete, hideComplete and revealComplete
// to trigger arrangeComplete
Isotope.prototype._bindArrangeComplete = function() {
// listen for 3 events to trigger arrangeComplete
var isLayoutComplete, isHideComplete, isRevealComplete;
var _this = this;
function arrangeParallelCallback() {
if ( isLayoutComplete && isHideComplete && isRevealComplete ) {
_this.dispatchEvent( 'arrangeComplete', null, [ _this.filteredItems ] );
}
}
this.once( 'layoutComplete', function() {
isLayoutComplete = true;
arrangeParallelCallback();
});
this.once( 'hideComplete', function() {
isHideComplete = true;
arrangeParallelCallback();
});
this.once( 'revealComplete', function() {
isRevealComplete = true;
arrangeParallelCallback();
});
};
// -------------------------- filter -------------------------- //
Isotope.prototype._filter = function( items ) {
var filter = this.options.filter;
filter = filter || '*';
var matches = [];
var hiddenMatched = [];
var visibleUnmatched = [];
var test = this._getFilterTest( filter );
// test each item
for ( var i=0, len = items.length; i < len; i++ ) {
var item = items[i];
if ( item.isIgnored ) {
continue;
}
// add item to either matched or unmatched group
var isMatched = test( item );
// item.isFilterMatched = isMatched;
// add to matches if its a match
if ( isMatched ) {
matches.push( item );
}
// add to additional group if item needs to be hidden or revealed
if ( isMatched && item.isHidden ) {
hiddenMatched.push( item );
} else if ( !isMatched && !item.isHidden ) {
visibleUnmatched.push( item );
}
}
// return collections of items to be manipulated
return {
matches: matches,
needReveal: hiddenMatched,
needHide: visibleUnmatched
};
};
// get a jQuery, function, or a matchesSelector test given the filter
Isotope.prototype._getFilterTest = function( filter ) {
if ( jQuery && this.options.isJQueryFiltering ) {
// use jQuery
return function( item ) {
return jQuery( item.element ).is( filter );
};
}
if ( typeof filter == 'function' ) {
// use filter as function
return function( item ) {
return filter( item.element );
};
}
// default, use filter as selector string
return function( item ) {
return matchesSelector( item.element, filter );
};
};
// -------------------------- sorting -------------------------- //
/**
* @params {Array} elems
* @public
*/
Isotope.prototype.updateSortData = function( elems ) {
// get items
var items;
if ( elems ) {
elems = utils.makeArray( elems );
items = this.getItems( elems );
} else {
// update all items if no elems provided
items = this.items;
}
this._getSorters();
this._updateItemsSortData( items );
};
Isotope.prototype._getSorters = function() {
var getSortData = this.options.getSortData;
for ( var key in getSortData ) {
var sorter = getSortData[ key ];
this._sorters[ key ] = mungeSorter( sorter );
}
};
/**
* @params {Array} items - of Isotope.Items
* @private
*/
Isotope.prototype._updateItemsSortData = function( items ) {
// do not update if no items
var len = items && items.length;
for ( var i=0; len && i < len; i++ ) {
var item = items[i];
item.updateSortData();
}
};
// ----- munge sorter ----- //
// encapsulate this, as we just need mungeSorter
// other functions in here are just for munging
var mungeSorter = ( function() {
// add a magic layer to sorters for convienent shorthands
// `.foo-bar` will use the text of .foo-bar querySelector
// `[foo-bar]` will use attribute
// you can also add parser
// `.foo-bar parseInt` will parse that as a number
function mungeSorter( sorter ) {
// if not a string, return function or whatever it is
if ( typeof sorter != 'string' ) {
return sorter;
}
// parse the sorter string
var args = trim( sorter ).split(' ');
var query = args[0];
// check if query looks like [an-attribute]
var attrMatch = query.match( /^\[(.+)\]$/ );
var attr = attrMatch && attrMatch[1];
var getValue = getValueGetter( attr, query );
// use second argument as a parser
var parser = Isotope.sortDataParsers[ args[1] ];
// parse the value, if there was a parser
sorter = parser ? function( elem ) {
return elem && parser( getValue( elem ) );
} :
// otherwise just return value
function( elem ) {
return elem && getValue( elem );
};
return sorter;
}
// get an attribute getter, or get text of the querySelector
function getValueGetter( attr, query ) {
var getValue;
// if query looks like [foo-bar], get attribute
if ( attr ) {
getValue = function( elem ) {
return elem.getAttribute( attr );
};
} else {
// otherwise, assume its a querySelector, and get its text
getValue = function( elem ) {
var child = elem.querySelector( query );
return child && getText( child );
};
}
return getValue;
}
return mungeSorter;
})();
// parsers used in getSortData shortcut strings
Isotope.sortDataParsers = {
'parseInt': function( val ) {
return parseInt( val, 10 );
},
'parseFloat': function( val ) {
return parseFloat( val );
}
};
// ----- sort method ----- //
// sort filteredItem order
Isotope.prototype._sort = function() {
var sortByOpt = this.options.sortBy;
if ( !sortByOpt ) {
return;
}
// concat all sortBy and sortHistory
var sortBys = [].concat.apply( sortByOpt, this.sortHistory );
// sort magic
var itemSorter = getItemSorter( sortBys, this.options.sortAscending );
this.filteredItems.sort( itemSorter );
// keep track of sortBy History
if ( sortByOpt != this.sortHistory[0] ) {
// add to front, oldest goes in last
this.sortHistory.unshift( sortByOpt );
}
};
// returns a function used for sorting
function getItemSorter( sortBys, sortAsc ) {
return function sorter( itemA, itemB ) {
// cycle through all sortKeys
for ( var i = 0, len = sortBys.length; i < len; i++ ) {
var sortBy = sortBys[i];
var a = itemA.sortData[ sortBy ];
var b = itemB.sortData[ sortBy ];
if ( a > b || a < b ) {
// if sortAsc is an object, use the value given the sortBy key
var isAscending = sortAsc[ sortBy ] !== undefined ? sortAsc[ sortBy ] : sortAsc;
var direction = isAscending ? 1 : -1;
return ( a > b ? 1 : -1 ) * direction;
}
}
return 0;
};
}
// -------------------------- methods -------------------------- //
// get layout mode
Isotope.prototype._mode = function() {
var layoutMode = this.options.layoutMode;
var mode = this.modes[ layoutMode ];
if ( !mode ) {
// TODO console.error
throw new Error( 'No layout mode: ' + layoutMode );
}
// HACK sync mode's options
// any options set after init for layout mode need to be synced
mode.options = this.options[ layoutMode ];
return mode;
};
Isotope.prototype._resetLayout = function() {
// trigger original reset layout
Outlayer.prototype._resetLayout.call( this );
this._mode()._resetLayout();
};
Isotope.prototype._getItemLayoutPosition = function( item ) {
return this._mode()._getItemLayoutPosition( item );
};
Isotope.prototype._manageStamp = function( stamp ) {
this._mode()._manageStamp( stamp );
};
Isotope.prototype._getContainerSize = function() {
return this._mode()._getContainerSize();
};
Isotope.prototype.needsResizeLayout = function() {
return this._mode().needsResizeLayout();
};
// -------------------------- adding & removing -------------------------- //
// HEADS UP overwrites default Outlayer appended
Isotope.prototype.appended = function( elems ) {
var items = this.addItems( elems );
if ( !items.length ) {
return;
}
// filter, layout, reveal new items
var filteredItems = this._filterRevealAdded( items );
// add to filteredItems
this.filteredItems = this.filteredItems.concat( filteredItems );
};
// HEADS UP overwrites default Outlayer prepended
Isotope.prototype.prepended = function( elems ) {
var items = this._itemize( elems );
if ( !items.length ) {
return;
}
// start new layout
this._resetLayout();
this._manageStamps();
// filter, layout, reveal new items
var filteredItems = this._filterRevealAdded( items );
// layout previous items
this.layoutItems( this.filteredItems );
// add to items and filteredItems
this.filteredItems = filteredItems.concat( this.filteredItems );
this.items = items.concat( this.items );
};
Isotope.prototype._filterRevealAdded = function( items ) {
var filtered = this._filter( items );
this.hide( filtered.needHide );
// reveal all new items
this.reveal( filtered.matches );
// layout new items, no transition
this.layoutItems( filtered.matches, true );
return filtered.matches;
};
/**
* Filter, sort, and layout newly-appended item elements
* @param {Array or NodeList or Element} elems
*/
Isotope.prototype.insert = function( elems ) {
var items = this.addItems( elems );
if ( !items.length ) {
return;
}
// append item elements
var i, item;
var len = items.length;
for ( i=0; i < len; i++ ) {
item = items[i];
this.element.appendChild( item.element );
}
// filter new stuff
var filteredInsertItems = this._filter( items ).matches;
// set flag
for ( i=0; i < len; i++ ) {
items[i].isLayoutInstant = true;
}
this.arrange();
// reset flag
for ( i=0; i < len; i++ ) {
delete items[i].isLayoutInstant;
}
this.reveal( filteredInsertItems );
};
var _remove = Isotope.prototype.remove;
Isotope.prototype.remove = function( elems ) {
elems = utils.makeArray( elems );
var removeItems = this.getItems( elems );
// do regular thing
_remove.call( this, elems );
// bail if no items to remove
var len = removeItems && removeItems.length;
if ( !len ) {
return;
}
// remove elems from filteredItems
for ( var i=0; i < len; i++ ) {
var item = removeItems[i];
// remove item from collection
utils.removeFrom( this.filteredItems, item );
}
};
Isotope.prototype.shuffle = function() {
// update random sortData
for ( var i=0, len = this.items.length; i < len; i++ ) {
var item = this.items[i];
item.sortData.random = Math.random();
}
this.options.sortBy = 'random';
this._sort();
this._layout();
};
/**
* trigger fn without transition
* kind of hacky to have this in the first place
* @param {Function} fn
* @returns ret
* @private
*/
Isotope.prototype._noTransition = function( fn ) {
// save transitionDuration before disabling
var transitionDuration = this.options.transitionDuration;
// disable transition
this.options.transitionDuration = 0;
// do it
var returnValue = fn.call( this );
// re-enable transition for reveal
this.options.transitionDuration = transitionDuration;
return returnValue;
};
// ----- helper methods ----- //
/**
* getter method for getting filtered item elements
* @returns {Array} elems - collection of item elements
*/
Isotope.prototype.getFilteredItemElements = function() {
var elems = [];
for ( var i=0, len = this.filteredItems.length; i < len; i++ ) {
elems.push( this.filteredItems[i].element );
}
return elems;
};
// ----- ----- //
return Isotope;
}));
/*!
* Packery layout mode PACKAGED v2.0.1
* sub-classes Packery
*/
/**
* Rect
* low-level utility class for basic geometry
*/
( function( window, factory ) {
// universal module definition
/* jshint strict: false */ /* globals define, module */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'packery/js/rect',factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory();
} else {
// browser global
window.Packery = window.Packery || {};
window.Packery.Rect = factory();
}
}( window, function factory() {
// -------------------------- Rect -------------------------- //
function Rect( props ) {
// extend properties from defaults
for ( var prop in Rect.defaults ) {
this[ prop ] = Rect.defaults[ prop ];
}
for ( prop in props ) {
this[ prop ] = props[ prop ];
}
}
Rect.defaults = {
x: 0,
y: 0,
width: 0,
height: 0
};
var proto = Rect.prototype;
/**
* Determines whether or not this rectangle wholly encloses another rectangle or point.
* @param {Rect} rect
* @returns {Boolean}
**/
proto.contains = function( rect ) {
// points don't have width or height
var otherWidth = rect.width || 0;
var otherHeight = rect.height || 0;
return this.x <= rect.x &&
this.y <= rect.y &&
this.x + this.width >= rect.x + otherWidth &&
this.y + this.height >= rect.y + otherHeight;
};
/**
* Determines whether or not the rectangle intersects with another.
* @param {Rect} rect
* @returns {Boolean}
**/
proto.overlaps = function( rect ) {
var thisRight = this.x + this.width;
var thisBottom = this.y + this.height;
var rectRight = rect.x + rect.width;
var rectBottom = rect.y + rect.height;
// http://stackoverflow.com/a/306332
return this.x < rectRight &&
thisRight > rect.x &&
this.y < rectBottom &&
thisBottom > rect.y;
};
/**
* @param {Rect} rect - the overlapping rect
* @returns {Array} freeRects - rects representing the area around the rect
**/
proto.getMaximalFreeRects = function( rect ) {
// if no intersection, return false
if ( !this.overlaps( rect ) ) {
return false;
}
var freeRects = [];
var freeRect;
var thisRight = this.x + this.width;
var thisBottom = this.y + this.height;
var rectRight = rect.x + rect.width;
var rectBottom = rect.y + rect.height;
// top
if ( this.y < rect.y ) {
freeRect = new Rect({
x: this.x,
y: this.y,
width: this.width,
height: rect.y - this.y
});
freeRects.push( freeRect );
}
// right
if ( thisRight > rectRight ) {
freeRect = new Rect({
x: rectRight,
y: this.y,
width: thisRight - rectRight,
height: this.height
});
freeRects.push( freeRect );
}
// bottom
if ( thisBottom > rectBottom ) {
freeRect = new Rect({
x: this.x,
y: rectBottom,
width: this.width,
height: thisBottom - rectBottom
});
freeRects.push( freeRect );
}
// left
if ( this.x < rect.x ) {
freeRect = new Rect({
x: this.x,
y: this.y,
width: rect.x - this.x,
height: this.height
});
freeRects.push( freeRect );
}
return freeRects;
};
proto.canFit = function( rect ) {
return this.width >= rect.width && this.height >= rect.height;
};
return Rect;
}));
/**
* Packer
* bin-packing algorithm
*/
( function( window, factory ) {
// universal module definition
/* jshint strict: false */ /* globals define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'packery/js/packer',[ './rect' ], factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
require('./rect')
);
} else {
// browser global
var Packery = window.Packery = window.Packery || {};
Packery.Packer = factory( Packery.Rect );
}
}( window, function factory( Rect ) {
// -------------------------- Packer -------------------------- //
/**
* @param {Number} width
* @param {Number} height
* @param {String} sortDirection
* topLeft for vertical, leftTop for horizontal
*/
function Packer( width, height, sortDirection ) {
this.width = width || 0;
this.height = height || 0;
this.sortDirection = sortDirection || 'downwardLeftToRight';
this.reset();
}
var proto = Packer.prototype;
proto.reset = function() {
this.spaces = [];
var initialSpace = new Rect({
x: 0,
y: 0,
width: this.width,
height: this.height
});
this.spaces.push( initialSpace );
// set sorter
this.sorter = sorters[ this.sortDirection ] || sorters.downwardLeftToRight;
};
// change x and y of rect to fit with in Packer's available spaces
proto.pack = function( rect ) {
for ( var i=0; i < this.spaces.length; i++ ) {
var space = this.spaces[i];
if ( space.canFit( rect ) ) {
this.placeInSpace( rect, space );
break;
}
}
};
proto.columnPack = function( rect ) {
for ( var i=0; i < this.spaces.length; i++ ) {
var space = this.spaces[i];
var canFitInSpaceColumn = space.x <= rect.x &&
space.x + space.width >= rect.x + rect.width &&
space.height >= rect.height - 0.01; // fudge number for rounding error
if ( canFitInSpaceColumn ) {
rect.y = space.y;
this.placed( rect );
break;
}
}
};
proto.rowPack = function( rect ) {
for ( var i=0; i < this.spaces.length; i++ ) {
var space = this.spaces[i];
var canFitInSpaceRow = space.y <= rect.y &&
space.y + space.height >= rect.y + rect.height &&
space.width >= rect.width - 0.01; // fudge number for rounding error
if ( canFitInSpaceRow ) {
rect.x = space.x;
this.placed( rect );
break;
}
}
};
proto.placeInSpace = function( rect, space ) {
// place rect in space
rect.x = space.x;
rect.y = space.y;
this.placed( rect );
};
// update spaces with placed rect
proto.placed = function( rect ) {
// update spaces
var revisedSpaces = [];
for ( var i=0; i < this.spaces.length; i++ ) {
var space = this.spaces[i];
var newSpaces = space.getMaximalFreeRects( rect );
// add either the original space or the new spaces to the revised spaces
if ( newSpaces ) {
revisedSpaces.push.apply( revisedSpaces, newSpaces );
} else {
revisedSpaces.push( space );
}
}
this.spaces = revisedSpaces;
this.mergeSortSpaces();
};
proto.mergeSortSpaces = function() {
// remove redundant spaces
Packer.mergeRects( this.spaces );
this.spaces.sort( this.sorter );
};
// add a space back
proto.addSpace = function( rect ) {
this.spaces.push( rect );
this.mergeSortSpaces();
};
// -------------------------- utility functions -------------------------- //
/**
* Remove redundant rectangle from array of rectangles
* @param {Array} rects: an array of Rects
* @returns {Array} rects: an array of Rects
**/
Packer.mergeRects = function( rects ) {
var i = 0;
var rect = rects[i];
rectLoop:
while ( rect ) {
var j = 0;
var compareRect = rects[ i + j ];
while ( compareRect ) {
if ( compareRect == rect ) {
j++; // next
} else if ( compareRect.contains( rect ) ) {
// remove rect
rects.splice( i, 1 );
rect = rects[i]; // set next rect
continue rectLoop; // bail on compareLoop
} else if ( rect.contains( compareRect ) ) {
// remove compareRect
rects.splice( i + j, 1 );
} else {
j++;
}
compareRect = rects[ i + j ]; // set next compareRect
}
i++;
rect = rects[i];
}
return rects;
};
// -------------------------- sorters -------------------------- //
// functions for sorting rects in order
var sorters = {
// top down, then left to right
downwardLeftToRight: function( a, b ) {
return a.y - b.y || a.x - b.x;
},
// left to right, then top down
rightwardTopToBottom: function( a, b ) {
return a.x - b.x || a.y - b.y;
}
};
// -------------------------- -------------------------- //
return Packer;
}));
/**
* Packery Item Element
**/
( function( window, factory ) {
// universal module definition
/* jshint strict: false */ /* globals define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'packery/js/item',[
'outlayer/outlayer',
'./rect'
],
factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
require('outlayer'),
require('./rect')
);
} else {
// browser global
window.Packery.Item = factory(
window.Outlayer,
window.Packery.Rect
);
}
}( window, function factory( Outlayer, Rect ) {
// -------------------------- Item -------------------------- //
var docElemStyle = document.documentElement.style;
var transformProperty = typeof docElemStyle.transform == 'string' ?
'transform' : 'WebkitTransform';
// sub-class Item
var Item = function PackeryItem() {
Outlayer.Item.apply( this, arguments );
};
var proto = Item.prototype = Object.create( Outlayer.Item.prototype );
var __create = proto._create;
proto._create = function() {
// call default _create logic
__create.call( this );
this.rect = new Rect();
};
var _moveTo = proto.moveTo;
proto.moveTo = function( x, y ) {
// don't shift 1px while dragging
var dx = Math.abs( this.position.x - x );
var dy = Math.abs( this.position.y - y );
var canHackGoTo = this.layout.dragItemCount && !this.isPlacing &&
!this.isTransitioning && dx < 1 && dy < 1;
if ( canHackGoTo ) {
this.goTo( x, y );
return;
}
_moveTo.apply( this, arguments );
};
// -------------------------- placing -------------------------- //
proto.enablePlacing = function() {
this.removeTransitionStyles();
// remove transform property from transition
if ( this.isTransitioning && transformProperty ) {
this.element.style[ transformProperty ] = 'none';
}
this.isTransitioning = false;
this.getSize();
this.layout._setRectSize( this.element, this.rect );
this.isPlacing = true;
};
proto.disablePlacing = function() {
this.isPlacing = false;
};
// ----- ----- //
// remove element from DOM
proto.removeElem = function() {
this.element.parentNode.removeChild( this.element );
// add space back to packer
this.layout.packer.addSpace( this.rect );
this.emitEvent( 'remove', [ this ] );
};
// ----- dropPlaceholder ----- //
proto.showDropPlaceholder = function() {
var dropPlaceholder = this.dropPlaceholder;
if ( !dropPlaceholder ) {
// create dropPlaceholder
dropPlaceholder = this.dropPlaceholder = document.createElement('div');
dropPlaceholder.className = 'packery-drop-placeholder';
dropPlaceholder.style.position = 'absolute';
}
dropPlaceholder.style.width = this.size.width + 'px';
dropPlaceholder.style.height = this.size.height + 'px';
this.positionDropPlaceholder();
this.layout.element.appendChild( dropPlaceholder );
};
proto.positionDropPlaceholder = function() {
this.dropPlaceholder.style[ transformProperty ] = 'translate(' +
this.rect.x + 'px, ' + this.rect.y + 'px)';
};
proto.hideDropPlaceholder = function() {
this.layout.element.removeChild( this.dropPlaceholder );
};
// ----- ----- //
return Item;
}));
/*!
* Packery v2.0.0
* Gapless, draggable grid layouts
*
* Licensed GPLv3 for open source use
* or Packery Commercial License for commercial use
*
* http://packery.metafizzy.co
* Copyright 2016 Metafizzy
*/
( function( window, factory ) {
// universal module definition
/* jshint strict: false */ /* globals define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'packery/js/packery',[
'get-size/get-size',
'outlayer/outlayer',
'./rect',
'./packer',
'./item'
],
factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
require('get-size'),
require('outlayer'),
require('./rect'),
require('./packer'),
require('./item')
);
} else {
// browser global
window.Packery = factory(
window.getSize,
window.Outlayer,
window.Packery.Rect,
window.Packery.Packer,
window.Packery.Item
);
}
}( window, function factory( getSize, Outlayer, Rect, Packer, Item ) {
// ----- Rect ----- //
// allow for pixel rounding errors IE8-IE11 & Firefox; #227
Rect.prototype.canFit = function( rect ) {
return this.width >= rect.width - 1 && this.height >= rect.height - 1;
};
// -------------------------- Packery -------------------------- //
// create an Outlayer layout class
var Packery = Outlayer.create('packery');
Packery.Item = Item;
var proto = Packery.prototype;
proto._create = function() {
// call super
Outlayer.prototype._create.call( this );
// initial properties
this.packer = new Packer();
// packer for drop targets
this.shiftPacker = new Packer();
this.isEnabled = true;
this.dragItemCount = 0;
// create drag handlers
var _this = this;
this.handleDraggabilly = {
dragStart: function() {
_this.itemDragStart( this.element );
},
dragMove: function() {
_this.itemDragMove( this.element, this.position.x, this.position.y );
},
dragEnd: function() {
_this.itemDragEnd( this.element );
}
};
this.handleUIDraggable = {
start: function handleUIDraggableStart( event, ui ) {
// HTML5 may trigger dragstart, dismiss HTML5 dragging
if ( !ui ) {
return;
}
_this.itemDragStart( event.currentTarget );
},
drag: function handleUIDraggableDrag( event, ui ) {
if ( !ui ) {
return;
}
_this.itemDragMove( event.currentTarget, ui.position.left, ui.position.top );
},
stop: function handleUIDraggableStop( event, ui ) {
if ( !ui ) {
return;
}
_this.itemDragEnd( event.currentTarget );
}
};
};
// ----- init & layout ----- //
/**
* logic before any new layout
*/
proto._resetLayout = function() {
this.getSize();
this._getMeasurements();
// reset packer
var width, height, sortDirection;
// packer settings, if horizontal or vertical
if ( this._getOption('horizontal') ) {
width = Infinity;
height = this.size.innerHeight + this.gutter;
sortDirection = 'rightwardTopToBottom';
} else {
width = this.size.innerWidth + this.gutter;
height = Infinity;
sortDirection = 'downwardLeftToRight';
}
this.packer.width = this.shiftPacker.width = width;
this.packer.height = this.shiftPacker.height = height;
this.packer.sortDirection = this.shiftPacker.sortDirection = sortDirection;
this.packer.reset();
// layout
this.maxY = 0;
this.maxX = 0;
};
/**
* update columnWidth, rowHeight, & gutter
* @private
*/
proto._getMeasurements = function() {
this._getMeasurement( 'columnWidth', 'width' );
this._getMeasurement( 'rowHeight', 'height' );
this._getMeasurement( 'gutter', 'width' );
};
proto._getItemLayoutPosition = function( item ) {
this._setRectSize( item.element, item.rect );
if ( this.isShifting || this.dragItemCount > 0 ) {
var packMethod = this._getPackMethod();
this.packer[ packMethod ]( item.rect );
} else {
this.packer.pack( item.rect );
}
this._setMaxXY( item.rect );
return item.rect;
};
proto.shiftLayout = function() {
this.isShifting = true;
this.layout();
delete this.isShifting;
};
proto._getPackMethod = function() {
return this._getOption('horizontal') ? 'rowPack' : 'columnPack';
};
/**
* set max X and Y value, for size of container
* @param {Packery.Rect} rect
* @private
*/
proto._setMaxXY = function( rect ) {
this.maxX = Math.max( rect.x + rect.width, this.maxX );
this.maxY = Math.max( rect.y + rect.height, this.maxY );
};
/**
* set the width and height of a rect, applying columnWidth and rowHeight
* @param {Element} elem
* @param {Packery.Rect} rect
*/
proto._setRectSize = function( elem, rect ) {
var size = getSize( elem );
var w = size.outerWidth;
var h = size.outerHeight;
// size for columnWidth and rowHeight, if available
// only check if size is non-zero, #177
if ( w || h ) {
w = this._applyGridGutter( w, this.columnWidth );
h = this._applyGridGutter( h, this.rowHeight );
}
// rect must fit in packer
rect.width = Math.min( w, this.packer.width );
rect.height = Math.min( h, this.packer.height );
};
/**
* fits item to columnWidth/rowHeight and adds gutter
* @param {Number} measurement - item width or height
* @param {Number} gridSize - columnWidth or rowHeight
* @returns measurement
*/
proto._applyGridGutter = function( measurement, gridSize ) {
// just add gutter if no gridSize
if ( !gridSize ) {
return measurement + this.gutter;
}
gridSize += this.gutter;
// fit item to columnWidth/rowHeight
var remainder = measurement % gridSize;
var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
measurement = Math[ mathMethod ]( measurement / gridSize ) * gridSize;
return measurement;
};
proto._getContainerSize = function() {
if ( this._getOption('horizontal') ) {
return {
width: this.maxX - this.gutter
};
} else {
return {
height: this.maxY - this.gutter
};
}
};
// -------------------------- stamp -------------------------- //
/**
* makes space for element
* @param {Element} elem
*/
proto._manageStamp = function( elem ) {
var item = this.getItem( elem );
var rect;
if ( item && item.isPlacing ) {
rect = item.rect;
} else {
var offset = this._getElementOffset( elem );
rect = new Rect({
x: this._getOption('originLeft') ? offset.left : offset.right,
y: this._getOption('originTop') ? offset.top : offset.bottom
});
}
this._setRectSize( elem, rect );
// save its space in the packer
this.packer.placed( rect );
this._setMaxXY( rect );
};
// -------------------------- methods -------------------------- //
function verticalSorter( a, b ) {
return a.position.y - b.position.y || a.position.x - b.position.x;
}
function horizontalSorter( a, b ) {
return a.position.x - b.position.x || a.position.y - b.position.y;
}
proto.sortItemsByPosition = function() {
var sorter = this._getOption('horizontal') ? horizontalSorter : verticalSorter;
this.items.sort( sorter );
};
/**
* Fit item element in its current position
* Packery will position elements around it
* useful for expanding elements
*
* @param {Element} elem
* @param {Number} x - horizontal destination position, optional
* @param {Number} y - vertical destination position, optional
*/
proto.fit = function( elem, x, y ) {
var item = this.getItem( elem );
if ( !item ) {
return;
}
// stamp item to get it out of layout
this.stamp( item.element );
// set placing flag
item.enablePlacing();
this.updateShiftTargets( item );
// fall back to current position for fitting
x = x === undefined ? item.rect.x: x;
y = y === undefined ? item.rect.y: y;
// position it best at its destination
this.shift( item, x, y );
this._bindFitEvents( item );
item.moveTo( item.rect.x, item.rect.y );
// layout everything else
this.shiftLayout();
// return back to regularly scheduled programming
this.unstamp( item.element );
this.sortItemsByPosition();
item.disablePlacing();
};
/**
* emit event when item is fit and other items are laid out
* @param {Packery.Item} item
* @private
*/
proto._bindFitEvents = function( item ) {
var _this = this;
var ticks = 0;
function onLayout() {
ticks++;
if ( ticks != 2 ) {
return;
}
_this.dispatchEvent( 'fitComplete', null, [ item ] );
}
// when item is laid out
item.once( 'layout', onLayout );
// when all items are laid out
this.once( 'layoutComplete', onLayout );
};
// -------------------------- resize -------------------------- //
// debounced, layout on resize
proto.resize = function() {
// don't trigger if size did not change
// or if resize was unbound. See #285, outlayer#9
if ( !this.isResizeBound || !this.needsResizeLayout() ) {
return;
}
if ( this.options.shiftPercentResize ) {
this.resizeShiftPercentLayout();
} else {
this.layout();
}
};
/**
* check if layout is needed post layout
* @returns Boolean
*/
proto.needsResizeLayout = function() {
var size = getSize( this.element );
var innerSize = this._getOption('horizontal') ? 'innerHeight' : 'innerWidth';
return size[ innerSize ] != this.size[ innerSize ];
};
proto.resizeShiftPercentLayout = function() {
var items = this._getItemsForLayout( this.items );
var isHorizontal = this._getOption('horizontal');
var coord = isHorizontal ? 'y' : 'x';
var measure = isHorizontal ? 'height' : 'width';
var segmentName = isHorizontal ? 'rowHeight' : 'columnWidth';
var innerSize = isHorizontal ? 'innerHeight' : 'innerWidth';
// proportional re-align items
var previousSegment = this[ segmentName ];
previousSegment = previousSegment && previousSegment + this.gutter;
if ( previousSegment ) {
this._getMeasurements();
var currentSegment = this[ segmentName ] + this.gutter;
items.forEach( function( item ) {
var seg = Math.round( item.rect[ coord ] / previousSegment );
item.rect[ coord ] = seg * currentSegment;
});
} else {
var currentSize = getSize( this.element )[ innerSize ] + this.gutter;
var previousSize = this.packer[ measure ];
items.forEach( function( item ) {
item.rect[ coord ] = ( item.rect[ coord ] / previousSize ) * currentSize;
});
}
this.shiftLayout();
};
// -------------------------- drag -------------------------- //
/**
* handle an item drag start event
* @param {Element} elem
*/
proto.itemDragStart = function( elem ) {
if ( !this.isEnabled ) {
return;
}
this.stamp( elem );
// this.ignore( elem );
var item = this.getItem( elem );
if ( !item ) {
return;
}
item.enablePlacing();
item.showDropPlaceholder();
this.dragItemCount++;
this.updateShiftTargets( item );
};
proto.updateShiftTargets = function( dropItem ) {
this.shiftPacker.reset();
// pack stamps
this._getBoundingRect();
var isOriginLeft = this._getOption('originLeft');
var isOriginTop = this._getOption('originTop');
this.stamps.forEach( function( stamp ) {
// ignore dragged item
var item = this.getItem( stamp );
if ( item && item.isPlacing ) {
return;
}
var offset = this._getElementOffset( stamp );
var rect = new Rect({
x: isOriginLeft ? offset.left : offset.right,
y: isOriginTop ? offset.top : offset.bottom
});
this._setRectSize( stamp, rect );
// save its space in the packer
this.shiftPacker.placed( rect );
}, this );
// reset shiftTargets
var isHorizontal = this._getOption('horizontal');
var segmentName = isHorizontal ? 'rowHeight' : 'columnWidth';
var measure = isHorizontal ? 'height' : 'width';
this.shiftTargetKeys = [];
this.shiftTargets = [];
var boundsSize;
var segment = this[ segmentName ];
segment = segment && segment + this.gutter;
if ( segment ) {
var segmentSpan = Math.ceil( dropItem.rect[ measure ] / segment );
var segs = Math.floor( ( this.shiftPacker[ measure ] + this.gutter ) / segment );
boundsSize = ( segs - segmentSpan ) * segment;
// add targets on top
for ( var i=0; i < segs; i++ ) {
this._addShiftTarget( i * segment, 0, boundsSize );
}
} else {
boundsSize = ( this.shiftPacker[ measure ] + this.gutter ) - dropItem.rect[ measure ];
this._addShiftTarget( 0, 0, boundsSize );
}
// pack each item to measure where shiftTargets are
var items = this._getItemsForLayout( this.items );
var packMethod = this._getPackMethod();
items.forEach( function( item ) {
var rect = item.rect;
this._setRectSize( item.element, rect );
this.shiftPacker[ packMethod ]( rect );
// add top left corner
this._addShiftTarget( rect.x, rect.y, boundsSize );
// add bottom left / top right corner
var cornerX = isHorizontal ? rect.x + rect.width : rect.x;
var cornerY = isHorizontal ? rect.y : rect.y + rect.height;
this._addShiftTarget( cornerX, cornerY, boundsSize );
if ( segment ) {
// add targets for each column on bottom / row on right
var segSpan = Math.round( rect[ measure ] / segment );
for ( var i=1; i < segSpan; i++ ) {
var segX = isHorizontal ? cornerX : rect.x + segment * i;
var segY = isHorizontal ? rect.y + segment * i : cornerY;
this._addShiftTarget( segX, segY, boundsSize );
}
}
}, this );
};
proto._addShiftTarget = function( x, y, boundsSize ) {
var checkCoord = this._getOption('horizontal') ? y : x;
if ( checkCoord !== 0 && checkCoord > boundsSize ) {
return;
}
// create string for a key, easier to keep track of what targets
var key = x + ',' + y;
var hasKey = this.shiftTargetKeys.indexOf( key ) != -1;
if ( hasKey ) {
return;
}
this.shiftTargetKeys.push( key );
this.shiftTargets.push({ x: x, y: y });
};
// -------------------------- drop -------------------------- //
proto.shift = function( item, x, y ) {
var shiftPosition;
var minDistance = Infinity;
var position = { x: x, y: y };
this.shiftTargets.forEach( function( target ) {
var distance = getDistance( target, position );
if ( distance < minDistance ) {
shiftPosition = target;
minDistance = distance;
}
});
item.rect.x = shiftPosition.x;
item.rect.y = shiftPosition.y;
};
function getDistance( a, b ) {
var dx = b.x - a.x;
var dy = b.y - a.y;
return Math.sqrt( dx * dx + dy * dy );
}
// -------------------------- drag move -------------------------- //
var DRAG_THROTTLE_TIME = 120;
/**
* handle an item drag move event
* @param {Element} elem
* @param {Number} x - horizontal change in position
* @param {Number} y - vertical change in position
*/
proto.itemDragMove = function( elem, x, y ) {
var item = this.isEnabled && this.getItem( elem );
if ( !item ) {
return;
}
x -= this.size.paddingLeft;
y -= this.size.paddingTop;
var _this = this;
function onDrag() {
_this.shift( item, x, y );
item.positionDropPlaceholder();
_this.layout();
}
// throttle
var now = new Date();
if ( this._itemDragTime && now - this._itemDragTime < DRAG_THROTTLE_TIME ) {
clearTimeout( this.dragTimeout );
this.dragTimeout = setTimeout( onDrag, DRAG_THROTTLE_TIME );
} else {
onDrag();
this._itemDragTime = now;
}
};
// -------------------------- drag end -------------------------- //
/**
* handle an item drag end event
* @param {Element} elem
*/
proto.itemDragEnd = function( elem ) {
var item = this.isEnabled && this.getItem( elem );
if ( !item ) {
return;
}
clearTimeout( this.dragTimeout );
item.element.classList.add('is-positioning-post-drag');
var completeCount = 0;
var _this = this;
function onDragEndLayoutComplete() {
completeCount++;
if ( completeCount != 2 ) {
return;
}
// reset drag item
item.element.classList.remove('is-positioning-post-drag');
item.hideDropPlaceholder();
_this.dispatchEvent( 'dragItemPositioned', null, [ item ] );
}
item.once( 'layout', onDragEndLayoutComplete );
this.once( 'layoutComplete', onDragEndLayoutComplete );
item.moveTo( item.rect.x, item.rect.y );
this.layout();
this.dragItemCount = Math.max( 0, this.dragItemCount - 1 );
this.sortItemsByPosition();
item.disablePlacing();
this.unstamp( item.element );
};
/**
* binds Draggabilly events
* @param {Draggabilly} draggie
*/
proto.bindDraggabillyEvents = function( draggie ) {
this._bindDraggabillyEvents( draggie, 'on' );
};
proto.unbindDraggabillyEvents = function( draggie ) {
this._bindDraggabillyEvents( draggie, 'off' );
};
proto._bindDraggabillyEvents = function( draggie, method ) {
var handlers = this.handleDraggabilly;
draggie[ method ]( 'dragStart', handlers.dragStart );
draggie[ method ]( 'dragMove', handlers.dragMove );
draggie[ method ]( 'dragEnd', handlers.dragEnd );
};
/**
* binds jQuery UI Draggable events
* @param {jQuery} $elems
*/
proto.bindUIDraggableEvents = function( $elems ) {
this._bindUIDraggableEvents( $elems, 'on' );
};
proto.unbindUIDraggableEvents = function( $elems ) {
this._bindUIDraggableEvents( $elems, 'off' );
};
proto._bindUIDraggableEvents = function( $elems, method ) {
var handlers = this.handleUIDraggable;
$elems
[ method ]( 'dragstart', handlers.start )
[ method ]( 'drag', handlers.drag )
[ method ]( 'dragstop', handlers.stop );
};
// ----- destroy ----- //
var _destroy = proto.destroy;
proto.destroy = function() {
_destroy.apply( this, arguments );
// disable flag; prevent drag events from triggering. #72
this.isEnabled = false;
};
// ----- ----- //
Packery.Rect = Rect;
Packery.Packer = Packer;
return Packery;
}));
/*!
* Packery layout mode v2.0.1
* sub-classes Packery
*/
/*jshint browser: true, strict: true, undef: true, unused: true */
( function( window, factory ) {
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( [
'isotope-layout/js/layout-mode',
'packery/js/packery'
],
factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
require('isotope-layout/js/layout-mode'),
require('packery')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode,
window.Packery
);
}
}( window, function factor( LayoutMode, Packery ) {
// create an Outlayer layout class
var PackeryMode = LayoutMode.create('packery');
var proto = PackeryMode.prototype;
var keepModeMethods = {
_getElementOffset: true,
_getMeasurement: true
};
// inherit Packery prototype
for ( var method in Packery.prototype ) {
// do not inherit mode methods
if ( !keepModeMethods[ method ] ) {
proto[ method ] = Packery.prototype[ method ];
}
}
// set packer in _resetLayout
var _resetLayout = proto._resetLayout;
proto._resetLayout = function() {
this.packer = this.packer || new Packery.Packer();
this.shiftPacker = this.shiftPacker || new Packery.Packer();
_resetLayout.apply( this, arguments );
};
var _getItemLayoutPosition = proto._getItemLayoutPosition;
proto._getItemLayoutPosition = function( item ) {
// set packery rect
item.rect = item.rect || new Packery.Rect();
return _getItemLayoutPosition.call( this, item );
};
// needsResizeLayout for vertical or horizontal
var _needsResizeLayout = proto.needsResizeLayout;
proto.needsResizeLayout = function() {
if ( this._getOption('horizontal') ) {
return this.needsVerticalResizeLayout();
} else {
return _needsResizeLayout.call( this );
}
};
// point to mode options for horizontal
var _getOption = proto._getOption;
proto._getOption = function( option ) {
if ( option == 'horizontal' ) {
return this.options.isHorizontal !== undefined ?
this.options.isHorizontal : this.options.horizontal;
}
return _getOption.apply( this.isotope, arguments );
};
return PackeryMode;
}));
/*!
* cellsByRows layout mode for Isotope
* v1.1.3
* http://isotope.metafizzy.co/layout-modes/cellsbyrow.html
*/
/*jshint browser: true, devel: false, strict: true, undef: true, unused: true */
( function( window, factory ) {
// universal module definition
/* jshint strict: false */ /*globals define, module, require */
if ( typeof define === 'function' && define.amd ) {
// AMD
define( [
'isotope/js/layout-mode'
],
factory );
} else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = factory(
require('isotope-layout/js/layout-mode')
);
} else {
// browser global
factory(
window.Isotope.LayoutMode
);
}
}( window, function factory( LayoutMode ) {
'use strict';
var CellsByRow = LayoutMode.create( 'cellsByRow' );
var proto = CellsByRow.prototype;
proto._resetLayout = function() {
// reset properties
this.itemIndex = 0;
// measurements
this.getColumnWidth();
this.getRowHeight();
// set cols
this.cols = Math.floor( this.isotope.size.innerWidth / this.columnWidth );
this.cols = Math.max( this.cols, 1 );
};
proto._getItemLayoutPosition = function( item ) {
item.getSize();
var col = this.itemIndex % this.cols;
var row = Math.floor( this.itemIndex / this.cols );
// center item within cell
var x = ( col + 0.5 ) * this.columnWidth - item.size.outerWidth / 2;
var y = ( row + 0.5 ) * this.rowHeight - item.size.outerHeight / 2;
this.itemIndex++;
return { x: x, y: y };
};
proto._getContainerSize = function() {
return {
height: Math.ceil( this.itemIndex / this.cols ) * this.rowHeight
};
};
return CellsByRow;
}));
/*global jQuery: true */
/*!
--------------------------------
Infinite Scroll
--------------------------------
+ https://github.com/paulirish/infinite-scroll
+ version 2.1.0
+ Copyright 2011/12 Paul Irish & Luke Shumard
+ Licensed under the MIT license
+ Documentation: http://infinite-scroll.com/
*/
// Uses AMD or browser globals to create a jQuery plugin.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(jQuery);
}
}(function ($, undefined) {
'use strict';
$.infinitescroll = function infscr(options, callback, element) {
this.element = $(element);
// Flag the object in the event of a failed creation
if (!this._create(options, callback)) {
this.failed = true;
}
};
$.infinitescroll.defaults = {
loading: {
finished: undefined,
finishedMsg: "<em>Congratulations, you've reached the end of the internet.</em>",
img: 'data:image/gif;base64,R0lGODlh3AATAPQeAPDy+MnQ6LW/4N3h8MzT6rjC4sTM5r/I5NHX7N7j8c7U6tvg8OLl8uXo9Ojr9b3G5MfP6Ovu9tPZ7PT1+vX2+tbb7vf4+8/W69jd7rC73vn5/O/x+K243ai02////wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQECgD/ACwAAAAA3AATAAAF/6AnjmRpnmiqrmzrvnAsz3Rt33iu73zv/8CgcEj0BAScpHLJbDqf0Kh0Sq1ar9isdioItAKGw+MAKYMFhbF63CW438f0mg1R2O8EuXj/aOPtaHx7fn96goR4hmuId4qDdX95c4+RBIGCB4yAjpmQhZN0YGYGXitdZBIVGAsLoq4BBKQDswm1CQRkcG6ytrYKubq8vbfAcMK9v7q7EMO1ycrHvsW6zcTKsczNz8HZw9vG3cjTsMIYqQkCLBwHCgsMDQ4RDAYIqfYSFxDxEfz88/X38Onr16+Bp4ADCco7eC8hQYMAEe57yNCew4IVBU7EGNDiRn8Z831cGLHhSIgdFf9chIeBg7oA7gjaWUWTVQAGE3LqBDCTlc9WOHfm7PkTqNCh54rePDqB6M+lR536hCpUqs2gVZM+xbrTqtGoWqdy1emValeXKzggYBBB5y1acFNZmEvXAoN2cGfJrTv3bl69Ffj2xZt3L1+/fw3XRVw4sGDGcR0fJhxZsF3KtBTThZxZ8mLMgC3fRatCbYMNFCzwLEqLgE4NsDWs/tvqdezZf13Hvk2A9Szdu2X3pg18N+68xXn7rh1c+PLksI/Dhe6cuO3ow3NfV92bdArTqC2Ebd3A8vjf5QWfH6Bg7Nz17c2fj69+fnq+8N2Lty+fuP78/eV2X13neIcCeBRwxorbZrA1ANoCDGrgoG8RTshahQ9iSKEEzUmYIYfNWViUhheCGJyIP5E4oom7WWjgCeBFAJNv1DVV01MAdJhhjdkplWNzO/5oXI846njjVEIqR2OS2B1pE5PVscajkxhMycqLJghQSwT40PgfAl4GqNSXYdZXJn5gSkmmmmJu1aZYb14V51do+pTOCmA40AqVCIhG5IJ9PvYnhIFOxmdqhpaI6GeHCtpooisuutmg+Eg62KOMKuqoTaXgicQWoIYq6qiklmoqFV0UoeqqrLbq6quwxirrrLTWauutJ4QAACH5BAUKABwALAcABADOAAsAAAX/IPd0D2dyRCoUp/k8gpHOKtseR9yiSmGbuBykler9XLAhkbDavXTL5k2oqFqNOxzUZPU5YYZd1XsD72rZpBjbeh52mSNnMSC8lwblKZGwi+0QfIJ8CncnCoCDgoVnBHmKfByGJimPkIwtiAeBkH6ZHJaKmCeVnKKTHIihg5KNq4uoqmEtcRUtEREMBggtEr4QDrjCuRC8h7/BwxENeicSF8DKy82pyNLMOxzWygzFmdvD2L3P0dze4+Xh1Arkyepi7dfFvvTtLQkZBC0T/FX3CRgCMOBHsJ+EHYQY7OinAGECgQsB+Lu3AOK+CewcWjwxQeJBihtNGHSoQOE+iQ3//4XkwBBhRZMcUS6YSXOAwIL8PGqEaSJCiYt9SNoCmnJPAgUVLChdaoFBURN8MAzl2PQphwQLfDFd6lTowglHve6rKpbjhK7/pG5VinZP1qkiz1rl4+tr2LRwWU64cFEihwEtZgbgR1UiHaMVvxpOSwBA37kzGz9e8G+B5MIEKLutOGEsAH2ATQwYfTmuX8aETWdGPZmiZcccNSzeTCA1Sw0bdiitC7LBWgu8jQr8HRzqgpK6gX88QbrB14z/kF+ELpwB8eVQj/JkqdylAudji/+ts3039vEEfK8Vz2dlvxZKG0CmbkKDBvllRd6fCzDvBLKBDSCeffhRJEFebFk1k/Mv9jVIoIJZSeBggwUaNeB+Qk34IE0cXlihcfRxkOAJFFhwGmKlmWDiakZhUJtnLBpnWWcnKaAZcxI0piFGGLBm1mc90kajSCveeBVWKeYEoU2wqeaQi0PetoE+rr14EpVC7oAbAUHqhYExbn2XHHsVqbcVew9tx8+XJKk5AZsqqdlddGpqAKdbAYBn1pcczmSTdWvdmZ17c1b3FZ99vnTdCRFM8OEcAhLwm1NdXnWcBBSMRWmfkWZqVlsmLIiAp/o1gGV2vpS4lalGYsUOqXrddcKCmK61aZ8SjEpUpVFVoCpTj4r661Km7kBHjrDyc1RAIQAAIfkEBQoAGwAsBwAEAM4ACwAABf/gtmUCd4goQQgFKj6PYKi0yrrbc8i4ohQt12EHcal+MNSQiCP8gigdz7iCioaCIvUmZLp8QBzW0EN2vSlCuDtFKaq4RyHzQLEKZNdiQDhRDVooCwkbfm59EAmKi4SGIm+AjIsKjhsqB4mSjT2IOIOUnICeCaB/mZKFNTSRmqVpmJqklSqskq6PfYYCDwYHDC4REQwGCBLGxxIQDsHMwhAIX8bKzcENgSLGF9PU1j3Sy9zX2NrgzQziChLk1BHWxcjf7N046tvN82715czn9Pryz6Ilc4ACj4EBOCZM8KEnAYYADBRKnACAYUMFv1wotIhCEcaJCisqwJFgAUSQGyX/kCSVUUTIdKMwJlyo0oXHlhskwrTJciZHEXsgaqS4s6PJiCAr1uzYU8kBBSgnWFqpoMJMUjGtDmUwkmfVmVypakWhEKvXsS4nhLW5wNjVroJIoc05wSzTr0PtiigpYe4EC2vj4iWrFu5euWIMRBhacaVJhYQBEFjA9jHjyQ0xEABwGceGAZYjY0YBOrRLCxUp29QM+bRkx5s7ZyYgVbTqwwti2ybJ+vLtDYpycyZbYOlptxdx0kV+V7lC5iJAyyRrwYKxAdiz82ng0/jnAdMJFz0cPi104Ec1Vj9/M6F173vKL/feXv156dw11tlqeMMnv4V5Ap53GmjQQH97nFfg+IFiucfgRX5Z8KAgbUlQ4IULIlghhhdOSB6AgX0IVn8eReghen3NRIBsRgnH4l4LuEidZBjwRpt6NM5WGwoW0KSjCwX6yJSMab2GwwAPDXfaBCtWpluRTQqC5JM5oUZAjUNS+VeOLWpJEQ7VYQANW0INJSZVDFSnZphjSikfmzE5N4EEbQI1QJmnWXCmHulRp2edwDXF43txukenJwvI9xyg9Q26Z3MzGUcBYFEChZh6DVTq34AU8Iflh51Sd+CnKFYQ6mmZkhqfBKfSxZWqA9DZanWjxmhrWwi0qtCrt/43K6WqVjjpmhIqgEGvculaGKklKstAACEAACH5BAUKABwALAcABADOAAsAAAX/ICdyQmaMYyAUqPgIBiHPxNpy79kqRXH8wAPsRmDdXpAWgWdEIYm2llCHqjVHU+jjJkwqBTecwItShMXkEfNWSh8e1NGAcLgpDGlRgk7EJ/6Ae3VKfoF/fDuFhohVeDeCfXkcCQqDVQcQhn+VNDOYmpSWaoqBlUSfmowjEA+iEAEGDRGztAwGCDcXEA60tXEiCrq8vREMEBLIyRLCxMWSHMzExnbRvQ2Sy7vN0zvVtNfU2tLY3rPgLdnDvca4VQS/Cpk3ABwSLQkYAQwT/P309vcI7OvXr94jBQMJ/nskkGA/BQBRLNDncAIAiDcG6LsxAWOLiQzmeURBKWSLCQbv/1F0eDGinJUKR47YY1IEgQASKk7Yc7ACRwZm7mHweRJoz59BJUogisKCUaFMR0x4SlJBVBFTk8pZivTR0K73rN5wqlXEAq5Fy3IYgHbEzQ0nLy4QSoCjXLoom96VOJEeCosK5n4kkFfqXjl94wa+l1gvAcGICbewAOAxY8l/Ky/QhAGz4cUkGxu2HNozhwMGBnCUqUdBg9UuW9eUynqSwLHIBujePef1ZGQZXcM+OFuEBeBhi3OYgLyqcuaxbT9vLkf4SeqyWxSQpKGB2gQpm1KdWbu72rPRzR9Ne2Nu9Kzr/1Jqj0yD/fvqP4aXOt5sW/5qsXXVcv1Nsp8IBUAmgswGF3llGgeU1YVXXKTN1FlhWFXW3gIE+DVChApysACHHo7Q4A35lLichh+ROBmLKAzgYmYEYDAhCgxKGOOMn4WR4kkDaoBBOxJtdNKQxFmg5JIWIBnQc07GaORfUY4AEkdV6jHlCEISSZ5yTXpp1pbGZbkWmcuZmQCaE6iJ0FhjMaDjTMsgZaNEHFRAQVp3bqXnZED1qYcECOz5V6BhSWCoVJQIKuKQi2KFKEkEFAqoAo7uYSmO3jk61wUUMKmknJ4SGimBmAa0qVQBhAAAIfkEBQoAGwAsBwAEAM4ACwAABf/gJm5FmRlEqhJC+bywgK5pO4rHI0D3pii22+Mg6/0Ej96weCMAk7cDkXf7lZTTnrMl7eaYoy10JN0ZFdco0XAuvKI6qkgVFJXYNwjkIBcNBgR8TQoGfRsJCRuCYYQQiI+ICosiCoGOkIiKfSl8mJkHZ4U9kZMbKaI3pKGXmJKrngmug4WwkhA0lrCBWgYFCCMQFwoQDRHGxwwGCBLMzRLEx8iGzMMO0cYNeCMKzBDW19lnF9DXDIY/48Xg093f0Q3s1dcR8OLe8+Y91OTv5wrj7o7B+7VNQqABIoRVCMBggsOHE36kSoCBIcSH3EbFangxogJYFi8CkJhqQciLJEf/LDDJEeJIBT0GsOwYUYJGBS0fjpQAMidGmyVP6sx4Y6VQhzs9VUwkwqaCCh0tmKoFtSMDmBOf9phg4SrVrROuasRQAaxXpVUhdsU6IsECZlvX3kwLUWzRt0BHOLTbNlbZG3vZinArge5Dvn7wbqtQkSYAAgtKmnSsYKVKo2AfW048uaPmG386i4Q8EQMBAIAnfB7xBxBqvapJ9zX9WgRS2YMpnvYMGdPK3aMjt/3dUcNI4blpj7iwkMFWDXDvSmgAlijrt9RTR78+PS6z1uAJZIe93Q8g5zcsWCi/4Y+C8bah5zUv3vv89uft30QP23punGCx5954oBBwnwYaNCDY/wYrsYeggnM9B2Fpf8GG2CEUVWhbWAtGouEGDy7Y4IEJVrbSiXghqGKIo7z1IVcXIkKWWR361QOLWWnIhwERpLaaCCee5iMBGJQmJGyPFTnbkfHVZGRtIGrg5HALEJAZbu39BuUEUmq1JJQIPtZilY5hGeSWsSk52G9XqsmgljdIcABytq13HyIM6RcUA+r1qZ4EBF3WHWB29tBgAzRhEGhig8KmqKFv8SeCeo+mgsF7YFXa1qWSbkDpom/mqR1PmHCqJ3fwNRVXjC7S6CZhFVCQ2lWvZiirhQq42SACt25IK2hv8TprriUV1usGgeka7LFcNmCldMLi6qZMgFLgpw16Cipb7bC1knXsBiEAACH5BAUKABsALAcABADOAAsAAAX/4FZsJPkUmUGsLCEUTywXglFuSg7fW1xAvNWLF6sFFcPb42C8EZCj24EJdCp2yoegWsolS0Uu6fmamg8n8YYcLU2bXSiRaXMGvqV6/KAeJAh8VgZqCX+BexCFioWAYgqNi4qAR4ORhRuHY408jAeUhAmYYiuVlpiflqGZa5CWkzc5fKmbbhIpsAoQDRG8vQwQCBLCwxK6vb5qwhfGxxENahvCEA7NzskSy7vNzzzK09W/PNHF1NvX2dXcN8K55cfh69Luveol3vO8zwi4Yhj+AQwmCBw4IYclDAAJDlQggVOChAoLKkgFkSCAHDwWLKhIEOONARsDKryogFPIiAUb/95gJNIiw4wnI778GFPhzBKFOAq8qLJEhQpiNArjMcHCmlTCUDIouTKBhApELSxFWiGiVKY4E2CAekPgUphDu0742nRrVLJZnyrFSqKQ2ohoSYAMW6IoDpNJ4bLdILTnAj8KUF7UeENjAKuDyxIgOuGiOI0EBBMgLNew5AUrDTMGsFixwBIaNCQuAXJB57qNJ2OWm2Aj4skwCQCIyNkhhtMkdsIuodE0AN4LJDRgfLPtn5YDLdBlraAByuUbBgxQwICxMOnYpVOPej074OFdlfc0TqC62OIbcppHjV4o+LrieWhfT8JC/I/T6W8oCl29vQ0XjLdBaA3s1RcPBO7lFvpX8BVoG4O5jTXRQRDuJ6FDTzEWF1/BCZhgbyAKE9qICYLloQYOFtahVRsWYlZ4KQJHlwHS/IYaZ6sZd9tmu5HQm2xi1UaTbzxYwJk/wBF5g5EEYOBZeEfGZmNdFyFZmZIR4jikbLThlh5kUUVJGmRT7sekkziRWUIACABk3T4qCsedgO4xhgGcY7q5pHJ4klBBTQRJ0CeHcoYHHUh6wgfdn9uJdSdMiebGJ0zUPTcoS286FCkrZxnYoYYKWLkBowhQoBeaOlZAgVhLidrXqg2GiqpQpZ4apwSwRtjqrB3muoF9BboaXKmshlqWqsWiGt2wphJkQbAU5hoCACH5BAUKABsALAcABADOAAsAAAX/oGFw2WZuT5oZROsSQnGaKjRvilI893MItlNOJ5v5gDcFrHhKIWcEYu/xFEqNv6B1N62aclysF7fsZYe5aOx2yL5aAUGSaT1oTYMBwQ5VGCAJgYIJCnx1gIOBhXdwiIl7d0p2iYGQUAQBjoOFSQR/lIQHnZ+Ue6OagqYzSqSJi5eTpTxGcjcSChANEbu8DBAIEsHBChe5vL13G7fFuscRDcnKuM3H0La3EA7Oz8kKEsXazr7Cw9/Gztar5uHHvte47MjktznZ2w0G1+D3BgirAqJmJMAQgMGEgwgn5Ei0gKDBhBMALGRYEOJBb5QcWlQo4cbAihZz3GgIMqFEBSM1/4ZEOWPAgpIIJXYU+PIhRG8ja1qU6VHlzZknJNQ6UanCjQkWCIGSUGEjAwVLjc44+DTqUQtPPS5gejUrTa5TJ3g9sWCr1BNUWZI161StiQUDmLYdGfesibQ3XMq1OPYthrwuA2yU2LBs2cBHIypYQPPlYAKFD5cVvNPtW8eVGbdcQADATsiNO4cFAPkvHpedPzc8kUcPgNGgZ5RNDZG05reoE9s2vSEP79MEGiQGy1qP8LA4ZcdtsJE48ONoLTBtTV0B9LsTnPceoIDBDQvS7W7vfjVY3q3eZ4A339J4eaAmKqU/sV58HvJh2RcnIBsDUw0ABqhBA5aV5V9XUFGiHfVeAiWwoFgJJrIXRH1tEMiDFV4oHoAEGlaWhgIGSGBO2nFomYY3mKjVglidaNYJGJDkWW2xxTfbjCbVaOGNqoX2GloR8ZeTaECS9pthRGJH2g0b3Agbk6hNANtteHD2GJUucfajCQBy5OOTQ25ZgUPvaVVQmbKh9510/qQpwXx3SQdfk8tZJOd5b6JJFplT3ZnmmX3qd5l1eg5q00HrtUkUn0AKaiGjClSAgKLYZcgWXwocGRcCFGCKwSB6ceqphwmYRUFYT/1WKlOdUpipmxW0mlCqHjYkAaeoZlqrqZ4qd+upQKaapn/AmgAegZ8KUtYtFAQQAgAh+QQFCgAbACwHAAQAzgALAAAF/+C2PUcmiCiZGUTrEkKBis8jQEquKwU5HyXIbEPgyX7BYa5wTNmEMwWsSXsqFbEh8DYs9mrgGjdK6GkPY5GOeU6ryz7UFopSQEzygOGhJBjoIgMDBAcBM0V/CYqLCQqFOwobiYyKjn2TlI6GKC2YjJZknouaZAcQlJUHl6eooJwKooobqoewrJSEmyKdt59NhRKFMxLEEA4RyMkMEAjDEhfGycqAG8TQx9IRDRDE3d3R2ctD1RLg0ttKEnbY5wZD3+zJ6M7X2RHi9Oby7u/r9g38UFjTh2xZJBEBMDAboogAgwkQI07IMUORwocSJwCgWDFBAIwZOaJIsOBjRogKJP8wTODw5ESVHVtm3AhzpEeQElOuNDlTZ0ycEUWKWFASqEahGwYUPbnxoAgEdlYSqDBkgoUNClAlIHbSAoOsqCRQnQHxq1axVb06FWFxLIqyaze0Tft1JVqyE+pWXMD1pF6bYl3+HTqAWNW8cRUFzmih0ZAAB2oGKukSAAGGRHWJgLiR6AylBLpuHKKUMlMCngMpDSAa9QIUggZVVvDaJobLeC3XZpvgNgCmtPcuwP3WgmXSq4do0DC6o2/guzcseECtUoO0hmcsGKDgOt7ssBd07wqesAIGZC1YIBa7PQHvb1+SFo+++HrJSQfB33xfav3i5eX3Hnb4CTJgegEq8tH/YQEOcIJzbm2G2EoYRLgBXFpVmFYDcREV4HIcnmUhiGBRouEMJGJGzHIspqgdXxK0yCKHRNXoIX4uorCdTyjkyNtdPWrA4Up82EbAbzMRxxZRR54WXVLDIRmRcag5d2R6ugl3ZXzNhTecchpMhIGVAKAYpgJjjsSklBEd99maZoo535ZvdamjBEpusJyctg3h4X8XqodBMx0tiNeg/oGJaKGABpogS40KSqiaEgBqlQWLUtqoVQnytekEjzo0hHqhRorppOZt2p923M2AAV+oBtpAnnPNoB6HaU6mAAIU+IXmi3j2mtFXuUoHKwXpzVrsjcgGOauKEjQrwq157hitGq2NoWmjh7z6Wmxb0m5w66+2VRAuXN/yFUAIACH5BAUKABsALAcABADOAAsAAAX/4CZuRiaM45MZqBgIRbs9AqTcuFLE7VHLOh7KB5ERdjJaEaU4ClO/lgKWjKKcMiJQ8KgumcieVdQMD8cbBeuAkkC6LYLhOxoQ2PF5Ys9PKPBMen17f0CCg4VSh32JV4t8jSNqEIOEgJKPlkYBlJWRInKdiJdkmQlvKAsLBxdABA4RsbIMBggtEhcQsLKxDBC2TAS6vLENdJLDxMZAubu8vjIbzcQRtMzJz79S08oQEt/guNiyy7fcvMbh4OezdAvGrakLAQwyABsELQkY9BP+//ckyPDD4J9BfAMh1GsBoImMeQUN+lMgUJ9CiRMa5msxoB9Gh/o8GmxYMZXIgxtR/yQ46S/gQAURR0pDwYDfywoyLPip5AdnCwsMFPBU4BPFhKBDi444quCmDKZOfwZ9KEGpCKgcN1jdALSpPqIYsabS+nSqvqplvYqQYAeDPgwKwjaMtiDl0oaqUAyo+3TuWwUAMPpVCfee0cEjVBGQq2ABx7oTWmQk4FglZMGN9fGVDMCuiH2AOVOu/PmyxM630gwM0CCn6q8LjVJ8GXvpa5Uwn95OTC/nNxkda1/dLSK475IjCD6dHbK1ZOa4hXP9DXs5chJ00UpVm5xo2qRpoxptwF2E4/IbJpB/SDz9+q9b1aNfQH08+p4a8uvX8B53fLP+ycAfemjsRUBgp1H20K+BghHgVgt1GXZXZpZ5lt4ECjxYR4ScUWiShEtZqBiIInRGWnERNnjiBglw+JyGnxUmGowsyiiZg189lNtPGACjV2+S9UjbU0JWF6SPvEk3QZEqsZYTk3UAaRSUnznJI5LmESCdBVSyaOWUWLK4I5gDUYVeV1T9l+FZClCAUVA09uSmRHBCKAECFEhW51ht6rnmWBXkaR+NjuHpJ40D3DmnQXt2F+ihZxlqVKOfQRACACH5BAUKABwALAcABADOAAsAAAX/ICdyUCkUo/g8mUG8MCGkKgspeC6j6XEIEBpBUeCNfECaglBcOVfJFK7YQwZHQ6JRZBUqTrSuVEuD3nI45pYjFuWKvjjSkCoRaBUMWxkwBGgJCXspQ36Bh4EEB0oKhoiBgyNLjo8Ki4QElIiWfJqHnISNEI+Ql5J9o6SgkqKkgqYihamPkW6oNBgSfiMMDQkGCBLCwxIQDhHIyQwQCGMKxsnKVyPCF9DREQ3MxMPX0cu4wt7J2uHWx9jlKd3o39MiuefYEcvNkuLt5O8c1ePI2tyELXGQwoGDAQf+iEC2xByDCRAjTlAgIUWCBRgCPJQ4AQBFXAs0coT40WLIjRxL/47AcHLkxIomRXL0CHPERZkpa4q4iVKiyp0tR/7kwHMkTUBBJR5dOCEBAVcKKtCAyOHpowXCpk7goABqBZdcvWploACpBKkpIJI1q5OD2rIWE0R1uTZu1LFwbWL9OlKuWb4c6+o9i3dEgw0RCGDUG9KlRw56gDY2qmCByZBaASi+TACA0TucAaTteCcy0ZuOK3N2vJlx58+LRQyY3Xm0ZsgjZg+oPQLi7dUcNXi0LOJw1pgNtB7XG6CBy+U75SYfPTSQAgZTNUDnQHt67wnbZyvwLgKiMN3oCZB3C76tdewpLFgIP2C88rbi4Y+QT3+8S5USMICZXWj1pkEDeUU3lOYGB3alSoEiMIjgX4WlgNF2EibIwQIXauWXSRg2SAOHIU5IIIMoZkhhWiJaiFVbKo6AQEgQXrTAazO1JhkBrBG3Y2Y6EsUhaGn95hprSN0oWpFE7rhkeaQBchGOEWnwEmc0uKWZj0LeuNV3W4Y2lZHFlQCSRjTIl8uZ+kG5HU/3sRlnTG2ytyadytnD3HrmuRcSn+0h1dycexIK1KCjYaCnjCCVqOFFJTZ5GkUUjESWaUIKU2lgCmAKKQIUjHapXRKE+t2og1VgankNYnohqKJ2CmKplso6GKz7WYCgqxeuyoF8u9IQAgA7',
msg: null,
msgText: '<em>Loading the next set of posts...</em>',
selector: null,
speed: 'fast',
start: undefined
},
state: {
isDuringAjax: false,
isInvalidPage: false,
isDestroyed: false,
isDone: false, // For when it goes all the way through the archive.
isPaused: false,
isBeyondMaxPage: false,
currPage: 1
},
debug: false,
behavior: undefined,
binder: $(window), // used to cache the selector
nextSelector: 'div.navigation a:first',
navSelector: 'div.navigation',
contentSelector: null, // rename to pageFragment
extraScrollPx: 150,
itemSelector: 'div.post',
animate: false,
pathParse: undefined,
dataType: 'html',
appendCallback: true,
bufferPx: 40,
errorCallback: function () { },
infid: 0, //Instance ID
pixelsFromNavToBottom: undefined,
path: undefined, // Either parts of a URL as an array (e.g. ["/page/", "/"] or a function that takes in the page number and returns a URL
prefill: false, // When the document is smaller than the window, load data until the document is larger or links are exhausted
maxPage: undefined // to manually control maximum page (when maxPage is undefined, maximum page limitation is not work)
};
$.infinitescroll.prototype = {
/*
----------------------------
Private methods
----------------------------
*/
// Bind or unbind from scroll
_binding: function infscr_binding(binding) {
var instance = this,
opts = instance.options;
opts.v = '2.0b2.120520';
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_binding_'+opts.behavior] !== undefined) {
this['_binding_'+opts.behavior].call(this);
return;
}
if (binding !== 'bind' && binding !== 'unbind') {
this._debug('Binding value ' + binding + ' not valid');
return false;
}
if (binding === 'unbind') {
(this.options.binder).unbind('smartscroll.infscr.' + instance.options.infid);
} else {
(this.options.binder)[binding]('smartscroll.infscr.' + instance.options.infid, function () {
instance.scroll();
});
}
this._debug('Binding', binding);
},
// Fundamental aspects of the plugin are initialized
_create: function infscr_create(options, callback) {
// Add custom options to defaults
var opts = $.extend(true, {}, $.infinitescroll.defaults, options);
this.options = opts;
var $window = $(window);
var instance = this;
// Validate selectors
if (!instance._validate(options)) {
return false;
}
// Validate page fragment path
var path = $(opts.nextSelector).attr('href');
if (!path) {
this._debug('Navigation selector not found');
return false;
}
// Set the path to be a relative URL from root.
opts.path = opts.path || this._determinepath(path);
// contentSelector is 'page fragment' option for .load() / .ajax() calls
opts.contentSelector = opts.contentSelector || this.element;
// loading.selector - if we want to place the load message in a specific selector, defaulted to the contentSelector
opts.loading.selector = opts.loading.selector || opts.contentSelector;
// Define loading.msg
opts.loading.msg = opts.loading.msg || $('<div id="infscr-loading"><img alt="Loading..." src="' + opts.loading.img + '" /><div>' + opts.loading.msgText + '</div></div>');
// Preload loading.img
(new Image()).src = opts.loading.img;
// distance from nav links to bottom
// computed as: height of the document + top offset of container - top offset of nav link
if(opts.pixelsFromNavToBottom === undefined) {
opts.pixelsFromNavToBottom = $(document).height() - $(opts.navSelector).offset().top;
this._debug('pixelsFromNavToBottom: ' + opts.pixelsFromNavToBottom);
}
var self = this;
// determine loading.start actions
opts.loading.start = opts.loading.start || function() {
$(opts.navSelector).hide();
opts.loading.msg
.appendTo(opts.loading.selector)
.show(opts.loading.speed, $.proxy(function() {
this.beginAjax(opts);
}, self));
};
// determine loading.finished actions
opts.loading.finished = opts.loading.finished || function() {
if (!opts.state.isBeyondMaxPage)
opts.loading.msg.fadeOut(opts.loading.speed);
};
// callback loading
opts.callback = function(instance, data, url) {
if (!!opts.behavior && instance['_callback_'+opts.behavior] !== undefined) {
instance['_callback_'+opts.behavior].call($(opts.contentSelector)[0], data, url);
}
if (callback) {
callback.call($(opts.contentSelector)[0], data, opts, url);
}
if (opts.prefill) {
$window.bind('resize.infinite-scroll', instance._prefill);
}
};
if (options.debug) {
// Tell IE9 to use its built-in console
if (Function.prototype.bind && (typeof console === 'object' || typeof console === 'function') && typeof console.log === 'object') {
['log','info','warn','error','assert','dir','clear','profile','profileEnd']
.forEach(function (method) {
console[method] = this.call(console[method], console);
}, Function.prototype.bind);
}
}
this._setup();
// Setups the prefill method for use
if (opts.prefill) {
this._prefill();
}
// Return true to indicate successful creation
return true;
},
_prefill: function infscr_prefill() {
var instance = this;
var $window = $(window);
function needsPrefill() {
return ( $(instance.options.contentSelector).height() <= $window.height() );
}
this._prefill = function() {
if (needsPrefill()) {
instance.scroll();
}
$window.bind('resize.infinite-scroll', function() {
if (needsPrefill()) {
$window.unbind('resize.infinite-scroll');
instance.scroll();
}
});
};
// Call self after setting up the new function
this._prefill();
},
// Console log wrapper
_debug: function infscr_debug() {
if (true !== this.options.debug) {
return;
}
if (typeof console !== 'undefined' && typeof console.log === 'function') {
// Modern browsers
// Single argument, which is a string
if ((Array.prototype.slice.call(arguments)).length === 1 && typeof Array.prototype.slice.call(arguments)[0] === 'string') {
console.log( (Array.prototype.slice.call(arguments)).toString() );
} else {
console.log( Array.prototype.slice.call(arguments) );
}
} else if (!Function.prototype.bind && typeof console !== 'undefined' && typeof console.log === 'object') {
// IE8
Function.prototype.call.call(console.log, console, Array.prototype.slice.call(arguments));
}
},
// find the number to increment in the path.
_determinepath: function infscr_determinepath(path) {
var opts = this.options;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_determinepath_'+opts.behavior] !== undefined) {
return this['_determinepath_'+opts.behavior].call(this,path);
}
if (!!opts.pathParse) {
this._debug('pathParse manual');
return opts.pathParse(path, this.options.state.currPage+1);
} else if (path.match(/^(.*?)\b2\b(.*?$)/)) {
path = path.match(/^(.*?)\b2\b(.*?$)/).slice(1);
// if there is any 2 in the url at all.
} else if (path.match(/^(.*?)2(.*?$)/)) {
// page= is used in django:
// http://www.infinite-scroll.com/changelog/comment-page-1/#comment-127
if (path.match(/^(.*?page=)2(\/.*|$)/)) {
path = path.match(/^(.*?page=)2(\/.*|$)/).slice(1);
return path;
}
path = path.match(/^(.*?)2(.*?$)/).slice(1);
} else {
// page= is used in drupal too but second page is page=1 not page=2:
// thx Jerod Fritz, vladikoff
if (path.match(/^(.*?page=)1(\/.*|$)/)) {
path = path.match(/^(.*?page=)1(\/.*|$)/).slice(1);
return path;
} else {
this._debug("Sorry, we couldn't parse your Next (Previous Posts) URL. Verify your the css selector points to the correct A tag. If you still get this error: yell, scream, and kindly ask for help at infinite-scroll.com.");
// Get rid of isInvalidPage to allow permalink to state
opts.state.isInvalidPage = true; //prevent it from running on this page.
}
}
this._debug('determinePath', path);
return path;
},
// Custom error
_error: function infscr_error(xhr) {
var opts = this.options;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_error_'+opts.behavior] !== undefined) {
this['_error_'+opts.behavior].call(this,xhr);
return;
}
if (xhr !== 'destroy' && xhr !== 'end') {
xhr = 'unknown';
}
this._debug('Error', xhr);
if (xhr === 'end' || opts.state.isBeyondMaxPage) {
this._showdonemsg();
}
opts.state.isDone = true;
opts.state.currPage = 1; // if you need to go back to this instance
opts.state.isPaused = false;
opts.state.isBeyondMaxPage = false;
this._binding('unbind');
},
// Load Callback
_loadcallback: function infscr_loadcallback(box, data, url) {
var opts = this.options,
callback = this.options.callback, // GLOBAL OBJECT FOR CALLBACK
result = (opts.state.isDone) ? 'done' : (!opts.appendCallback) ? 'no-append' : 'append',
frag;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_loadcallback_'+opts.behavior] !== undefined) {
this['_loadcallback_'+opts.behavior].call(this,box,data);
return;
}
switch (result) {
case 'done':
this._showdonemsg();
return false;
case 'no-append':
if (opts.dataType === 'html') {
data = '<div>' + data + '</div>';
data = $(data).find(opts.itemSelector);
}
// if it didn't return anything
if (data.length === 0) {
return this._error('end');
}
break;
case 'append':
var children = box.children();
// if it didn't return anything
if (children.length === 0) {
return this._error('end');
}
// use a documentFragment because it works when content is going into a table or UL
frag = document.createDocumentFragment();
while (box[0].firstChild) {
frag.appendChild(box[0].firstChild);
}
this._debug('contentSelector', $(opts.contentSelector)[0]);
$(opts.contentSelector)[0].appendChild(frag);
// previously, we would pass in the new DOM element as context for the callback
// however we're now using a documentfragment, which doesn't have parents or children,
// so the context is the contentContainer guy, and we pass in an array
// of the elements collected as the first argument.
data = children.get();
break;
}
// loadingEnd function
opts.loading.finished.call($(opts.contentSelector)[0],opts);
// smooth scroll to ease in the new content
if (opts.animate) {
var scrollTo = $(window).scrollTop() + $(opts.loading.msg).height() + opts.extraScrollPx + 'px';
$('html,body').animate({ scrollTop: scrollTo }, 800, function () { opts.state.isDuringAjax = false; });
}
if (!opts.animate) {
// once the call is done, we can allow it again.
opts.state.isDuringAjax = false;
}
callback(this, data, url);
if (opts.prefill) {
this._prefill();
}
},
_nearbottom: function infscr_nearbottom() {
var opts = this.options,
pixelsFromWindowBottomToBottom = 0 + $(document).height() - (opts.binder.scrollTop()) - $(window).height();
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_nearbottom_'+opts.behavior] !== undefined) {
return this['_nearbottom_'+opts.behavior].call(this);
}
this._debug('math:', pixelsFromWindowBottomToBottom, opts.pixelsFromNavToBottom);
// if distance remaining in the scroll (including buffer) is less than the orignal nav to bottom....
return (pixelsFromWindowBottomToBottom - opts.bufferPx < opts.pixelsFromNavToBottom);
},
// Pause / temporarily disable plugin from firing
_pausing: function infscr_pausing(pause) {
var opts = this.options;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_pausing_'+opts.behavior] !== undefined) {
this['_pausing_'+opts.behavior].call(this,pause);
return;
}
// If pause is not 'pause' or 'resume', toggle it's value
if (pause !== 'pause' && pause !== 'resume' && pause !== null) {
this._debug('Invalid argument. Toggling pause value instead');
}
pause = (pause && (pause === 'pause' || pause === 'resume')) ? pause : 'toggle';
switch (pause) {
case 'pause':
opts.state.isPaused = true;
break;
case 'resume':
opts.state.isPaused = false;
break;
case 'toggle':
opts.state.isPaused = !opts.state.isPaused;
break;
}
this._debug('Paused', opts.state.isPaused);
return false;
},
// Behavior is determined
// If the behavior option is undefined, it will set to default and bind to scroll
_setup: function infscr_setup() {
var opts = this.options;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_setup_'+opts.behavior] !== undefined) {
this['_setup_'+opts.behavior].call(this);
return;
}
this._binding('bind');
return false;
},
// Show done message
_showdonemsg: function infscr_showdonemsg() {
var opts = this.options;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['_showdonemsg_'+opts.behavior] !== undefined) {
this['_showdonemsg_'+opts.behavior].call(this);
return;
}
opts.loading.msg
.find('img')
.hide()
.parent()
.find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function () {
$(this).parent().fadeOut(opts.loading.speed);
});
// user provided callback when done
opts.errorCallback.call($(opts.contentSelector)[0],'done');
},
// grab each selector option and see if any fail
_validate: function infscr_validate(opts) {
for (var key in opts) {
if (key.indexOf && key.indexOf('Selector') > -1 && $(opts[key]).length === 0) {
this._debug('Your ' + key + ' found no elements.');
return false;
}
}
return true;
},
/*
----------------------------
Public methods
----------------------------
*/
// Bind to scroll
bind: function infscr_bind() {
this._binding('bind');
},
// Destroy current instance of plugin
destroy: function infscr_destroy() {
this.options.state.isDestroyed = true;
this.options.loading.finished();
return this._error('destroy');
},
// Set pause value to false
pause: function infscr_pause() {
this._pausing('pause');
},
// Set pause value to false
resume: function infscr_resume() {
this._pausing('resume');
},
beginAjax: function infscr_ajax(opts) {
var instance = this,
path = opts.path,
box, desturl, method, condition;
// increment the URL bit. e.g. /page/3/
opts.state.currPage++;
// Manually control maximum page
if ( opts.maxPage !== undefined && opts.state.currPage > opts.maxPage ){
opts.state.isBeyondMaxPage = true;
this.destroy();
return;
}
// if we're dealing with a table we can't use DIVs
box = $(opts.contentSelector).is('table, tbody') ? $('<tbody/>') : $('<div/>');
desturl = (typeof path === 'function') ? path(opts.state.currPage) : path.join(opts.state.currPage);
instance._debug('heading into ajax', desturl);
method = (opts.dataType === 'html' || opts.dataType === 'json' ) ? opts.dataType : 'html+callback';
if (opts.appendCallback && opts.dataType === 'html') {
method += '+callback';
}
switch (method) {
case 'html+callback':
instance._debug('Using HTML via .load() method');
box.load(desturl + ' ' + opts.itemSelector, undefined, function infscr_ajax_callback(responseText) {
instance._loadcallback(box, responseText, desturl);
});
break;
case 'html':
instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
$.ajax({
// params
url: desturl,
dataType: opts.dataType,
complete: function infscr_ajax_callback(jqXHR, textStatus) {
condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === 'success' || textStatus === 'notmodified');
if (condition) {
instance._loadcallback(box, jqXHR.responseText, desturl);
} else {
instance._error('end');
}
}
});
break;
case 'json':
instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
$.ajax({
dataType: 'json',
type: 'GET',
url: desturl,
success: function (data, textStatus, jqXHR) {
condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === 'success' || textStatus === 'notmodified');
if (opts.appendCallback) {
// if appendCallback is true, you must defined template in options.
// note that data passed into _loadcallback is already an html (after processed in opts.template(data)).
if (opts.template !== undefined) {
var theData = opts.template(data);
box.append(theData);
if (condition) {
instance._loadcallback(box, theData);
} else {
instance._error('end');
}
} else {
instance._debug('template must be defined.');
instance._error('end');
}
} else {
// if appendCallback is false, we will pass in the JSON object. you should handle it yourself in your callback.
if (condition) {
instance._loadcallback(box, data, desturl);
} else {
instance._error('end');
}
}
},
error: function() {
instance._debug('JSON ajax request failed.');
instance._error('end');
}
});
break;
}
},
// Retrieve next set of content items
retrieve: function infscr_retrieve(pageNum) {
pageNum = pageNum || null;
var instance = this,
opts = instance.options;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['retrieve_'+opts.behavior] !== undefined) {
this['retrieve_'+opts.behavior].call(this,pageNum);
return;
}
// for manual triggers, if destroyed, get out of here
if (opts.state.isDestroyed) {
this._debug('Instance is destroyed');
return false;
}
// we dont want to fire the ajax multiple times
opts.state.isDuringAjax = true;
opts.loading.start.call($(opts.contentSelector)[0],opts);
},
// Check to see next page is needed
scroll: function infscr_scroll() {
var opts = this.options,
state = opts.state;
// if behavior is defined and this function is extended, call that instead of default
if (!!opts.behavior && this['scroll_'+opts.behavior] !== undefined) {
this['scroll_'+opts.behavior].call(this);
return;
}
if (state.isDuringAjax || state.isInvalidPage || state.isDone || state.isDestroyed || state.isPaused) {
return;
}
if (!this._nearbottom()) {
return;
}
this.retrieve();
},
// Toggle pause value
toggle: function infscr_toggle() {
this._pausing();
},
// Unbind from scroll
unbind: function infscr_unbind() {
this._binding('unbind');
},
// update options
update: function infscr_options(key) {
if ($.isPlainObject(key)) {
this.options = $.extend(true,this.options,key);
}
}
};
/*
----------------------------
Infinite Scroll function
----------------------------
Borrowed logic from the following...
jQuery UI
- https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.widget.js
jCarousel
- https://github.com/jsor/jcarousel/blob/master/lib/jquery.jcarousel.js
Masonry
- https://github.com/desandro/masonry/blob/master/jquery.masonry.js
*/
$.fn.infinitescroll = function infscr_init(options, callback) {
var thisCall = typeof options;
switch (thisCall) {
// method
case 'string':
var args = Array.prototype.slice.call(arguments, 1);
this.each(function () {
var instance = $.data(this, 'infinitescroll');
if (!instance) {
// not setup yet
// return $.error('Method ' + options + ' cannot be called until Infinite Scroll is setup');
return false;
}
if (!$.isFunction(instance[options]) || options.charAt(0) === '_') {
// return $.error('No such method ' + options + ' for Infinite Scroll');
return false;
}
// no errors!
instance[options].apply(instance, args);
});
break;
// creation
case 'object':
this.each(function () {
var instance = $.data(this, 'infinitescroll');
if (instance) {
// update options of current instance
instance.update(options);
} else {
// initialize new instance
instance = new $.infinitescroll(options, callback, this);
// don't attach if instantiation failed
if (!instance.failed) {
$.data(this, 'infinitescroll', instance);
}
}
});
break;
}
return this;
};
/*
* smartscroll: debounced scroll event for jQuery *
* https://github.com/lukeshumard/smartscroll
* Based on smartresize by @louis_remi: https://github.com/lrbabe/jquery.smartresize.js *
* Copyright 2011 Louis-Remi & Luke Shumard * Licensed under the MIT license. *
*/
var event = $.event,
scrollTimeout;
event.special.smartscroll = {
setup: function () {
$(this).bind('scroll', event.special.smartscroll.handler);
},
teardown: function () {
$(this).unbind('scroll', event.special.smartscroll.handler);
},
handler: function (event, execAsap) {
// Save the context
var context = this,
args = arguments;
// set correct event type
event.type = 'smartscroll';
if (scrollTimeout) { clearTimeout(scrollTimeout); }
scrollTimeout = setTimeout(function () {
$(context).trigger('smartscroll', args);
}, execAsap === 'execAsap' ? 0 : 100);
}
};
$.fn.smartscroll = function (fn) {
return fn ? this.bind('smartscroll', fn) : this.trigger('smartscroll', ['execAsap']);
};
}));
/*!
Waypoints - 4.0.1
Copyright © 2011-2016 Caleb Troughton
Licensed under the MIT license.
https://github.com/imakewebthings/waypoints/blob/master/licenses.txt
*/
(function() {
'use strict'
var keyCounter = 0
var allWaypoints = {}
/* http://imakewebthings.com/waypoints/api/waypoint */
function Waypoint(options) {
if (!options) {
throw new Error('No options passed to Waypoint constructor')
}
if (!options.element) {
throw new Error('No element option passed to Waypoint constructor')
}
if (!options.handler) {
throw new Error('No handler option passed to Waypoint constructor')
}
this.key = 'waypoint-' + keyCounter
this.options = Waypoint.Adapter.extend({}, Waypoint.defaults, options)
this.element = this.options.element
this.adapter = new Waypoint.Adapter(this.element)
this.callback = options.handler
this.axis = this.options.horizontal ? 'horizontal' : 'vertical'
this.enabled = this.options.enabled
this.triggerPoint = null
this.group = Waypoint.Group.findOrCreate({
name: this.options.group,
axis: this.axis
})
this.context = Waypoint.Context.findOrCreateByElement(this.options.context)
if (Waypoint.offsetAliases[this.options.offset]) {
this.options.offset = Waypoint.offsetAliases[this.options.offset]
}
this.group.add(this)
this.context.add(this)
allWaypoints[this.key] = this
keyCounter += 1
}
/* Private */
Waypoint.prototype.queueTrigger = function(direction) {
this.group.queueTrigger(this, direction)
}
/* Private */
Waypoint.prototype.trigger = function(args) {
if (!this.enabled) {
return
}
if (this.callback) {
this.callback.apply(this, args)
}
}
/* Public */
/* http://imakewebthings.com/waypoints/api/destroy */
Waypoint.prototype.destroy = function() {
this.context.remove(this)
this.group.remove(this)
delete allWaypoints[this.key]
}
/* Public */
/* http://imakewebthings.com/waypoints/api/disable */
Waypoint.prototype.disable = function() {
this.enabled = false
return this
}
/* Public */
/* http://imakewebthings.com/waypoints/api/enable */
Waypoint.prototype.enable = function() {
this.context.refresh()
this.enabled = true
return this
}
/* Public */
/* http://imakewebthings.com/waypoints/api/next */
Waypoint.prototype.next = function() {
return this.group.next(this)
}
/* Public */
/* http://imakewebthings.com/waypoints/api/previous */
Waypoint.prototype.previous = function() {
return this.group.previous(this)
}
/* Private */
Waypoint.invokeAll = function(method) {
var allWaypointsArray = []
for (var waypointKey in allWaypoints) {
allWaypointsArray.push(allWaypoints[waypointKey])
}
for (var i = 0, end = allWaypointsArray.length; i < end; i++) {
allWaypointsArray[i][method]()
}
}
/* Public */
/* http://imakewebthings.com/waypoints/api/destroy-all */
Waypoint.destroyAll = function() {
Waypoint.invokeAll('destroy')
}
/* Public */
/* http://imakewebthings.com/waypoints/api/disable-all */
Waypoint.disableAll = function() {
Waypoint.invokeAll('disable')
}
/* Public */
/* http://imakewebthings.com/waypoints/api/enable-all */
Waypoint.enableAll = function() {
Waypoint.Context.refreshAll()
for (var waypointKey in allWaypoints) {
allWaypoints[waypointKey].enabled = true
}
return this
}
/* Public */
/* http://imakewebthings.com/waypoints/api/refresh-all */
Waypoint.refreshAll = function() {
Waypoint.Context.refreshAll()
}
/* Public */
/* http://imakewebthings.com/waypoints/api/viewport-height */
Waypoint.viewportHeight = function() {
return window.innerHeight || document.documentElement.clientHeight
}
/* Public */
/* http://imakewebthings.com/waypoints/api/viewport-width */
Waypoint.viewportWidth = function() {
return document.documentElement.clientWidth
}
Waypoint.adapters = []
Waypoint.defaults = {
context: window,
continuous: true,
enabled: true,
group: 'default',
horizontal: false,
offset: 0
}
Waypoint.offsetAliases = {
'bottom-in-view': function() {
return this.context.innerHeight() - this.adapter.outerHeight()
},
'right-in-view': function() {
return this.context.innerWidth() - this.adapter.outerWidth()
}
}
window.Waypoint = Waypoint
}())
;(function() {
'use strict'
function requestAnimationFrameShim(callback) {
window.setTimeout(callback, 1000 / 60)
}
var keyCounter = 0
var contexts = {}
var Waypoint = window.Waypoint
var oldWindowLoad = window.onload
/* http://imakewebthings.com/waypoints/api/context */
function Context(element) {
this.element = element
this.Adapter = Waypoint.Adapter
this.adapter = new this.Adapter(element)
this.key = 'waypoint-context-' + keyCounter
this.didScroll = false
this.didResize = false
this.oldScroll = {
x: this.adapter.scrollLeft(),
y: this.adapter.scrollTop()
}
this.waypoints = {
vertical: {},
horizontal: {}
}
element.waypointContextKey = this.key
contexts[element.waypointContextKey] = this
keyCounter += 1
if (!Waypoint.windowContext) {
Waypoint.windowContext = true
Waypoint.windowContext = new Context(window)
}
this.createThrottledScrollHandler()
this.createThrottledResizeHandler()
}
/* Private */
Context.prototype.add = function(waypoint) {
var axis = waypoint.options.horizontal ? 'horizontal' : 'vertical'
this.waypoints[axis][waypoint.key] = waypoint
this.refresh()
}
/* Private */
Context.prototype.checkEmpty = function() {
var horizontalEmpty = this.Adapter.isEmptyObject(this.waypoints.horizontal)
var verticalEmpty = this.Adapter.isEmptyObject(this.waypoints.vertical)
var isWindow = this.element == this.element.window
if (horizontalEmpty && verticalEmpty && !isWindow) {
this.adapter.off('.waypoints')
delete contexts[this.key]
}
}
/* Private */
Context.prototype.createThrottledResizeHandler = function() {
var self = this
function resizeHandler() {
self.handleResize()
self.didResize = false
}
this.adapter.on('resize.waypoints', function() {
if (!self.didResize) {
self.didResize = true
Waypoint.requestAnimationFrame(resizeHandler)
}
})
}
/* Private */
Context.prototype.createThrottledScrollHandler = function() {
var self = this
function scrollHandler() {
self.handleScroll()
self.didScroll = false
}
this.adapter.on('scroll.waypoints', function() {
if (!self.didScroll || Waypoint.isTouch) {
self.didScroll = true
Waypoint.requestAnimationFrame(scrollHandler)
}
})
}
/* Private */
Context.prototype.handleResize = function() {
Waypoint.Context.refreshAll()
}
/* Private */
Context.prototype.handleScroll = function() {
var triggeredGroups = {}
var axes = {
horizontal: {
newScroll: this.adapter.scrollLeft(),
oldScroll: this.oldScroll.x,
forward: 'right',
backward: 'left'
},
vertical: {
newScroll: this.adapter.scrollTop(),
oldScroll: this.oldScroll.y,
forward: 'down',
backward: 'up'
}
}
for (var axisKey in axes) {
var axis = axes[axisKey]
var isForward = axis.newScroll > axis.oldScroll
var direction = isForward ? axis.forward : axis.backward
for (var waypointKey in this.waypoints[axisKey]) {
var waypoint = this.waypoints[axisKey][waypointKey]
if (waypoint.triggerPoint === null) {
continue
}
var wasBeforeTriggerPoint = axis.oldScroll < waypoint.triggerPoint
var nowAfterTriggerPoint = axis.newScroll >= waypoint.triggerPoint
var crossedForward = wasBeforeTriggerPoint && nowAfterTriggerPoint
var crossedBackward = !wasBeforeTriggerPoint && !nowAfterTriggerPoint
if (crossedForward || crossedBackward) {
waypoint.queueTrigger(direction)
triggeredGroups[waypoint.group.id] = waypoint.group
}
}
}
for (var groupKey in triggeredGroups) {
triggeredGroups[groupKey].flushTriggers()
}
this.oldScroll = {
x: axes.horizontal.newScroll,
y: axes.vertical.newScroll
}
}
/* Private */
Context.prototype.innerHeight = function() {
/*eslint-disable eqeqeq */
if (this.element == this.element.window) {
return Waypoint.viewportHeight()
}
/*eslint-enable eqeqeq */
return this.adapter.innerHeight()
}
/* Private */
Context.prototype.remove = function(waypoint) {
delete this.waypoints[waypoint.axis][waypoint.key]
this.checkEmpty()
}
/* Private */
Context.prototype.innerWidth = function() {
/*eslint-disable eqeqeq */
if (this.element == this.element.window) {
return Waypoint.viewportWidth()
}
/*eslint-enable eqeqeq */
return this.adapter.innerWidth()
}
/* Public */
/* http://imakewebthings.com/waypoints/api/context-destroy */
Context.prototype.destroy = function() {
var allWaypoints = []
for (var axis in this.waypoints) {
for (var waypointKey in this.waypoints[axis]) {
allWaypoints.push(this.waypoints[axis][waypointKey])
}
}
for (var i = 0, end = allWaypoints.length; i < end; i++) {
allWaypoints[i].destroy()
}
}
/* Public */
/* http://imakewebthings.com/waypoints/api/context-refresh */
Context.prototype.refresh = function() {
/*eslint-disable eqeqeq */
var isWindow = this.element == this.element.window
/*eslint-enable eqeqeq */
var contextOffset = isWindow ? undefined : this.adapter.offset()
var triggeredGroups = {}
var axes
this.handleScroll()
axes = {
horizontal: {
contextOffset: isWindow ? 0 : contextOffset.left,
contextScroll: isWindow ? 0 : this.oldScroll.x,
contextDimension: this.innerWidth(),
oldScroll: this.oldScroll.x,
forward: 'right',
backward: 'left',
offsetProp: 'left'
},
vertical: {
contextOffset: isWindow ? 0 : contextOffset.top,
contextScroll: isWindow ? 0 : this.oldScroll.y,
contextDimension: this.innerHeight(),
oldScroll: this.oldScroll.y,
forward: 'down',
backward: 'up',
offsetProp: 'top'
}
}
for (var axisKey in axes) {
var axis = axes[axisKey]
for (var waypointKey in this.waypoints[axisKey]) {
var waypoint = this.waypoints[axisKey][waypointKey]
var adjustment = waypoint.options.offset
var oldTriggerPoint = waypoint.triggerPoint
var elementOffset = 0
var freshWaypoint = oldTriggerPoint == null
var contextModifier, wasBeforeScroll, nowAfterScroll
var triggeredBackward, triggeredForward
if (waypoint.element !== waypoint.element.window) {
elementOffset = waypoint.adapter.offset()[axis.offsetProp]
}
if (typeof adjustment === 'function') {
adjustment = adjustment.apply(waypoint)
}
else if (typeof adjustment === 'string') {
adjustment = parseFloat(adjustment)
if (waypoint.options.offset.indexOf('%') > - 1) {
adjustment = Math.ceil(axis.contextDimension * adjustment / 100)
}
}
contextModifier = axis.contextScroll - axis.contextOffset
waypoint.triggerPoint = Math.floor(elementOffset + contextModifier - adjustment)
wasBeforeScroll = oldTriggerPoint < axis.oldScroll
nowAfterScroll = waypoint.triggerPoint >= axis.oldScroll
triggeredBackward = wasBeforeScroll && nowAfterScroll
triggeredForward = !wasBeforeScroll && !nowAfterScroll
if (!freshWaypoint && triggeredBackward) {
waypoint.queueTrigger(axis.backward)
triggeredGroups[waypoint.group.id] = waypoint.group
}
else if (!freshWaypoint && triggeredForward) {
waypoint.queueTrigger(axis.forward)
triggeredGroups[waypoint.group.id] = waypoint.group
}
else if (freshWaypoint && axis.oldScroll >= waypoint.triggerPoint) {
waypoint.queueTrigger(axis.forward)
triggeredGroups[waypoint.group.id] = waypoint.group
}
}
}
Waypoint.requestAnimationFrame(function() {
for (var groupKey in triggeredGroups) {
triggeredGroups[groupKey].flushTriggers()
}
})
return this
}
/* Private */
Context.findOrCreateByElement = function(element) {
return Context.findByElement(element) || new Context(element)
}
/* Private */
Context.refreshAll = function() {
for (var contextId in contexts) {
contexts[contextId].refresh()
}
}
/* Public */
/* http://imakewebthings.com/waypoints/api/context-find-by-element */
Context.findByElement = function(element) {
return contexts[element.waypointContextKey]
}
window.onload = function() {
if (oldWindowLoad) {
oldWindowLoad()
}
Context.refreshAll()
}
Waypoint.requestAnimationFrame = function(callback) {
var requestFn = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
requestAnimationFrameShim
requestFn.call(window, callback)
}
Waypoint.Context = Context
}())
;(function() {
'use strict'
function byTriggerPoint(a, b) {
return a.triggerPoint - b.triggerPoint
}
function byReverseTriggerPoint(a, b) {
return b.triggerPoint - a.triggerPoint
}
var groups = {
vertical: {},
horizontal: {}
}
var Waypoint = window.Waypoint
/* http://imakewebthings.com/waypoints/api/group */
function Group(options) {
this.name = options.name
this.axis = options.axis
this.id = this.name + '-' + this.axis
this.waypoints = []
this.clearTriggerQueues()
groups[this.axis][this.name] = this
}
/* Private */
Group.prototype.add = function(waypoint) {
this.waypoints.push(waypoint)
}
/* Private */
Group.prototype.clearTriggerQueues = function() {
this.triggerQueues = {
up: [],
down: [],
left: [],
right: []
}
}
/* Private */
Group.prototype.flushTriggers = function() {
for (var direction in this.triggerQueues) {
var waypoints = this.triggerQueues[direction]
var reverse = direction === 'up' || direction === 'left'
waypoints.sort(reverse ? byReverseTriggerPoint : byTriggerPoint)
for (var i = 0, end = waypoints.length; i < end; i += 1) {
var waypoint = waypoints[i]
if (waypoint.options.continuous || i === waypoints.length - 1) {
waypoint.trigger([direction])
}
}
}
this.clearTriggerQueues()
}
/* Private */
Group.prototype.next = function(waypoint) {
this.waypoints.sort(byTriggerPoint)
var index = Waypoint.Adapter.inArray(waypoint, this.waypoints)
var isLast = index === this.waypoints.length - 1
return isLast ? null : this.waypoints[index + 1]
}
/* Private */
Group.prototype.previous = function(waypoint) {
this.waypoints.sort(byTriggerPoint)
var index = Waypoint.Adapter.inArray(waypoint, this.waypoints)
return index ? this.waypoints[index - 1] : null
}
/* Private */
Group.prototype.queueTrigger = function(waypoint, direction) {
this.triggerQueues[direction].push(waypoint)
}
/* Private */
Group.prototype.remove = function(waypoint) {
var index = Waypoint.Adapter.inArray(waypoint, this.waypoints)
if (index > -1) {
this.waypoints.splice(index, 1)
}
}
/* Public */
/* http://imakewebthings.com/waypoints/api/first */
Group.prototype.first = function() {
return this.waypoints[0]
}
/* Public */
/* http://imakewebthings.com/waypoints/api/last */
Group.prototype.last = function() {
return this.waypoints[this.waypoints.length - 1]
}
/* Private */
Group.findOrCreate = function(options) {
return groups[options.axis][options.name] || new Group(options)
}
Waypoint.Group = Group
}())
;(function() {
'use strict'
var $ = window.jQuery
var Waypoint = window.Waypoint
function JQueryAdapter(element) {
this.$element = $(element)
}
$.each([
'innerHeight',
'innerWidth',
'off',
'offset',
'on',
'outerHeight',
'outerWidth',
'scrollLeft',
'scrollTop'
], function(i, method) {
JQueryAdapter.prototype[method] = function() {
var args = Array.prototype.slice.call(arguments)
return this.$element[method].apply(this.$element, args)
}
})
$.each([
'extend',
'inArray',
'isEmptyObject'
], function(i, method) {
JQueryAdapter[method] = $[method]
})
Waypoint.adapters.push({
name: 'jquery',
Adapter: JQueryAdapter
})
Waypoint.Adapter = JQueryAdapter
}())
;(function() {
'use strict'
var Waypoint = window.Waypoint
function createExtension(framework) {
return function() {
var waypoints = []
var overrides = arguments[0]
if (framework.isFunction(arguments[0])) {
overrides = framework.extend({}, arguments[1])
overrides.handler = arguments[0]
}
this.each(function() {
var options = framework.extend({}, overrides, {
element: this
})
if (typeof options.context === 'string') {
options.context = framework(this).closest(options.context)[0]
}
waypoints.push(new Waypoint(options))
})
return waypoints
}
}
if (window.jQuery) {
window.jQuery.fn.waypoint = createExtension(window.jQuery)
}
if (window.Zepto) {
window.Zepto.fn.waypoint = createExtension(window.Zepto)
}
}())
;
/*!
Waypoints Inview Shortcut - 4.0.1
Copyright © 2011-2016 Caleb Troughton
Licensed under the MIT license.
https://github.com/imakewebthings/waypoints/blob/master/licenses.txt
*/
(function() {
'use strict'
function noop() {}
var Waypoint = window.Waypoint
/* http://imakewebthings.com/waypoints/shortcuts/inview */
function Inview(options) {
this.options = Waypoint.Adapter.extend({}, Inview.defaults, options)
this.axis = this.options.horizontal ? 'horizontal' : 'vertical'
this.waypoints = []
this.element = this.options.element
this.createWaypoints()
}
/* Private */
Inview.prototype.createWaypoints = function() {
var configs = {
vertical: [{
down: 'enter',
up: 'exited',
offset: '100%'
}, {
down: 'entered',
up: 'exit',
offset: 'bottom-in-view'
}, {
down: 'exit',
up: 'entered',
offset: 0
}, {
down: 'exited',
up: 'enter',
offset: function() {
return -this.adapter.outerHeight()
}
}],
horizontal: [{
right: 'enter',
left: 'exited',
offset: '100%'
}, {
right: 'entered',
left: 'exit',
offset: 'right-in-view'
}, {
right: 'exit',
left: 'entered',
offset: 0
}, {
right: 'exited',
left: 'enter',
offset: function() {
return -this.adapter.outerWidth()
}
}]
}
for (var i = 0, end = configs[this.axis].length; i < end; i++) {
var config = configs[this.axis][i]
this.createWaypoint(config)
}
}
/* Private */
Inview.prototype.createWaypoint = function(config) {
var self = this
this.waypoints.push(new Waypoint({
context: this.options.context,
element: this.options.element,
enabled: this.options.enabled,
handler: (function(config) {
return function(direction) {
self.options[config[direction]].call(self, direction)
}
}(config)),
offset: config.offset,
horizontal: this.options.horizontal
}))
}
/* Public */
Inview.prototype.destroy = function() {
for (var i = 0, end = this.waypoints.length; i < end; i++) {
this.waypoints[i].destroy()
}
this.waypoints = []
}
Inview.prototype.disable = function() {
for (var i = 0, end = this.waypoints.length; i < end; i++) {
this.waypoints[i].disable()
}
}
Inview.prototype.enable = function() {
for (var i = 0, end = this.waypoints.length; i < end; i++) {
this.waypoints[i].enable()
}
}
Inview.defaults = {
context: window,
enabled: true,
enter: noop,
entered: noop,
exit: noop,
exited: noop
}
Waypoint.Inview = Inview
}())
;
/*
* SmartMenus jQuery v0.9.6
* http://www.smartmenus.org/
*
* Copyright 2014 Vasil Dinkov, Vadikom Web Ltd.
* http://vadikom.com/
*
* Released under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
(function($) {
var menuTrees = [],
IE = !!window.createPopup, // we need to detect it, unfortunately
IElt9 = IE && !document.defaultView,
IElt8 = IE && !document.querySelector,
IE6 = IE && typeof document.documentElement.currentStyle.minWidth == 'undefined',
mouse = false, // optimize for touch by default - we will detect for mouse input
mouseDetectionEnabled = false;
// Handle detection for mouse input (i.e. desktop browsers, tablets with a mouse, etc.)
function initMouseDetection(disable) {
if (!mouseDetectionEnabled && !disable) {
// if we get two consecutive mousemoves within 2 pixels from each other and within 300ms, we assume a real mouse/cursor is present
// in practice, this seems like impossible to trick unintentianally with a real mouse and a pretty safe detection on touch devices (even with older browsers that do not support touch events)
var firstTime = true,
lastMove = null;
$(document).bind({
'mousemove.smartmenus_mouse': function(e) {
var thisMove = { x: e.pageX, y: e.pageY, timeStamp: new Date().getTime() };
if (lastMove) {
var deltaX = Math.abs(lastMove.x - thisMove.x),
deltaY = Math.abs(lastMove.y - thisMove.y);
if ((deltaX > 0 || deltaY > 0) && deltaX <= 2 && deltaY <= 2 && thisMove.timeStamp - lastMove.timeStamp <= 300) {
mouse = true;
// if this is the first check after page load, check if we are not over some item by chance and call the mouseenter handler if yes
if (firstTime) {
var $a = $(e.target).closest('a');
if ($a.is('a')) {
$.each(menuTrees, function() {
if ($.contains(this.$root[0], $a[0])) {
this.itemEnter({ currentTarget: $a[0] });
return false;
}
});
}
firstTime = false;
}
}
}
lastMove = thisMove;
},
'touchstart.smartmenus_mouse pointerover.smartmenus_mouse MSPointerOver.smartmenus_mouse': function(e) {
if (!/^(4|mouse)$/.test(e.originalEvent.pointerType)) {
mouse = false;
}
}
});
mouseDetectionEnabled = true;
} else if (mouseDetectionEnabled && disable) {
$(document).unbind('.smartmenus_mouse');
mouseDetectionEnabled = false;
}
};
$.SmartMenus = function(elm, options) {
this.$root = $(elm);
this.opts = options;
this.rootId = ''; // internal
this.$subArrow = null;
this.subMenus = []; // all sub menus in the tree (UL elms) in no particular order (only real - e.g. UL's in mega sub menus won't be counted)
this.activatedItems = []; // stores last activated A's for each level
this.visibleSubMenus = []; // stores visible sub menus UL's
this.showTimeout = 0;
this.hideTimeout = 0;
this.scrollTimeout = 0;
this.clickActivated = false;
this.zIndexInc = 0;
this.$firstLink = null; // we'll use these for some tests
this.$firstSub = null; // at runtime so we'll cache them
this.disabled = false;
this.$disableOverlay = null;
this.init();
};
$.extend($.SmartMenus, {
hideAll: function() {
$.each(menuTrees, function() {
this.menuHideAll();
});
},
destroy: function() {
while (menuTrees.length) {
menuTrees[0].destroy();
}
initMouseDetection(true);
},
prototype: {
init: function(refresh) {
var self = this;
if (!refresh) {
menuTrees.push(this);
this.rootId = (new Date().getTime() + Math.random() + '').replace(/\D/g, '');
if (this.$root.hasClass('sm-rtl')) {
this.opts.rightToLeftSubMenus = true;
}
// init root (main menu)
this.$root
.data('smartmenus', this)
.attr('data-smartmenus-id', this.rootId)
.dataSM('level', 1)
.bind({
'mouseover.smartmenus focusin.smartmenus': $.proxy(this.rootOver, this),
'mouseout.smartmenus focusout.smartmenus': $.proxy(this.rootOut, this)
})
.delegate('a', {
'mouseenter.smartmenus': $.proxy(this.itemEnter, this),
'mouseleave.smartmenus': $.proxy(this.itemLeave, this),
'mousedown.smartmenus': $.proxy(this.itemDown, this),
'focus.smartmenus': $.proxy(this.itemFocus, this),
'blur.smartmenus': $.proxy(this.itemBlur, this),
'click.smartmenus': $.proxy(this.itemClick, this),
'touchend.smartmenus': $.proxy(this.itemTouchEnd, this)
});
var eNamespace = '.smartmenus' + this.rootId;
// hide menus on tap or click outside the root UL
if (this.opts.hideOnClick) {
$(document).bind('touchstart' + eNamespace, $.proxy(this.docTouchStart, this))
.bind('touchmove' + eNamespace, $.proxy(this.docTouchMove, this))
.bind('touchend' + eNamespace, $.proxy(this.docTouchEnd, this))
// for Opera Mobile < 11.5, webOS browser, etc. we'll check click too
.bind('click' + eNamespace, $.proxy(this.docClick, this));
}
// hide sub menus on resize
$(window).bind('resize' + eNamespace + ' orientationchange' + eNamespace, $.proxy(this.winResize, this));
$(window).bind('scroll' + eNamespace + ' orientationchange' + eNamespace, $.proxy(this.winResize, this));
if (this.opts.subIndicators) {
this.$subArrow = $('<span/>').addClass('sub-arrow');
if (this.opts.subIndicatorsText) {
this.$subArrow.html(this.opts.subIndicatorsText);
}
}
// make sure mouse detection is enabled
initMouseDetection();
}
// init sub menus
this.$firstSub = this.$root.find('ul').each(function() { self.menuInit($(this)); }).eq(0);
this.$firstLink = this.$root.find('a').eq(0);
// find current item
if (this.opts.markCurrentItem) {
var reDefaultDoc = /(index|default)\.[^#\?\/]*/i,
reHash = /#.*/,
locHref = window.location.href.replace(reDefaultDoc, ''),
locHrefNoHash = locHref.replace(reHash, '');
this.$root.find('a').each(function() {
var href = this.href.replace(reDefaultDoc, ''),
$this = $(this);
if (href == locHref || href == locHrefNoHash) {
$this.addClass('current');
if (self.opts.markCurrentTree) {
$this.parents('li').each(function() {
var $this = $(this);
if ($this.dataSM('sub')) {
$this.children('a').addClass('current');
}
});
}
}
});
}
},
destroy: function() {
this.menuHideAll();
this.$root
.removeData('smartmenus')
.removeAttr('data-smartmenus-id')
.removeDataSM('level')
.unbind('.smartmenus')
.undelegate('.smartmenus');
var eNamespace = '.smartmenus' + this.rootId;
$(document).unbind(eNamespace);
$(window).unbind(eNamespace);
if (this.opts.subIndicators) {
this.$subArrow = null;
}
var self = this;
$.each(this.subMenus, function() {
if (this.hasClass('mega-menu')) {
this.find('ul').removeDataSM('in-mega');
}
if (this.dataSM('shown-before')) {
if (IElt8) {
this.children().css({ styleFloat: '', width: '' });
}
if (self.opts.subMenusMinWidth || self.opts.subMenusMaxWidth) {
if (!IE6) {
this.css({ width: '', minWidth: '', maxWidth: '' }).removeClass('sm-nowrap');
} else {
this.css({ width: '', overflowX: '', overflowY: '' }).children().children('a').css('white-space', '');
}
}
if (this.dataSM('scroll-arrows')) {
this.dataSM('scroll-arrows').remove();
}
this.css({ zIndex: '', top: '', left: '', marginLeft: '', marginTop: '', display: '' });
}
if (self.opts.subIndicators) {
this.dataSM('parent-a').removeClass('has-submenu').children('span.sub-arrow').remove();
}
this.removeDataSM('shown-before')
.removeDataSM('ie-shim')
.removeDataSM('scroll-arrows')
.removeDataSM('parent-a')
.removeDataSM('level')
.removeDataSM('beforefirstshowfired')
.parent().removeDataSM('sub');
});
if (this.opts.markCurrentItem) {
this.$root.find('a.current').removeClass('current');
}
this.$root = null;
this.$firstLink = null;
this.$firstSub = null;
if (this.$disableOverlay) {
this.$disableOverlay.remove();
this.$disableOverlay = null;
}
menuTrees.splice($.inArray(this, menuTrees), 1);
},
disable: function(noOverlay) {
if (!this.disabled) {
this.menuHideAll();
// display overlay over the menu to prevent interaction
if (!noOverlay && !this.opts.isPopup && this.$root.is(':visible')) {
var pos = this.$root.offset();
this.$disableOverlay = $('<div class="sm-jquery-disable-overlay"/>').css({
position: 'absolute',
top: pos.top,
left: pos.left,
width: this.$root.outerWidth(),
height: this.$root.outerHeight(),
zIndex: this.getStartZIndex() + 1,
opacity: 0
}).appendTo(document.body);
}
this.disabled = true;
}
},
docClick: function(e) {
// hide on any click outside the menu or on a menu link
if (this.visibleSubMenus.length && !$.contains(this.$root[0], e.target) || $(e.target).is('a')) {
this.menuHideAll($(e.target));
}
},
docTouchEnd: function(e) {
if (!this.lastTouch) {
return;
}
if (this.visibleSubMenus.length && (this.lastTouch.x2 === undefined || this.lastTouch.x1 == this.lastTouch.x2) && (this.lastTouch.y2 === undefined || this.lastTouch.y1 == this.lastTouch.y2) && (!this.lastTouch.target || !$.contains(this.$root[0], this.lastTouch.target))) {
if (this.hideTimeout) {
clearTimeout(this.hideTimeout);
this.hideTimeout = 0;
}
// hide with a delay to prevent triggering accidental unwanted click on some page element
var self = this;
this.hideTimeout = setTimeout(function() { self.menuHideAll($(e.target)); }, 350);
}
this.lastTouch = null;
},
docTouchMove: function(e) {
if (!this.lastTouch) {
return;
}
var touchPoint = e.originalEvent.touches[0];
this.lastTouch.x2 = touchPoint.pageX;
this.lastTouch.y2 = touchPoint.pageY;
},
docTouchStart: function(e) {
var touchPoint = e.originalEvent.touches[0];
this.lastTouch = { x1: touchPoint.pageX, y1: touchPoint.pageY, target: touchPoint.target };
},
enable: function() {
if (this.disabled) {
if (this.$disableOverlay) {
this.$disableOverlay.remove();
this.$disableOverlay = null;
}
this.disabled = false;
}
},
getHeight: function($elm) {
return this.getOffset($elm, true);
},
// returns precise width/height float values in IE9+, FF4+, recent WebKit
// http://vadikom.com/dailies/offsetwidth-offsetheight-useless-in-ie9-firefox4/
getOffset: function($elm, height) {
var old;
if ($elm.css('display') == 'none') {
old = { position: $elm[0].style.position, visibility: $elm[0].style.visibility };
$elm.css({ position: 'absolute', visibility: 'hidden' }).show();
}
var defaultView = $elm[0].ownerDocument.defaultView,
compStyle = defaultView && defaultView.getComputedStyle && defaultView.getComputedStyle($elm[0], null),
val = compStyle && parseFloat(compStyle[height ? 'height' : 'width']);
if (val) {
val += parseFloat(compStyle[height ? 'paddingTop' : 'paddingLeft'])
+ parseFloat(compStyle[height ? 'paddingBottom' : 'paddingRight'])
+ parseInt(compStyle[height ? 'borderTopWidth' : 'borderLeftWidth'])
+ parseInt(compStyle[height ? 'borderBottomWidth' : 'borderRightWidth']);
} else {
val = height ? $elm[0].offsetHeight : $elm[0].offsetWidth;
}
if (old) {
$elm.hide().css(old);
}
return val;
},
getWidth: function($elm) {
return this.getOffset($elm);
},
getStartZIndex: function() {
var zIndex = parseInt(this.$root.css('z-index'));
return !isNaN(zIndex) ? zIndex : 1;
},
handleEvents: function() {
return !this.disabled && this.isCSSOn();
},
handleItemEvents: function($a) {
return this.handleEvents() && !this.isLinkInMegaMenu($a);
},
isCollapsible: function() {
return this.$firstSub.css('position') == 'static';
},
isCSSOn: function() {
return this.$firstLink.css('display') == 'block' || this.$firstLink.css('display') == 'inline';
},
isFixed: function() {
return this.$root.css('position') == 'fixed';
},
isLinkInMegaMenu: function($a) {
return !$a.parent().parent().dataSM('level');
},
isTouchMode: function() {
return !mouse || this.isCollapsible();
},
itemActivate: function($a) {
var $li = $a.parent(),
$ul = $li.parent(),
level = $ul.dataSM('level');
// if for some reason the parent item is not activated (e.g. this is an API call to activate the item), activate all parent items first
if (level > 1 && (!this.activatedItems[level - 2] || this.activatedItems[level - 2][0] != $ul.dataSM('parent-a')[0])) {
var self = this;
$($ul.parentsUntil('[data-smartmenus-id]', 'ul').get().reverse()).add($ul).each(function() {
self.itemActivate($(this).dataSM('parent-a'));
});
}
// hide any visible deeper level sub menus
if (this.visibleSubMenus.length > level) {
for (var i = this.visibleSubMenus.length - 1, l = !this.activatedItems[level - 1] || this.activatedItems[level - 1][0] != $a[0] ? level - 1 : level; i > l; i--) {
this.menuHide(this.visibleSubMenus[i]);
}
}
// save new active item and sub menu for this level
this.activatedItems[level - 1] = $a;
this.visibleSubMenus[level - 1] = $ul;
if (this.$root.triggerHandler('activate.smapi', $a[0]) === false) {
return;
}
// show the sub menu if this item has one
var $sub = $li.dataSM('sub');
if ($sub && (this.isTouchMode() || (!this.opts.showOnClick || this.clickActivated))) {
this.menuShow($sub);
}
},
itemBlur: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
this.$root.triggerHandler('blur.smapi', $a[0]);
},
itemClick: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
$a.removeDataSM('mousedown');
if (this.$root.triggerHandler('click.smapi', $a[0]) === false) {
return false;
}
var $sub = $a.parent().dataSM('sub');
if (this.isTouchMode()) {
// undo fix: prevent the address bar on iPhone from sliding down when expanding a sub menu
if ($a.dataSM('href')) {
$a.attr('href', $a.dataSM('href')).removeDataSM('href');
}
// if the sub is not visible
if ($sub && (!$sub.dataSM('shown-before') || !$sub.is(':visible'))) {
// try to activate the item and show the sub
this.itemActivate($a);
// if "itemActivate" showed the sub, prevent the click so that the link is not loaded
// if it couldn't show it, then the sub menus are disabled with an !important declaration (e.g. via mobile styles) so let the link get loaded
if ($sub.is(':visible')) {
return false;
}
}
} else if (this.opts.showOnClick && $a.parent().parent().dataSM('level') == 1 && $sub) {
this.clickActivated = true;
this.menuShow($sub);
return false;
}
if ($a.hasClass('disabled')) {
return false;
}
if (this.$root.triggerHandler('select.smapi', $a[0]) === false) {
return false;
}
},
itemDown: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
$a.dataSM('mousedown', true);
},
itemEnter: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
if (!this.isTouchMode()) {
if (this.showTimeout) {
clearTimeout(this.showTimeout);
this.showTimeout = 0;
}
var self = this;
this.showTimeout = setTimeout(function() { self.itemActivate($a); }, this.opts.showOnClick && $a.parent().parent().dataSM('level') == 1 ? 1 : this.opts.showTimeout);
}
this.$root.triggerHandler('mouseenter.smapi', $a[0]);
},
itemFocus: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
// fix (the mousedown check): in some browsers a tap/click produces consecutive focus + click events so we don't need to activate the item on focus
if ((!this.isTouchMode() || !$a.dataSM('mousedown')) && (!this.activatedItems.length || this.activatedItems[this.activatedItems.length - 1][0] != $a[0])) {
this.itemActivate($a);
}
this.$root.triggerHandler('focus.smapi', $a[0]);
},
itemLeave: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
if (!this.isTouchMode()) {
if ($a[0].blur) {
$a[0].blur();
}
if (this.showTimeout) {
clearTimeout(this.showTimeout);
this.showTimeout = 0;
}
}
$a.removeDataSM('mousedown');
this.$root.triggerHandler('mouseleave.smapi', $a[0]);
},
itemTouchEnd: function(e) {
var $a = $(e.currentTarget);
if (!this.handleItemEvents($a)) {
return;
}
// prevent the address bar on iPhone from sliding down when expanding a sub menu
var $sub = $a.parent().dataSM('sub');
if ($a.attr('href').charAt(0) !== '#' && $sub && (!$sub.dataSM('shown-before') || !$sub.is(':visible'))) {
$a.dataSM('href', $a.attr('href'));
$a.attr('href', '#');
}
},
menuFixLayout: function($ul) {
// fixes a menu that is being shown for the first time
if (!$ul.dataSM('shown-before')) {
$ul.hide().dataSM('shown-before', true);
// fix the layout of the items in IE<8
if (IElt8) {
$ul.children().css({ styleFloat: 'left', width: '100%' });
}
}
},
menuHide: function($sub) {
if (this.$root.triggerHandler('beforehide.smapi', $sub[0]) === false) {
return;
}
$sub.stop(true, true);
if ($sub.is(':visible')) {
var complete = function() {
// unset z-index
if (IElt9) {
$sub.parent().css('z-index', '');
} else {
$sub.css('z-index', '');
}
};
// if sub is collapsible (mobile view)
if (this.isCollapsible()) {
if (this.opts.collapsibleHideFunction) {
this.opts.collapsibleHideFunction.call(this, $sub, complete);
} else {
$sub.hide(this.opts.collapsibleHideDuration, complete);
}
} else {
if (this.opts.hideFunction) {
this.opts.hideFunction.call(this, $sub, complete);
} else {
$sub.hide(this.opts.hideDuration, complete);
}
}
// remove IE iframe shim
if ($sub.dataSM('ie-shim')) {
$sub.dataSM('ie-shim').remove();
}
// deactivate scrolling if it is activated for this sub
if ($sub.dataSM('scroll')) {
$sub.unbind('.smartmenus_scroll').removeDataSM('scroll').dataSM('scroll-arrows').hide();
}
// unhighlight parent item
$sub.dataSM('parent-a').removeClass('highlighted');
var level = $sub.dataSM('level');
this.activatedItems.splice(level - 1, 1);
this.visibleSubMenus.splice(level - 1, 1);
this.$root.triggerHandler('hide.smapi', $sub[0]);
}
},
menuHideAll: function($item) {
if ($item != undefined && $item.parent().hasClass('menu-item') && !$item.parent().hasClass('menu-item-has-children')) return;
if ( $('body').hasClass('vmenu') ) return;
if (this.showTimeout) {
clearTimeout(this.showTimeout);
this.showTimeout = 0;
}
// hide all subs
for (var i = this.visibleSubMenus.length - 1; i > 0; i--) {
this.menuHide(this.visibleSubMenus[i]);
}
// hide root if it's popup
if (this.opts.isPopup) {
this.$root.stop(true, true);
if (this.$root.is(':visible')) {
if (this.opts.hideFunction) {
this.opts.hideFunction.call(this, this.$root);
} else {
this.$root.hide(this.opts.hideDuration);
}
// remove IE iframe shim
if (this.$root.dataSM('ie-shim')) {
this.$root.dataSM('ie-shim').remove();
}
}
}
this.activatedItems = [];
this.visibleSubMenus = [];
this.clickActivated = false;
// reset z-index increment
this.zIndexInc = 0;
},
menuIframeShim: function($ul) {
// create iframe shim for the menu
if (IE && this.opts.overlapControlsInIE && !$ul.dataSM('ie-shim')) {
$ul.dataSM('ie-shim', $('<iframe/>').attr({ src: 'javascript:0', tabindex: -9 })
.css({ position: 'absolute', top: 'auto', left: '0', opacity: 0, border: '0' })
);
}
},
menuInit: function($ul) {
if (!$ul.dataSM('in-mega')) {
this.subMenus.push($ul);
// mark UL's in mega drop downs (if any) so we can neglect them
if ($ul.hasClass('mega-menu')) {
$ul.find('ul').dataSM('in-mega', true);
}
// get level (much faster than, for example, using parentsUntil)
var level = 2,
par = $ul[0];
while ((par = par.parentNode.parentNode) != this.$root[0]) {
level++;
}
// cache stuff
$ul.dataSM('parent-a', $ul.prevAll('a').eq(-1))
.dataSM('level', level)
.parent().dataSM('sub', $ul);
// add sub indicator to parent item
if (this.opts.subIndicators) {
$ul.dataSM('parent-a').addClass('has-submenu')[this.opts.subIndicatorsPos](this.$subArrow.clone());
}
}
},
menuPosition: function($sub) {
var fixIE = $('html.ie').length;
// if (fixIE) {
// var $rowParent = $($sub).closest('.main-menu-container');
// $rowParent.height($rowParent.height());
// }
var $a = $sub.dataSM('parent-a'),
$li = $sub.parent(),
$ul = $sub.parent().parent(),
$container = $ul.closest('.row-menu-inner'),
level = $sub.dataSM('level'),
subW = this.getWidth($sub),
subH = this.getHeight($sub),
itemOffset = $a.offset(),
itemX = itemOffset.left,
itemY = itemOffset.top,
itemW = this.getWidth($a),
itemH = this.getHeight($a),
$win = $(window),
winX = $win.scrollLeft(),
winY = $win.scrollTop(),
winW = $win.width(),
winH = $win.height(),
containerW = $container.width(),
containerOffsetX = containerW + ((winW - containerW) / 2),
horizontalParent = $ul.hasClass('sm') && !$ul.hasClass('sm-vertical'),
subOffsetX = level == 2 ? this.opts.mainMenuSubOffsetX : this.opts.subMenusSubOffsetX,
subOffsetY = level == 2 ? this.opts.mainMenuSubOffsetY : this.opts.subMenusSubOffsetY,
x, y, leftPos;
if (horizontalParent) {
x = this.opts.rightToLeftSubMenus ? itemW - subW - subOffsetX : subOffsetX;
y = this.opts.bottomToTopSubMenus ? -subH - subOffsetY : itemH + subOffsetY;
} else {
x = this.opts.rightToLeftSubMenus ? subOffsetX - subW : itemW - subOffsetX;
y = this.opts.bottomToTopSubMenus ? itemH - subOffsetY - subH : subOffsetY;
}
if (this.opts.keepInViewport && !this.isCollapsible()) {
if (this.isFixed()) {
itemX -= winX;
itemY -= winY;
winX = winY = 0;
}
var absX = itemX + x,
absY = itemY + y;
if (this.opts.rightToLeftSubMenus && absX < winX) {
x = horizontalParent ? winX - absX + x : itemW - subOffsetX;
} else if (!this.opts.rightToLeftSubMenus && absX + subW > winX + containerOffsetX ) {
x = horizontalParent ? winX + containerOffsetX - subW - absX + x : subOffsetX - subW;
}
if (!horizontalParent) {
if (subH < winH && absY + subH > winY + winH) {
y += winY + winH - subH - absY;
} else if (subH >= winH || absY < winY) {
y += winY - absY;
}
}
// do we need scrolling?
// 0.49 added for the sake of IE9/FF4+ where we might be dealing with float numbers for "subH"
if (mouse && (horizontalParent && (absY + subH > winY + winH + 0.49 || absY < winY) || !horizontalParent && subH > winH + 0.49)) {
var self = this;
if (!$sub.dataSM('scroll-arrows')) {
$sub.dataSM('scroll-arrows', $([$('<span class="scroll-up"><span class="scroll-up-arrow"></span></span>')[0], $('<span class="scroll-down"><span class="scroll-down-arrow"></span></span>')[0]])
.bind({
mouseenter: function() { self.menuScroll($sub, $(this).hasClass('scroll-up')); },
mouseleave: function(e) {
self.menuScrollStop($sub);
self.menuScrollOut($sub, e);
},
'mousewheel DOMMouseScroll': function(e) { e.preventDefault(); }
})
.insertAfter($sub)
);
}
// bind events to show/hide arrows on hover and save scrolling data for this sub
var vportY = winY - (itemY + itemH);
$sub.dataSM('scroll', {
vportY: vportY,
subH: subH,
winH: winH,
step: 1
})
.bind({
'mouseover.smartmenus_scroll': function(e) { self.menuScrollOver($sub, e); },
'mouseout.smartmenus_scroll': function(e) { self.menuScrollOut($sub, e); },
'mousewheel.smartmenus_scroll DOMMouseScroll.smartmenus_scroll': function(e) { self.menuScrollMousewheel($sub, e); }
})
.dataSM('scroll-arrows').css({ top: 'auto', left: '0', marginLeft: x + (parseInt($sub.css('border-left-width')) || 0), width: this.getWidth($sub) - (parseInt($sub.css('border-left-width')) || 0) - (parseInt($sub.css('border-right-width')) || 0), zIndex: this.getStartZIndex() + this.zIndexInc })
.eq(0).css('margin-top', vportY).end()
.eq(1).css('margin-top', vportY + winH - this.getHeight($sub.dataSM('scroll-arrows').eq(1))).end()
.eq(horizontalParent && this.opts.bottomToTopSubMenus ? 0 : 1).show();
}
}
// if ($sub.hasClass('mega-menu-inner')) {
// if ($('.menu-wrapper .megamenu-diff').length > 0) {
// leftPos = parseFloat($('.menu-wrapper .megamenu-diff').outerWidth());
// leftPos = -leftPos;
// } else leftPos = parseFloat($('.menu-wrapper .main-menu-container').css('paddingLeft'));
// if ($('body.header-full-width').length > 0) {
// $sub.css({ width: $('.box-container').width()});
// leftPos = (leftPos - parseFloat($('.menu-wrapper .row-menu-inner').css('paddingLeft')));
// } else $sub.css({ width: containerW});
// leftPos = leftPos + 'px';
// } else {
// leftPos = $li.position().left + 'px';
// }
if ($sub.hasClass('mega-menu-inner')) {
$sub.css({ width: containerW});
if ( $('body.hmenu-center-double').length ) {
leftPos = '0px';
} else {
if ( $('body.hmenu-center-split').length > 0 && !$sub.closest('.navbar-cta').length && ! $('body.hormenu-position-right').length ) {
leftPos = - ($sub.closest('.menu-primary-inner')[0].offsetLeft) + 'px';
} else {
if ( $sub.closest('.navbar-cta').length && !$('body.hmenu').length && !$('body.hmenu-center').length ) {
leftPos = - ( parseFloat($sub.closest('.navbar-cta').offset().left) - parseFloat($sub.closest('.row-menu-inner').find('.logo-container').offset().left) ) + 'px';
} else if ($sub.closest('.row-menu-inner').find('.logo-container').length > 0 && !$('body.hmenu-center-split').length) {
leftPos = - (parseFloat($sub.closest('.row-menu-inner').find('.logo-container').css('paddingRight')) + ($sub.closest('.row-menu-inner').find('.logo-container').width())) + 'px';
} else {
leftPos = '0px';
}
}
}
} else {
leftPos = (level > 2 ? $li.position().left - parseFloat($li.closest('ul').css('paddingLeft')) : $li.position().left ) + 'px';
x = (level > 2 && x >= 0) ? x + (parseFloat($li.closest('ul').css('paddingLeft')) * 2) + 1 : x - 1;
}
$sub.css({ top: (level > 2) ? $a[0].offsetTop : (fixIE ? itemH : '100%'), left: leftPos, marginLeft: x, marginTop: (level > 2) ? 0 : y - itemH + ($sub.closest('.menu-mini').length ? 0 : 1) });
// IE iframe shim
this.menuIframeShim($sub);
if ($sub.dataSM('ie-shim')) {
$sub.dataSM('ie-shim').css({ zIndex: $sub.css('z-index'), width: subW, height: subH, marginLeft: x, marginTop: y - itemH + ($sub.closest('.menu-mini').length ? 0 : 1) });
}
},
menuScroll: function($sub, up, wheel) {
var y = parseFloat($sub.css('margin-top')),
scroll = $sub.dataSM('scroll'),
end = scroll.vportY + (up ? 0 : scroll.winH - scroll.subH),
step = wheel || !this.opts.scrollAccelerate ? this.opts.scrollStep : Math.floor($sub.dataSM('scroll').step);
$sub.add($sub.dataSM('ie-shim')).css('margin-top', Math.abs(end - y) > step ? y + (up ? step : -step) : end);
y = parseFloat($sub.css('margin-top'));
// show opposite arrow if appropriate
if (up && y + scroll.subH > scroll.vportY + scroll.winH || !up && y < scroll.vportY) {
$sub.dataSM('scroll-arrows').eq(up ? 1 : 0).show();
}
// accelerate when not using mousewheel to scroll
if (!wheel && this.opts.scrollAccelerate && $sub.dataSM('scroll').step < this.opts.scrollStep) {
$sub.dataSM('scroll').step += 0.5;
}
// "y" and "end" might be float numbers in IE9/FF4+ so this weird way to check is used
if (Math.abs(y - end) < 1) {
$sub.dataSM('scroll-arrows').eq(up ? 0 : 1).hide();
$sub.dataSM('scroll').step = 1;
} else if (!wheel) {
var self = this;
this.scrollTimeout = setTimeout(function() { self.menuScroll($sub, up); }, this.opts.scrollInterval);
}
},
menuScrollMousewheel: function($sub, e) {
var $closestSub = $(e.target).closest('ul');
while ($closestSub.dataSM('in-mega')) {
$closestSub = $closestSub.parent().closest('ul');
}
if ($closestSub[0] == $sub[0]) {
var up = (e.originalEvent.wheelDelta || -e.originalEvent.detail) > 0;
if ($sub.dataSM('scroll-arrows').eq(up ? 0 : 1).is(':visible')) {
this.menuScroll($sub, up, true);
}
}
e.preventDefault();
},
menuScrollOut: function($sub, e) {
var reClass = /^scroll-(up|down)/,
$closestSub = $(e.relatedTarget).closest('ul');
while ($closestSub.dataSM('in-mega')) {
$closestSub = $closestSub.parent().closest('ul');
}
if (!reClass.test((e.relatedTarget || '').className) && ($sub[0] != e.relatedTarget && !$.contains($sub[0], e.relatedTarget) || $closestSub[0] != $sub[0])) {
$sub.dataSM('scroll-arrows').css('visibility', 'hidden');
}
},
menuScrollOver: function($sub, e) {
var reClass = /^scroll-(up|down)/,
$closestSub = $(e.target).closest('ul');
while ($closestSub.dataSM('in-mega')) {
$closestSub = $closestSub.parent().closest('ul');
}
if (!reClass.test(e.target.className) && $closestSub[0] == $sub[0]) {
$sub.dataSM('scroll-arrows').css('visibility', 'visible');
}
},
menuScrollStop: function($sub) {
if (this.scrollTimeout) {
clearTimeout(this.scrollTimeout);
this.scrollTimeout = 0;
$sub.dataSM('scroll').step = 1;
}
},
menuShow: function($sub) {
if (!$sub.dataSM('beforefirstshowfired')) {
$sub.dataSM('beforefirstshowfired', true);
if (this.$root.triggerHandler('beforefirstshow.smapi', $sub[0]) === false) {
return;
}
}
if (this.$root.triggerHandler('beforeshow.smapi', $sub[0]) === false) {
return;
}
this.menuFixLayout($sub);
$sub.stop(true, true);
if (!$sub.is(':visible')) {
// set z-index - for IE < 9 set it to the parent LI
var zIndex = this.getStartZIndex() + (++this.zIndexInc);
if (IElt9) {
$sub.parent().css('z-index', zIndex);
} else {
$sub.css('z-index', zIndex);
}
// highlight parent item
if (this.opts.keepHighlighted || this.isCollapsible()) {
if ($sub.dataSM('parent-a').attr('data-type') != 'title')
$sub.dataSM('parent-a').addClass('highlighted');
}
// min/max-width fix - no way to rely purely on CSS as all UL's are nested
if (this.opts.subMenusMinWidth || this.opts.subMenusMaxWidth) {
if (!IElt8) {
$sub.css({ width: ($sub.hasClass('mega-menu-inner')) ? $('.box-container').outerWidth() + 'px' : 'auto', minWidth: '', maxWidth: '' }).addClass('sm-nowrap');
if (this.opts.subMenusMinWidth) {
$sub.css('min-width', this.opts.subMenusMinWidth);
}
if (this.opts.subMenusMaxWidth) {
var noMaxWidth = this.getWidth($sub);
$sub.css('max-width', this.opts.subMenusMaxWidth);
if (noMaxWidth > this.getWidth($sub)) {
$sub.removeClass('sm-nowrap').css('width', this.opts.subMenusMaxWidth);
}
}
// IE6,7
} else {
$sub.children().css('styleFloat', 'none');
if (IE6) {
$sub.width(this.opts.subMenusMinWidth ? this.opts.subMenusMinWidth : 1)
.children().children('a').css('white-space', 'nowrap');
} else { // IE7
$sub.css({ width: ($sub.hasClass('mega-menu-inner')) ? $('.box-container').outerWidth() + 'px' : 'auto', minWidth: '', maxWidth: '' }).addClass('sm-nowrap');
if (this.opts.subMenusMinWidth) {
$sub.css('min-width', this.opts.subMenusMinWidth);
}
}
if (this.opts.subMenusMaxWidth) {
var noMaxWidth = $sub.width();
if (IE6) {
var maxWidth = $sub.css({ width: this.opts.subMenusMaxWidth, overflowX: 'hidden', overflowY: 'hidden' }).width();
if (noMaxWidth > maxWidth) {
$sub.css({ width: maxWidth, overflowX: 'visible', overflowY: 'visible' }).children().children('a').css('white-space', '');
} else {
$sub.css({ width: noMaxWidth, overflowX: 'visible', overflowY: 'visible' });
}
} else { // IE7
$sub.css('max-width', this.opts.subMenusMaxWidth);
if (noMaxWidth > $sub.width()) {
$sub.removeClass('sm-nowrap').css('width', this.opts.subMenusMaxWidth);
} else {
$sub.width(noMaxWidth);
}
}
} else {
$sub.width($sub.width());
}
$sub.children().css('styleFloat', 'left');
}
}
this.menuPosition($sub);
// insert IE iframe shim
if ($sub.dataSM('ie-shim')) {
$sub.dataSM('ie-shim').insertBefore($sub);
}
var complete = function() {
// fix: "overflow: hidden;" is not reset on animation complete in jQuery < 1.9.0 in Chrome when global "box-sizing: border-box;" is used
$sub.css('overflow', '');
};
// if sub is collapsible (mobile view)
if (this.isCollapsible()) {
if (this.opts.collapsibleShowFunction) {
this.opts.collapsibleShowFunction.call(this, $sub, complete);
} else {
$sub.show(this.opts.collapsibleShowDuration, complete);
}
} else {
if (this.opts.showFunction) {
this.opts.showFunction.call(this, $sub, complete);
} else {
$sub.show(this.opts.showDuration, complete);
}
}
// save new sub menu for this level
this.visibleSubMenus[$sub.dataSM('level') - 1] = $sub;
this.$root.triggerHandler('show.smapi', $sub[0]);
}
},
popupHide: function(noHideTimeout) {
if (this.hideTimeout) {
clearTimeout(this.hideTimeout);
this.hideTimeout = 0;
}
var self = this;
this.hideTimeout = setTimeout(function() {
self.menuHideAll();
}, noHideTimeout ? 1 : this.opts.hideTimeout);
},
popupShow: function(left, top) {
if (!this.opts.isPopup) {
alert('SmartMenus jQuery Error:\n\nIf you want to show this menu via the "popupShow" method, set the isPopup:true option.');
return;
}
if (this.hideTimeout) {
clearTimeout(this.hideTimeout);
this.hideTimeout = 0;
}
this.menuFixLayout(this.$root);
this.$root.stop(true, true);
if (!this.$root.is(':visible')) {
this.$root.css({ left: left, top: top });
// IE iframe shim
this.menuIframeShim(this.$root);
if (this.$root.dataSM('ie-shim')) {
this.$root.dataSM('ie-shim').css({ zIndex: this.$root.css('z-index'), width: this.getWidth(this.$root), height: this.getHeight(this.$root), left: left, top: top }).insertBefore(this.$root);
}
// show menu
if (this.opts.showFunction) {
this.opts.showFunction.call(this, this.$root);
} else {
this.$root.show(this.opts.showDuration);
}
this.visibleSubMenus[0] = this.$root;
}
},
refresh: function() {
this.menuHideAll();
this.$root.find('ul').each(function() {
var $this = $(this);
if ($this.dataSM('scroll-arrows')) {
$this.dataSM('scroll-arrows').remove();
}
})
.removeDataSM('in-mega')
.removeDataSM('shown-before')
.removeDataSM('ie-shim')
.removeDataSM('scroll-arrows')
.removeDataSM('parent-a')
.removeDataSM('level')
.removeDataSM('beforefirstshowfired');
this.$root.find('a.has-submenu').removeClass('has-submenu')
.parent().removeDataSM('sub');
if (this.opts.subIndicators) {
this.$root.find('span.sub-arrow').remove();
}
if (this.opts.markCurrentItem) {
this.$root.find('a.current').removeClass('current');
}
this.subMenus = [];
this.init(true);
},
rootOut: function(e) {
if (!this.handleEvents() || this.isTouchMode() || e.target == this.$root[0]) {
return;
}
if (this.hideTimeout) {
clearTimeout(this.hideTimeout);
this.hideTimeout = 0;
}
if (!this.opts.showOnClick || !this.opts.hideOnClick) {
var self = this;
this.hideTimeout = setTimeout(function() { self.menuHideAll(); }, this.opts.hideTimeout);
}
},
rootOver: function(e) {
if (!this.handleEvents() || this.isTouchMode() || e.target == this.$root[0]) {
return;
}
if (this.hideTimeout) {
clearTimeout(this.hideTimeout);
this.hideTimeout = 0;
}
},
winResize: function(e) {
if (!this.handleEvents()) {
// we still need to resize the disable overlay if it's visible
if (this.$disableOverlay) {
var pos = this.$root.offset();
this.$disableOverlay.css({
top: pos.top,
left: pos.left,
width: this.$root.outerWidth(),
height: this.$root.outerHeight()
});
}
return;
}
// hide sub menus on resize - on mobile do it only on orientation change
if (!this.isCollapsible() && (!('onorientationchange' in window) || e.type == 'orientationchange')) {
if (this.activatedItems.length) {
this.activatedItems[this.activatedItems.length - 1][0].blur();
}
this.menuHideAll();
}
}
}
});
$.fn.dataSM = function(key, val) {
if (val) {
return this.data(key + '_smartmenus', val);
}
return this.data(key + '_smartmenus');
}
$.fn.removeDataSM = function(key) {
return this.removeData(key + '_smartmenus');
}
$.fn.smartmenus = function(options) {
if (typeof options == 'string') {
var args = arguments,
method = options;
Array.prototype.shift.call(args);
return this.each(function() {
var smartmenus = $(this).data('smartmenus');
if (smartmenus && smartmenus[method]) {
smartmenus[method].apply(smartmenus, args);
}
});
}
var opts = $.extend({}, $.fn.smartmenus.defaults, options);
return this.each(function() {
new $.SmartMenus(this, opts);
});
}
// default settings
$.fn.smartmenus.defaults = {
isPopup: false, // is this a popup menu (can be shown via the popupShow/popupHide methods) or a permanent menu bar
mainMenuSubOffsetX: 0, // pixels offset from default position
mainMenuSubOffsetY: 0, // pixels offset from default position
subMenusSubOffsetX: 0, // pixels offset from default position
subMenusSubOffsetY: 0, // pixels offset from default position
subMenusMinWidth: '10em', // min-width for the sub menus (any CSS unit) - if set, the fixed width set in CSS will be ignored
subMenusMaxWidth: '20em', // max-width for the sub menus (any CSS unit) - if set, the fixed width set in CSS will be ignored
subIndicators: true, // create sub menu indicators - creates a SPAN and inserts it in the A
subIndicatorsPos: 'prepend', // position of the SPAN relative to the menu item content ('prepend', 'append')
subIndicatorsText: '+', // [optionally] add text in the SPAN (e.g. '+') (you may want to check the CSS for the sub indicators too)
scrollStep: 30, // pixels step when scrolling long sub menus that do not fit in the viewport height
scrollInterval: 30, // interval between each scrolling step
scrollAccelerate: true, // accelerate scrolling or use a fixed step
showTimeout: 250, // timeout before showing the sub menus
hideTimeout: 500, // timeout before hiding the sub menus
showDuration: 0, // duration for show animation - set to 0 for no animation - matters only if showFunction:null
showFunction: null, // custom function to use when showing a sub menu (the default is the jQuery 'show')
// don't forget to call complete() at the end of whatever you do
// e.g.: function($ul, complete) { $ul.fadeIn(250, complete); }
hideDuration: 0, // duration for hide animation - set to 0 for no animation - matters only if hideFunction:null
hideFunction: function($ul, complete) { $ul.fadeOut(200, complete); }, // custom function to use when hiding a sub menu (the default is the jQuery 'hide')
// don't forget to call complete() at the end of whatever you do
// e.g.: function($ul, complete) { $ul.fadeOut(250, complete); }
collapsibleShowDuration:0, // duration for show animation for collapsible sub menus - matters only if collapsibleShowFunction:null
collapsibleShowFunction:function($ul, complete) { $ul.slideDown(200, complete); }, // custom function to use when showing a collapsible sub menu
// (i.e. when mobile styles are used to make the sub menus collapsible)
collapsibleHideDuration:0, // duration for hide animation for collapsible sub menus - matters only if collapsibleHideFunction:null
collapsibleHideFunction:function($ul, complete) { $ul.slideUp(200, complete); }, // custom function to use when hiding a collapsible sub menu
// (i.e. when mobile styles are used to make the sub menus collapsible)
showOnClick: false, // show the first-level sub menus onclick instead of onmouseover (matters only for mouse input)
hideOnClick: true, // hide the sub menus on click/tap anywhere on the page
keepInViewport: true, // reposition the sub menus if needed to make sure they always appear inside the viewport
keepHighlighted: true, // keep all ancestor items of the current sub menu highlighted (adds the 'highlighted' class to the A's)
markCurrentItem: false, // automatically add the 'current' class to the A element of the item linking to the current URL
markCurrentTree: true, // add the 'current' class also to the A elements of all ancestor items of the current item
rightToLeftSubMenus: false, // right to left display of the sub menus (check the CSS for the sub indicators' position)
bottomToTopSubMenus: false, // bottom to top display of the sub menus
overlapControlsInIE: true // make sure sub menus appear on top of special OS controls in IE (i.e. SELECT, OBJECT, EMBED, etc.)
};
})(jQuery);
/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*
* Uses the built in easing capabilities added In jQuery 1.1
* to offer multiple easing options
*
* TERMS OF USE - jQuery Easing
*
* Open source under the BSD License.
*
* Copyright © 2008 George McGinley Smith
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the author nor the names of contributors may be used to endorse
* or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
//alert(jQuery.easing.default);
return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInCubic: function (x, t, b, c, d) {
return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
easeInQuart: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t + b;
},
easeOutQuart: function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeInOutQuart: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeInQuint: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
},
easeOutQuint: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeInOutQuint: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeInSine: function (x, t, b, c, d) {
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
easeOutSine: function (x, t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
},
easeInOutSine: function (x, t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
easeInExpo: function (x, t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
easeOutExpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeInOutExpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function (x, t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeInElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
easeOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
easeInOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
easeInBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeInOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeInBounce: function (x, t, b, c, d) {
return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
easeInOutBounce: function (x, t, b, c, d) {
if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});
/*
*
* TERMS OF USE - EASING EQUATIONS
*
* Open source under the BSD License.
*
* Copyright © 2001 Robert Penner
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the author nor the names of contributors may be used to endorse
* or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
(function($, window, undefined) {
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
var lastTime = 0,
running,
animate = function (elem) {
if (running) {
window.requestAnimationFrame(animate, elem);
jQuery.fx.tick();
}
},
vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(fn, element) {
var currTime = new Date().getTime(),
delta = currTime - lastTime,
timeToCall = Math.max(0, 16 - delta);
var id = window.setTimeout(function() {
fn(currTime + timeToCall);
},
timeToCall
);
lastTime = currTime + timeToCall;
return id;
};
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
jQuery.fx.timer = function (timer) {
if (timer() && jQuery.timers.push(timer) && !running) {
running = true;
animate(timer.elem);
}
};
jQuery.fx.stop = function() {
running = false;
};
}(jQuery, this));
/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
* Thanks to: Seamus Leahy for adding deltaX and deltaY
*
* Version: 3.0.6
*
* Requires: 1.2.2+
*/
(function($) {
var types = ['DOMMouseScroll', 'mousewheel'];
if ($.event.fixHooks) {
for (var i = types.length; i;) {
$.event.fixHooks[types[--i]] = $.event.mouseHooks;
}
}
$.event.special.mousewheel = {
setup: function() {
if (this.addEventListener) {
for (var i = types.length; i;) {
this.addEventListener(types[--i], handler, false);
}
} else {
this.onmousewheel = handler;
}
},
teardown: function() {
if (this.removeEventListener) {
for (var i = types.length; i;) {
this.removeEventListener(types[--i], handler, false);
}
} else {
this.onmousewheel = null;
}
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
},
unmousewheel: function(fn) {
return this.unbind("mousewheel", fn);
}
});
function handler(event) {
var orgEvent = event || window.event,
args = [].slice.call(arguments, 1),
delta = 0,
returnValue = true,
deltaX = 0,
deltaY = 0;
event = $.event.fix(orgEvent);
event.type = "mousewheel";
// Old school scrollwheel delta
if (orgEvent.wheelDelta) {
delta = orgEvent.wheelDelta / 120;
}
if (orgEvent.detail) {
delta = -orgEvent.detail / 3;
}
// New school multidimensional scroll (touchpads) deltas
deltaY = delta;
// Gecko
if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
deltaY = 0;
deltaX = -1 * delta;
}
// Webkit
if (orgEvent.wheelDeltaY !== undefined) {
deltaY = orgEvent.wheelDeltaY / 120;
}
if (orgEvent.wheelDeltaX !== undefined) {
deltaX = -1 * orgEvent.wheelDeltaX / 120;
}
// Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
})(jQuery);
/**
* jQuery iLightBox - Revolutionary Lightbox Plugin
* http://www.ilightbox.net/
*
* @version: 2.2.4 - October 14, 2017
*
* @author: iProDev (Hemn Chawroka)
* http://www.iprodev.com/
*
*/
(function($, window, undefined) {
var extensions = {
flash: ['swf'],
image: ['bmp', 'gif', 'jpeg', 'jpg', 'png', 'tiff', 'tif', 'jfif', 'jpe'],
iframe: ['asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'jsp', 'php', 'pl', 'php3', 'php4', 'php5', 'phtml', 'rb', 'rhtml', 'shtml', 'txt'],
video: ['avi', 'mov', 'mpg', 'mpeg', 'movie', 'mp4', 'webm', 'ogv', 'ogg', '3gp', 'm4v']
},
// Global DOM elements
$win = $(window),
$doc = $(document),
// Support indicators
browser,
transform,
gpuAcceleration,
fullScreenApi = '',
userAgent = navigator.userAgent || navigator.vendor || window.opera,
supportTouch = !!('ontouchstart' in window) && (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)),
isMobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(userAgent.substr(0, 4)),
// Events
clickEvent = supportTouch ? "itap.iLightBox" : "click.iLightBox",
touchStartEvent = supportTouch ? "touchstart.iLightBox" : "mousedown.iLightBox",
touchStopEvent = supportTouch ? "touchend.iLightBox" : "mouseup.iLightBox",
touchMoveEvent = supportTouch ? "touchmove.iLightBox" : "mousemove.iLightBox",
// Math shorthands
abs = Math.abs,
sqrt = Math.sqrt,
round = Math.round,
max = Math.max,
min = Math.min,
floor = Math.floor,
random = Math.random,
pluginspages = {
quicktime: 'http://www.apple.com/quicktime/download',
flash: 'http://www.adobe.com/go/getflash'
},
iLightBox = function(el, options, items, instant) {
var iL = this;
iL.options = options,
iL.selector = el.selector || el,
iL.context = el.context,
iL.instant = instant;
if (items.length < 1) iL.attachItems();
else iL.items = items;
iL.vars = {
total: iL.items.length,
start: 0,
current: null,
next: null,
prev: null,
BODY: $('body'),
loadRequests: 0,
overlay: $('<div class="ilightbox-overlay"></div>'),
loader: $('<div class="ilightbox-loader"><div></div></div>'),
toolbar: $('<div class="ilightbox-toolbar"></div>'),
innerToolbar: $('<div class="ilightbox-inner-toolbar"></div>'),
title: $('<div class="ilightbox-title"></div>'),
closeButton: $('<a class="ilightbox-close" title="' + iL.options.text.close + '"></a>'),
fullScreenButton: $('<a class="ilightbox-fullscreen" title="' + iL.options.text.enterFullscreen + '"></a>'),
innerPlayButton: $('<a class="ilightbox-play" title="' + iL.options.text.slideShow + '"></a>'),
innerNextButton: $('<a class="ilightbox-next-button" title="' + iL.options.text.next + '"></a>'),
innerPrevButton: $('<a class="ilightbox-prev-button" title="' + iL.options.text.previous + '"></a>'),
holder: $('<div class="ilightbox-holder' + (supportTouch ? ' supportTouch' : '') + '" ondragstart="return false;"><div class="ilightbox-container"></div></div>'),
nextPhoto: $('<div class="ilightbox-holder' + (supportTouch ? ' supportTouch' : '') + ' ilightbox-next" ondragstart="return false;"><div class="ilightbox-container"></div></div>'),
prevPhoto: $('<div class="ilightbox-holder' + (supportTouch ? ' supportTouch' : '') + ' ilightbox-prev" ondragstart="return false;"><div class="ilightbox-container"></div></div>'),
nextButton: $('<a class="ilightbox-button ilightbox-next-button" ondragstart="return false;" title="' + iL.options.text.next + '"><span></span></a>'),
prevButton: $('<a class="ilightbox-button ilightbox-prev-button" ondragstart="return false;" title="' + iL.options.text.previous + '"><span></span></a>'),
thumbnails: $('<div class="ilightbox-thumbnails" ondragstart="return false;"><div class="ilightbox-thumbnails-container"><a class="ilightbox-thumbnails-dragger"></a><div class="ilightbox-thumbnails-grid"></div></div></div>'),
thumbs: false,
nextLock: false,
prevLock: false,
hashLock: false,
isMobile: false,
mobileMaxWidth: 980,
isInFullScreen: false,
isSwipe: false,
mouseID: 0,
cycleID: 0,
isPaused: 0,
captionHeight: 39,
};
// Hideable elements with mousemove event
iL.vars.hideableElements = iL.vars.nextButton.add(iL.vars.prevButton);
iL.normalizeItems();
//Check necessary plugins
iL.availPlugins();
//Set startFrom
iL.options.startFrom = (iL.options.startFrom > 0 && iL.options.startFrom >= iL.vars.total) ? iL.vars.total - 1 : iL.options.startFrom;
//If randomStart
iL.options.startFrom = (iL.options.randomStart) ? floor(random() * iL.vars.total) : iL.options.startFrom;
iL.vars.start = iL.options.startFrom;
if (instant) iL.instantCall();
else iL.patchItemsEvents();
if (iL.options.linkId) {
iL.hashChangeHandler();
$win.iLightBoxHashChange(function() {
iL.hashChangeHandler();
});
}
if (supportTouch) {
var RegExp = /(click|mouseenter|mouseleave|mouseover|mouseout)/ig,
replace = "itap";
iL.options.caption.show = iL.options.caption.show.replace(RegExp, replace),
iL.options.caption.hide = iL.options.caption.hide.replace(RegExp, replace),
iL.options.social.show = iL.options.social.show.replace(RegExp, replace),
iL.options.social.hide = iL.options.social.hide.replace(RegExp, replace);
}
if (iL.options.controls.arrows || $(window).width() < UNCODE.mediaQuery) {
$.extend(iL.options.styles, {
nextOffsetX: ($(window).width() > UNCODE.mediaQuery) ? 36 : 4,
prevOffsetX: ($(window).width() > UNCODE.mediaQuery) ? 36 : 4,
nextOpacity: 0,
prevOpacity: 0
});
}
};
//iLightBox helpers
iLightBox.prototype = {
showLoader: function() {
var iL = this;
iL.vars.loadRequests += 1;
if (iL.options.path.toLowerCase() == "horizontal") iL.vars.loader.addClass('ilightbox-show').stop().animate({
//top: '-30px'
opacity: '1'
}, iL.options.show.speed, 'easeOutCirc');
else iL.vars.loader.addClass('ilightbox-show').stop().animate({
//left: '-30px'
opacity: '1'
}, iL.options.show.speed, 'easeOutCirc');
},
hideLoader: function() {
var iL = this;
iL.vars.loadRequests -= 1;
iL.vars.loadRequests = (iL.vars.loadRequests < 0) ? 0 : iL.vars.loadRequests;
if (iL.options.path.toLowerCase() == "horizontal") {
if (iL.vars.loadRequests <= 0) iL.vars.loader.removeClass('ilightbox-show').stop().animate({
//top: '-192px'
opacity: '0'
}, iL.options.show.speed, 'easeInCirc');
} else {
if (iL.vars.loadRequests <= 0) iL.vars.loader.removeClass('ilightbox-show').stop().animate({
//left: '-192px'
opacity: '0'
}, iL.options.show.speed, 'easeInCirc');
}
},
createUI: function() {
var iL = this;
iL.ui = {
currentElement: iL.vars.holder,
nextElement: iL.vars.nextPhoto,
prevElement: iL.vars.prevPhoto,
currentItem: iL.vars.current,
nextItem: iL.vars.next,
prevItem: iL.vars.prev,
hide: function() {
iL.closeAction();
},
refresh: function() {
(arguments.length > 0) ? iL.repositionPhoto(true): iL.repositionPhoto();
},
fullscreen: function() {
iL.fullScreenAction();
}
};
},
attachItems: function() {
var iL = this,
itemsObject = new Array(),
items = new Array();
$(iL.selector, iL.context).each(function() {
var t = $(this),
URL = t.attr(iL.options.attr) || null,
options = t.data("options") && eval("({" + t.data("options") + "})") || {},
caption = t.data('caption'),
title = t.data('title'),
type = t.data('type') || getTypeByExtension(URL),
clone = t.data('lbox-clone') || false;
if (t.data('lbox-clone') != undefined) return;
//Uncode addition ##START##
if ( typeof t.attr('data-album') != 'undefined' && t.attr('data-album') != '' ) {
var ALBUM_URLS = JSON.parse(t.attr('data-album')),
URL_i,
URLS_LENGHT = ALBUM_URLS.length;
for (URL_i = 0; URL_i < URLS_LENGHT; URL_i++) {
if ( typeof ALBUM_URLS[URL_i].url !== 'undefined' && ALBUM_URLS[URL_i].url != '' ) {
var item_opts = 'width:' + ALBUM_URLS[URL_i].width + ',height:' + ALBUM_URLS[URL_i].height + ',thumbnail: \'' + ALBUM_URLS[URL_i].thumbnail + '\'';
item_opts = item_opts && eval("({" + item_opts + "})") || {},
items.push({
URL: ALBUM_URLS[URL_i].url,
caption: ALBUM_URLS[URL_i].caption,
title: ALBUM_URLS[URL_i].title,
type: getTypeByExtension(ALBUM_URLS[URL_i].url),
options: item_opts,
clone: clone
});
var newT = t;
newT.attr('href',ALBUM_URLS[URL_i].url);
if (!iL.instant) itemsObject.push(newT);
}
}
} else {
//Uncode addition ##END##
items.push({
URL: URL,
caption: caption,
title: title,
type: type,
options: options,
clone: clone
});
}
if (iL.vars != undefined) iL.vars.total = items.length;
if (!iL.instant) itemsObject.push(t);
});
iL.items = items,
iL.itemsObject = itemsObject;
},
normalizeItems: function() {
var iL = this,
newItems = new Array();
$.each(iL.items, function(key, val) {
if (typeof val == "string") val = {
url: val
};
var URL = val.url || val.URL || null,
options = val.options || {},
caption = val.caption || null,
title = val.title || null,
type = (val.type) ? val.type.toLowerCase() : getTypeByExtension(URL),
ext = (typeof URL != 'object') ? getExtension(URL) : '';
options.thumbnail = options.thumbnail || ((type == "image") ? URL : null),
options.videoType = options.videoType || null,
options.skin = options.skin || iL.options.skin,
options.width = options.width || null,
options.height = options.height || null,
options.mousewheel = (typeof options.mousewheel != 'undefined') ? options.mousewheel : true,
options.swipe = (typeof options.swipe != 'undefined') ? options.swipe : true,
options.social = (typeof options.social != 'undefined') ? options.social : iL.options.social.buttons && $.extend({}, {}, iL.options.social.buttons);
if (type == "video") {
options.html5video = (typeof options.html5video != 'undefined') ? options.html5video : {};
options.html5video.webm = options.html5video.webm || options.html5video.WEBM || null;
options.html5video.controls = (typeof options.html5video.controls != 'undefined') ? options.html5video.controls : "controls";
options.html5video.preload = options.html5video.preload || "metadata";
options.html5video.autoplay = (typeof options.html5video.autoplay != 'undefined') ? options.html5video.autoplay : false;
//UNCODE addition
options.html5video.loop = (typeof options.html5video.loop != 'undefined') ? options.html5video.loop : false;
}
if (!options.width || !options.height) {
if (type == "video") options.width = 1280, options.height = 720;
else if (type == "iframe") options.width = '100%', options.height = '90%';
else if (type == "flash") options.width = 1280, options.height = 720;
}
delete val.url;
val.index = key;
val.URL = URL;
val.caption = caption;
val.title = title;
val.type = type;
val.options = options;
val.ext = ext;
newItems.push(val);
});
iL.items = newItems;
},
instantCall: function() {
var iL = this,
key = iL.vars.start;
iL.vars.current = key;
iL.vars.next = (iL.items[key + 1]) ? key + 1 : null;
iL.vars.prev = (iL.items[key - 1]) ? key - 1 : null;
iL.addContents();
iL.patchEvents();
},
addContents: function() {
var iL = this,
vars = iL.vars,
opts = iL.options,
viewport = getViewport(),
path = opts.path.toLowerCase(),
recognizingItems = vars.total > 0 && iL.items.filter(function(e, i, arr) {
return ['image', 'flash', 'video'].indexOf(e.type) === -1 && typeof e.recognized === 'undefined' && (opts.smartRecognition || e.options.smartRecognition);
}),
needRecognition = recognizingItems.length > 0;
if (opts.mobileOptimizer && !opts.innerToolbar)
vars.isMobile = viewport.width <= vars.mobileMaxWidth;
vars.overlay.addClass(opts.skin).hide().css('opacity', opts.overlay.opacity);
if (opts.linkId)
vars.overlay[0].setAttribute('linkid', opts.linkId);
//Add Toolbar Buttons
if (opts.controls.toolbar) {
vars.toolbar.addClass(opts.skin).append(vars.closeButton);
if (opts.controls.fullscreen)
vars.toolbar.append(vars.fullScreenButton);
if (opts.controls.slideshow)
vars.toolbar.append(vars.innerPlayButton);
if (vars.total > 1)
vars.toolbar.append(vars.innerPrevButton).append(vars.innerNextButton);
}
//Append elements to body
vars.BODY.addClass('ilightbox-noscroll').append(vars.overlay).append(vars.loader).append(vars.holder).append(vars.nextPhoto).append(vars.prevPhoto);
if (!opts.innerToolbar)
vars.BODY.append(vars.toolbar);
if (opts.controls.arrows)
vars.BODY.append(vars.nextButton).append(vars.prevButton);
if (opts.controls.thumbnail && vars.total > 1) {
vars.BODY.append(vars.thumbnails);
vars.thumbnails.addClass(opts.skin).addClass('ilightbox-' + path);
$('div.ilightbox-thumbnails-grid', vars.thumbnails).empty();
vars.thumbs = true;
}
//Configure loader and arrows
var loaderCss = (opts.path.toLowerCase() == "horizontal") ? {
left: parseInt((viewport.width / 2) - (vars.loader.outerWidth() / 2))
} : {
top: parseInt((viewport.height / 2) - (vars.loader.outerHeight() / 2))
};
vars.loader.addClass(opts.skin).css(loaderCss);
vars.nextButton.add(vars.prevButton).addClass(opts.skin);
if (path == "horizontal")
vars.loader.add(vars.nextButton).add(vars.prevButton).addClass('horizontal');
// Configure arrow buttons
vars.BODY[vars.isMobile ? 'addClass' : 'removeClass']('isMobile');
if (!opts.infinite) {
vars.prevButton.add(vars.prevButton).add(vars.innerPrevButton).add(vars.innerNextButton).removeClass('disabled');
if (vars.current == 0)
vars.prevButton.add(vars.innerPrevButton).addClass('disabled');
if (vars.current >= vars.total - 1)
vars.nextButton.add(vars.innerNextButton).addClass('disabled');
}
if (opts.show.effect) {
vars.overlay.stop().fadeIn(opts.show.speed);
vars.toolbar.stop().fadeIn(opts.show.speed);
} else {
vars.overlay.show();
vars.toolbar.show();
}
var length = recognizingItems.length;
if (needRecognition) {
iL.showLoader();
$.each(recognizingItems, function(key, val) {
var resultFnc = function(result) {
var key = -1,
filter = iL.items.filter(function(e, i, arr) {
if (e.URL == result.url)
key = i;
return e.URL == result.url;
}),
self = iL.items[key];
if (result)
$.extend(true, self, {
URL: result.source,
type: result.type,
recognized: true,
options: {
html5video: result.html5video,
width: (result.type == "image") ? 0 : (result.width || self.width),
height: (result.type == "image") ? 0 : (result.height || self.height),
thumbnail: self.options.thumbnail || result.thumbnail
}
});
length--;
if (length == 0) {
iL.hideLoader();
vars.dontGenerateThumbs = false;
iL.generateThumbnails();
if (opts.show.effect)
setTimeout(function() {
iL.generateBoxes();
}, opts.show.speed);
else
iL.generateBoxes();
}
};
iL.ogpRecognition(this, resultFnc);
});
}
else {
if (opts.show.effect)
setTimeout(function() {
iL.generateBoxes();
}, opts.show.speed);
else
iL.generateBoxes();
}
iL.createUI();
window.iLightBox = {
close: function() {
iL.closeAction();
},
fullscreen: function() {
iL.fullScreenAction();
},
moveNext: function() {
iL.moveTo('next');
},
movePrev: function() {
iL.moveTo('prev');
},
goTo: function(index) {
iL.goTo(index);
},
refresh: function() {
iL.refresh();
},
reposition: function() {
(arguments.length > 0) ? iL.repositionPhoto(true): iL.repositionPhoto();
},
setOption: function(options) {
iL.setOption(options);
},
destroy: function() {
iL.closeAction();
iL.dispatchItemsEvents();
}
};
if (opts.linkId) {
vars.hashLock = true;
window.location.hash = opts.linkId + '/' + vars.current;
setTimeout(function() {
vars.hashLock = false;
}, 55);
}
if (!opts.slideshow.startPaused) {
iL.resume();
vars.innerPlayButton.removeClass('ilightbox-play').addClass('ilightbox-pause');
}
//Trigger the onOpen callback
if (typeof iL.options.callback.onOpen == 'function') iL.options.callback.onOpen.call(iL);
},
loadContent: function(obj, opt, speed) {
var iL = this,
holder, item;
iL.createUI();
obj.speed = speed || iL.options.effects.loadedFadeSpeed;
if (opt == 'current') {
if (!obj.options.mousewheel) iL.vars.lockWheel = true;
else iL.vars.lockWheel = false;
if (!obj.options.swipe) iL.vars.lockSwipe = true;
else iL.vars.lockSwipe = false;
}
switch (opt) {
case 'current':
holder = iL.vars.holder, item = iL.vars.current;
break;
case 'next':
holder = iL.vars.nextPhoto, item = iL.vars.next;
break;
case 'prev':
holder = iL.vars.prevPhoto, item = iL.vars.prev;
break;
}
holder.removeAttr('style class').addClass('ilightbox-holder' + (supportTouch ? ' supportTouch' : '')).addClass(obj.options.skin);
$('div.ilightbox-inner-toolbar', holder).remove();
if (obj.title || iL.options.innerToolbar) {
var innerToolbar = iL.vars.innerToolbar.clone();
if (obj.title && iL.options.show.title) {
var title = iL.vars.title.clone();
title.empty().html(obj.title);
innerToolbar.append(title);
}
if (iL.options.innerToolbar) {
innerToolbar.append((iL.vars.total > 1) ? iL.vars.toolbar.clone() : iL.vars.toolbar);
}
holder.prepend(innerToolbar);
}
//console.warn('loadContent', arguments);
iL.loadSwitcher(obj, holder, item, opt);
},
loadSwitcher: function(obj, holder, item, opt) {
var iL = this,
opts = iL.options,
api = {
element: holder,
position: item
};
switch (obj.type) {
case 'image':
//Trigger the onBeforeLoad callback
if (typeof opts.callback.onBeforeLoad == 'function') opts.callback.onBeforeLoad.call(iL, iL.ui, item);
if (typeof obj.options.onBeforeLoad == 'function') obj.options.onBeforeLoad.call(iL, api);
iL.loadImage(obj.URL, function(img) {
//Trigger the onAfterLoad callback
if (typeof opts.callback.onAfterLoad == 'function') opts.callback.onAfterLoad.call(iL, iL.ui, item);
if (typeof obj.options.onAfterLoad == 'function') obj.options.onAfterLoad.call(iL, api);
var width = (img) ? img.width : 400,
height = (img) ? img.height : 200;
holder.data({
naturalWidth: width,
naturalHeight: height
});
$('div.ilightbox-container', holder).empty().append((img) ? '<img src="' + obj.URL + '" class="ilightbox-image" />' : '<span class="ilightbox-alert">' + opts.errors.loadImage + '</span>');
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
iL.configureHolder(obj, opt, holder);
});
break;
case 'video':
holder.data({
naturalWidth: obj.options.width,
naturalHeight: obj.options.height
});
if (opt === 'current') {
iL.addContent(holder, obj);
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
} else {
$('div.ilightbox-container', holder).empty();
}
iL.configureHolder(obj, opt, holder);
break;
case 'iframe':
//iL.showLoader();
holder.data({
naturalWidth: obj.options.width,
naturalHeight: obj.options.height
});
iL.configureHolder(obj, opt, holder);
if (opt === 'current') {
var el = iL.addContent(holder, obj);
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
//Trigger the onBeforeLoad callback
if (typeof opts.callback.onBeforeLoad == 'function') opts.callback.onBeforeLoad.call(iL, iL.ui, item);
if (typeof obj.options.onBeforeLoad == 'function') obj.options.onBeforeLoad.call(iL, api);
el.bind('load', function() {
//Trigger the onAfterLoad callback
if (typeof opts.callback.onAfterLoad == 'function') opts.callback.onAfterLoad.call(iL, iL.ui, item);
if (typeof obj.options.onAfterLoad == 'function') obj.options.onAfterLoad.call(iL, api);
//iL.hideLoader();
el.unbind('load');
});
} else {
$('div.ilightbox-container', holder).empty();
}
break;
case 'inline':
var el = $(obj.URL),
content = iL.addContent(holder, obj),
images = findImageInElement(holder);
holder.data({
naturalWidth: (iL.items[item].options.width || el.outerWidth()),
naturalHeight: (iL.items[item].options.height || el.outerHeight())
});
content.children().eq(0).show();
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
//Trigger the onBeforeLoad callback
if (typeof opts.callback.onBeforeLoad == 'function') opts.callback.onBeforeLoad.call(iL, iL.ui, item);
if (typeof obj.options.onBeforeLoad == 'function') obj.options.onBeforeLoad.call(iL, api);
iL.loadImage(images, function() {
//Trigger the onAfterLoad callback
if (typeof opts.callback.onAfterLoad == 'function') opts.callback.onAfterLoad.call(iL, iL.ui, item);
if (typeof obj.options.onAfterLoad == 'function') obj.options.onAfterLoad.call(iL, api);
iL.configureHolder(obj, opt, holder);
});
break;
case 'flash':
var el = iL.addContent(holder, obj);
holder.data({
naturalWidth: (iL.items[item].options.width || el.outerWidth()),
naturalHeight: (iL.items[item].options.height || el.outerHeight())
});
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
iL.configureHolder(obj, opt, holder);
break;
case 'ajax':
var ajax = obj.options.ajax || {};
//Trigger the onBeforeLoad callback
if (typeof opts.callback.onBeforeLoad == 'function') opts.callback.onBeforeLoad.call(iL, iL.ui, item);
if (typeof obj.options.onBeforeLoad == 'function') obj.options.onBeforeLoad.call(iL, api);
iL.showLoader();
$.ajax({
url: obj.URL || opts.ajaxSetup.url,
data: ajax.data || null,
dataType: ajax.dataType || "html",
type: ajax.type || opts.ajaxSetup.type,
cache: ajax.cache || opts.ajaxSetup.cache,
crossDomain: ajax.crossDomain || opts.ajaxSetup.crossDomain,
global: ajax.global || opts.ajaxSetup.global,
ifModified: ajax.ifModified || opts.ajaxSetup.ifModified,
username: ajax.username || opts.ajaxSetup.username,
password: ajax.password || opts.ajaxSetup.password,
beforeSend: ajax.beforeSend || opts.ajaxSetup.beforeSend,
complete: ajax.complete || opts.ajaxSetup.complete,
success: function(data, textStatus, jqXHR) {
iL.hideLoader();
var el = $(data),
container = $('div.ilightbox-container', holder),
elWidth = iL.items[item].options.width || parseInt(el[0].getAttribute('width')),
elHeight = iL.items[item].options.height || parseInt(el[0].getAttribute('height')),
css = (el[0].getAttribute('width') && el[0].getAttribute('height')) ? {
'overflow': 'hidden'
} : {};
container.empty().append($('<div class="ilightbox-wrapper"></div>').css(css).html(el));
holder.show().data({
naturalWidth: (elWidth || container.outerWidth()),
naturalHeight: (elHeight || container.outerHeight())
}).hide();
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
var images = findImageInElement(holder);
iL.loadImage(images, function() {
//Trigger the onAfterLoad callback
if (typeof opts.callback.onAfterLoad == 'function') opts.callback.onAfterLoad.call(iL, iL.ui, item);
if (typeof obj.options.onAfterLoad == 'function') obj.options.onAfterLoad.call(iL, api);
iL.configureHolder(obj, opt, holder);
});
opts.ajaxSetup.success(data, textStatus, jqXHR);
if (typeof ajax.success == 'function') ajax.success(data, textStatus, jqXHR);
},
error: function(jqXHR, textStatus, errorThrown) {
//Trigger the onAfterLoad callback
if (typeof opts.callback.onAfterLoad == 'function') opts.callback.onAfterLoad.call(iL, iL.ui, item);
if (typeof obj.options.onAfterLoad == 'function') obj.options.onAfterLoad.call(iL, api);
iL.hideLoader();
$('div.ilightbox-container', holder).empty().append('<span class="ilightbox-alert">' + opts.errors.loadContents + '</span>');
iL.configureHolder(obj, opt, holder);
opts.ajaxSetup.error(jqXHR, textStatus, errorThrown);
if (typeof ajax.error == 'function') ajax.error(jqXHR, textStatus, errorThrown);
}
});
break;
case 'html':
var object = obj.URL,
el
container = $('div.ilightbox-container', holder);
if (object[0].nodeName) el = object.clone();
else {
var dom = $(object);
if (dom.selector) el = $('<div>' + dom + '</div>');
else el = dom;
}
var elWidth = iL.items[item].options.width || parseInt(el.attr('width')),
elHeight = iL.items[item].options.height || parseInt(el.attr('height'));
iL.addContent(holder, obj);
el.appendTo(document.documentElement).hide();
//Trigger the onRender callback
if (typeof opts.callback.onRender == 'function') opts.callback.onRender.call(iL, iL.ui, item);
if (typeof obj.options.onRender == 'function') obj.options.onRender.call(iL, api);
var images = findImageInElement(holder);
//Trigger the onBeforeLoad callback
if (typeof opts.callback.onBeforeLoad == 'function') opts.callback.onBeforeLoad.call(iL, iL.ui, item);
if (typeof obj.options.onBeforeLoad == 'function') obj.options.onBeforeLoad.call(iL, api);
iL.loadImage(images, function() {
//Trigger the onAfterLoad callback
if (typeof opts.callback.onAfterLoad == 'function') opts.callback.onAfterLoad.call(iL, iL.ui, item);
if (typeof obj.options.onAfterLoad == 'function') obj.options.onAfterLoad.call(iL, api);
holder.show().data({
naturalWidth: (elWidth || container.outerWidth()),
naturalHeight: (elHeight || container.outerHeight())
}).hide();
el.remove();
iL.configureHolder(obj, opt, holder);
});
break;
}
},
configureHolder: function(obj, opt, holder) {
var iL = this,
vars = iL.vars,
opts = iL.options;
if (opt != "current")(opt == "next") ? holder.addClass('ilightbox-next') : holder.addClass('ilightbox-prev');
if (opt == "current")
var item = vars.current;
else if (opt == "next")
var opacity = opts.styles.nextOpacity,
item = vars.next;
else
var opacity = opts.styles.prevOpacity,
item = vars.prev;
var api = {
element: holder,
position: item
};
iL.items[item].options.width = iL.items[item].options.width || 0,
iL.items[item].options.height = iL.items[item].options.height || 0;
if (opt == "current") {
if (opts.show.effect) holder.css(transform, gpuAcceleration).fadeIn(obj.speed, function() {
holder.css(transform, '');
if (obj.caption) {
iL.setCaption(obj, holder);
var caption = $('div.ilightbox-caption', holder),
percent = parseInt((caption.outerHeight() / holder.outerHeight()) * 100);
if (opts.caption.start & percent <= 50) caption.fadeIn(opts.effects.fadeSpeed);
}
var social = obj.options.social;
if (social) {
iL.setSocial(social, obj.URL, holder);
if (opts.social.start) $('div.ilightbox-social', holder).fadeIn(opts.effects.fadeSpeed);
}
//Generate thumbnails
iL.generateThumbnails();
//Trigger the onShow callback
if (typeof opts.callback.onShow == 'function') opts.callback.onShow.call(iL, iL.ui, item);
if (typeof obj.options.onShow == 'function') obj.options.onShow.call(iL, api);
});
else {
holder.show();
//Generate thumbnails
iL.generateThumbnails();
//Trigger the onShow callback
if (typeof opts.callback.onShow == 'function') opts.callback.onShow.call(iL, iL.ui, item);
if (typeof obj.options.onShow == 'function') obj.options.onShow.call(iL, api);
}
} else {
if (opts.show.effect) holder.fadeTo(obj.speed, opacity, function() {
if (opt == "next") vars.nextLock = false;
else vars.prevLock = false;
//Generate thumbnails
iL.generateThumbnails();
//Trigger the onShow callback
if (typeof opts.callback.onShow == 'function') opts.callback.onShow.call(iL, iL.ui, item);
if (typeof obj.options.onShow == 'function') obj.options.onShow.call(iL, api);
});
else {
holder.css({
opacity: opacity
}).show();
if (opt == "next") vars.nextLock = false;
else vars.prevLock = false;
//Generate thumbnails
iL.generateThumbnails();
//Trigger the onShow callback
if (typeof opts.callback.onShow == 'function') opts.callback.onShow.call(iL, iL.ui, item);
if (typeof obj.options.onShow == 'function') obj.options.onShow.call(iL, api);
}
}
setTimeout(function() {
iL.repositionPhoto();
}, 0);
},
generateBoxes: function() {
var iL = this,
vars = iL.vars,
opts = iL.options;
if (opts.infinite && vars.total >= 3) {
if (vars.current == vars.total - 1) vars.next = 0;
if (vars.current == 0) vars.prev = vars.total - 1;
} else opts.infinite = false;
//UNCODE addition
if ( typeof iL.items[vars.current] == 'undefined' )
vars.current = 0;
iL.loadContent(iL.items[vars.current], 'current', opts.show.speed);
if (iL.items[vars.next]) iL.loadContent(iL.items[vars.next], 'next', opts.show.speed);
if (iL.items[vars.prev]) iL.loadContent(iL.items[vars.prev], 'prev', opts.show.speed);
},
generateThumbnails: function() {
var iL = this,
vars = iL.vars,
opts = iL.options,
timeOut = null;
if (vars.thumbs && !iL.vars.dontGenerateThumbs) {
var thumbnails = vars.thumbnails,
container = $('div.ilightbox-thumbnails-container', thumbnails),
grid = $('div.ilightbox-thumbnails-grid', container),
i = 0;
grid.removeAttr('style').empty();
$.each(iL.items, function(key, val) {
var isActive = (vars.current == key) ? 'ilightbox-active' : '',
opacity = (vars.current == key) ? opts.thumbnails.activeOpacity : opts.thumbnails.normalOpacity,
thumb = val.options.thumbnail,
thumbnail = $('<div class="ilightbox-thumbnail"></div>'),
icon = $('<div class="ilightbox-thumbnail-icon"></div>');
thumbnail.css({
opacity: 0
}).addClass(isActive);
if ((val.type == "video" || val.type == "flash") && typeof val.options.icon == 'undefined') {
icon.addClass('ilightbox-thumbnail-video');
thumbnail.append(icon);
} else if (val.options.icon) {
icon.addClass('ilightbox-thumbnail-' + val.options.icon);
thumbnail.append(icon);
}
if (thumb) iL.loadImage(thumb, function(img) {
i++;
if (img) thumbnail.data({
naturalWidth: img.width,
naturalHeight: img.height
}).append('<img src="' + thumb + '" border="0" />');
else thumbnail.data({
naturalWidth: opts.thumbnails.maxWidth,
naturalHeight: opts.thumbnails.maxHeight
});
clearTimeout(timeOut);
timeOut = setTimeout(function() {
iL.positionThumbnails(thumbnails, container, grid);
}, 20);
setTimeout(function() {
thumbnail.fadeTo(opts.effects.loadedFadeSpeed, opacity);
}, i * 20);
});
grid.append(thumbnail);
});
iL.vars.dontGenerateThumbs = true;
}
},
positionThumbnails: function(thumbnails, container, grid) {
var iL = this,
vars = iL.vars,
opts = iL.options,
viewport = getViewport(),
path = opts.path.toLowerCase();
if (!thumbnails) thumbnails = vars.thumbnails;
if (!container) container = $('div.ilightbox-thumbnails-container', thumbnails);
if (!grid) grid = $('div.ilightbox-thumbnails-grid', container);
var thumbs = $('.ilightbox-thumbnail', grid),
widthAvail = (path == 'horizontal') ? viewport.width - opts.styles.pageOffsetX : thumbs.eq(0).outerWidth() - opts.styles.pageOffsetX,
heightAvail = (path == 'horizontal') ? thumbs.eq(0).outerHeight() - opts.styles.pageOffsetY : viewport.height - opts.styles.pageOffsetY,
gridWidth = (path == 'horizontal') ? 0 : widthAvail,
gridHeight = (path == 'horizontal') ? heightAvail : 0,
active = $('.ilightbox-active', grid),
gridCss = {},
css = {};
if (arguments.length < 3) {
thumbs.css({
opacity: opts.thumbnails.normalOpacity
});
active.css({
opacity: opts.thumbnails.activeOpacity
});
}
thumbs.each(function(i) {
var t = $(this),
data = t.data(),
width = (path == 'horizontal') ? 0 : opts.thumbnails.maxWidth;
height = (path == 'horizontal') ? opts.thumbnails.maxHeight : 0;
dims = iL.getNewDimenstions(width, height, data.naturalWidth, data.naturalHeight, true);
t.css({
width: dims.width,
height: dims.height
});
if (path == 'horizontal') t.css({
'float': 'left'
});
(path == 'horizontal') ? (
gridWidth += t.outerWidth()
) : (
gridHeight += t.outerHeight()
);
});
gridCss = {
width: gridWidth,
height: gridHeight
};
grid.css(gridCss);
gridCss = {};
var gridOffset = grid.offset(),
activeOffset = (active.length) ? active.offset() : {
top: parseInt(heightAvail / 2),
left: parseInt(widthAvail / 2)
};
gridOffset.top = (gridOffset.top - $doc.scrollTop()),
gridOffset.left = (gridOffset.left - $doc.scrollLeft()),
activeOffset.top = (activeOffset.top - gridOffset.top - $doc.scrollTop()),
activeOffset.left = (activeOffset.left - gridOffset.left - $doc.scrollLeft());
(path == 'horizontal') ? (
gridCss.top = 0,
gridCss.left = parseInt((widthAvail / 2) - activeOffset.left - (active.outerWidth() / 2))
) : (
gridCss.top = parseInt(((heightAvail / 2) - activeOffset.top - (active.outerHeight() / 2))),
gridCss.left = 0
);
if (arguments.length < 3) grid.stop().animate(gridCss, opts.effects.repositionSpeed, 'easeOutCirc');
else grid.css(gridCss);
},
loadImage: function(image, callback) {
if (!$.isArray(image)) image = [image];
var iL = this,
length = image.length;
if (length > 0) {
iL.showLoader();
$.each(image, function(index, value) {
var img = new Image();
img.onload = function() {
length -= 1;
if (length == 0) {
iL.hideLoader();
callback(img);
}
};
img.onerror = img.onabort = function() {
length -= 1;
if (length == 0) {
iL.hideLoader();
callback(false);
}
};
img.src = image[index];
});
} else callback(false);
},
patchItemsEvents: function() {
var iL = this,
vars = iL.vars,
clickEvent = supportTouch ? "itap.iL" : "click.iL",
vEvent = supportTouch ? "click.iL" : "itap.iL";
if (iL.context && iL.selector) {
var $items = $(iL.selector, iL.context);
$(iL.context).on(clickEvent, iL.selector, function() {
var $this = $(this),
//UNCODE addition
key = typeof $(this).data('lb-index') !== '' && $(this).closest('.owl-item').length ? $(this).data('lb-index') : $items.index($this);
if (UNCODE.isMobile) {
var isCarousel = $this.closest('.owl-carousel');
if (isCarousel.length) {
if (isCarousel.hasClass('owl-translating')) return false;
}
}
vars.current = key;
vars.next = iL.items[key + 1] ? key + 1 : null;
vars.prev = iL.items[key - 1] ? key - 1 : null;
//UNCODE addition
if ( vars.BODY.hasClass('fp-slide-scrolling') )
return false;
iL.addContents();
iL.patchEvents();
return false;
}).on(vEvent, iL.selector, function() {
return false;
});
} else
$.each(iL.itemsObject, function(key, val) {
val.on(clickEvent, function() {
vars.current = key;
vars.next = iL.items[key + 1] ? key + 1 : null;
vars.prev = iL.items[key - 1] ? key - 1 : null;
iL.addContents();
iL.patchEvents();
return false;
}).on(vEvent, function() {
return false;
});
});
},
dispatchItemsEvents: function() {
var iL = this,
vars = iL.vars,
opts = iL.options;
if (iL.context && iL.selector)
$(iL.context).off('.iL', iL.selector);
else
$.each(iL.itemsObject, function(key, val) {
val.off('.iL');
});
},
refresh: function() {
var iL = this;
iL.dispatchItemsEvents();
iL.attachItems();
iL.normalizeItems();
iL.patchItemsEvents();
},
patchEvents: function() {
var iL = this,
vars = iL.vars,
opts = iL.options,
path = opts.path.toLowerCase(),
holders = $('.ilightbox-holder'),
fullscreenEvent = fullScreenApi.fullScreenEventName + '.iLightBox',
durationThreshold = 1000,
horizontalDistanceThreshold =
verticalDistanceThreshold = 100,
buttonsArray = [vars.nextButton[0], vars.prevButton[0], vars.nextButton[0].firstChild, vars.prevButton[0].firstChild];
$win.bind('resize.iLightBox', function() {
var viewport = getViewport();
if (opts.mobileOptimizer && !opts.innerToolbar) vars.isMobile = viewport.width <= vars.mobileMaxWidth;
vars.BODY[vars.isMobile ? 'addClass' : 'removeClass']('isMobile');
iL.repositionPhoto(null);
if (supportTouch) {
clearTimeout(vars.setTime);
vars.setTime = setTimeout(function() {
var scrollTop = getScrollXY().y;
window.scrollTo(0, scrollTop - 30);
window.scrollTo(0, scrollTop + 30);
window.scrollTo(0, scrollTop);
}, 2000);
}
if (vars.thumbs) iL.positionThumbnails();
}).bind('keydown.iLightBox', function(event) {
if (opts.controls.keyboard) {
switch (event.keyCode) {
case 13:
if (event.shiftKey && opts.keyboard.shift_enter) iL.fullScreenAction();
break;
case 27:
if (opts.keyboard.esc) iL.closeAction();
break;
case 37:
if (opts.keyboard.left && !vars.lockKey) iL.moveTo('prev');
break;
case 38:
if (opts.keyboard.up && !vars.lockKey) iL.moveTo('prev');
break;
case 39:
if (opts.keyboard.right && !vars.lockKey) iL.moveTo('next');
break;
case 40:
if (opts.keyboard.down && !vars.lockKey) iL.moveTo('next');
break;
}
}
});
if (fullScreenApi.supportsFullScreen) $win.bind(fullscreenEvent, function() {
iL.doFullscreen();
});
var holderEventsArr = [opts.caption.show + '.iLightBox', opts.caption.hide + '.iLightBox', opts.social.show + '.iLightBox', opts.social.hide + '.iLightBox'].filter(function(e, i, arr) {
return arr.lastIndexOf(e) === i;
}),
holderEvents = "";
$.each(holderEventsArr, function(key, val) {
if (key != 0) holderEvents += ' ';
holderEvents += val;
});
$doc.on(clickEvent, '.ilightbox-overlay', function() {
if (opts.overlay.blur) iL.closeAction();
}).on(clickEvent, '.ilightbox-next, .ilightbox-next-button', function() {
iL.moveTo('next');
}).on(clickEvent, '.ilightbox-prev, .ilightbox-prev-button', function() {
iL.moveTo('prev');
}).on(clickEvent, '.ilightbox-thumbnail', function() {
var t = $(this),
thumbs = $('.ilightbox-thumbnail', vars.thumbnails),
index = thumbs.index(t);
if (index != vars.current) iL.goTo(index);
}).on(holderEvents, '.ilightbox-holder:not(.ilightbox-next, .ilightbox-prev)', function(e) {
var caption = $('div.ilightbox-caption', vars.holder),
social = $('div.ilightbox-social', vars.holder),
fadeSpeed = opts.effects.fadeSpeed;
if (vars.nextLock || vars.prevLock) {
if (e.type == opts.caption.show && !caption.is(':visible')) caption.fadeIn(fadeSpeed);
else if (e.type == opts.caption.hide && caption.is(':visible')) caption.fadeOut(fadeSpeed);
if (e.type == opts.social.show && !social.is(':visible')) social.fadeIn(fadeSpeed);
else if (e.type == opts.social.hide && social.is(':visible')) social.fadeOut(fadeSpeed);
} else {
if (e.type == opts.caption.show && !caption.is(':visible')) caption.stop().fadeIn(fadeSpeed);
else if (e.type == opts.caption.hide && caption.is(':visible')) caption.stop().fadeOut(fadeSpeed);
if (e.type == opts.social.show && !social.is(':visible')) social.stop().fadeIn(fadeSpeed);
else if (e.type == opts.social.hide && social.is(':visible')) social.stop().fadeOut(fadeSpeed);
}
}).on('mouseenter.iLightBox mouseleave.iLightBox', '.ilightbox-wrapper', function(e) {
if (e.type == 'mouseenter') vars.lockWheel = true;
else vars.lockWheel = false;
}).on(clickEvent, '.ilightbox-toolbar a.ilightbox-close, .ilightbox-toolbar a.ilightbox-fullscreen, .ilightbox-toolbar a.ilightbox-play, .ilightbox-toolbar a.ilightbox-pause', function() {
var t = $(this);
if (t.hasClass('ilightbox-fullscreen')) iL.fullScreenAction();
else if (t.hasClass('ilightbox-play')) {
iL.resume();
t.addClass('ilightbox-pause').removeClass('ilightbox-play');
} else if (t.hasClass('ilightbox-pause')) {
iL.pause();
t.addClass('ilightbox-play').removeClass('ilightbox-pause');
} else iL.closeAction();
}).on(touchMoveEvent, '.ilightbox-overlay, .ilightbox-thumbnails-container', function(e) {
// prevent scrolling
e.preventDefault();
});
function mouseMoveHandler(e) {
if (!vars.isMobile) {
if (!vars.mouseID) {
vars.hideableElements.show();
}
vars.mouseID = clearTimeout(vars.mouseID);
if (buttonsArray.indexOf(e.target) === -1)
vars.mouseID = setTimeout(function() {
vars.hideableElements.hide();
vars.mouseID = clearTimeout(vars.mouseID);
}, 3000);
}
}
if (opts.controls.arrows && !supportTouch) $doc.on('mousemove.iLightBox', mouseMoveHandler);
if (opts.controls.slideshow && opts.slideshow.pauseOnHover) $doc.on('mouseenter.iLightBox mouseleave.iLightBox', '.ilightbox-holder:not(.ilightbox-next, .ilightbox-prev)', function(e) {
if (e.type == 'mouseenter' && vars.cycleID) iL.pause();
else if (e.type == 'mouseleave' && vars.isPaused) iL.resume();
});
var switchers = $('.ilightbox-overlay, .ilightbox-holder, .ilightbox-thumbnails');
if (opts.controls.mousewheel) switchers.on('mousewheel.iLightBox', function(event, delta) {
if (!vars.lockWheel) {
event.preventDefault();
if (delta < 0) iL.moveTo('next');
else if (delta > 0) iL.moveTo('prev');
}
});
if (opts.controls.swipe) holders.on(touchStartEvent, function(event) {
if (vars.nextLock || vars.prevLock || vars.total == 1 || vars.lockSwipe) return;
vars.BODY.addClass('ilightbox-closedhand');
var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event,
scrollTop = $doc.scrollTop(),
scrollLeft = $doc.scrollLeft(),
offsets = [
holders.eq(0).offset(),
holders.eq(1).offset(),
holders.eq(2).offset()
],
offSet = [{
top: offsets[0].top - scrollTop,
left: offsets[0].left - scrollLeft
}, {
top: offsets[1].top - scrollTop,
left: offsets[1].left - scrollLeft
}, {
top: offsets[2].top - scrollTop,
left: offsets[2].left - scrollLeft
}],
start = {
time: (new Date()).getTime(),
coords: [data.pageX - scrollLeft, data.pageY - scrollTop]
},
stop;
function moveEachHandler(i) {
var t = $(this),
offset = offSet[i],
scroll = [(start.coords[0] - stop.coords[0]), (start.coords[1] - stop.coords[1])];
t[0].style[path == "horizontal" ? 'left' : 'top'] = (path == "horizontal" ? offset.left - scroll[0] : offset.top - scroll[1]) + 'px';
}
function moveHandler(event) {
if (!start) return;
var data = event.originalEvent.touches ? event.originalEvent.touches[0] : event;
stop = {
time: (new Date()).getTime(),
coords: [data.pageX - scrollLeft, data.pageY - scrollTop]
};
holders.each(moveEachHandler);
// prevent scrolling
event.preventDefault();
}
function repositionHolders() {
holders.each(function() {
var t = $(this),
offset = t.data('offset') || {
top: t.offset().top - scrollTop,
left: t.offset().left - scrollLeft
},
top = offset.top,
left = offset.left;
t.css(transform, gpuAcceleration).stop().animate({
top: top,
left: left
}, 500, 'easeOutCirc', function() {
t.css(transform, '');
});
});
}
holders.bind(touchMoveEvent, moveHandler);
$doc.one(touchStopEvent, function(event) {
holders.unbind(touchMoveEvent, moveHandler);
vars.BODY.removeClass('ilightbox-closedhand');
if (start && stop) {
if (path == "horizontal" && stop.time - start.time < durationThreshold && abs(start.coords[0] - stop.coords[0]) > horizontalDistanceThreshold && abs(start.coords[1] - stop.coords[1]) < verticalDistanceThreshold) {
if (start.coords[0] > stop.coords[0]) {
if (vars.current == vars.total - 1 && !opts.infinite) repositionHolders();
else {
vars.isSwipe = true;
iL.moveTo('next');
}
} else {
if (vars.current == 0 && !opts.infinite) repositionHolders();
else {
vars.isSwipe = true;
iL.moveTo('prev');
}
}
} else if (path == "vertical" && stop.time - start.time < durationThreshold && abs(start.coords[1] - stop.coords[1]) > horizontalDistanceThreshold && abs(start.coords[0] - stop.coords[0]) < verticalDistanceThreshold) {
if (start.coords[1] > stop.coords[1]) {
if (vars.current == vars.total - 1 && !opts.infinite) repositionHolders();
else {
vars.isSwipe = true;
iL.moveTo('next');
}
} else {
if (vars.current == 0 && !opts.infinite) repositionHolders();
else {
vars.isSwipe = true;
iL.moveTo('prev');
}
}
} else repositionHolders();
}
start = stop = undefined;
});
});
},
goTo: function(index) {
var iL = this,
vars = iL.vars,
opts = iL.options,
diff = (index - vars.current);
if (opts.infinite) {
if (index == vars.total - 1 && vars.current == 0) diff = -1;
if (vars.current == vars.total - 1 && index == 0) diff = 1;
}
if (diff == 1) iL.moveTo('next');
else if (diff == -1) iL.moveTo('prev');
else {
if (vars.nextLock || vars.prevLock) return false;
//Trigger the onBeforeChange callback
if (typeof opts.callback.onBeforeChange == 'function') opts.callback.onBeforeChange.call(iL, iL.ui);
if (opts.linkId) {
vars.hashLock = true;
window.location.hash = opts.linkId + '/' + index;
}
if (iL.items[index]) {
if (!iL.items[index].options.mousewheel) vars.lockWheel = true;
else iL.vars.lockWheel = false;
if (!iL.items[index].options.swipe) vars.lockSwipe = true;
else vars.lockSwipe = false;
}
$.each([vars.holder, vars.nextPhoto, vars.prevPhoto], function(key, val) {
val.css(transform, gpuAcceleration).fadeOut(opts.effects.loadedFadeSpeed);
});
vars.current = index;
vars.next = index + 1;
vars.prev = index - 1;
iL.createUI();
setTimeout(function() {
iL.generateBoxes();
}, opts.effects.loadedFadeSpeed + 50);
$('.ilightbox-thumbnail', vars.thumbnails).removeClass('ilightbox-active').eq(index).addClass('ilightbox-active');
iL.positionThumbnails();
if (opts.linkId) setTimeout(function() {
vars.hashLock = false;
}, 55);
// Configure arrow buttons
if (!opts.infinite) {
vars.nextButton.add(vars.prevButton).add(vars.innerPrevButton).add(vars.innerNextButton).removeClass('disabled');
if (vars.current == 0) {
vars.prevButton.add(vars.innerPrevButton).addClass('disabled');
}
if (vars.current >= vars.total - 1) {
vars.nextButton.add(vars.innerNextButton).addClass('disabled');
}
}
// Reset next cycle timeout
iL.resetCycle();
//Trigger the onAfterChange callback
if (typeof opts.callback.onAfterChange == 'function') opts.callback.onAfterChange.call(iL, iL.ui);
}
},
moveTo: function(side) {
var iL = this,
vars = iL.vars,
opts = iL.options,
path = opts.path.toLowerCase(),
viewport = getViewport(),
switchSpeed = opts.effects.switchSpeed;
if (vars.nextLock || vars.prevLock) return false;
else {
var item = (side == "next") ? vars.next : vars.prev;
if (opts.linkId) {
vars.hashLock = true;
window.location.hash = opts.linkId + '/' + item;
}
if (side == "next") {
if (!iL.items[item]) return false;
var firstHolder = vars.nextPhoto,
secondHolder = vars.holder,
lastHolder = vars.prevPhoto,
firstClass = 'ilightbox-prev',
secondClass = 'ilightbox-next';
} else if (side == "prev") {
if (!iL.items[item]) return false;
var firstHolder = vars.prevPhoto,
secondHolder = vars.holder,
lastHolder = vars.nextPhoto,
firstClass = 'ilightbox-next',
secondClass = 'ilightbox-prev';
}
//Trigger the onBeforeChange callback
if (typeof opts.callback.onBeforeChange == 'function')
opts.callback.onBeforeChange.call(iL, iL.ui);
(side == "next") ? vars.nextLock = true: vars.prevLock = true;
var captionFirst = $('div.ilightbox-caption', secondHolder),
socialFirst = $('div.ilightbox-social', secondHolder);
if (captionFirst.length)
captionFirst.stop().fadeOut(switchSpeed, function() {
$(this).remove();
});
if (socialFirst.length)
socialFirst.stop().fadeOut(switchSpeed, function() {
$(this).remove();
});
if (iL.items[item].caption) {
iL.setCaption(iL.items[item], firstHolder);
var caption = $('div.ilightbox-caption', firstHolder),
percent = parseInt((caption.outerHeight() / firstHolder.outerHeight()) * 100);
if (opts.caption.start && percent <= 50) caption.fadeIn(switchSpeed);
}
var social = iL.items[item].options.social;
if (social) {
iL.setSocial(social, iL.items[item].URL, firstHolder);
if (opts.social.start) $('div.ilightbox-social', firstHolder).fadeIn(opts.effects.fadeSpeed);
}
$.each([firstHolder, secondHolder, lastHolder], function(key, val) {
val.removeClass('ilightbox-next ilightbox-prev');
});
var firstOffset = firstHolder.data('offset'),
winW = (viewport.width - (opts.styles.pageOffsetX)),
winH = (viewport.height - (opts.styles.pageOffsetY)),
width = firstOffset.newDims.width,
height = firstOffset.newDims.height,
thumbsOffset = firstOffset.thumbsOffset,
diff = firstOffset.diff,
top = parseInt((winH / 2) - (height / 2) - diff.H - (thumbsOffset.H / 2)),
left = parseInt((winW / 2) - (width / 2) - diff.W - (thumbsOffset.W / 2));
var secondOffset = secondHolder.data('offset'),
object = secondOffset.object;
/*if (object.item.caption && !isNaN(width) && !isNaN(height) && UNCODE.wwidth > UNCODE.mediaQuery) {
var objRatio = width / height;
height = height - vars.captionHeight;
width = height * objRatio;
top = path == 'horizontal' ? parseInt((winH / 2) - (height / 2) - diff.H - (thumbsOffset.H / 2)) : top,
left = parseInt((winW / 2) - (width / 2) - diff.W - (thumbsOffset.W / 2));
}*/
firstHolder.show().css(transform, gpuAcceleration).animate({
top: top,
left: left,
opacity: 1
}, switchSpeed, (vars.isSwipe) ? 'easeOutCirc' : 'easeInOutCirc', function() {
firstHolder.css(transform, '');
});
$('div.ilightbox-container', firstHolder).animate({
width: width,
height: height
}, switchSpeed, (vars.isSwipe) ? 'easeOutCirc' : 'easeInOutCirc');
diff = secondOffset.diff;
width = secondOffset.newDims.width,
height = secondOffset.newDims.height;
width = parseInt(width * opts.styles[side == 'next' ? 'prevScale' : 'nextScale']),
height = parseInt(height * opts.styles[side == 'next' ? 'prevScale' : 'nextScale']),
top = (path == 'horizontal') ? parseInt((winH / 2) - object.offsetY - (height / 2) - diff.H - (thumbsOffset.H / 2)) : parseInt(winH - object.offsetX - diff.H - (thumbsOffset.H / 2));
if (side == 'prev')
left = (path == 'horizontal') ? parseInt(winW - object.offsetX - diff.W - (thumbsOffset.W / 2)) : parseInt((winW / 2) - (width / 2) - diff.W - object.offsetY - (thumbsOffset.W / 2));
else {
top = (path == 'horizontal') ? top : parseInt(object.offsetX - diff.H - height - (thumbsOffset.H / 2)),
left = (path == 'horizontal') ? parseInt(object.offsetX - diff.W - width - (thumbsOffset.W / 2)) : parseInt((winW / 2) - object.offsetY - (width / 2) - diff.W - (thumbsOffset.W / 2));
}
/*if (object.item.caption && !isNaN(width) && !isNaN(height) && UNCODE.wwidth > UNCODE.mediaQuery) {
var objRatio = width / height;
height = height - vars.captionHeight;
width = height * objRatio;
top = path == 'horizontal' ? parseInt((winH / 2) - (height / 2) - diff.H - (thumbsOffset.H / 2)) : top;
}*/
$('div.ilightbox-container', secondHolder).animate({
width: width,
height: height
}, switchSpeed, (vars.isSwipe) ? 'easeOutCirc' : 'easeInOutCirc');
secondHolder.addClass(firstClass).css(transform, gpuAcceleration).animate({
top: top,
left: left,
opacity: opts.styles.prevOpacity,
}, switchSpeed, (vars.isSwipe) ? 'easeOutCirc' : 'easeInOutCirc', function() {
secondHolder.css(transform, '');
$('.ilightbox-thumbnail', vars.thumbnails).removeClass('ilightbox-active').eq(item).addClass('ilightbox-active');
iL.positionThumbnails();
if (iL.items[item]) {
if (!iL.items[item].options.mousewheel) vars.lockWheel = true;
else vars.lockWheel = false;
if (!iL.items[item].options.swipe) vars.lockSwipe = true;
else vars.lockSwipe = false;
}
vars.isSwipe = false;
// Remove iframe & video from previous slide
if (['iframe', 'video'].indexOf(iL.items[vars.current].type) !== -1) {
$('div.ilightbox-container', secondHolder).empty();
}
if (side == "next") {
vars.nextPhoto = lastHolder,
vars.prevPhoto = secondHolder,
vars.holder = firstHolder;
vars.nextPhoto.hide();
vars.next = vars.next + 1,
vars.prev = vars.current,
vars.current = vars.current + 1;
if (opts.infinite) {
if (vars.current > vars.total - 1) vars.current = 0;
if (vars.current == vars.total - 1) vars.next = 0;
if (vars.current == 0) vars.prev = vars.total - 1;
}
iL.createUI();
if (!iL.items[vars.next])
vars.nextLock = false;
else
iL.loadContent(iL.items[vars.next], 'next');
} else {
vars.prevPhoto = lastHolder;
vars.nextPhoto = secondHolder;
vars.holder = firstHolder;
vars.prevPhoto.hide();
vars.next = vars.current;
vars.current = vars.prev;
vars.prev = vars.current - 1;
if (opts.infinite) {
if (vars.current == vars.total - 1) vars.next = 0;
if (vars.current == 0) vars.prev = vars.total - 1;
}
iL.createUI();
if (!iL.items[vars.prev])
vars.prevLock = false;
else
iL.loadContent(iL.items[vars.prev], 'prev');
}
// Add iframe & video content for current slide
if (['iframe', 'video'].indexOf(iL.items[vars.current].type) !== -1) {
iL.loadContent(iL.items[vars.current], 'current');
}
if (opts.linkId) setTimeout(function() {
vars.hashLock = false;
}, 55);
// Configure arrow buttons
if (!opts.infinite) {
vars.nextButton.add(vars.prevButton).add(vars.innerPrevButton).add(vars.innerNextButton).removeClass('disabled');
if (vars.current == 0)
vars.prevButton.add(vars.innerPrevButton).addClass('disabled');
if (vars.current >= vars.total - 1)
vars.nextButton.add(vars.innerNextButton).addClass('disabled');
}
iL.repositionPhoto();
// Reset next cycle timeout
iL.resetCycle();
//Trigger the onAfterChange callback
if (typeof opts.callback.onAfterChange == 'function')
opts.callback.onAfterChange.call(iL, iL.ui);
});
top = (path == 'horizontal') ? getPixel(lastHolder, 'top') : ((side == "next") ? parseInt(-(winH / 2) - lastHolder.outerHeight()) : parseInt(top * 2)),
left = (path == 'horizontal') ? ((side == "next") ? parseInt(-(winW / 2) - lastHolder.outerWidth()) : parseInt(left * 2)) : getPixel(lastHolder, 'left');
lastHolder.css(transform, gpuAcceleration).animate({
top: top,
left: left,
opacity: opts.styles.nextOpacity
}, switchSpeed, (vars.isSwipe) ? 'easeOutCirc' : 'easeInOutCirc', function() {
lastHolder.css(transform, '');
}).addClass(secondClass);
}
},
setCaption: function(obj, target) {
var iL = this,
caption = $('<div class="ilightbox-caption"></div>');
if (obj.caption) {
caption.html(obj.caption);
$('div.ilightbox-container', target).append(caption);
}
},
normalizeSocial: function(obj, url) {
var iL = this,
vars = iL.vars,
opts = iL.options,
baseURL = window.location.href;
$.each(obj, function(key, value) {
if (!value)
return true;
var item = key.toLowerCase(),
source, text;
switch (item) {
case 'facebook':
source = "http://www.facebook.com/share.php?v=4&src=bm&u={URL}",
text = "Share on Facebook";
break;
case 'twitter':
source = "http://twitter.com/home?status={URL}",
text = "Share on Twitter";
break;
case 'googleplus':
source = "https://plus.google.com/share?url={URL}",
text = "Share on Google+";
break;
case 'delicious':
source = "http://delicious.com/post?url={URL}",
text = "Share on Delicious";
break;
case 'digg':
source = "http://digg.com/submit?phase=2&url={URL}",
text = "Share on Digg";
break;
case 'reddit':
source = "http://reddit.com/submit?url={URL}",
text = "Share on reddit";
break;
}
obj[key] = {
URL: value.URL && absolutizeURI(baseURL, value.URL) || opts.linkId && window.location.href || typeof url !== 'string' && baseURL || url && absolutizeURI(baseURL, url) || baseURL,
source: value.source || source || value.URL && absolutizeURI(baseURL, value.URL) || url && absolutizeURI(baseURL, url),
text: value.text || text || "Share on " + key,
width: (typeof(value.width) != 'undefined' && !isNaN(value.width)) ? parseInt(value.width) : 640,
height: value.height || 360
};
});
return obj;
},
setSocial: function(obj, url, target) {
var iL = this,
socialBar = $('<div class="ilightbox-social"></div>'),
buttons = '<ul>';
obj = iL.normalizeSocial(obj, url);
$.each(obj, function(key, value) {
var item = key.toLowerCase(),
source = value.source.replace(/\{URL\}/g, encodeURIComponent(value.URL).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+'));
buttons += '<li class="' + key + '"><a href="' + source + '" onclick="javascript:window.open(this.href' + ((value.width <= 0 || value.height <= 0) ? '' : ', \'\', \'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=' + value.height + ',width=' + value.width + ',left=40,top=40\'') + ');return false;" title="' + value.text + '" target="_blank"></a></li>';
});
buttons += '</ul>';
socialBar.html(buttons);
$('div.ilightbox-container', target).append(socialBar);
},
fullScreenAction: function() {
var iL = this,
vars = iL.vars;
if (fullScreenApi.supportsFullScreen) {
if (fullScreenApi.isFullScreen()) fullScreenApi.cancelFullScreen(document.documentElement);
else fullScreenApi.requestFullScreen(document.documentElement);
} else {
iL.doFullscreen();
}
},
doFullscreen: function() {
var iL = this,
vars = iL.vars,
viewport = getViewport(),
opts = iL.options;
if (opts.fullAlone) {
var currentHolder = vars.holder,
current = iL.items[vars.current],
windowWidth = viewport.width,
windowHeight = viewport.height,
elements = [currentHolder, vars.nextPhoto, vars.prevPhoto, vars.nextButton, vars.prevButton, vars.overlay, vars.toolbar, vars.thumbnails, vars.loader],
hideElements = [vars.nextPhoto, vars.prevPhoto, vars.nextButton, vars.prevButton, vars.loader, vars.thumbnails];
if (!vars.isInFullScreen) {
vars.isInFullScreen = vars.lockKey = vars.lockWheel = vars.lockSwipe = true;
vars.overlay.css({
opacity: 1
});
$.each(hideElements, function(i, element) {
element.hide();
});
vars.fullScreenButton.attr('title', opts.text.exitFullscreen);
if (opts.fullStretchTypes.indexOf(current.type) != -1) currentHolder.data({
naturalWidthOld: currentHolder.data('naturalWidth'),
naturalHeightOld: currentHolder.data('naturalHeight'),
naturalWidth: windowWidth,
naturalHeight: windowHeight
});
else {
var viewport = current.options.fullViewPort || opts.fullViewPort || '',
newWidth = windowWidth,
newHeight = windowHeight,
width = currentHolder.data('naturalWidth'),
height = currentHolder.data('naturalHeight');
if (viewport.toLowerCase() == 'fill') {
newHeight = (newWidth / width) * height;
if (newHeight < windowHeight) {
newWidth = (windowHeight / height) * width,
newHeight = windowHeight;
}
} else if (viewport.toLowerCase() == 'fit') {
var dims = iL.getNewDimenstions(newWidth, newHeight, width, height, true);
newWidth = dims.width,
newHeight = dims.height;
} else if (viewport.toLowerCase() == 'stretch') {
newWidth = newWidth,
newHeight = newHeight;
} else {
var scale = (width > newWidth || height > newHeight) ? true : false,
dims = iL.getNewDimenstions(newWidth, newHeight, width, height, scale);
newWidth = dims.width,
newHeight = dims.height;
}
currentHolder.data({
naturalWidthOld: currentHolder.data('naturalWidth'),
naturalHeightOld: currentHolder.data('naturalHeight'),
naturalWidth: newWidth,
naturalHeight: newHeight
});
}
$.each(elements, function(key, val) {
val.addClass('ilightbox-fullscreen');
});
//Trigger the onEnterFullScreen callback
if (typeof opts.callback.onEnterFullScreen == 'function') opts.callback.onEnterFullScreen.call(iL, iL.ui);
} else {
vars.isInFullScreen = vars.lockKey = vars.lockWheel = vars.lockSwipe = false;
vars.overlay.css({
opacity: iL.options.overlay.opacity
});
$.each(hideElements, function(i, element) {
element.show();
});
vars.fullScreenButton.attr('title', opts.text.enterFullscreen);
currentHolder.data({
naturalWidth: currentHolder.data('naturalWidthOld'),
naturalHeight: currentHolder.data('naturalHeightOld'),
naturalWidthOld: null,
naturalHeightOld: null
});
$.each(elements, function(key, val) {
val.removeClass('ilightbox-fullscreen');
});
//Trigger the onExitFullScreen callback
if (typeof opts.callback.onExitFullScreen == 'function') opts.callback.onExitFullScreen.call(iL, iL.ui);
}
} else {
if (!vars.isInFullScreen) vars.isInFullScreen = true;
else vars.isInFullScreen = false;
}
iL.repositionPhoto(true);
},
closeAction: function() {
var iL = this,
vars = iL.vars,
opts = iL.options;
$win.unbind('.iLightBox');
$doc.off('.iLightBox');
if (vars.isInFullScreen) fullScreenApi.cancelFullScreen(document.documentElement);
$('.ilightbox-overlay, .ilightbox-holder, .ilightbox-thumbnails').off('.iLightBox');
if (opts.hide.effect) vars.overlay.stop().fadeOut(opts.hide.speed, function() {
vars.overlay.remove();
vars.BODY.removeClass('ilightbox-noscroll').off('.iLightBox');
});
else {
vars.overlay.remove();
vars.BODY.removeClass('ilightbox-noscroll').off('.iLightBox');
}
var fadeOuts = [vars.toolbar, vars.holder, vars.nextPhoto, vars.prevPhoto, vars.nextButton, vars.prevButton, vars.loader, vars.thumbnails];
$.each(fadeOuts, function(i, element) {
element.removeAttr('style').remove();
});
vars.dontGenerateThumbs = vars.isInFullScreen = false;
window.iLightBox = null;
if (opts.linkId) {
vars.hashLock = true;
removeHash();
setTimeout(function() {
vars.hashLock = false;
}, 55);
}
//Trigger the onHide callback
if (typeof opts.callback.onHide == 'function') opts.callback.onHide.call(iL, iL.ui);
},
repositionPhoto: function() {
var iL = this,
vars = iL.vars,
opts = iL.options,
path = opts.path.toLowerCase(),
viewport = getViewport(),
winWidth = viewport.width,
winHeight = viewport.height;
if (viewport.width < UNCODE.mediaQuery) opts.styles.nextOffsetX = 0;
var thumbsOffsetW = (vars.isInFullScreen && opts.fullAlone || vars.isMobile) ? 0 : ((path == 'horizontal') ? 0 : vars.thumbnails.outerWidth()),
thumbsOffsetH = vars.isMobile ? vars.toolbar.outerHeight() : ((vars.isInFullScreen && opts.fullAlone) ? 0 : ((path == 'horizontal') ? vars.thumbnails.outerHeight() : 0)),
width = (vars.isInFullScreen && opts.fullAlone) ? winWidth : (winWidth - (opts.styles.pageOffsetX)),
height = (vars.isInFullScreen && opts.fullAlone) ? winHeight : (winHeight - (opts.styles.pageOffsetY)),
offsetW = (path == 'horizontal') ? parseInt((iL.items[vars.next] || iL.items[vars.prev]) ? ((opts.styles.nextOffsetX + opts.styles.prevOffsetX)) * 2 : (((width / 10) <= 30) ? 30 : (width / 10))) : parseInt(((width / 10) <= 30) ? 30 : (width / 10)) + thumbsOffsetW,
offsetH = (path == 'horizontal') ? parseInt(((height / 10) <= 30) ? 30 : (height / 10)) + thumbsOffsetH : parseInt((iL.items[vars.next] || iL.items[vars.prev]) ? ((opts.styles.nextOffsetX + opts.styles.prevOffsetX)) * 2 : (((height / 10) <= 30) ? 30 : (height / 10)));
var elObject = {
type: 'current',
width: width,
height: height,
item: iL.items[vars.current],
offsetW: offsetW,
offsetH: offsetH,
thumbsOffsetW: thumbsOffsetW,
thumbsOffsetH: thumbsOffsetH,
animate: arguments.length,
holder: vars.holder
};
iL.repositionEl(elObject);
if (iL.items[vars.next]) {
elObject = $.extend(elObject, {
type: 'next',
item: iL.items[vars.next],
offsetX: opts.styles.nextOffsetX,
offsetY: opts.styles.nextOffsetY,
holder: vars.nextPhoto
});
iL.repositionEl(elObject);
}
if (iL.items[vars.prev]) {
elObject = $.extend(elObject, {
type: 'prev',
item: iL.items[vars.prev],
offsetX: opts.styles.nextOffsetX,
offsetY: opts.styles.prevOffsetY,
holder: vars.prevPhoto
});
iL.repositionEl(elObject);
}
var loaderCss = (path == "horizontal") ? {
left: parseInt((width / 2) - (vars.loader.outerWidth() / 2))
} : {
top: parseInt((height / 2) - (vars.loader.outerHeight() / 2))
};
vars.loader.css(loaderCss);
},
repositionEl: function(obj) {
var iL = this,
vars = iL.vars,
opts = iL.options,
path = opts.path.toLowerCase(),
widthAvail = (obj.type == 'current') ? ((vars.isInFullScreen && opts.fullAlone) ? obj.width : (obj.width - obj.offsetW)) : (obj.width - obj.offsetW),
heightAvail = (obj.type == 'current') ? ((vars.isInFullScreen && opts.fullAlone) ? obj.height : (obj.height - obj.offsetH)) : (obj.height - obj.offsetH),
itemParent = obj.item,
item = obj.item.options,
holder = obj.holder,
offsetX = obj.offsetX || 0,
offsetY = obj.offsetY || 0,
thumbsOffsetW = obj.thumbsOffsetW,
thumbsOffsetH = obj.thumbsOffsetH;
if (obj.type == 'current') {
if (typeof item.width == 'number' && item.width) widthAvail = ((vars.isInFullScreen && opts.fullAlone) && (opts.fullStretchTypes.indexOf(itemParent.type) != -1 || item.fullViewPort || opts.fullViewPort)) ? widthAvail : ((item.width > widthAvail) ? widthAvail : item.width);
if (typeof item.height == 'number' && item.height) heightAvail = ((vars.isInFullScreen && opts.fullAlone) && (opts.fullStretchTypes.indexOf(itemParent.type) != -1 || item.fullViewPort || opts.fullViewPort)) ? heightAvail : ((item.height > heightAvail) ? heightAvail : item.height);
} else {
if (typeof item.width == 'number' && item.width) widthAvail = (item.width > widthAvail) ? widthAvail : item.width;
if (typeof item.height == 'number' && item.height) heightAvail = (item.height > heightAvail) ? heightAvail : item.height;
}
heightAvail = parseInt(heightAvail - $('.ilightbox-inner-toolbar', holder).outerHeight());
var width = (typeof item.width == 'string' && item.width.indexOf('%') != -1) ? percentToValue(parseInt(item.width.replace('%', '')), obj.width) : holder.data('naturalWidth'),
height = (typeof item.height == 'string' && item.height.indexOf('%') != -1) ? percentToValue(parseInt(item.height.replace('%', '')), obj.height) : holder.data('naturalHeight');
var dims = ((typeof item.width == 'string' && item.width.indexOf('%') != -1 || typeof item.height == 'string' && item.height.indexOf('%') != -1) ? {
width: width,
height: height
} : iL.getNewDimenstions(widthAvail, heightAvail, width, height)),
newDims = $.extend({}, dims, {});
if (obj.type == 'prev' || obj.type == 'next')
width = parseInt(dims.width * ((obj.type == 'next') ? opts.styles.nextScale : opts.styles.prevScale)),
height = parseInt(dims.height * ((obj.type == 'next') ? opts.styles.nextScale : opts.styles.prevScale));
else
width = dims.width,
height = dims.height;
var widthDiff = parseInt((getPixel(holder, 'padding-left') + getPixel(holder, 'padding-right') + getPixel(holder, 'border-left-width') + getPixel(holder, 'border-right-width')) / 2),
heightDiff = parseInt((getPixel(holder, 'padding-top') + getPixel(holder, 'padding-bottom') + getPixel(holder, 'border-top-width') + getPixel(holder, 'border-bottom-width') + ($('.ilightbox-inner-toolbar', holder).outerHeight() || 0)) / 2);
switch (obj.type) {
case 'current':
var top = parseInt((obj.height / 2) - (height / 2) - heightDiff - (thumbsOffsetH / 2)),
left = parseInt((obj.width / 2) - (width / 2) - widthDiff - (thumbsOffsetW / 2));
break;
case 'next':
var top = (path == 'horizontal') ? parseInt((obj.height / 2) - offsetY - (height / 2) - heightDiff - (thumbsOffsetH / 2)) : parseInt(obj.height - offsetX - heightDiff - (thumbsOffsetH / 2)),
left = (path == 'horizontal') ? parseInt(obj.width - offsetX - widthDiff - (thumbsOffsetW / 2)) : parseInt((obj.width / 2) - (width / 2) - widthDiff - offsetY - (thumbsOffsetW / 2));
break;
case 'prev':
var top = (path == 'horizontal') ? parseInt((obj.height / 2) - offsetY - (height / 2) - heightDiff - (thumbsOffsetH / 2)) : parseInt(offsetX - heightDiff - height - (thumbsOffsetH / 2)),
left = (path == 'horizontal') ? parseInt(offsetX - widthDiff - width - (thumbsOffsetW / 2)) : parseInt((obj.width / 2) - offsetY - (width / 2) - widthDiff - (thumbsOffsetW / 2));
break;
}
holder.data('offset', {
top: top,
left: left,
newDims: newDims,
diff: {
W: widthDiff,
H: heightDiff
},
thumbsOffset: {
W: thumbsOffsetW,
H: thumbsOffsetH
},
object: obj
});
var opacityMobile;
if ( isMobile ) {
opacityMobile = {
opacity: 1,
top: top,
left: left
};
} else {
opacityMobile = {
top: top,
left: left
};
}
if (obj.animate > 0 && opts.effects.reposition) {
holder.css(transform, gpuAcceleration).stop().animate(
opacityMobile,
opts.effects.repositionSpeed, 'easeOutCirc', function() {
holder.css(transform, '');
});
$('div.ilightbox-container', holder).stop().animate({
width: width,
height: height
}, opts.effects.repositionSpeed, 'easeOutCirc');
$('div.ilightbox-inner-toolbar', holder).stop().animate({
width: width
}, opts.effects.repositionSpeed, 'easeOutCirc', function() {
$(this).css('overflow', 'visible');
});
} else {
holder.css(opacityMobile);
$('div.ilightbox-container', holder).css({
width: width,
height: height
});
$('div.ilightbox-inner-toolbar', holder).css({
width: width
});
}
},
resume: function(priority) {
var iL = this,
vars = iL.vars,
opts = iL.options;
if (!opts.slideshow.pauseTime || opts.controls.slideshow && vars.total <= 1 || priority < vars.isPaused) {
return;
}
vars.isPaused = 0;
if (vars.cycleID) {
vars.cycleID = clearTimeout(vars.cycleID);
}
vars.cycleID = setTimeout(function() {
if (vars.current == vars.total - 1) iL.goTo(0);
else iL.moveTo('next');
}, opts.slideshow.pauseTime);
},
pause: function(priority) {
var iL = this,
vars = iL.vars,
opts = iL.options;
if (priority < vars.isPaused) {
return;
}
vars.isPaused = priority || 100;
if (vars.cycleID) {
vars.cycleID = clearTimeout(vars.cycleID);
}
},
resetCycle: function() {
var iL = this,
vars = iL.vars,
opts = iL.options;
if (opts.controls.slideshow && vars.cycleID && !vars.isPaused) {
iL.resume();
}
},
getNewDimenstions: function(width, height, width_old, height_old, thumb) {
var iL = this;
if (!width) factor = height / height_old;
else if (!height) factor = width / width_old;
else factor = min(width / width_old, height / height_old);
if (!thumb) {
if (factor > iL.options.maxScale) factor = iL.options.maxScale;
else if (factor < iL.options.minScale) factor = iL.options.minScale;
}
var final_width = (iL.options.keepAspectRatio) ? round(width_old * factor) : width,
final_height = (iL.options.keepAspectRatio) ? round(height_old * factor) : height;
return {
width: final_width,
height: final_height,
ratio: factor
};
},
setOption: function(options) {
var iL = this;
iL.options = $.extend(true, iL.options, options || {});
iL.refresh();
},
availPlugins: function() {
var iL = this,
testEl = document.createElement("video");
iL.plugins = {
flash: !isMobile,
quicktime: (parseInt(PluginDetect.getVersion("QuickTime")) >= 0) ? true : false,
html5H264: !!(testEl.canPlayType && testEl.canPlayType('video/mp4').replace(/no/, '')),
html5WebM: !!(testEl.canPlayType && testEl.canPlayType('video/webm').replace(/no/, '')),
html5Vorbis: !!(testEl.canPlayType && testEl.canPlayType('video/ogg').replace(/no/, '')),
html5QuickTime: !!(testEl.canPlayType && testEl.canPlayType('video/quicktime').replace(/no/, ''))
};
},
addContent: function(element, obj) {
var iL = this,
el;
switch (obj.type) {
case 'video':
var HTML5 = false,
videoType = obj.videoType,
html5video = obj.options.html5video;
if (((videoType == 'video/mp4' || obj.ext == 'mp4' || obj.ext == 'm4v') || html5video.h264) && iL.plugins.html5H264)
obj.ext = 'mp4',
obj.URL = html5video.h264 || obj.URL;
else if (html5video.webm && iL.plugins.html5WebM)
obj.ext = 'webm',
obj.URL = html5video.webm || obj.URL;
else if (html5video.ogg && iL.plugins.html5Vorbis)
obj.ext = 'ogv',
obj.URL = html5video.ogg || obj.URL;
if (iL.plugins.html5H264 && (videoType == 'video/mp4' || obj.ext == 'mp4' || obj.ext == 'm4v')) HTML5 = true, videoType = "video/mp4";
else if (iL.plugins.html5WebM && (videoType == 'video/webm' || obj.ext == 'webm')) HTML5 = true, videoType = "video/webm";
else if (iL.plugins.html5Vorbis && (videoType == 'video/ogg' || obj.ext == 'ogv')) HTML5 = true, videoType = "video/ogg";
else if (iL.plugins.html5QuickTime && (videoType == 'video/quicktime' || obj.ext == 'mov' || obj.ext == 'qt')) HTML5 = true, videoType = "video/quicktime";
if (HTML5) {
el = $('<video />', {
"width": "100%",
"height": "100%",
"preload": html5video.preload,
"autoplay": html5video.autoplay,
"loop": html5video.loop,
"poster": html5video.poster,
"controls": html5video.controls,
"controlslist": "nodownload"
}).append($('<source />', {
"src": obj.URL,
"type": videoType
}));
} else {
if (!iL.plugins.quicktime) el = $('<span />', {
"class": "ilightbox-alert",
html: iL.options.errors.missingPlugin.replace('{pluginspage}', pluginspages.quicktime).replace('{type}', 'QuickTime')
});
else {
el = $('<object />', {
"type": "video/quicktime",
"pluginspage": pluginspages.quicktime
}).attr({
"data": obj.URL,
"width": "100%",
"height": "100%"
}).append($('<param />', {
"name": "src",
"value": obj.URL
})).append($('<param />', {
"name": "autoplay",
"value": "false"
})).append($('<param />', {
"name": "loop",
"value": "false"
})).append($('<param />', {
"name": "scale",
"value": "tofit"
}));
if (browser.msie) el = QT_GenerateOBJECTText(obj.URL, '100%', '100%', '', 'SCALE', 'tofit', 'AUTOPLAY', 'false', 'LOOP', 'false');
}
}
break;
case 'flash':
if (!iL.plugins.flash) el = $('<span />', {
"class": "ilightbox-alert",
html: iL.options.errors.missingPlugin.replace('{pluginspage}', pluginspages.flash).replace('{type}', 'Adobe Flash player')
});
else {
var flashvars = "",
i = 0;
if (obj.options.flashvars) $.each(obj.options.flashvars, function(k, v) {
if (i != 0) flashvars += "&";
flashvars += k + "=" + encodeURIComponent(v);
i++;
});
else flashvars = null;
el = $('<embed />').attr({
"type": "application/x-shockwave-flash",
"src": obj.URL,
"width": (typeof obj.options.width == 'number' && obj.options.width && iL.options.minScale == '1' && iL.options.maxScale == '1') ? obj.options.width : "100%",
"height": (typeof obj.options.height == 'number' && obj.options.height && iL.options.minScale == '1' && iL.options.maxScale == '1') ? obj.options.height : "100%",
"quality": "high",
"bgcolor": "#000000",
"play": "true",
"loop": "true",
"menu": "true",
"wmode": "transparent",
"scale": "showall",
"allowScriptAccess": "always",
"allowFullScreen": "true",
"flashvars": flashvars,
"fullscreen": "yes"
});
}
break;
case 'iframe':
el = $('<iframe />').attr({
"width": (typeof obj.options.width == 'number' && obj.options.width && iL.options.minScale == '1' && iL.options.maxScale == '1') ? obj.options.width : "100%",
"height": (typeof obj.options.height == 'number' && obj.options.height && iL.options.minScale == '1' && iL.options.maxScale == '1') ? obj.options.height : "100%",
src: obj.URL,
frameborder: 0,
'hspace': 0,
'vspace': 0,
'scrolling': supportTouch ? 'auto' : 'scroll',
'webkitAllowFullScreen': '',
'mozallowfullscreen': '',
'allowFullScreen': ''
});
break;
case 'inline':
el = $('<div class="ilightbox-wrapper"></div>').html($(obj.URL).clone(true));
break;
case 'html':
var object = obj.URL,
el;
if (object[0].nodeName) {
el = $('<div class="ilightbox-wrapper"></div>').html(object);
} else {
var dom = $(obj.URL),
html = (dom.selector) ? $('<div>' + dom + '</div>') : dom;
el = $('<div class="ilightbox-wrapper"></div>').html(html);
}
break;
}
$('div.ilightbox-container', element).empty().html(el);
// For fixing Chrome about just playing the video for first time
if (el[0].tagName.toLowerCase() === 'video' && browser.webkit) setTimeout(function() {
var src = el[0].currentSrc + '?' + floor(random() * 30000);
el[0].currentSrc = src;
el[0].src = src;
});
return el;
},
ogpRecognition: function(obj, callback) {
var iL = this,
url = obj.URL;
iL.showLoader();
doAjax(url, function(data) {
iL.hideLoader();
if (data) {
var object = new Object();
object.length = false,
object.url = data.url;
if (data.status == 200) {
var result = data.results,
type = result.type,
source = result.source;
object.source = source.src,
object.width = source.width && parseInt(source.width) || 0,
object.height = source.height && parseInt(source.height) || 0,
object.type = type,
object.thumbnail = source.thumbnail || result.images && result.images[0],
object.html5video = result.html5video || {},
object.length = true;
if (source.type == 'application/x-shockwave-flash') object.type = "flash";
else if (source.type.indexOf("video/") != -1) object.type = "video";
else if (source.type.indexOf("/html") != -1) object.type = "iframe";
else if (source.type.indexOf("image/") != -1) object.type = "image";
} else if (typeof data.response != 'undefined')
throw data.response;
callback.call(this, object.length ? object : false);
}
});
},
hashChangeHandler: function(url) {
var iL = this,
vars = iL.vars,
opts = iL.options,
URL = url || window.location.href,
hash = parseURI(URL).hash,
split = hash.split('/'),
index = split[1];
if (vars.hashLock || ('#' + opts.linkId != split[0] && hash.length > 1)) return;
if (index) {
var target = split[1] || 0;
if (iL.items[target]) {
var overlay = $('.ilightbox-overlay');
if (overlay.length && overlay.attr('linkid') == opts.linkId) {
iL.goTo(target);
} else {
iL.itemsObject[target].trigger(supportTouch ? 'itap' : 'click');
//iL.goTo(target);
}
} else {
var overlay = $('.ilightbox-overlay');
if (overlay.length) iL.closeAction();
}
} else {
var overlay = $('.ilightbox-overlay');
if (overlay.length) iL.closeAction();
}
}
};
/**
* Parse style to pixels.
*
* @param {Object} $element jQuery object with element.
* @param {Property} property CSS property to get the pixels from.
*
* @return {Int}
*/
function getPixel($element, property) {
return parseInt($element.css(property), 10) || 0;
}
/**
* Make sure that number is within the limits.
*
* @param {Number} number
* @param {Number} min
* @param {Number} max
*
* @return {Number}
*/
function within(number, min, max) {
return number < min ? min : number > max ? max : number;
}
/**
* Get viewport/window size (width and height).
*
* @return {Object}
*/
function getViewport() {
var e = window,
a = 'inner';
if (!('innerWidth' in window)) {
a = 'client';
e = document.documentElement || document.body;
}
return {
width: e[a + 'Width'],
height: e[a + 'Height']
}
}
/**
* Remove hash tag from the URL
*
* @return {Void}
*/
function removeHash() {
var scroll = getScrollXY();
//UNCODE change
//window.location.hash = "";
history.pushState("", document.title, window.location.pathname + window.location.search);
// Restore the scroll offset, should be flicker free
window.scrollTo(scroll.x, scroll.y);
}
/**
* Do the ajax requests with callback.
*
* @param {String} url
* @param {Function} callback
*
* @return {Void}
*/
function doAjax(url, callback) {
var url = "//ilightbox.net/getSource/jsonp.php?url=" + encodeURIComponent(url).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
$.ajax({
url: url,
dataType: 'jsonp'
});
iLCallback = function(data) {
callback.call(this, data);
};
}
/**
* Find image from DOM elements
*
* @param {Element} element
*
* @return {Void}
*/
function findImageInElement(element) {
var elements = $('*', element),
imagesArr = new Array();
elements.each(function() {
var url = "",
element = this;
if ($(element).css("background-image") != "none") {
url = $(element).css("background-image");
} else if (typeof($(element).attr("src")) != "undefined" && element.nodeName.toLowerCase() == "img") {
url = $(element).attr("src");
}
if (url.indexOf("gradient") == -1) {
url = url.replace(/url\(\"/g, "");
url = url.replace(/url\(/g, "");
url = url.replace(/\"\)/g, "");
url = url.replace(/\)/g, "");
var urls = url.split(",");
for (var i = 0; i < urls.length; i++) {
if (urls[i].length > 0 && $.inArray(urls[i], imagesArr) == -1) {
var extra = "";
if (browser.msie && browser.version < 9) {
extra = "?" + floor(random() * 3000);
}
imagesArr.push(urls[i] + extra);
}
}
}
});
return imagesArr;
}
/**
* Get file extension.
*
* @param {String} URL
*
* @return {String}
*/
function getExtension(URL) {
if (URL !== null) {
var ext = URL.split('.').pop().toLowerCase(),
extra = ext.indexOf('?') !== -1 ? ext.split('?').pop() : '';
//UNCODE: fix issue to detect media type with query strings
ext = ext.replace('?'+extra, '');
return ext.replace(extra, '');
}
}
/**
* Get type via extension.
*
* @param {String} URL
*
* @return {String}
*/
function getTypeByExtension(URL) {
var type,
ext = getExtension(URL);
if (extensions.image.indexOf(ext) !== -1) type = 'image';
else if (extensions.flash.indexOf(ext) !== -1) type = 'flash';
else if (extensions.video.indexOf(ext) !== -1) type = 'video';
else if (ext.substring(0, 1) == "#") type = 'inline'; //Uncode addition
else type = 'iframe';
return type;
}
/**
* Return value from percent of a number.
*
* @param {Number} percent
* @param {Number} total
*
* @return {Number}
*/
function percentToValue(percent, total) {
return parseInt((total / 100) * percent);
}
/**
* A JavaScript equivalent of PHP’s parse_url.
*
* @param {String} url The URL to parse.
*
* @return {Mixed}
*/
function parseURI(url) {
var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
// authority = '//' + user + ':' + pass '@' + hostname + ':' port
return (m ? {
href: m[0] || '',
protocol: m[1] || '',
authority: m[2] || '',
host: m[3] || '',
hostname: m[4] || '',
port: m[5] || '',
pathname: m[6] || '',
search: m[7] || '',
hash: m[8] || ''
} : null);
}
/**
* Gets the absolute URI.
*
* @param {String} href The relative URL.
* @param {String} base The base URL.
*
* @return {String} The absolute URL.
*/
function absolutizeURI(base, href) { // RFC 3986
var iL = this;
function removeDotSegments(input) {
var output = [];
input.replace(/^(\.\.?(\/|$))+/, '')
.replace(/\/(\.(\/|$))+/g, '/')
.replace(/\/\.\.$/, '/../')
.replace(/\/?[^\/]*/g, function(p) {
if (p === '/..') {
output.pop();
} else {
output.push(p);
}
});
return output.join('').replace(/^\//, input.charAt(0) === '/' ? '/' : '');
}
href = parseURI(href || '');
base = parseURI(base || '');
return !href || !base ? null : (href.protocol || base.protocol) +
(href.protocol || href.authority ? href.authority : base.authority) +
removeDotSegments(href.protocol || href.authority || href.pathname.charAt(0) === '/' ? href.pathname : (href.pathname ? ((base.authority && !base.pathname ? '/' : '') + base.pathname.slice(0, base.pathname.lastIndexOf('/') + 1) + href.pathname) : base.pathname)) +
(href.protocol || href.authority || href.pathname ? href.search : (href.search || base.search)) +
href.hash;
}
/**
* A JavaScript equivalent of PHP’s version_compare.
*
* @param {String} v1
* @param {String} v2
* @param {String} operator
*
* @return {Boolean}
*/
function version_compare(v1, v2, operator) {
this.php_js = this.php_js || {};
this.php_js.ENV = this.php_js.ENV || {};
var i = 0,
x = 0,
compare = 0,
vm = {
'dev': -6,
'alpha': -5,
'a': -5,
'beta': -4,
'b': -4,
'RC': -3,
'rc': -3,
'#': -2,
'p': 1,
'pl': 1
},
prepVersion = function(v) {
v = ('' + v).replace(/[_\-+]/g, '.');
v = v.replace(/([^.\d]+)/g, '.$1.').replace(/\.{2,}/g, '.');
return (!v.length ? [-8] : v.split('.'));
},
numVersion = function(v) {
return !v ? 0 : (isNaN(v) ? vm[v] || -7 : parseInt(v, 10));
};
v1 = prepVersion(v1);
v2 = prepVersion(v2);
x = max(v1.length, v2.length);
for (i = 0; i < x; i++) {
if (v1[i] == v2[i]) {
continue;
}
v1[i] = numVersion(v1[i]);
v2[i] = numVersion(v2[i]);
if (v1[i] < v2[i]) {
compare = -1;
break;
} else if (v1[i] > v2[i]) {
compare = 1;
break;
}
}
if (!operator) {
return compare;
}
switch (operator) {
case '>':
case 'gt':
return (compare > 0);
case '>=':
case 'ge':
return (compare >= 0);
case '<=':
case 'le':
return (compare <= 0);
case '==':
case '=':
case 'eq':
return (compare === 0);
case '<>':
case '!=':
case 'ne':
return (compare !== 0);
case '':
case '<':
case 'lt':
return (compare < 0);
default:
return null;
}
}
// Begin the iLightBox plugin
$.fn.iLightBox = function() {
var args = arguments,
opt = ($.isPlainObject(args[0])) ? args[0] : args[1],
items = ($.isArray(args[0]) || typeof args[0] == 'string') ? args[0] : args[1];
if (!opt) opt = {};
// Default options. Play carefully.
var options = $.extend(true, {
attr: 'href',
path: 'vertical',
skin: 'dark',
linkId: false,
infinite: false,
startFrom: 0,
randomStart: false,
keepAspectRatio: true,
maxScale: 1,
minScale: .2,
innerToolbar: false,
smartRecognition: false,
mobileOptimizer: true,
fullAlone: true,
fullViewPort: null,
fullStretchTypes: 'flash, video',
overlay: {
blur: true,
opacity: .85
},
controls: {
arrows: false,
slideshow: false,
toolbar: true,
fullscreen: true,
thumbnail: true,
keyboard: true,
mousewheel: true,
swipe: true
},
keyboard: {
left: true, // previous
right: true, // next
up: true, // previous
down: true, // next
esc: true, // close
shift_enter: true // fullscreen
},
show: {
effect: true,
speed: 300,
title: true
},
hide: {
effect: true,
speed: 300
},
caption: {
start: true,
show: 'mouseenter',
hide: 'mouseleave'
},
social: {
start: true,
show: 'mouseenter',
hide: 'mouseleave',
buttons: false
},
styles: {
pageOffsetX: 0,
pageOffsetY: 0,
nextOffsetX: 45,
nextOffsetY: 0,
nextOpacity: 1,
nextScale: 1,
prevOffsetX: 45,
prevOffsetY: 0,
prevOpacity: 1,
prevScale: 1
},
thumbnails: {
maxWidth: 120,
maxHeight: 80,
normalOpacity: 1,
activeOpacity: .6
},
effects: {
reposition: true,
repositionSpeed: 200,
switchSpeed: 500,
loadedFadeSpeed: 180,
fadeSpeed: 200
},
slideshow: {
pauseTime: 5000,
pauseOnHover: false,
startPaused: true
},
text: {
close: "Press Esc to close",
enterFullscreen: "Enter Fullscreen (Shift+Enter)",
exitFullscreen: "Exit Fullscreen (Shift+Enter)",
slideShow: "Slideshow",
next: "Next",
previous: "Previous"
},
errors: {
loadImage: "An error occurred when trying to load photo.",
loadContents: "An error occurred when trying to load contents.",
missingPlugin: "The content your are attempting to view requires the <a href='{pluginspage}' target='_blank'>{type} plugin<\/a>."
},
ajaxSetup: {
url: '',
beforeSend: function(jqXHR, settings) {},
cache: false,
complete: function(jqXHR, textStatus) {},
crossDomain: false,
error: function(jqXHR, textStatus, errorThrown) {},
success: function(data, textStatus, jqXHR) {},
global: true,
ifModified: false,
username: null,
password: null,
type: 'GET'
},
callback: {}
}, opt);
var instant = ($.isArray(items) || typeof items == 'string') ? true : false;
items = $.isArray(items) ? items : new Array();
if (typeof args[0] == 'string') items[0] = args[0];
if (version_compare($.fn.jquery, '1.8', '>=')) {
var iLB = new iLightBox($(this), options, items, instant);
return {
close: function() {
iLB.closeAction();
},
fullscreen: function() {
iLB.fullScreenAction();
},
moveNext: function() {
iLB.moveTo('next');
},
movePrev: function() {
iLB.moveTo('prev');
},
goTo: function(index) {
iLB.goTo(index);
},
refresh: function() {
iLB.refresh();
},
reposition: function() {
(arguments.length > 0) ? iLB.repositionPhoto(true): iLB.repositionPhoto();
},
setOption: function(options) {
iLB.setOption(options);
},
destroy: function() {
iLB.closeAction();
iLB.dispatchItemsEvents();
}
};
} else {
throw "The jQuery version that was loaded is too old. iLightBox requires jQuery 1.8+";
}
};
$.iLightBox = function() {
return $.fn.iLightBox(arguments[0], arguments[1]);
};
$.extend($.easing, {
easeInCirc: function(x, t, b, c, d) {
return -c * (sqrt(1 - (t /= d) * t) - 1) + b;
},
easeOutCirc: function(x, t, b, c, d) {
return c * sqrt(1 - (t = t / d - 1) * t) + b;
},
easeInOutCirc: function(x, t, b, c, d) {
if ((t /= d / 2) < 1) return -c / 2 * (sqrt(1 - t * t) - 1) + b;
return c / 2 * (sqrt(1 - (t -= 2) * t) + 1) + b;
}
});
function getScrollXY() {
var scrOfX = 0,
scrOfY = 0;
if (typeof(window.pageYOffset) == 'number') {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return {
x: scrOfX,
y: scrOfY
};
}
(function() {
// add new event shortcuts
$.each(("touchstart touchmove touchend " +
"tap taphold " +
"swipe swipeleft swiperight " +
"scrollstart scrollstop").split(" "), function(i, name) {
$.fn[name] = function(fn) {
return fn ? this.bind(name, fn) : this.trigger(name);
};
// jQuery < 1.8
// if ($.attrFn) {
// $.attrFn[name] = true;
// }
});
var tapSettings = {
startEvent: 'touchstart.iTap',
endEvent: 'touchend.iTap'
};
// tap Event:
$.event.special.itap = {
setup: function() {
var self = this,
$self = $(this),
start, stop;
$self.bind(tapSettings.startEvent, function(event) {
start = getScrollXY();
$self.one(tapSettings.endEvent, function(event) {
stop = getScrollXY();
var orgEvent = event || window.event;
event = $.event.fix(orgEvent);
event.type = "itap";
if ((start && stop) && (start.x == stop.x && start.y == stop.y))($.event.dispatch || $.event.handle).call(self, event);
start = stop = undefined;
});
});
},
teardown: function() {
$(this).unbind(tapSettings.startEvent);
}
};
}());
//Fullscreen API
(function() {
fullScreenApi = {
supportsFullScreen: false,
isFullScreen: function() {
return false;
},
requestFullScreen: function() {},
cancelFullScreen: function() {},
fullScreenEventName: '',
prefix: ''
},
browserPrefixes = 'webkit moz o ms khtml'.split(' ');
// check for native support
if (typeof document.cancelFullScreen != 'undefined') {
fullScreenApi.supportsFullScreen = true;
} else {
// check for fullscreen support by vendor prefix
for (var i = 0, il = browserPrefixes.length; i < il; i++) {
fullScreenApi.prefix = browserPrefixes[i];
if (typeof document[fullScreenApi.prefix + 'CancelFullScreen'] != 'undefined') {
fullScreenApi.supportsFullScreen = true;
break;
}
}
}
// update methods to do something useful
if (fullScreenApi.supportsFullScreen) {
fullScreenApi.fullScreenEventName = fullScreenApi.prefix + 'fullscreenchange';
fullScreenApi.isFullScreen = function() {
switch (this.prefix) {
case '':
return document.fullScreen;
case 'webkit':
return document.webkitIsFullScreen;
default:
return document[this.prefix + 'FullScreen'];
}
}
fullScreenApi.requestFullScreen = function(el) {
return (this.prefix === '') ? el.requestFullScreen() : el[this.prefix + 'RequestFullScreen']();
}
fullScreenApi.cancelFullScreen = function(el) {
return (this.prefix === '') ? document.cancelFullScreen() : document[this.prefix + 'CancelFullScreen']();
}
}
}());
// Browser detect
(function() {
function uaMatch(ua) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || [];
return {
browser: match[1] || "",
version: match[2] || "0"
};
}
var matched = uaMatch(navigator.userAgent);
browser = {};
if (matched.browser) {
browser[matched.browser] = true;
browser.version = matched.version;
}
// Chrome is Webkit, but Webkit is also Safari.
if (browser.chrome) {
browser.webkit = true;
} else if (browser.webkit) {
browser.safari = true;
}
}());
// Feature detects
(function() {
var prefixes = ['', 'webkit', 'moz', 'ms', 'o'];
var el = document.createElement('div');
function testProp(prop) {
for (var p = 0, pl = prefixes.length; p < pl; p++) {
var prefixedProp = prefixes[p] ? prefixes[p] + prop.charAt(0).toUpperCase() + prop.slice(1) : prop;
if (el.style[prefixedProp] !== undefined) {
return prefixedProp;
}
}
}
// Global support indicators
transform = testProp('transform') || '';
gpuAcceleration = testProp('perspective') ? 'translateZ(0) ' : '';
}());
/*
PluginDetect v0.7.9
www.pinlady.net/PluginDetect/license/
[ getVersion onWindowLoaded BetterIE ]
[ Flash QuickTime Shockwave ]
*/
var PluginDetect={version:"0.7.9",name:"PluginDetect",handler:function(c,b,a){return function(){c(b,a)}},openTag:"<",isDefined:function(b){return typeof b!="undefined"},isArray:function(b){return(/array/i).test(Object.prototype.toString.call(b))},isFunc:function(b){return typeof b=="function"},isString:function(b){return typeof b=="string"},isNum:function(b){return typeof b=="number"},isStrNum:function(b){return(typeof b=="string"&&(/\d/).test(b))},getNumRegx:/[\d][\d\.\_,-]*/,splitNumRegx:/[\.\_,-]/g,getNum:function(b,c){var d=this,a=d.isStrNum(b)?(d.isDefined(c)?new RegExp(c):d.getNumRegx).exec(b):null;return a?a[0]:null},compareNums:function(h,f,d){var e=this,c,b,a,g=parseInt;if(e.isStrNum(h)&&e.isStrNum(f)){if(e.isDefined(d)&&d.compareNums){return d.compareNums(h,f)}c=h.split(e.splitNumRegx);b=f.split(e.splitNumRegx);for(a=0;a<min(c.length,b.length);a++){if(g(c[a],10)>g(b[a],10)){return 1}if(g(c[a],10)<g(b[a],10)){return -1}}}return 0},formatNum:function(b,c){var d=this,a,e;if(!d.isStrNum(b)){return null}if(!d.isNum(c)){c=4}c--;e=b.replace(/\s/g,"").split(d.splitNumRegx).concat(["0","0","0","0"]);for(a=0;a<4;a++){if(/^(0+)(.+)$/.test(e[a])){e[a]=RegExp.$2}if(a>c||!(/\d/).test(e[a])){e[a]="0"}}return e.slice(0,4).join(",")},$$hasMimeType:function(a){return function(c){if(!a.isIE&&c){var f,e,b,d=a.isArray(c)?c:(a.isString(c)?[c]:[]);for(b=0;b<d.length;b++){if(a.isString(d[b])&&/[^\s]/.test(d[b])){f=navigator.mimeTypes[d[b]];e=f?f.enabledPlugin:0;if(e&&(e.name||e.description)){return f}}}}return null}},findNavPlugin:function(l,e,c){var j=this,h=new RegExp(l,"i"),d=(!j.isDefined(e)||e)?/\d/:0,k=c?new RegExp(c,"i"):0,a=navigator.plugins,g="",f,b,m;for(f=0;f<a.length;f++){m=a[f].description||g;b=a[f].name||g;if((h.test(m)&&(!d||d.test(RegExp.leftContext+RegExp.rightContext)))||(h.test(b)&&(!d||d.test(RegExp.leftContext+RegExp.rightContext)))){if(!k||!(k.test(m)||k.test(b))){return a[f]}}}return null},getMimeEnabledPlugin:function(k,m,c){var e=this,f,b=new RegExp(m,"i"),h="",g=c?new RegExp(c,"i"):0,a,l,d,j=e.isString(k)?[k]:k;for(d=0;d<j.length;d++){if((f=e.hasMimeType(j[d]))&&(f=f.enabledPlugin)){l=f.description||h;a=f.name||h;if(b.test(l)||b.test(a)){if(!g||!(g.test(l)||g.test(a))){return f}}}}return 0},getPluginFileVersion:function(f,b){var h=this,e,d,g,a,c=-1;if(h.OS>2||!f||!f.version||!(e=h.getNum(f.version))){return b}if(!b){return e}e=h.formatNum(e);b=h.formatNum(b);d=b.split(h.splitNumRegx);g=e.split(h.splitNumRegx);for(a=0;a<d.length;a++){if(c>-1&&a>c&&d[a]!="0"){return b}if(g[a]!=d[a]){if(c==-1){c=a}if(d[a]!="0"){return b}}}return e},AXO:window.ActiveXObject,getAXO:function(a){var f=null,d,b=this,c={};try{f=new b.AXO(a)}catch(d){}return f},convertFuncs:function(f){var a,g,d,b=/^[\$][\$]/,c=this;for(a in f){if(b.test(a)){try{g=a.slice(2);if(g.length>0&&!f[g]){f[g]=f[a](f);delete f[a]}}catch(d){}}}},initObj:function(e,b,d){var a,c;if(e){if(e[b[0]]==1||d){for(a=0;a<b.length;a=a+2){e[b[a]]=b[a+1]}}for(a in e){c=e[a];if(c&&c[b[0]]==1){this.initObj(c,b)}}}},initScript:function(){var d=this,a=navigator,h,i=document,l=a.userAgent||"",j=a.vendor||"",b=a.platform||"",k=a.product||"";d.initObj(d,["$",d]);for(h in d.Plugins){if(d.Plugins[h]){d.initObj(d.Plugins[h],["$",d,"$$",d.Plugins[h]],1)}}d.convertFuncs(d);d.OS=100;if(b){var g=["Win",1,"Mac",2,"Linux",3,"FreeBSD",4,"iPhone",21.1,"iPod",21.2,"iPad",21.3,"Win.*CE",22.1,"Win.*Mobile",22.2,"Pocket\\s*PC",22.3,"",100];for(h=g.length-2;h>=0;h=h-2){if(g[h]&&new RegExp(g[h],"i").test(b)){d.OS=g[h+1];break}}};d.head=i.getElementsByTagName("head")[0]||i.getElementsByTagName("body")[0]||i.body||null;d.isIE=new Function("return/*@cc_on!@*/!1")();d.verIE=d.isIE&&(/MSIE\s*(\d+\.?\d*)/i).test(l)?parseFloat(RegExp.$1,10):null;d.verIEfull=null;d.docModeIE=null;if(d.isIE){var f,n,c=document.createElement("div");try{c.style.behavior="url(#default#clientcaps)";d.verIEfull=(c.getComponentVersion("{89820200-ECBD-11CF-8B85-00AA005B4383}","componentid")).replace(/,/g,".")}catch(f){}n=parseFloat(d.verIEfull||"0",10);d.docModeIE=i.documentMode||((/back/i).test(i.compatMode||"")?5:n)||d.verIE;d.verIE=n||d.docModeIE};d.ActiveXEnabled=false;if(d.isIE){var h,m=["Msxml2.XMLHTTP","Msxml2.DOMDocument","Microsoft.XMLDOM","ShockwaveFlash.ShockwaveFlash","TDCCtl.TDCCtl","Shell.UIHelper","Scripting.Dictionary","wmplayer.ocx"];for(h=0;h<m.length;h++){if(d.getAXO(m[h])){d.ActiveXEnabled=true;break}}};d.isGecko=(/Gecko/i).test(k)&&(/Gecko\s*\/\s*\d/i).test(l);d.verGecko=d.isGecko?d.formatNum((/rv\s*\:\s*([\.\,\d]+)/i).test(l)?RegExp.$1:"0.9"):null;d.isChrome=(/Chrome\s*\/\s*(\d[\d\.]*)/i).test(l);d.verChrome=d.isChrome?d.formatNum(RegExp.$1):null;d.isSafari=((/Apple/i).test(j)||(!j&&!d.isChrome))&&(/Safari\s*\/\s*(\d[\d\.]*)/i).test(l);d.verSafari=d.isSafari&&(/Version\s*\/\s*(\d[\d\.]*)/i).test(l)?d.formatNum(RegExp.$1):null;d.isOpera=(/Opera\s*[\/]?\s*(\d+\.?\d*)/i).test(l);d.verOpera=d.isOpera&&((/Version\s*\/\s*(\d+\.?\d*)/i).test(l)||1)?parseFloat(RegExp.$1,10):null;d.addWinEvent("load",d.handler(d.runWLfuncs,d))},init:function(d){var c=this,b,d,a={status:-3,plugin:0};if(!c.isString(d)){return a}if(d.length==1){c.getVersionDelimiter=d;return a}d=d.toLowerCase().replace(/\s/g,"");b=c.Plugins[d];if(!b||!b.getVersion){return a}a.plugin=b;if(!c.isDefined(b.installed)){b.installed=null;b.version=null;b.version0=null;b.getVersionDone=null;b.pluginName=d}c.garbage=false;if(c.isIE&&!c.ActiveXEnabled&&d!=="java"){a.status=-2;return a}a.status=1;return a},fPush:function(b,a){var c=this;if(c.isArray(a)&&(c.isFunc(b)||(c.isArray(b)&&b.length>0&&c.isFunc(b[0])))){a.push(b)}},callArray:function(b){var c=this,a;if(c.isArray(b)){for(a=0;a<b.length;a++){if(b[a]===null){return}c.call(b[a]);b[a]=null}}},call:function(c){var b=this,a=b.isArray(c)?c.length:-1;if(a>0&&b.isFunc(c[0])){c[0](b,a>1?c[1]:0,a>2?c[2]:0,a>3?c[3]:0)}else{if(b.isFunc(c)){c(b)}}},getVersionDelimiter:",",$$getVersion:function(a){return function(g,d,c){var e=a.init(g),f,b,h={};if(e.status<0){return null};f=e.plugin;if(f.getVersionDone!=1){f.getVersion(null,d,c);if(f.getVersionDone===null){f.getVersionDone=1}}a.cleanup();b=(f.version||f.version0);b=b?b.replace(a.splitNumRegx,a.getVersionDelimiter):b;return b}},cleanup:function(){var a=this;if(a.garbage&&a.isDefined(window.CollectGarbage)){window.CollectGarbage()}},isActiveXObject:function(d,b){var f=this,a=false,g,c='<object width="1" height="1" style="display:none" '+d.getCodeBaseVersion(b)+">"+d.HTML+f.openTag+"/object>";if(!f.head){return a}f.head.insertBefore(document.createElement("object"),f.head.firstChild);f.head.firstChild.outerHTML=c;try{f.head.firstChild.classid=d.classID}catch(g){}try{if(f.head.firstChild.object){a=true}}catch(g){}try{if(a&&f.head.firstChild.readyState<4){f.garbage=true}}catch(g){}f.head.removeChild(f.head.firstChild);return a},codebaseSearch:function(f,b){var c=this;if(!c.ActiveXEnabled||!f){return null}if(f.BIfuncs&&f.BIfuncs.length&&f.BIfuncs[f.BIfuncs.length-1]!==null){c.callArray(f.BIfuncs)}var d,o=f.SEARCH,k={};if(c.isStrNum(b)){if(o.match&&o.min&&c.compareNums(b,o.min)<=0){return true}if(o.match&&o.max&&c.compareNums(b,o.max)>=0){return false}d=c.isActiveXObject(f,b);if(d&&(!o.min||c.compareNums(b,o.min)>0)){o.min=b}if(!d&&(!o.max||c.compareNums(b,o.max)<0)){o.max=b}return d};var e=[0,0,0,0],l=[].concat(o.digits),a=o.min?1:0,j,i,h,g,m,n=function(p,r){var q=[].concat(e);q[p]=r;return c.isActiveXObject(f,q.join(","))};if(o.max){g=o.max.split(c.splitNumRegx);for(j=0;j<g.length;j++){g[j]=parseInt(g[j],10)}if(g[0]<l[0]){l[0]=g[0]}}if(o.min){m=o.min.split(c.splitNumRegx);for(j=0;j<m.length;j++){m[j]=parseInt(m[j],10)}if(m[0]>e[0]){e[0]=m[0]}}if(m&&g){for(j=1;j<m.length;j++){if(m[j-1]!=g[j-1]){break}if(g[j]<l[j]){l[j]=g[j]}if(m[j]>e[j]){e[j]=m[j]}}}if(o.max){for(j=1;j<l.length;j++){if(g[j]>0&&l[j]==0&&l[j-1]<o.digits[j-1]){l[j-1]+=1;break}}};for(j=0;j<l.length;j++){h={};for(i=0;i<20;i++){if(l[j]-e[j]<1){break}d=round((l[j]+e[j])/2);if(h["a"+d]){break}h["a"+d]=1;if(n(j,d)){e[j]=d;a=1}else{l[j]=d}}l[j]=e[j];if(!a&&n(j,e[j])){a=1};if(!a){break}};return a?e.join(","):null},addWinEvent:function(d,c){var e=this,a=window,b;if(e.isFunc(c)){if(a.addEventListener){a.addEventListener(d,c,false)}else{if(a.attachEvent){a.attachEvent("on"+d,c)}else{b=a["on"+d];a["on"+d]=e.winHandler(c,b)}}}},winHandler:function(d,c){return function(){d();if(typeof c=="function"){c()}}},WLfuncs0:[],WLfuncs:[],runWLfuncs:function(a){var b={};a.winLoaded=true;a.callArray(a.WLfuncs0);a.callArray(a.WLfuncs);if(a.onDoneEmptyDiv){a.onDoneEmptyDiv()}},winLoaded:false,$$onWindowLoaded:function(a){return function(b){if(a.winLoaded){a.call(b)}else{a.fPush(b,a.WLfuncs)}}},div:null,divID:"plugindetect",divWidth:50,pluginSize:1,emptyDiv:function(){var d=this,b,h,c,a,f,g;if(d.div&&d.div.childNodes){for(b=d.div.childNodes.length-1;b>=0;b--){c=d.div.childNodes[b];if(c&&c.childNodes){for(h=c.childNodes.length-1;h>=0;h--){g=c.childNodes[h];try{c.removeChild(g)}catch(f){}}}if(c){try{d.div.removeChild(c)}catch(f){}}}}if(!d.div){a=document.getElementById(d.divID);if(a){d.div=a}}if(d.div&&d.div.parentNode){try{d.div.parentNode.removeChild(d.div)}catch(f){}d.div=null}},DONEfuncs:[],onDoneEmptyDiv:function(){var c=this,a,b;if(!c.winLoaded){return}if(c.WLfuncs&&c.WLfuncs.length&&c.WLfuncs[c.WLfuncs.length-1]!==null){return}for(a in c){b=c[a];if(b&&b.funcs){if(b.OTF==3){return}if(b.funcs.length&&b.funcs[b.funcs.length-1]!==null){return}}}for(a=0;a<c.DONEfuncs.length;a++){c.callArray(c.DONEfuncs)}c.emptyDiv()},getWidth:function(c){if(c){var a=c.scrollWidth||c.offsetWidth,b=this;if(b.isNum(a)){return a}}return -1},getTagStatus:function(m,g,a,b){var c=this,f,k=m.span,l=c.getWidth(k),h=a.span,j=c.getWidth(h),d=g.span,i=c.getWidth(d);if(!k||!h||!d||!c.getDOMobj(m)){return -2}if(j<i||l<0||j<0||i<0||i<=c.pluginSize||c.pluginSize<1){return 0}if(l>=i){return -1}try{if(l==c.pluginSize&&(!c.isIE||c.getDOMobj(m).readyState==4)){if(!m.winLoaded&&c.winLoaded){return 1}if(m.winLoaded&&c.isNum(b)){if(!c.isNum(m.count)){m.count=b}if(b-m.count>=10){return 1}}}}catch(f){}return 0},getDOMobj:function(g,a){var f,d=this,c=g?g.span:0,b=c&&c.firstChild?1:0;try{if(b&&a){d.div.focus()}}catch(f){}return b?c.firstChild:null},setStyle:function(b,g){var f=b.style,a,d,c=this;if(f&&g){for(a=0;a<g.length;a=a+2){try{f[g[a]]=g[a+1]}catch(d){}}}},insertDivInBody:function(i,g){var f,c=this,h="pd33993399",b=null,d=g?window.top.document:window.document,a=d.getElementsByTagName("body")[0]||d.body;if(!a){try{d.write('<div id="'+h+'">.'+c.openTag+"/div>");b=d.getElementById(h)}catch(f){}}a=d.getElementsByTagName("body")[0]||d.body;if(a){a.insertBefore(i,a.firstChild);if(b){a.removeChild(b)}}},insertHTML:function(f,b,g,a,k){var l,m=document,j=this,p,o=m.createElement("span"),n,i;var c=["outlineStyle","none","borderStyle","none","padding","0px","margin","0px","visibility","visible"];var h="outline-style:none;border-style:none;padding:0px;margin:0px;visibility:visible;";if(!j.isDefined(a)){a=""}if(j.isString(f)&&(/[^\s]/).test(f)){f=f.toLowerCase().replace(/\s/g,"");p=j.openTag+f+' width="'+j.pluginSize+'" height="'+j.pluginSize+'" ';p+='style="'+h+'display:inline;" ';for(n=0;n<b.length;n=n+2){if(/[^\s]/.test(b[n+1])){p+=b[n]+'="'+b[n+1]+'" '}}p+=">";for(n=0;n<g.length;n=n+2){if(/[^\s]/.test(g[n+1])){p+=j.openTag+'param name="'+g[n]+'" value="'+g[n+1]+'" />'}}p+=a+j.openTag+"/"+f+">"}else{p=a}if(!j.div){i=m.getElementById(j.divID);if(i){j.div=i}else{j.div=m.createElement("div");j.div.id=j.divID}j.setStyle(j.div,c.concat(["width",j.divWidth+"px","height",(j.pluginSize+3)+"px","fontSize",(j.pluginSize+3)+"px","lineHeight",(j.pluginSize+3)+"px","verticalAlign","baseline","display","block"]));if(!i){j.setStyle(j.div,["position","absolute","right","0px","top","0px"]);j.insertDivInBody(j.div)}}if(j.div&&j.div.parentNode){j.setStyle(o,c.concat(["fontSize",(j.pluginSize+3)+"px","lineHeight",(j.pluginSize+3)+"px","verticalAlign","baseline","display","inline"]));try{o.innerHTML=p}catch(l){};try{j.div.appendChild(o)}catch(l){};return{span:o,winLoaded:j.winLoaded,tagName:f,outerHTML:p}}return{span:null,winLoaded:j.winLoaded,tagName:"",outerHTML:p}},Plugins:{quicktime:{mimeType:["video/quicktime","application/x-quicktimeplayer","image/x-macpaint","image/x-quicktime"],progID:"QuickTimeCheckObject.QuickTimeCheck.1",progID0:"QuickTime.QuickTime",classID:"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B",minIEver:7,HTML:'<param name="src" value="" /><param name="controller" value="false" />',getCodeBaseVersion:function(a){return'codebase="#version='+a+'"'},SEARCH:{min:0,max:0,match:0,digits:[16,128,128,0]},getVersion:function(c){var f=this,d=f.$,a=null,e=null,b;if(!d.isIE){if(d.hasMimeType(f.mimeType)){e=d.OS!=3?d.findNavPlugin("QuickTime.*Plug-?in",0):null;if(e&&e.name){a=d.getNum(e.name)}}}else{if(d.isStrNum(c)){b=c.split(d.splitNumRegx);if(b.length>3&&parseInt(b[3],10)>0){b[3]="9999"}c=b.join(",")}if(d.isStrNum(c)&&d.verIE>=f.minIEver&&f.canUseIsMin()>0){f.installed=f.isMin(c);f.getVersionDone=0;return}f.getVersionDone=1;if(!a&&d.verIE>=f.minIEver){a=f.CDBASE2VER(d.codebaseSearch(f))}if(!a){e=d.getAXO(f.progID);if(e&&e.QuickTimeVersion){a=e.QuickTimeVersion.toString(16);a=parseInt(a.charAt(0),16)+"."+parseInt(a.charAt(1),16)+"."+parseInt(a.charAt(2),16)}}}f.installed=a?1:(e?0:-1);f.version=d.formatNum(a,3)},cdbaseUpper:["7,60,0,0","0,0,0,0"],cdbaseLower:["7,50,0,0",null],cdbase2ver:[function(c,b){var a=b.split(c.$.splitNumRegx);return[a[0],a[1].charAt(0),a[1].charAt(1),a[2]].join(",")},null],CDBASE2VER:function(f){var e=this,c=e.$,b,a=e.cdbaseUpper,d=e.cdbaseLower;if(f){f=c.formatNum(f);for(b=0;b<a.length;b++){if(a[b]&&c.compareNums(f,a[b])<0&&d[b]&&c.compareNums(f,d[b])>=0&&e.cdbase2ver[b]){return e.cdbase2ver[b](e,f)}}}return f},canUseIsMin:function(){var f=this,d=f.$,b,c=f.canUseIsMin,a=f.cdbaseUpper,e=f.cdbaseLower;if(!c.value){c.value=-1;for(b=0;b<a.length;b++){if(a[b]&&d.codebaseSearch(f,a[b])){c.value=1;break}if(e[b]&&d.codebaseSearch(f,e[b])){c.value=-1;break}}}f.SEARCH.match=c.value==1?1:0;return c.value},isMin:function(c){var b=this,a=b.$;return a.codebaseSearch(b,c)?0.7:-1}},flash:{mimeType:"application/x-shockwave-flash",progID:"ShockwaveFlash.ShockwaveFlash",classID:"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000",getVersion:function(){var b=function(i){if(!i){return null}var e=/[\d][\d\,\.\s]*[rRdD]{0,1}[\d\,]*/.exec(i);return e?e[0].replace(/[rRdD\.]/g,",").replace(/\s/g,""):null};var j=this,g=j.$,k,h,l=null,c=null,a=null,f,m,d;if(!g.isIE){m=g.hasMimeType(j.mimeType);if(m){f=g.getDOMobj(g.insertHTML("object",["type",j.mimeType],[],"",j));try{l=g.getNum(f.GetVariable("$version"))}catch(k){}}if(!l){d=m?m.enabledPlugin:null;if(d&&d.description){l=b(d.description)}if(l){l=g.getPluginFileVersion(d,l)}}}else{for(h=15;h>2;h--){c=g.getAXO(j.progID+"."+h);if(c){a=h.toString();break}}if(!c){c=g.getAXO(j.progID)}if(a=="6"){try{c.AllowScriptAccess="always"}catch(k){return"6,0,21,0"}}try{l=b(c.GetVariable("$version"))}catch(k){}if(!l&&a){l=a}}j.installed=l?1:-1;j.version=g.formatNum(l);return true}},shockwave:{mimeType:"application/x-director",progID:"SWCtl.SWCtl",classID:"clsid:166B1BCA-3F9C-11CF-8075-444553540000",getVersion:function(){var a=null,b=null,g,f,d=this,c=d.$;if(!c.isIE){f=c.findNavPlugin("Shockwave\\s*for\\s*Director");if(f&&f.description&&c.hasMimeType(d.mimeType)){a=c.getNum(f.description)}if(a){a=c.getPluginFileVersion(f,a)}}else{try{b=c.getAXO(d.progID).ShockwaveVersion("")}catch(g){}if(c.isString(b)&&b.length>0){a=c.getNum(b)}else{if(c.getAXO(d.progID+".8")){a="8"}else{if(c.getAXO(d.progID+".7")){a="7"}else{if(c.getAXO(d.progID+".1")){a="6"}}}}}d.installed=a?1:-1;d.version=c.formatNum(a)}},zz:0}};PluginDetect.initScript();
var gArgCountErr='The "%%" function requires an even number of arguments.\nArguments should be in the form "atttributeName", "attributeValue", ...',gTagAttrs=null,gQTGeneratorVersion=1;function AC_QuickTimeVersion(){return gQTGeneratorVersion}function _QTComplain(a,b){b=b.replace("%%",a);alert(b)}function _QTAddAttribute(a,b,c){var d;d=gTagAttrs[a+b];null==d&&(d=gTagAttrs[b]);return null!=d?(0==b.indexOf(a)&&null==c&&(c=b.substring(a.length)),null==c&&(c=b),c+'="'+d+'" '):""}function _QTAddObjectAttr(a,b){if(0==a.indexOf("emb#"))return"";0==a.indexOf("obj#")&&null==b&&(b=a.substring(4));return _QTAddAttribute("obj#",a,b)}function _QTAddEmbedAttr(a,b){if(0==a.indexOf("obj#"))return"";0==a.indexOf("emb#")&&null==b&&(b=a.substring(4));return _QTAddAttribute("emb#",a,b)}function _QTAddObjectParam(a,b){var c,d="",e=b?" />":">";-1==a.indexOf("emb#")&&(c=gTagAttrs["obj#"+a],null==c&&(c=gTagAttrs[a]),0==a.indexOf("obj#")&&(a=a.substring(4)),null!=c&&(d=' <param name="'+a+'" value="'+c+'"'+e+"\n"));return d}function _QTDeleteTagAttrs(){for(var a=0;a<arguments.length;a++){var b=arguments[a];delete gTagAttrs[b];delete gTagAttrs["emb#"+b];delete gTagAttrs["obj#"+b]}}function _QTGenerate(a,b,c){if(4>c.length||0!=c.length%2)return _QTComplain(a,gArgCountErr),"";gTagAttrs=[];gTagAttrs.src=c[0];gTagAttrs.width=c[1];gTagAttrs.height=c[2];gTagAttrs.classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";gTagAttrs.pluginspage="http://www.apple.com/quicktime/download/";a=c[3];if(null==a||""==a)a="6,0,2,0";gTagAttrs.codebase="http://www.apple.com/qtactivex/qtplugin.cab#version="+a;for(var d,e=4;e<c.length;e+=2)d=c[e].toLowerCase(),a=c[e+1],"name"==d||"id"==d?gTagAttrs.name=a:gTagAttrs[d]=a;c="<object "+_QTAddObjectAttr("classid")+_QTAddObjectAttr("width")+_QTAddObjectAttr("height")+_QTAddObjectAttr("codebase")+_QTAddObjectAttr("name","id")+_QTAddObjectAttr("tabindex")+_QTAddObjectAttr("hspace")+_QTAddObjectAttr("vspace")+_QTAddObjectAttr("border")+_QTAddObjectAttr("align")+_QTAddObjectAttr("class")+_QTAddObjectAttr("title")+_QTAddObjectAttr("accesskey")+_QTAddObjectAttr("noexternaldata")+">\n"+_QTAddObjectParam("src",b);e=" <embed "+_QTAddEmbedAttr("src")+_QTAddEmbedAttr("width")+_QTAddEmbedAttr("height")+_QTAddEmbedAttr("pluginspage")+_QTAddEmbedAttr("name")+_QTAddEmbedAttr("align")+_QTAddEmbedAttr("tabindex");_QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex","hspace","vspace","border","align","noexternaldata","class","title","accesskey");for(d in gTagAttrs)a=gTagAttrs[d],null!=a&&(e+=_QTAddEmbedAttr(d),c+=_QTAddObjectParam(d,b));return c+e+"> </embed>\n</object>"}function QT_GenerateOBJECTText(){return _QTGenerate("QT_GenerateOBJECTText",!1,arguments)};
/*
jQuery hashchange event v1.3
https://github.com/cowboy/jquery-hashchange
Copyright (c) 2010 "Cowboy" Ben Alman
Dual licensed under the MIT and GPL licenses.
*/
(function(){function e(a){a=a||location.href;return"#"+a.replace(/^[^#]*#?(.*)$/,"$1")}var k=document,b,f=$.event.special,p=k.documentMode,m="oniLightBoxHashChange"in window&&(void 0===p||7<p);$.fn.iLightBoxHashChange=function(a){return a?this.bind("iLightBoxHashChange",a):this.trigger("iLightBoxHashChange")};$.fn.iLightBoxHashChange.delay=50;f.iLightBoxHashChange=$.extend(f.iLightBoxHashChange,{setup:function(){if(m)return!1;$(b.start)},teardown:function(){if(m)return!1;$(b.stop)}});b=function(){function a(){var c=
e(),d=f(l);c!==l?(n(l=c,d),$(window).trigger("iLightBoxHashChange")):d!==l&&(location.href=location.href.replace(/#.*/,"")+d);g=setTimeout(a,$.fn.iLightBoxHashChange.delay)}var h={},g,l=e(),b=function(c){return c},n=b,f=b;h.start=function(){g||a()};h.stop=function(){g&&clearTimeout(g);g=void 0};browser.msie&&!m&&function(){var c,d;h.start=function(){c||(d=(d=$.fn.iLightBoxHashChange.src)&&d+e(),c=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){d||n(e());a()}).attr("src",d||
"javascript:0").insertAfter("body")[0].contentWindow,k.onpropertychange=function(){try{"title"===event.propertyName&&(c.document.title=k.title)}catch(a){}})};h.stop=b;f=function(){return e(c.location.href)};n=function(a,d){var b=c.document,e=$.fn.iLightBoxHashChange.domain;a!==d&&(b.title=k.title,b.open(),e&&b.write('<script>document.domain="'+e+'"\x3c/script>'),b.close(),c.location.hash=a)}}();return h}()})();
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp */ ) {
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
var val = t[i]; // in case fun mutates this
if (fun.call(thisp, val, i, t))
res.push(val);
}
}
return res;
};
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(searchElement, fromIndex) {
var k;
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var O = Object(this);
var len = O.length >>> 0;
if (len === 0) {
return -1;
}
var n = +fromIndex || 0;
if (abs(n) === Infinity) {
n = 0;
}
if (n >= len) {
return -1;
}
k = max(n >= 0 ? n : len - abs(n), 0);
while (k < len) {
var kValue;
if (k in O && O[k] === searchElement) {
return k;
}
k++;
}
return -1;
};
}
if (!Array.prototype.lastIndexOf) {
Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/ ) {
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (len === 0)
return -1;
var n = len;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n)
n = 0;
else if (n != 0 && n != (1 / 0) && n != -(1 / 0))
n = (n > 0 || -1) * floor(abs(n));
}
var k = n >= 0 ? min(n, len - 1) : len - abs(n);
for (; k >= 0; k--) {
if (k in t && t[k] === searchElement)
return k;
}
return -1;
};
}
})(jQuery, this);
/**
* Owl carousel
* @version 2.0.0-beta.3
* @author Bartosz Wojciechowski
* @license The MIT License (MIT)
* @todo Lazy Load Icon
* @todo prevent animationend bubling
* @todo itemsScaleUp
* @todo Test Zepto
* @todo stagePadding calculate wrong active classes
*/
;(function($, window, document, undefined) {
/**
* Creates a carousel.
* @class The Owl Carousel.
* @public
* @param {HTMLElement|jQuery} element - The element to create the carousel for.
* @param {Object} [options] - The options
*/
function Owl(element, options) {
/**
* Current settings for the carousel.
* @public
*/
this.settings = null;
/**
* Current options set by the caller including defaults.
* @public
*/
this.options = $.extend({}, Owl.Defaults, options);
/**
* Plugin element.
* @public
*/
this.$element = $(element);
/**
* Proxied event handlers.
* @protected
*/
this._handlers = {};
/**
* References to the running plugins of this carousel.
* @protected
*/
this._plugins = {};
/**
* Currently suppressed events to prevent them from beeing retriggered.
* @protected
*/
this._supress = {};
/**
* Absolute current position.
* @protected
*/
this._current = null;
/**
* Animation speed in milliseconds.
* @protected
*/
this._speed = null;
/**
* Coordinates of all items in pixel.
* @todo The name of this member is missleading.
* @protected
*/
this._coordinates = [];
/**
* Current breakpoint.
* @todo Real media queries would be nice.
* @protected
*/
this._breakpoint = null;
/**
* Current width of the plugin element.
*/
this._width = null;
/**
* All real items.
* @protected
*/
this._items = [];
/**
* All cloned items.
* @protected
*/
this._clones = [];
/**
* Merge values of all items.
* @todo Maybe this could be part of a plugin.
* @protected
*/
this._mergers = [];
/**
* Widths of all items.
*/
this._widths = [];
/**
* Invalidated parts within the update process.
* @protected
*/
this._invalidated = {};
/**
* Ordered list of workers for the update process.
* @protected
*/
this._pipe = [];
/**
* Current state information for the drag operation.
* @todo #261
* @protected
*/
this._drag = {
time: null,
target: null,
pointer: null,
stage: {
start: null,
current: null
},
direction: null
};
/**
* Current state information and their tags.
* @type {Object}
* @protected
*/
this._states = {
current: {},
tags: {
'initializing': [ 'busy' ],
'animating': [ 'busy' ],
'dragging': [ 'interacting' ]
}
};
$.each([ 'onResize', 'onThrottledResize' ], $.proxy(function(i, handler) {
this._handlers[handler] = $.proxy(this[handler], this);
}, this));
$.each(Owl.Plugins, $.proxy(function(key, plugin) {
this._plugins[key.charAt(0).toLowerCase() + key.slice(1)]
= new plugin(this);
}, this));
$.each(Owl.Workers, $.proxy(function(priority, worker) {
this._pipe.push({
'filter': worker.filter,
'run': $.proxy(worker.run, this)
});
}, this));
this.setup();
this.initialize();
}
/**
* Default options for the carousel.
* @public
*/
Owl.Defaults = {
items: 3,
loop: false,
center: false,
rewind: false,
mouseDrag: true,
touchDrag: true,
pullDrag: true,
freeDrag: false,
margin: 0,
stagePadding: 0,
merge: false,
mergeFit: true,
autoWidth: false,
startPosition: 0,
rtl: false,
smartSpeed: 250,
fluidSpeed: false,
dragEndSpeed: false,
responsive: {},
responsiveRefreshRate: 200,
responsiveBaseElement: window,
fallbackEasing: 'swing',
info: false,
nestedItemSelector: false,
itemElement: 'div',
stageElement: 'div',
refreshClass: 'owl-refresh',
loadedClass: 'owl-loaded',
loadingClass: 'owl-loading',
rtlClass: 'owl-rtl',
responsiveClass: 'owl-responsive',
dragClass: 'owl-drag',
itemClass: 'owl-item',
stageClass: 'owl-stage',
stageOuterClass: 'owl-stage-outer',
grabClass: 'owl-grab'
};
/**
* Enumeration for width.
* @public
* @readonly
* @enum {String}
*/
Owl.Width = {
Default: 'default',
Inner: 'inner',
Outer: 'outer'
};
/**
* Enumeration for types.
* @public
* @readonly
* @enum {String}
*/
Owl.Type = {
Event: 'event',
State: 'state'
};
/**
* Contains all registered plugins.
* @public
*/
Owl.Plugins = {};
/**
* List of workers involved in the update process.
*/
Owl.Workers = [ {
filter: [ 'width', 'settings' ],
run: function() {
this._width = (this.$element.closest('.px-gutter').length) ? 12 * Math.ceil(this.$element.width() / 12) : this.$element.width();
//this._width = (UNCODE.isMobile) ? this.$element.width() : 12 * Math.ceil(this.$element.width() / 12);
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function(cache) {
cache.current = this._items && this._items[this.relative(this._current)];
}
}, {
filter: [ 'items', 'settings' ],
run: function() {
this.$stage.children('.cloned').remove();
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function(cache) {
var margin = this.settings.margin || '',
grid = !this.settings.autoWidth,
rtl = this.settings.rtl,
css = {
'width': 'auto',
'margin-left': rtl ? margin : '',
'margin-right': rtl ? '' : margin
};
!grid && this.$stage.children().css(css);
cache.css = css;
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function(cache) {
//UNCODE edit to fix Chrome stage padding issue
var width = Math.round((this.width() / this.settings.items).toFixed(3) - this.settings.margin),
merge = null,
iterator = this._items.length,
grid = !this.settings.autoWidth,
widths = [];
cache.items = {
merge: false,
width: width
};
while (iterator--) {
merge = this._mergers[iterator];
merge = this.settings.mergeFit && Math.min(merge, this.settings.items) || merge;
cache.items.merge = merge > 1 || cache.items.merge;
widths[iterator] = !grid ? this._items[iterator].width() : width * merge;
}
this._widths = widths;
}
}, {
filter: [ 'items', 'settings' ],
run: function() {
var clones = [],
items = this._items,
settings = this.settings,
view = Math.max(settings.items * 2, 4),
size = Math.ceil(items.length / 2) * 2,
repeat = settings.loop && items.length ? settings.rewind ? view : Math.max(view, size) : 0,
append = '',
prepend = '';
repeat /= 2;
while (repeat--) {
clones.push(this.normalize(clones.length / 2, true));
append = append + items[clones[clones.length - 1]][0].outerHTML;
clones.push(this.normalize(items.length - 1 - (clones.length - 1) / 2, true));
prepend = items[clones[clones.length - 1]][0].outerHTML + prepend;
}
this._clones = clones;
// var appendVideo = $(append).find('.uncode-video-container');
// if (appendVideo.length) {
// appendVideo.attr('data-id', Math.round(Math.random() * 100000));
// }
// var prependVideo = $(prepend).find('.uncode-video-container');
// if (prependVideo.length) {
// prependVideo.attr('data-id', Math.round(Math.random() * 100000));
// }
$(append).addClass('cloned').appendTo(this.$stage);
$(prepend).addClass('cloned').prependTo(this.$stage);
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function() {
var rtl = this.settings.rtl ? 1 : -1,
size = this._clones.length + this._items.length,
iterator = -1,
previous = 0,
current = 0,
coordinates = [];
while (++iterator < size) {
previous = coordinates[iterator - 1] || 0;
current = this._widths[this.relative(iterator)] + this.settings.margin;
coordinates.push(previous + current * rtl);
}
this._coordinates = coordinates;
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function() {
var stagePadding = (this._width < 480 && this.settings.stagePadding > 0) ? 41 : (this._width * this.settings.stagePadding) / 200,
padding = stagePadding,
coordinates = this._coordinates,
css = {
'width': Math.ceil(Math.abs(coordinates[coordinates.length - 1])) + padding * 2,
'padding-left': padding || '',
'padding-right': padding || ''
};
this.$stage.css(css);
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function(cache) {
var iterator = this._coordinates.length,
grid = !this.settings.autoWidth,
items = this.$stage.children();
if (grid && cache.items.merge) {
while (iterator--) {
cache.css.width = this._widths[this.relative(iterator)];
items.eq(iterator).css(cache.css);
}
} else if (grid) {
cache.css.width = cache.items.width;
items.css(cache.css);
}
}
}, {
filter: [ 'items' ],
run: function() {
this._coordinates.length < 1 && this.$stage.removeAttr('style');
}
}, {
filter: [ 'width', 'items', 'settings' ],
run: function(cache) {
cache.current = cache.current ? this.$stage.children().index(cache.current) : 0;
cache.current = Math.max(this.minimum(), Math.min(this.maximum(), cache.current));
this.reset(cache.current);
}
}, {
filter: [ 'position' ],
run: function() {
this.animate(this.coordinates(this._current));
}
}, {
filter: [ 'width', 'position', 'items', 'settings' ],
run: function() {
var stagePadding = (this._width < 480 && this.settings.stagePadding > 0) ? 41 : (this._width * this.settings.stagePadding) / 200,
rtl = this.settings.rtl ? 1 : -1,
padding = this.settings.stagePadding * 2,
begin = this.coordinates(this.current()) + padding,
end = begin + this.width() * rtl,
inner, outer, matches = [], i, n;
for (i = 0, n = this._coordinates.length; i < n; i++) {
inner = this._coordinates[i - 1] || 0;
outer = Math.abs(this._coordinates[i]) + padding * rtl;
if ((this.op(inner, '<=', begin) && (this.op(inner, '>', end)))
|| (this.op(outer, '<', begin) && this.op(outer, '>', end))) {
matches.push(i);
}
}
this.$stage.children('.active').removeClass('active');
this.$stage.children(':eq(' + matches.join('), :eq(') + ')').addClass('active');
if (this.settings.center) {
this.$stage.children('.center').removeClass('center');
this.$stage.children().eq(this.current()).addClass('center');
}
}
} ];
/**
* Initializes the carousel.
* @protected
*/
Owl.prototype.initialize = function() {
this.enter('initializing');
this.trigger('initialize');
this.$element.toggleClass(this.settings.rtlClass, this.settings.rtl);
if (this.settings.autoWidth && !this.is('pre-loading')) {
var imgs, nestedSelector, width;
imgs = this.$element.find('img');
nestedSelector = this.settings.nestedItemSelector ? '.' + this.settings.nestedItemSelector : undefined;
width = this.$element.children(nestedSelector).width();
if (imgs.length && width <= 0) {
this.preloadAutoWidthImages(imgs);
}
}
this.$element.addClass(this.options.loadingClass);
// create stage
this.$stage = $('<' + this.settings.stageElement + ' class="' + this.settings.stageClass + '"/>')
.wrap('<div class="' + this.settings.stageOuterClass + '"/>');
// append stage
this.$element.append(this.$stage.parent());
// append content
this.replace(this.$element.children().not(this.$stage.parent()));
// check visibility
if (this.$element.is(':visible')) {
// update view
this.refresh();
} else {
// invalidate width
this.invalidate('width');
}
this.$element
.removeClass(this.options.loadingClass)
.addClass(this.options.loadedClass);
// register event handlers
this.registerEventHandlers();
this.leave('initializing');
this.trigger('initialized');
};
/**
* Setups the current settings.
* @todo Remove responsive classes. Why should adaptive designs be brought into IE8?
* @todo Support for media queries by using `matchMedia` would be nice.
* @public
*/
Owl.prototype.setup = function() {
var viewport = this.viewport(),
overwrites = this.options.responsive,
match = -1,
settings = null;
if (!overwrites) {
settings = $.extend({}, this.options);
} else {
$.each(overwrites, function(breakpoint) {
if (breakpoint <= viewport && breakpoint > match) {
match = Number(breakpoint);
}
});
settings = $.extend({}, this.options, overwrites[match]);
delete settings.responsive;
// responsive class
if (settings.responsiveClass) {
this.$element.attr('class',
this.$element.attr('class').replace(new RegExp('(' + this.options.responsiveClass + '-)\\S+\\s', 'g'), '$1' + match)
);
}
}
if (this.settings === null || this._breakpoint !== match) {
this.trigger('change', { property: { name: 'settings', value: settings } });
this._breakpoint = match;
this.settings = settings;
this.invalidate('settings');
this.trigger('changed', { property: { name: 'settings', value: this.settings } });
}
};
/**
* Updates option logic if necessery.
* @protected
*/
Owl.prototype.optionsLogic = function() {
if (this.settings.autoWidth) {
this.settings.stagePadding = false;
this.settings.merge = false;
}
};
/**
* Prepares an item before add.
* @todo Rename event parameter `content` to `item`.
* @protected
* @returns {jQuery|HTMLElement} - The item container.
*/
Owl.prototype.prepare = function(item, index) {
var event = this.trigger('prepare', { content: item });
if (!event.data) {
event.data = $('<' + this.settings.itemElement + '/>')
.addClass(this.options.itemClass).attr('data-index', index + 1).append(item)
}
this.trigger('prepared', { content: event.data });
return event.data;
};
/**
* Updates the view.
* @public
*/
Owl.prototype.update = function() {
var i = 0,
n = this._pipe.length,
filter = $.proxy(function(p) { return this[p] }, this._invalidated),
cache = {};
while (i < n) {
if (this._invalidated.all || $.grep(this._pipe[i].filter, filter).length > 0) {
this._pipe[i].run(cache);
}
i++;
}
this._invalidated = {};
!this.is('valid') && this.enter('valid');
};
/**
* Gets the width of the view.
* @public
* @param {Owl.Width} [dimension=Owl.Width.Default] - The dimension to return.
* @returns {Number} - The width of the view in pixel.
*/
Owl.prototype.width = function(dimension) {
dimension = dimension || Owl.Width.Default;
var stagePadding = (this._width < 480 && this.settings.stagePadding > 0) ? 41 : (this._width * this.settings.stagePadding) / 200;
switch (dimension) {
case Owl.Width.Inner:
case Owl.Width.Outer:
return this._width;
default:
return this._width - stagePadding * 2 + this.settings.margin;
}
};
/**
* Refreshes the carousel primarily for adaptive purposes.
* @public
*/
Owl.prototype.refresh = function() {
this.enter('refreshing');
this.trigger('refresh');
this.setup();
this.optionsLogic();
this.$element.addClass(this.options.refreshClass);
this.update();
this.$element.removeClass(this.options.refreshClass);
this.leave('refreshing');
this.trigger('refreshed');
};
/**
* Checks window `resize` event.
* @protected
*/
Owl.prototype.onThrottledResize = function() {
window.clearTimeout(this.resizeTimer);
this.resizeTimer = window.setTimeout(this._handlers.onResize, this.settings.responsiveRefreshRate);
};
/**
* Checks window `resize` event.
* @protected
*/
Owl.prototype.onResize = function() {
if (!this._items.length) {
return false;
}
if (this._width === this.$element.width()) {
return false;
}
if (!this.$element.is(':visible')) {
return false;
}
this.enter('resizing');
if (this.trigger('resize').isDefaultPrevented()) {
this.leave('resizing');
return false;
}
this.invalidate('width');
this.refresh();
this.leave('resizing');
this.trigger('resized');
};
/**
* Registers event handlers.
* @todo Check `msPointerEnabled`
* @todo #261
* @protected
*/
Owl.prototype.registerEventHandlers = function() {
if ($.support.transition) {
this.$stage.on($.support.transition.end + '.owl.core', $.proxy(this.onTransitionEnd, this));
}
if (this.settings.responsive !== false) {
this.on(window, 'resize', this._handlers.onThrottledResize);
}
if (this.settings.mouseDrag) {
this.$element.addClass(this.options.dragClass);
this.$stage.on('mousedown.owl.core', $.proxy(this.onDragStart, this));
this.$stage.on('dragstart.owl.core selectstart.owl.core', function() { return false });
}
if (this.settings.touchDrag){
this.$stage.on('touchstart.owl.core', $.proxy(this.onDragStart, this));
this.$stage.on('touchcancel.owl.core', $.proxy(this.onDragEnd, this));
}
};
/**
* Handles `touchstart` and `mousedown` events.
* @todo Horizontal swipe threshold as option
* @todo #261
* @protected
* @param {Event} event - The event arguments.
*/
Owl.prototype.onDragStart = function(event) {
var stage = null;
if (event.which === 3) {
return;
}
if ($.support.transform) {
stage = this.$stage.css('transform').replace(/.*\(|\)| /g, '').split(',');
stage = {
x: stage[stage.length === 16 ? 12 : 4],
y: stage[stage.length === 16 ? 13 : 5]
};
} else {
stage = this.$stage.position();
stage = {
x: this.settings.rtl ?
stage.left + this.$stage.width() - this.width() + this.settings.margin :
stage.left,
y: stage.top
};
}
if (this.is('animating')) {
$.support.transform ? this.animate(stage.x) : this.$stage.stop()
this.invalidate('position');
}
this.$element.toggleClass(this.options.grabClass, event.type === 'mousedown');
this.speed(0);
this._drag.time = new Date().getTime();
this._drag.target = $(event.target);
this._drag.stage.start = stage;
this._drag.stage.current = stage;
this._drag.pointer = this.pointer(event);
$(document).on('mouseup.owl.core touchend.owl.core', $.proxy(this.onDragEnd, this));
$(document).one('mousemove.owl.core touchmove.owl.core', $.proxy(function(event) {
var delta = this.difference(this._drag.pointer, this.pointer(event));
$(document).on('mousemove.owl.core touchmove.owl.core', $.proxy(this.onDragMove, this));
if (Math.abs(delta.x) < Math.abs(delta.y) && this.is('valid')) {
return;
}
event.preventDefault();
this.enter('dragging');
this.trigger('drag');
}, this));
};
/**
* Handles the `touchmove` and `mousemove` events.
* @todo #261
* @protected
* @param {Event} event - The event arguments.
*/
Owl.prototype.onDragMove = function(event) {
var minimum = null,
maximum = null,
pull = null,
delta = this.difference(this._drag.pointer, this.pointer(event)),
stage = this.difference(this._drag.stage.start, delta);
if (!this.is('dragging')) {
return;
}
event.preventDefault();
if (this.settings.loop) {
minimum = this.coordinates(this.minimum());
maximum = this.coordinates(this.maximum() + 1) - minimum;
stage.x = (((stage.x - minimum) % maximum + maximum) % maximum) + minimum;
} else {
minimum = this.settings.rtl ? this.coordinates(this.maximum()) : this.coordinates(this.minimum());
maximum = this.settings.rtl ? this.coordinates(this.minimum()) : this.coordinates(this.maximum());
pull = this.settings.pullDrag ? -1 * delta.x / 5 : 0;
stage.x = Math.max(Math.min(stage.x, minimum + pull), maximum + pull);
}
this._drag.stage.current = stage;
this.animate(stage.x);
};
/**
* Handles the `touchend` and `mouseup` events.
* @todo #261
* @todo Threshold for click event
* @protected
* @param {Event} event - The event arguments.
*/
Owl.prototype.onDragEnd = function(event) {
var delta = this.difference(this._drag.pointer, this.pointer(event)),
stage = this._drag.stage.current,
direction = delta.x > 0 ^ this.settings.rtl ? 'left' : 'right';
$(document).off('.owl.core');
this.$element.removeClass(this.options.grabClass);
if (delta.x !== 0 && this.is('dragging') || !this.is('valid')) {
this.speed(this.settings.dragEndSpeed || this.settings.smartSpeed);
this.current(this.closest(stage.x, delta.x !== 0 ? direction : this._drag.direction));
this.invalidate('position');
this.update();
this._drag.direction = direction;
if (Math.abs(delta.x) > 3 || new Date().getTime() - this._drag.time > 300) {
this._drag.target.one('click.owl.core', function() { return false; });
}
}
if (!this.is('dragging')) {
return;
}
this.leave('dragging');
this.trigger('dragged');
};
/**
* Gets absolute position of the closest item for a coordinate.
* @todo Setting `freeDrag` makes `closest` not reusable. See #165.
* @protected
* @param {Number} coordinate - The coordinate in pixel.
* @param {String} direction - The direction to check for the closest item. Ether `left` or `right`.
* @return {Number} - The absolute position of the closest item.
*/
Owl.prototype.closest = function(coordinate, direction) {
var position = -1,
pull = 30,
width = this.width(),
coordinates = this.coordinates();
if (!this.settings.freeDrag) {
// check closest item
$.each(coordinates, $.proxy(function(index, value) {
if (coordinate > value - pull && coordinate < value + pull) {
position = index;
} else if (this.op(coordinate, '<', value)
&& this.op(coordinate, '>', coordinates[index + 1] || value - width)) {
position = direction === 'left' ? index + 1 : index;
}
return position === -1;
}, this));
}
if (!this.settings.loop) {
// non loop boundries
if (this.op(coordinate, '>', coordinates[this.minimum()])) {
position = coordinate = this.minimum();
} else if (this.op(coordinate, '<', coordinates[this.maximum()])) {
position = coordinate = this.maximum();
}
}
return position;
};
/**
* Animates the stage.
* @todo #270
* @public
* @param {Number} coordinate - The coordinate in pixels.
*/
Owl.prototype.animate = function(coordinate) {
var animate = this.speed() > 0;
this.is('animating') && this.onTransitionEnd();
if (animate) {
this.enter('animating');
this.trigger('translate');
}
if ($.support.transform3d && $.support.transition) {
this.$stage.css({
transform: 'translate3d(' + coordinate + 'px,0px,0px)',
transition: (this.speed() / 1000) + 's'
});
} else if (animate) {
this.$stage.animate({
left: coordinate + 'px'
}, this.speed(), this.settings.fallbackEasing, $.proxy(this.onTransitionEnd, this));
} else {
this.$stage.css({
left: coordinate + 'px'
});
}
};
/**
* Checks whether the carousel is in a specific state or not.
* @param {String} state - The state to check.
* @returns {Boolean} - The flag which indicates if the carousel is busy.
*/
Owl.prototype.is = function(state) {
return this._states.current[state] && this._states.current[state] > 0;
};
/**
* Sets the absolute position of the current item.
* @public
* @param {Number} [position] - The new absolute position or nothing to leave it unchanged.
* @returns {Number} - The absolute position of the current item.
*/
Owl.prototype.current = function(position) {
if (position === undefined) {
return this._current;
}
if (this._items.length === 0) {
return undefined;
}
position = this.normalize(position);
if (this._current !== position) {
var event = this.trigger('change', { property: { name: 'position', value: position } });
if (event.data !== undefined) {
position = this.normalize(event.data);
}
this._current = position;
this.invalidate('position');
this.trigger('changed', { property: { name: 'position', value: this._current } });
}
return this._current;
};
/**
* Invalidates the given part of the update routine.
* @param {String} [part] - The part to invalidate.
* @returns {Array.<String>} - The invalidated parts.
*/
Owl.prototype.invalidate = function(part) {
if ($.type(part) === 'string') {
this._invalidated[part] = true;
this.is('valid') && this.leave('valid');
}
return $.map(this._invalidated, function(v, i) { return i });
};
/**
* Resets the absolute position of the current item.
* @public
* @param {Number} position - The absolute position of the new item.
*/
Owl.prototype.reset = function(position) {
position = this.normalize(position);
if (position === undefined) {
return;
}
this._speed = 0;
this._current = position;
this.suppress([ 'translate', 'translated' ]);
this.animate(this.coordinates(position));
this.release([ 'translate', 'translated' ]);
};
/**
* Normalizes an absolute or a relative position of an item.
* @public
* @param {Number} position - The absolute or relative position to normalize.
* @param {Boolean} [relative=false] - Whether the given position is relative or not.
* @returns {Number} - The normalized position.
*/
Owl.prototype.normalize = function(position, relative) {
var n = this._items.length,
m = relative ? 0 : this._clones.length;
if (!$.isNumeric(position) || n < 1) {
position = undefined;
} else if (position < 0 || position >= n + m) {
position = ((position - m / 2) % n + n) % n + m / 2;
}
return position;
};
/**
* Converts an absolute position of an item into a relative one.
* @public
* @param {Number} position - The absolute position to convert.
* @returns {Number} - The converted position.
*/
Owl.prototype.relative = function(position) {
position -= this._clones.length / 2;
return this.normalize(position, true);
};
/**
* Gets the maximum position for the current item.
* @public
* @param {Boolean} [relative=false] - Whether to return an absolute position or a relative position.
* @returns {Number}
*/
Owl.prototype.maximum = function(relative) {
var settings = this.settings,
maximum = this._coordinates.length,
boundary = Math.abs(this._coordinates[maximum - 1]) - this._width,
i = -1, j;
if (settings.loop) {
maximum = this._clones.length / 2 + this._items.length - 1;
} else if (settings.autoWidth || settings.merge) {
// binary search
while (maximum - i > 1) {
Math.abs(this._coordinates[j = maximum + i >> 1]) < boundary
? i = j : maximum = j;
}
} else if (settings.center) {
maximum = this._items.length - 1;
} else {
maximum = this._items.length - settings.items;
}
if (relative) {
maximum -= this._clones.length / 2;
}
return Math.max(maximum, 0);
};
/**
* Gets the minimum position for the current item.
* @public
* @param {Boolean} [relative=false] - Whether to return an absolute position or a relative position.
* @returns {Number}
*/
Owl.prototype.minimum = function(relative) {
return relative ? 0 : this._clones.length / 2;
};
/**
* Gets an item at the specified relative position.
* @public
* @param {Number} [position] - The relative position of the item.
* @return {jQuery|Array.<jQuery>} - The item at the given position or all items if no position was given.
*/
Owl.prototype.items = function(position) {
if (position === undefined) {
return this._items.slice();
}
position = this.normalize(position, true);
return this._items[position];
};
/**
* Gets an item at the specified relative position.
* @public
* @param {Number} [position] - The relative position of the item.
* @return {jQuery|Array.<jQuery>} - The item at the given position or all items if no position was given.
*/
Owl.prototype.mergers = function(position) {
if (position === undefined) {
return this._mergers.slice();
}
position = this.normalize(position, true);
return this._mergers[position];
};
/**
* Gets the absolute positions of clones for an item.
* @public
* @param {Number} [position] - The relative position of the item.
* @returns {Array.<Number>} - The absolute positions of clones for the item or all if no position was given.
*/
Owl.prototype.clones = function(position) {
var odd = this._clones.length / 2,
even = odd + this._items.length,
map = function(index) { return index % 2 === 0 ? even + index / 2 : odd - (index + 1) / 2 };
if (position === undefined) {
return $.map(this._clones, function(v, i) { return map(i) });
}
return $.map(this._clones, function(v, i) { return v === position ? map(i) : null });
};
/**
* Sets the current animation speed.
* @public
* @param {Number} [speed] - The animation speed in milliseconds or nothing to leave it unchanged.
* @returns {Number} - The current animation speed in milliseconds.
*/
Owl.prototype.speed = function(speed) {
if (speed !== undefined) {
this._speed = speed;
}
return this._speed;
};
/**
* Gets the coordinate of an item.
* @todo The name of this method is missleanding.
* @public
* @param {Number} position - The absolute position of the item within `minimum()` and `maximum()`.
* @returns {Number|Array.<Number>} - The coordinate of the item in pixel or all coordinates.
*/
Owl.prototype.coordinates = function(position) {
var coordinate = null;
if (position === undefined) {
return $.map(this._coordinates, $.proxy(function(coordinate, index) {
return this.coordinates(index);
}, this));
}
if (this.settings.center) {
coordinate = this._coordinates[position];
coordinate += (this.width() - coordinate + (this._coordinates[position - 1] || 0)) / 2 * (this.settings.rtl ? -1 : 1);
} else {
coordinate = this._coordinates[position - 1] || 0;
}
return coordinate;
};
/**
* Calculates the speed for a translation.
* @protected
* @param {Number} from - The absolute position of the start item.
* @param {Number} to - The absolute position of the target item.
* @param {Number} [factor=undefined] - The time factor in milliseconds.
* @returns {Number} - The time in milliseconds for the translation.
*/
Owl.prototype.duration = function(from, to, factor) {
return Math.min(Math.max(Math.abs(to - from), 1), 6) * Math.abs((factor || this.settings.smartSpeed));
};
/**
* Slides to the specified item.
* @public
* @param {Number} position - The position of the item.
* @param {Number} [speed] - The time in milliseconds for the transition.
*/
Owl.prototype.to = function(position, speed) {
var current = this.current(),
revert = null,
distance = position - this.relative(current),
direction = (distance > 0) - (distance < 0),
items = this._items.length,
minimum = this.minimum(),
maximum = this.maximum();
if (this.settings.loop) {
if (!this.settings.rewind && Math.abs(distance) > items / 2) {
distance += direction * -1 * items;
}
position = current + distance;
revert = ((position - minimum) % items + items) % items + minimum;
if (revert !== position && revert - distance <= maximum && revert - distance > 0) {
current = revert - distance;
position = revert;
this.reset(current);
}
} else if (this.settings.rewind) {
maximum += 1;
position = (position % maximum + maximum) % maximum;
} else {
position = Math.max(minimum, Math.min(maximum, position));
}
this.speed(this.duration(current, position, speed));
this.current(position);
if (this.$element.is(':visible')) {
this.update();
}
};
/**
* Slides to the next item.
* @public
* @param {Number} [speed] - The time in milliseconds for the transition.
*/
Owl.prototype.next = function(speed) {
speed = speed || false;
this.to(this.relative(this.current()) + 1, speed);
};
/**
* Slides to the previous item.
* @public
* @param {Number} [speed] - The time in milliseconds for the transition.
*/
Owl.prototype.prev = function(speed) {
speed = speed || false;
this.to(this.relative(this.current()) - 1, speed);
};
/**
* Handles the end of an animation.
* @protected
* @param {Event} event - The event arguments.
*/
Owl.prototype.onTransitionEnd = function(event) {
// if css2 animation then event object is undefined
if (event !== undefined) {
event.stopPropagation();
// Catch only owl-stage transitionEnd event
if ((event.target || event.srcElement || event.originalTarget) !== this.$stage.get(0)) {
return false;
}
}
this.leave('animating');
this.trigger('translated');
};
/**
* Gets viewport width.
* @protected
* @return {Number} - The width in pixel.
*/
Owl.prototype.viewport = function() {
var width;
if (this.options.responsiveBaseElement !== window) {
width = $(this.options.responsiveBaseElement).width();
} else if (window.innerWidth) {
width = window.innerWidth;
} else if (document.documentElement && document.documentElement.clientWidth) {
width = document.documentElement.clientWidth;
} else {
throw 'Can not detect viewport width.';
}
return width;
};
/**
* Replaces the current content.
* @public
* @param {HTMLElement|jQuery|String} content - The new content.
*/
Owl.prototype.replace = function(content) {
this.$stage.empty();
this._items = [];
if (content) {
content = (content instanceof jQuery) ? content : $(content);
}
if (this.settings.nestedItemSelector) {
content = content.find('.' + this.settings.nestedItemSelector);
}
content.filter(function() {
return this.nodeType === 1;
}).each($.proxy(function(index, item) {
item = this.prepare(item, index);
this.$stage.append(item);
this._items.push(item);
this._mergers.push(item.find('[data-merge]').addBack('[data-merge]').attr('data-merge') * 1 || 1);
}, this));
this.reset($.isNumeric(this.settings.startPosition) ? this.settings.startPosition : 0);
this.invalidate('items');
};
/**
* Adds an item.
* @todo Use `item` instead of `content` for the event arguments.
* @public
* @param {HTMLElement|jQuery|String} content - The item content to add.
* @param {Number} [position] - The relative position at which to insert the item otherwise the item will be added to the end.
*/
Owl.prototype.add = function(content, position) {
var current = this.relative(this._current);
position = position === undefined ? this._items.length : this.normalize(position, true);
content = content instanceof jQuery ? content : $(content);
this.trigger('add', { content: content, position: position });
content = this.prepare(content, this._items[current].index());
if (this._items.length === 0 || position === this._items.length) {
this._items.length === 0 && this.$stage.append(content);
this._items.length !== 0 && this._items[position - 1].after(content);
this._items.push(content);
this._mergers.push(content.find('[data-merge]').andSelf('[data-merge]').attr('data-merge') * 1 || 1);
} else {
this._items[position].before(content);
this._items.splice(position, 0, content);
this._mergers.splice(position, 0, content.find('[data-merge]').andSelf('[data-merge]').attr('data-merge') * 1 || 1);
}
this._items[current] && this.reset(this._items[current].index());
this.invalidate('items');
this.trigger('added', { content: content, position: position });
};
/**
* Removes an item by its position.
* @todo Use `item` instead of `content` for the event arguments.
* @public
* @param {Number} position - The relative position of the item to remove.
*/
Owl.prototype.remove = function(position) {
position = this.normalize(position, true);
if (position === undefined) {
return;
}
this.trigger('remove', { content: this._items[position], position: position });
this._items[position].remove();
this._items.splice(position, 1);
this._mergers.splice(position, 1);
this.invalidate('items');
this.trigger('removed', { content: null, position: position });
};
/**
* Preloads images with auto width.
* @todo Replace by a more generic approach
* @protected
*/
Owl.prototype.preloadAutoWidthImages = function(images) {
images.each($.proxy(function(i, element) {
this.enter('pre-loading');
element = $(element);
$(new Image()).one('load', $.proxy(function(e) {
element.attr('src', e.target.src);
element.css('opacity', 1);
this.leave('pre-loading');
!this.is('pre-loading') && !this.is('initializing') && this.refresh();
}, this)).attr('src', element.attr('src') || element.attr('data-src') || element.attr('data-src-retina'));
}, this));
};
/**
* Destroys the carousel.
* @public
*/
Owl.prototype.destroy = function() {
this.$element.off('.owl.core');
this.$stage.off('.owl.core');
$(document).off('.owl.core');
if (this.settings.responsive !== false) {
window.clearTimeout(this.resizeTimer);
this.off(window, 'resize', this._handlers.onThrottledResize);
}
for (var i in this._plugins) {
this._plugins[i].destroy();
}
this.$stage.children('.cloned').remove();
this.$stage.unwrap();
this.$stage.children().contents().unwrap();
this.$stage.children().unwrap();
this.$element
.removeClass(this.options.refreshClass)
.removeClass(this.options.loadingClass)
.removeClass(this.options.loadedClass)
.removeClass(this.options.rtlClass)
.removeClass(this.options.dragClass)
.removeClass(this.options.grabClass)
.attr('class', this.$element.attr('class').replace(new RegExp(this.options.responsiveClass + '-\\S+\\s', 'g'), ''))
.removeData('owl.carousel');
};
/**
* Operators to calculate right-to-left and left-to-right.
* @protected
* @param {Number} [a] - The left side operand.
* @param {String} [o] - The operator.
* @param {Number} [b] - The right side operand.
*/
Owl.prototype.op = function(a, o, b) {
var rtl = this.settings.rtl;
switch (o) {
case '<':
return rtl ? a > b : a < b;
case '>':
return rtl ? a < b : a > b;
case '>=':
return rtl ? a <= b : a >= b;
case '<=':
return rtl ? a >= b : a <= b;
default:
break;
}
};
/**
* Attaches to an internal event.
* @protected
* @param {HTMLElement} element - The event source.
* @param {String} event - The event name.
* @param {Function} listener - The event handler to attach.
* @param {Boolean} capture - Wether the event should be handled at the capturing phase or not.
*/
Owl.prototype.on = function(element, event, listener, capture) {
if (element.addEventListener) {
element.addEventListener(event, listener, capture);
} else if (element.attachEvent) {
element.attachEvent('on' + event, listener);
}
};
/**
* Detaches from an internal event.
* @protected
* @param {HTMLElement} element - The event source.
* @param {String} event - The event name.
* @param {Function} listener - The attached event handler to detach.
* @param {Boolean} capture - Wether the attached event handler was registered as a capturing listener or not.
*/
Owl.prototype.off = function(element, event, listener, capture) {
if (element.removeEventListener) {
element.removeEventListener(event, listener, capture);
} else if (element.detachEvent) {
element.detachEvent('on' + event, listener);
}
};
/**
* Triggers a public event.
* @todo Remove `status`, `relatedTarget` should be used instead.
* @protected
* @param {String} name - The event name.
* @param {*} [data=null] - The event data.
* @param {String} [namespace=carousel] - The event namespace.
* @param {String} [state] - The state which is associated with the event.
* @param {Boolean} [enter=false] - Indicates if the call enters the specified state or not.
* @returns {Event} - The event arguments.
*/
Owl.prototype.trigger = function(name, data, namespace, state, enter) {
var status = {
item: { count: this._items.length, index: this.current() }
}, handler = $.camelCase(
$.grep([ 'on', name, namespace ], function(v) { return v })
.join('-').toLowerCase()
), event = $.Event(
[ name, 'owl', namespace || 'carousel' ].join('.').toLowerCase(),
$.extend({ relatedTarget: this }, status, data)
);
if (!this._supress[name]) {
$.each(this._plugins, function(name, plugin) {
if (plugin.onTrigger) {
plugin.onTrigger(event);
}
});
this.register({ type: Owl.Type.Event, name: name });
this.$element.trigger(event);
if (this.settings && typeof this.settings[handler] === 'function') {
this.settings[handler].call(this, event);
}
}
return event;
};
/**
* Enters a state.
* @param name - The state name.
*/
Owl.prototype.enter = function(name) {
$.each([ name ].concat(this._states.tags[name] || []), $.proxy(function(i, name) {
if (this._states.current[name] === undefined) {
this._states.current[name] = 0;
}
this._states.current[name]++;
}, this));
};
/**
* Leaves a state.
* @param name - The state name.
*/
Owl.prototype.leave = function(name) {
$.each([ name ].concat(this._states.tags[name] || []), $.proxy(function(i, name) {
this._states.current[name]--;
}, this));
};
/**
* Registers an event or state.
* @public
* @param {Object} object - The event or state to register.
*/
Owl.prototype.register = function(object) {
if (object.type === Owl.Type.Event) {
if (!$.event.special[object.name]) {
$.event.special[object.name] = {};
}
if (!$.event.special[object.name].owl) {
var _default = $.event.special[object.name]._default;
$.event.special[object.name]._default = function(e) {
if (_default && _default.apply && (!e.namespace || e.namespace.indexOf('owl') === -1)) {
return _default.apply(this, arguments);
}
return e.namespace && e.namespace.indexOf('owl') > -1;
};
$.event.special[object.name].owl = true;
}
} else if (object.type === Owl.Type.State) {
if (!this._states.tags[object.name]) {
this._states.tags[object.name] = object.tags;
} else {
this._states.tags[object.name] = this._states.tags[object.name].concat(object.tags);
}
this._states.tags[object.name] = $.grep(this._states.tags[object.name], $.proxy(function(tag, i) {
return $.inArray(tag, this._states.tags[object.name]) === i;
}, this));
}
};
/**
* Suppresses events.
* @protected
* @param {Array.<String>} events - The events to suppress.
*/
Owl.prototype.suppress = function(events) {
$.each(events, $.proxy(function(index, event) {
this._supress[event] = true;
}, this));
};
/**
* Releases suppressed events.
* @protected
* @param {Array.<String>} events - The events to release.
*/
Owl.prototype.release = function(events) {
$.each(events, $.proxy(function(index, event) {
delete this._supress[event];
}, this));
};
/**
* Gets unified pointer coordinates from event.
* @todo #261
* @protected
* @param {Event} - The `mousedown` or `touchstart` event.
* @returns {Object} - Contains `x` and `y` coordinates of current pointer position.
*/
Owl.prototype.pointer = function(event) {
var result = { x: null, y: null };
event = event.originalEvent || event || window.event;
event = event.touches && event.touches.length ?
event.touches[0] : event.changedTouches && event.changedTouches.length ?
event.changedTouches[0] : event;
if (event.pageX) {
result.x = event.pageX;
result.y = event.pageY;
} else {
result.x = event.clientX;
result.y = event.clientY;
}
return result;
};
/**
* Gets the difference of two vectors.
* @todo #261
* @protected
* @param {Object} - The first vector.
* @param {Object} - The second vector.
* @returns {Object} - The difference.
*/
Owl.prototype.difference = function(first, second) {
return {
x: first.x - second.x,
y: first.y - second.y
};
};
/**
* The jQuery Plugin for the Owl Carousel
* @todo Navigation plugin `next` and `prev`
* @public
*/
$.fn.owlCarousel = function(option) {
var args = Array.prototype.slice.call(arguments, 1);
return this.each(function() {
var $this = $(this),
data = $this.data('owl.carousel');
if (!data) {
data = new Owl(this, typeof option == 'object' && option);
$this.data('owl.carousel', data);
$.each([
'next', 'prev', 'to', 'destroy', 'refresh', 'replace', 'add', 'remove'
], function(i, event) {
data.register({ type: Owl.Type.Event, name: event });
data.$element.on(event + '.owl.carousel.core', $.proxy(function(e) {
if (e.namespace && e.relatedTarget !== this) {
this.suppress([ event ]);
data[event].apply(this, [].slice.call(arguments, 1));
this.release([ event ]);
}
}, data));
});
}
if (typeof option == 'string' && option.charAt(0) !== '_') {
data[option].apply(data, args);
}
});
};
/**
* The constructor for the jQuery Plugin
* @public
*/
$.fn.owlCarousel.Constructor = Owl;
})(window.Zepto || window.jQuery, window, document);
/**
* AutoRefresh Plugin
* @version 2.0.0-beta.3
* @author Artus Kolanowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
/**
* Creates the auto refresh plugin.
* @class The Auto Refresh Plugin
* @param {Owl} carousel - The Owl Carousel
*/
var AutoRefresh = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* Refresh interval.
* @protected
* @type {number}
*/
this._interval = null;
/**
* Whether the element is currently visible or not.
* @protected
* @type {Boolean}
*/
this._visible = null;
/**
* All event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
'initialized.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.autoRefresh) {
this.watch();
}
}, this)
};
// set default options
this._core.options = $.extend({}, AutoRefresh.Defaults, this._core.options);
// register event handlers
this._core.$element.on(this._handlers);
};
/**
* Default options.
* @public
*/
AutoRefresh.Defaults = {
autoRefresh: true,
autoRefreshInterval: 500
};
/**
* Watches the element.
*/
AutoRefresh.prototype.watch = function() {
if (this._interval) {
return;
}
this._visible = this._core.$element.is(':visible');
this._interval = window.setInterval($.proxy(this.refresh, this), this._core.settings.autoRefreshInterval);
};
/**
* Refreshes the element.
*/
AutoRefresh.prototype.refresh = function() {
if (this._core.$element.is(':visible') === this._visible) {
return;
}
this._visible = !this._visible;
this._core.$element.toggleClass('owl-hidden', !this._visible);
this._visible && (this._core.invalidate('width') && this._core.refresh());
};
/**
* Destroys the plugin.
*/
AutoRefresh.prototype.destroy = function() {
var handler, property;
window.clearInterval(this._interval);
for (handler in this._handlers) {
this._core.$element.off(handler, this._handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.AutoRefresh = AutoRefresh;
})(window.Zepto || window.jQuery, window, document);
/**
* Lazy Plugin
* @version 2.0.0-beta.3
* @author Bartosz Wojciechowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
/**
* Creates the lazy plugin.
* @class The Lazy Plugin
* @param {Owl} carousel - The Owl Carousel
*/
var Lazy = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* Already loaded items.
* @protected
* @type {Array.<jQuery>}
*/
this._loaded = [];
/**
* Event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
'initialized.owl.carousel change.owl.carousel': $.proxy(function(e) {
if (!e.namespace) {
return;
}
if (!this._core.settings || !this._core.settings.lazyLoad) {
return;
}
if ((e.property && e.property.name == 'position') || e.type == 'initialized') {
var settings = this._core.settings,
n = (settings.center && Math.ceil(settings.items / 2) || settings.items),
i = ((settings.center && n * -1) || 0),
position = ((e.property && e.property.value) || this._core.current()) + i,
clones = this._core.clones().length,
load = $.proxy(function(i, v) { this.load(v) }, this);
while (i++ < n) {
this.load(clones / 2 + this._core.relative(position));
clones && $.each(this._core.clones(this._core.relative(position)), load);
position++;
}
}
}, this)
};
// set the default options
this._core.options = $.extend({}, Lazy.Defaults, this._core.options);
// register event handler
this._core.$element.on(this._handlers);
}
/**
* Default options.
* @public
*/
Lazy.Defaults = {
lazyLoad: false
}
/**
* Loads all resources of an item at the specified position.
* @param {Number} position - The absolute position of the item.
* @protected
*/
Lazy.prototype.load = function(position) {
var $item = this._core.$stage.children().eq(position),
$elements = $item && $item.find('.owl-lazy');
if (!$elements || $.inArray($item.get(0), this._loaded) > -1) {
return;
}
$elements.each($.proxy(function(index, element) {
var $element = $(element), image,
url = (window.devicePixelRatio > 1 && $element.attr('data-src-retina')) || $element.attr('data-src');
this._core.trigger('load', { element: $element, url: url }, 'lazy');
if ($element.is('img')) {
$element.one('load.owl.lazy', $.proxy(function() {
$element.css('opacity', 1);
this._core.trigger('loaded', { element: $element, url: url }, 'lazy');
}, this)).attr('src', url);
} else {
image = new Image();
image.onload = $.proxy(function() {
$element.css({
'background-image': 'url(' + url + ')',
'opacity': '1'
});
this._core.trigger('loaded', { element: $element, url: url }, 'lazy');
}, this);
image.src = url;
}
}, this));
this._loaded.push($item.get(0));
}
/**
* Destroys the plugin.
* @public
*/
Lazy.prototype.destroy = function() {
var handler, property;
for (handler in this.handlers) {
this._core.$element.off(handler, this.handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.Lazy = Lazy;
})(window.Zepto || window.jQuery, window, document);
/**
* AutoHeight Plugin
* @version 2.0.0-beta.3
* @author Bartosz Wojciechowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
/**
* Creates the auto height plugin.
* @class The Auto Height Plugin
* @param {Owl} carousel - The Owl Carousel
*/
var AutoHeight = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* All event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
'initialized.owl.carousel refreshed.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.autoHeight) {
this.update();
}
}, this),
'changed.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.autoHeight && e.property.name == 'position'){
this.update();
}
}, this),
'loaded.owl.lazy': $.proxy(function(e) {
if (e.namespace && this._core.settings.autoHeight
&& e.element.closest('.' + this._core.settings.itemClass).index() === this._core.current()) {
this.update();
}
}, this)
};
// set default options
this._core.options = $.extend({}, AutoHeight.Defaults, this._core.options);
// register event handlers
this._core.$element.on(this._handlers);
};
/**
* Default options.
* @public
*/
AutoHeight.Defaults = {
autoHeight: false,
autoHeightClass: 'owl-height'
};
/**
* Updates the view.
*/
AutoHeight.prototype.update = function() {
var start = this._core._current,
end = start + this._core.settings.items,
visible = this._core.$stage.children().toArray().slice(start, end);
heights = [],
maxheight = 0;
$.each(visible, function(index, item) {
heights.push($(item).height());
});
maxheight = Math.max.apply(null, heights);
this._core.$stage.parent()
.height(maxheight)
.addClass(this._core.settings.autoHeightClass);
};
AutoHeight.prototype.destroy = function() {
var handler, property;
for (handler in this._handlers) {
this._core.$element.off(handler, this._handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.AutoHeight = AutoHeight;
})(window.Zepto || window.jQuery, window, document);
/**
* Video Plugin
* @version 2.0.0-beta.3
* @author Bartosz Wojciechowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
/**
* Creates the video plugin.
* @class The Video Plugin
* @param {Owl} carousel - The Owl Carousel
*/
var Video = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* Cache all video URLs.
* @protected
* @type {Object}
*/
this._videos = {};
/**
* Current playing item.
* @protected
* @type {jQuery}
*/
this._playing = null;
/**
* All event handlers.
* @todo The cloned content removale is too late
* @protected
* @type {Object}
*/
this._handlers = {
'initialized.owl.carousel': $.proxy(function(e) {
if (e.namespace) {
this._core.register({ type: 'state', name: 'playing', tags: [ 'interacting' ] });
}
}, this),
'resize.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.video && this.isInFullScreen()) {
e.preventDefault();
}
}, this),
'refreshed.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.is('resizing')) {
this._core.$stage.find('.cloned .owl-video-frame').remove();
}
}, this),
'changed.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name === 'position' && this._playing) {
this.stop();
}
}, this),
'prepared.owl.carousel': $.proxy(function(e) {
if (!e.namespace) {
return;
}
var $element = $(e.content).find('.owl-video');
if ($element.length) {
$element.css('display', 'none');
this.fetch($element, $(e.content));
}
}, this)
};
// set default options
this._core.options = $.extend({}, Video.Defaults, this._core.options);
// register event handlers
this._core.$element.on(this._handlers);
this._core.$element.on('click.owl.video', '.owl-video-play-icon', $.proxy(function(e) {
this.play(e);
}, this));
};
/**
* Default options.
* @public
*/
Video.Defaults = {
video: false,
videoHeight: false,
videoWidth: false
};
/**
* Gets the video ID and the type (YouTube/Vimeo only).
* @protected
* @param {jQuery} target - The target containing the video data.
* @param {jQuery} item - The item containing the video.
*/
Video.prototype.fetch = function(target, item) {
var type = target.attr('data-vimeo-id') ? 'vimeo' : 'youtube',
id = target.attr('data-vimeo-id') || target.attr('data-youtube-id'),
width = target.attr('data-width') || this._core.settings.videoWidth,
height = target.attr('data-height') || this._core.settings.videoHeight,
url = target.attr('href');
if (url) {
id = url.match(/(http:|https:|)\/\/(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?/);
if (id[3].indexOf('youtu') > -1) {
type = 'youtube';
} else if (id[3].indexOf('vimeo') > -1) {
type = 'vimeo';
} else {
throw new Error('Video URL not supported.');
}
id = id[6];
} else {
throw new Error('Missing video URL.');
}
this._videos[url] = {
type: type,
id: id,
width: width,
height: height
};
item.attr('data-video', url);
this.thumbnail(target, this._videos[url]);
};
/**
* Creates video thumbnail.
* @protected
* @param {jQuery} target - The target containing the video data.
* @param {Object} info - The video info object.
* @see `fetch`
*/
Video.prototype.thumbnail = function(target, video) {
var tnLink,
icon,
path,
dimensions = video.width && video.height ? 'style="width:' + video.width + 'px;height:' + video.height + 'px;"' : '',
customTn = target.find('img'),
srcType = 'src',
lazyClass = '',
settings = this._core.settings,
create = function(path) {
icon = '<div class="owl-video-play-icon"></div>';
if (settings.lazyLoad) {
tnLink = '<div class="owl-video-tn ' + lazyClass + '" ' + srcType + '="' + path + '"></div>';
} else {
tnLink = '<div class="owl-video-tn" style="opacity:1;background-image:url(' + path + ')"></div>';
}
target.after(tnLink);
target.after(icon);
};
// wrap video content into owl-video-wrapper div
target.wrap('<div class="owl-video-wrapper"' + dimensions + '></div>');
if (this._core.settings.lazyLoad) {
srcType = 'data-src';
lazyClass = 'owl-lazy';
}
// custom thumbnail
if (customTn.length) {
create(customTn.attr(srcType));
customTn.remove();
return false;
}
if (video.type === 'youtube') {
path = "//img.youtube.com/vi/" + video.id + "/hqdefault.jpg";
create(path);
} else if (video.type === 'vimeo') {
$.ajax({
type: 'GET',
url: '//vimeo.com/api/v2/video/' + video.id + '.json',
jsonp: 'callback',
dataType: 'jsonp',
success: function(data) {
path = data[0].thumbnail_large;
create(path);
}
});
}
};
/**
* Stops the current video.
* @public
*/
Video.prototype.stop = function() {
this._core.trigger('stop', null, 'video');
this._playing.find('.owl-video-frame').remove();
this._playing.removeClass('owl-video-playing');
this._playing = null;
this._core.leave('playing');
this._core.trigger('stopped', null, 'video');
};
/**
* Starts the current video.
* @public
* @param {Event} event - The event arguments.
*/
Video.prototype.play = function(event) {
var target = $(event.target),
item = target.closest('.' + this._core.settings.itemClass),
video = this._videos[item.attr('data-video')],
width = video.width || '100%',
height = video.height || this._core.$stage.height(),
html;
if (this._playing) {
return;
}
this._core.enter('playing');
this._core.trigger('play', null, 'video');
item = this._core.items(this._core.relative(item.index()));
this._core.reset(item.index());
if (video.type === 'youtube') {
html = '<iframe width="' + width + '" height="' + height + '" src="//www.youtube.com/embed/' +
video.id + '?autoplay=1&v=' + video.id + '" frameborder="0" allowfullscreen></iframe>';
} else if (video.type === 'vimeo') {
html = '<iframe src="//player.vimeo.com/video/' + video.id +
'?autoplay=1" width="' + width + '" height="' + height +
'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
}
$('<div class="owl-video-frame">' + html + '</div>').insertAfter(item.find('.owl-video'));
this._playing = item.addClass('owl-video-playing');
};
/**
* Checks whether an video is currently in full screen mode or not.
* @todo Bad style because looks like a readonly method but changes members.
* @protected
* @returns {Boolean}
*/
Video.prototype.isInFullScreen = function() {
var element = document.fullscreenElement || document.mozFullScreenElement ||
document.webkitFullscreenElement;
return element && $(element).parent().hasClass('owl-video-frame');
};
/**
* Destroys the plugin.
*/
Video.prototype.destroy = function() {
var handler, property;
this._core.$element.off('click.owl.video');
for (handler in this._handlers) {
this._core.$element.off(handler, this._handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.Video = Video;
})(window.Zepto || window.jQuery, window, document);
/**
* Animate Plugin
* @version 2.0.0-beta.3
* @author Bartosz Wojciechowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
/**
* Creates the animate plugin.
* @class The Navigation Plugin
* @param {Owl} scope - The Owl Carousel
*/
var Animate = function(scope) {
this.core = scope;
this.core.options = $.extend({}, Animate.Defaults, this.core.options);
this.swapping = true;
this.previous = undefined;
this.next = undefined;
this.handlers = {
'change.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name == 'position') {
this.previous = this.core.current();
this.next = e.property.value;
}
}, this),
'drag.owl.carousel dragged.owl.carousel translated.owl.carousel': $.proxy(function(e) {
if (e.namespace) {
this.swapping = e.type == 'translated';
}
}, this),
'translate.owl.carousel': $.proxy(function(e) {
if (e.namespace && this.swapping && (this.core.options.animateOut || this.core.options.animateIn)) {
this.swap();
}
}, this)
};
this.core.$element.on(this.handlers);
};
/**
* Default options.
* @public
*/
Animate.Defaults = {
animateOut: false,
animateIn: false
};
/**
* Toggles the animation classes whenever an translations starts.
* @protected
* @returns {Boolean|undefined}
*/
Animate.prototype.swap = function() {
if (this.core.settings.items !== 1) {
return;
}
if (!$.support.animation || !$.support.transition) {
return;
}
this.core.speed(0);
var left,
clear = $.proxy(this.clear, this),
previous = this.core.$stage.children().eq(this.previous),
next = this.core.$stage.children().eq(this.next),
incoming = this.core.settings.animateIn,
outgoing = this.core.settings.animateOut;
if (this.core.current() === this.previous) {
return;
}
if (outgoing) {
left = this.core.coordinates(this.previous) - this.core.coordinates(this.next);
previous.css( { 'left': left + 'px' } )
.addClass('animated owl-animated-out')
.addClass(outgoing)
.on($.support.animation.end, clear);
}
if (incoming) {
next.addClass('animated owl-animated-in')
.addClass(incoming)
.on($.support.animation.end, clear);
}
};
Animate.prototype.clear = function(e) {
if ($(e.target).hasClass('animated')) {
$(e.target).css( { 'left': '' } )
.removeClass('animated owl-animated-out owl-animated-in')
.removeClass(this.core.settings.animateIn)
.removeClass(this.core.settings.animateOut);
this.core.onTransitionEnd();
}
};
/**
* Destroys the plugin.
* @public
*/
Animate.prototype.destroy = function() {
var handler, property;
for (handler in this.handlers) {
this.core.$element.off(handler, this.handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.Animate = Animate;
})(window.Zepto || window.jQuery, window, document);
/**
* Autoplay Plugin
* @version 2.0.0-beta.3
* @author Bartosz Wojciechowski
* @author Artus Kolanowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
/**
* Creates the autoplay plugin.
* @class The Autoplay Plugin
* @param {Owl} scope - The Owl Carousel
*/
var Autoplay = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* The autoplay interval.
* @type {Number}
*/
this._interval = null;
/**
* Indicates whenever the autoplay is paused.
* @type {Boolean}
*/
this._paused = false;
/**
* All event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
'changed.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name === 'settings') {
if (this._core.settings.autoplay) {
this.play();
} else {
this.stop();
}
}
}, this),
'initialized.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.autoplay) {
this.play();
}
}, this),
'play.owl.autoplay': $.proxy(function(e, t, s) {
if (e.namespace) {
this.play(t, s);
}
}, this),
'stop.owl.autoplay': $.proxy(function(e) {
if (e.namespace) {
this.stop();
}
}, this),
'mouseover.owl.autoplay': $.proxy(function() {
if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) {
this.pause();
}
}, this),
'mouseleave.owl.autoplay': $.proxy(function() {
if (this._core.settings.autoplayHoverPause && this._core.is('rotating')) {
this.play();
}
}, this)
};
// register event handlers
this._core.$element.on(this._handlers);
// set default options
this._core.options = $.extend({}, Autoplay.Defaults, this._core.options);
};
/**
* Default options.
* @public
*/
Autoplay.Defaults = {
autoplay: false,
autoplayTimeout: 5000,
autoplayHoverPause: false,
autoplaySpeed: false
};
/**
* Starts the autoplay.
* @public
* @param {Number} [timeout] - The interval before the next animation starts.
* @param {Number} [speed] - The animation speed for the animations.
*/
Autoplay.prototype.play = function(timeout, speed) {
this._paused = false;
if (this._core.is('rotating')) {
return;
}
this._core.enter('rotating');
this._interval = window.setInterval($.proxy(function() {
if (this._paused || this._core.is('busy') || this._core.is('interacting') || document.hidden) {
return;
}
this._core.next(speed || this._core.settings.autoplaySpeed);
}, this), timeout || this._core.settings.autoplayTimeout);
};
/**
* Stops the autoplay.
* @public
*/
Autoplay.prototype.stop = function() {
if (!this._core.is('rotating')) {
return;
}
window.clearInterval(this._interval);
this._core.leave('rotating');
};
/**
* Stops the autoplay.
* @public
*/
Autoplay.prototype.pause = function() {
if (!this._core.is('rotating')) {
return;
}
this._paused = true;
};
/**
* Destroys the plugin.
*/
Autoplay.prototype.destroy = function() {
var handler, property;
this.stop();
for (handler in this._handlers) {
this._core.$element.off(handler, this._handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.autoplay = Autoplay;
})(window.Zepto || window.jQuery, window, document);
/**
* Navigation Plugin
* @version 2.0.0-beta.3
* @author Artus Kolanowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
'use strict';
/**
* Creates the navigation plugin.
* @class The Navigation Plugin
* @param {Owl} carousel - The Owl Carousel.
*/
var Navigation = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* Indicates whether the plugin is initialized or not.
* @protected
* @type {Boolean}
*/
this._initialized = false;
/**
* The current paging indexes.
* @protected
* @type {Array}
*/
this._pages = [];
/**
* All DOM elements of the user interface.
* @protected
* @type {Object}
*/
this._controls = {};
/**
* Markup for an indicator.
* @protected
* @type {Array.<String>}
*/
this._templates = [];
/**
* The carousel element.
* @type {jQuery}
*/
this.$element = this._core.$element;
/**
* Overridden methods of the carousel.
* @protected
* @type {Object}
*/
this._overrides = {
next: this._core.next,
prev: this._core.prev,
to: this._core.to
};
/**
* All event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
'prepared.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.dotsData) {
this._templates.push('<div class="' + this._core.settings.dotClass + '">' +
$(e.content).find('[data-dot]').andSelf('[data-dot]').attr('data-dot') + '</div>');
}
}, this),
'added.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.dotsData) {
this._templates.splice(e.position, 0, this._templates.pop());
}
}, this),
'remove.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.dotsData) {
this._templates.splice(e.position, 1);
}
}, this),
'changed.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name == 'position') {
this.draw();
}
}, this),
'initialized.owl.carousel': $.proxy(function(e) {
if (e.namespace && !this._initialized) {
this._core.trigger('initialize', null, 'navigation');
this.initialize();
this.update();
this.draw();
this._initialized = true;
this._core.trigger('initialized', null, 'navigation');
}
}, this),
'refreshed.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._initialized) {
this._core.trigger('refresh', null, 'navigation');
this.update();
this.draw();
this._core.trigger('refreshed', null, 'navigation');
}
}, this)
};
// set default options
this._core.options = $.extend({}, Navigation.Defaults, this._core.options);
// register event handlers
this.$element.on(this._handlers);
};
/**
* Default options.
* @public
* @todo Rename `slideBy` to `navBy`
*/
Navigation.Defaults = {
nav: false,
navText: [ 'prev', 'next' ],
navSpeed: false,
navElement: 'div',
navContainer: false,
navContainerClass: 'owl-nav',
navClass: [ 'owl-prev', 'owl-next' ],
slideBy: 1,
dotClass: 'owl-dot',
dotsClass: 'owl-dots',
dots: true,
dotsEach: false,
dotsData: false,
dotsSpeed: false,
dotsContainer: false
};
/**
* Initializes the layout of the plugin and extends the carousel.
* @protected
*/
Navigation.prototype.initialize = function() {
var override,
settings = this._core.settings;
// create DOM structure for relative navigation
this._controls.$relative = (settings.navContainer ? $(settings.navContainer)
: $('<div>').addClass(settings.navContainerClass).appendTo(this.$element)).addClass('disabled');
this._controls.$previous = $('<' + settings.navElement + '>')
.addClass(settings.navClass[0])
.html(settings.navText[0])
.prependTo(this._controls.$relative)
.on('click', $.proxy(function(e) {
this.prev(settings.navSpeed);
}, this));
this._controls.$next = $('<' + settings.navElement + '>')
.addClass(settings.navClass[1])
.html(settings.navText[1])
.appendTo(this._controls.$relative)
.on('click', $.proxy(function(e) {
this.next(settings.navSpeed);
}, this));
// create DOM structure for absolute navigation
if (!settings.dotsData) {
this._templates = [ $('<div>')
.addClass(settings.dotClass)
.append($('<span>'))
.prop('outerHTML') ];
}
this._controls.$absolute = (settings.dotsContainer ? $(settings.dotsContainer)
: $('<div>').addClass(settings.dotsClass).appendTo(this.$element)).addClass('disabled');
this._controls.$absolute.on('click', 'div', $.proxy(function(e) {
var index = $(e.target).parent().is(this._controls.$absolute)
? $(e.target).index() : $(e.target).parent().index();
e.preventDefault();
this.to(index, settings.dotsSpeed);
}, this));
// override public methods of the carousel
for (override in this._overrides) {
this._core[override] = $.proxy(this[override], this);
}
};
/**
* Destroys the plugin.
* @protected
*/
Navigation.prototype.destroy = function() {
var handler, control, property, override;
for (handler in this._handlers) {
this.$element.off(handler, this._handlers[handler]);
}
for (control in this._controls) {
this._controls[control].remove();
}
for (override in this.overides) {
this._core[override] = this._overrides[override];
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
/**
* Updates the internal state.
* @protected
*/
Navigation.prototype.update = function() {
var i, j, k,
lower = this._core.clones().length / 2,
upper = lower + this._core.items().length,
maximum = this._core.maximum(true),
settings = this._core.settings,
size = settings.center || settings.autoWidth || settings.dotsData
? 1 : settings.dotsEach || settings.items;
if (settings.slideBy !== 'page') {
settings.slideBy = Math.min(settings.slideBy, settings.items);
}
if (settings.dots || settings.slideBy == 'page') {
this._pages = [];
for (i = lower, j = 0, k = 0; i < upper; i++) {
if (j >= size || j === 0) {
this._pages.push({
start: Math.min(maximum, i - lower),
end: i - lower + size - 1
});
if (Math.min(maximum, i - lower) === maximum) {
break;
}
j = 0, ++k;
}
j += this._core.mergers(this._core.relative(i));
}
}
};
/**
* Draws the user interface.
* @todo The option `dotsData` wont work.
* @protected
*/
Navigation.prototype.draw = function() {
var difference,
settings = this._core.settings,
disabled = this._core.items().length <= settings.items,
index = this._core.relative(this._core.current()),
loop = settings.loop || settings.rewind;
this._controls.$relative.toggleClass('disabled', !settings.nav || disabled);
if (settings.nav) {
this._controls.$previous.toggleClass('disabled', !loop && index <= this._core.minimum(true));
this._controls.$next.toggleClass('disabled', !loop && index >= this._core.maximum(true));
}
this._controls.$absolute.toggleClass('disabled', !settings.dots || disabled);
if (settings.dots) {
difference = this._pages.length - this._controls.$absolute.children().length;
if (settings.dotsData && difference !== 0) {
this._controls.$absolute.html(this._templates.join(''));
} else if (difference > 0) {
this._controls.$absolute.append(new Array(difference + 1).join(this._templates[0]));
} else if (difference < 0) {
this._controls.$absolute.children().slice(difference).remove();
}
this._controls.$absolute.find('.active').removeClass('active');
this._controls.$absolute.children().eq($.inArray(this.current(), this._pages)).addClass('active');
}
};
/**
* Extends event data.
* @protected
* @param {Event} event - The event object which gets thrown.
*/
Navigation.prototype.onTrigger = function(event) {
var settings = this._core.settings;
event.page = {
index: $.inArray(this.current(), this._pages),
count: this._pages.length,
size: settings && (settings.center || settings.autoWidth || settings.dotsData
? 1 : settings.dotsEach || settings.items)
};
};
/**
* Gets the current page position of the carousel.
* @protected
* @returns {Number}
*/
Navigation.prototype.current = function() {
var current = this._core.relative(this._core.current());
return $.grep(this._pages, $.proxy(function(page, index) {
return page.start <= current && page.end >= current;
}, this)).pop();
};
/**
* Gets the current succesor/predecessor position.
* @protected
* @returns {Number}
*/
Navigation.prototype.getPosition = function(successor) {
var position, length,
settings = this._core.settings;
if (settings.slideBy == 'page') {
position = $.inArray(this.current(), this._pages);
length = this._pages.length;
successor ? ++position : --position;
position = this._pages[((position % length) + length) % length].start;
} else {
position = this._core.relative(this._core.current());
length = this._core.items().length;
successor ? position += settings.slideBy : position -= settings.slideBy;
}
return position;
};
/**
* Slides to the next item or page.
* @public
* @param {Number} [speed=false] - The time in milliseconds for the transition.
*/
Navigation.prototype.next = function(speed) {
$.proxy(this._overrides.to, this._core)(this.getPosition(true), speed);
};
/**
* Slides to the previous item or page.
* @public
* @param {Number} [speed=false] - The time in milliseconds for the transition.
*/
Navigation.prototype.prev = function(speed) {
$.proxy(this._overrides.to, this._core)(this.getPosition(false), speed);
};
/**
* Slides to the specified item or page.
* @public
* @param {Number} position - The position of the item or page.
* @param {Number} [speed] - The time in milliseconds for the transition.
* @param {Boolean} [standard=false] - Whether to use the standard behaviour or not.
*/
Navigation.prototype.to = function(position, speed, standard) {
var length;
if (!standard) {
length = this._pages.length;
$.proxy(this._overrides.to, this._core)(this._pages[((position % length) + length) % length].start, speed);
} else {
$.proxy(this._overrides.to, this._core)(position, speed);
}
};
$.fn.owlCarousel.Constructor.Plugins.Navigation = Navigation;
})(window.Zepto || window.jQuery, window, document);
/**
* Hash Plugin
* @version 2.0.0-beta.3
* @author Artus Kolanowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
'use strict';
/**
* Creates the hash plugin.
* @class The Hash Plugin
* @param {Owl} carousel - The Owl Carousel
*/
var Hash = function(carousel) {
/**
* Reference to the core.
* @protected
* @type {Owl}
*/
this._core = carousel;
/**
* Hash index for the items.
* @protected
* @type {Object}
*/
this._hashes = {};
/**
* The carousel element.
* @type {jQuery}
*/
this.$element = this._core.$element;
/**
* All event handlers.
* @protected
* @type {Object}
*/
this._handlers = {
/*'initialized.owl.carousel': $.proxy(function(e) {
if (e.namespace && this._core.settings.startPosition === 'URLHash') {
$(window).trigger('hashchange.owl.navigation');
}
}, this),*/
'prepared.owl.carousel': $.proxy(function(e) {
if (e.namespace) {
var hash = $(e.content).find('[data-hash]').addBack('[data-hash]').attr('data-hash');
if (!hash) {
return;
}
this._hashes[hash] = e.content;
}
}, this),
'changed.owl.carousel': $.proxy(function(e) {
if (e.namespace && e.property.name === 'position') {
var current = this._core.items(this._core.relative(this._core.current())),
hash = $.map(this._hashes, function(item, hash) {
return item === current ? hash : null;
}).join();
if (!hash || window.location.hash.slice(1) === hash) {
return;
}
window.location.hash = hash;
}
}, this)
};
// set default options
this._core.options = $.extend({}, Hash.Defaults, this._core.options);
// register the event handlers
this.$element.on(this._handlers);
// register event listener for hash navigation
/*$(window).on('hashchange.owl.navigation', $.proxy(function(e) {
var hash = window.location.hash.substring(1),
items = this._core.$stage.children(),
position = this._hashes[hash] && items.index(this._hashes[hash]);
if (position === undefined || position === this._core.current()) {
return;
}
this._core.to(this._core.relative(position), false, true);
}, this));*/
};
/**
* Default options.
* @public
*/
Hash.Defaults = {
URLhashListener: false
};
/**
* Destroys the plugin.
* @public
*/
Hash.prototype.destroy = function() {
var handler, property;
$(window).off('hashchange.owl.navigation');
for (handler in this._handlers) {
this._core.$element.off(handler, this._handlers[handler]);
}
for (property in Object.getOwnPropertyNames(this)) {
typeof this[property] != 'function' && (this[property] = null);
}
};
$.fn.owlCarousel.Constructor.Plugins.Hash = Hash;
})(window.Zepto || window.jQuery, window, document);
/**
* Support Plugin
*
* @version 2.0.0-beta.3
* @author Vivid Planet Software GmbH
* @author Artus Kolanowski
* @license The MIT License (MIT)
*/
;(function($, window, document, undefined) {
var style = $('<support>').get(0).style,
prefixes = 'Webkit Moz O ms'.split(' '),
events = {
transition: {
end: {
WebkitTransition: 'webkitTransitionEnd',
MozTransition: 'transitionend',
OTransition: 'oTransitionEnd',
transition: 'transitionend'
}
},
animation: {
end: {
WebkitAnimation: 'webkitAnimationEnd',
MozAnimation: 'animationend',
OAnimation: 'oAnimationEnd',
animation: 'animationend'
}
}
},
tests = {
csstransforms: function() {
return !!test('transform');
},
csstransforms3d: function() {
return !!test('perspective');
},
csstransitions: function() {
return !!test('transition');
},
cssanimations: function() {
return !!test('animation');
}
};
function test(property, prefixed) {
var result = false,
upper = property.charAt(0).toUpperCase() + property.slice(1);
$.each((property + ' ' + prefixes.join(upper + ' ') + upper).split(' '), function(i, property) {
if (style[property] !== undefined) {
result = prefixed ? property : true;
return false;
}
});
return result;
}
function prefixed(property) {
return test(property, true);
}
if (tests.csstransitions()) {
/* jshint -W053 */
$.support.transition = new String(prefixed('transition'))
$.support.transition.end = events.transition.end[ $.support.transition ];
}
if (tests.cssanimations()) {
/* jshint -W053 */
$.support.animation = new String(prefixed('animation'))
$.support.animation.end = events.animation.end[ $.support.animation ];
}
if (tests.csstransforms()) {
/* jshint -W053 */
$.support.transform = new String(prefixed('transform'));
$.support.transform3d = tests.csstransforms3d();
}
})(window.Zepto || window.jQuery, window, document);
(function(window, document, undefined) {
/**
* Find the absolute position of an element
*/
var absPos = function(element) {
var offsetLeft, offsetTop;
offsetLeft = offsetTop = 0;
if (element.offsetParent) {
do {
offsetLeft += element.offsetLeft;
offsetTop += element.offsetTop;
} while (element = element.offsetParent);
}
return [offsetLeft, offsetTop];
};
/**
* @constructor Progress Circle class
* @param params.canvas Canvas on which the circles will be drawn.
* @param params.minRadius Inner radius of the innermost circle, in px.
* @param params.arcWidth Width of each circle(to be more accurate, ring).
* @param params.gapWidth Space between each circle.
* @param params.centerX X coordinate of the center of circles.
* @param params.centerY Y coordinate of the center of circles.
* @param params.infoLineBaseAngle Base angle of the info line.
* @param params.infoLineAngleInterval Angles between the info lines.
*/
var ProgressCircle = function(params) {
this.canvas = params.canvas;
this.minRadius = params.minRadius || 15;
this.arcWidth = params.arcWidth || 5;
this.gapWidth = params.gapWidth || 3;
this.centerX = params.centerX || this.canvas.width / 2;
this.centerY = params.centerY || this.canvas.height / 2;
this.infoLineLength = params.infoLineLength || 60;
this.horizLineLength = params.horizLineLength || 10;
this.infoLineAngleInterval = params.infoLineAngleInterval || Math.PI / 8;
this.infoLineBaseAngle = params.infoLineBaseAngle || Math.PI / 6;
this.context = this.canvas.getContext('2d');
this.width = this.canvas.width;
this.height = this.canvas.height;
this.circles = [];
this.runningCount = 0;
};
ProgressCircle.prototype = {
constructor: ProgressCircle,
/**
* @method Adds an progress monitor entry.
* @param params.fillColor Color to fill in the circle.
* @param params.outlineColor Color to outline the circle.
* @param params.progressListener Callback function to fetch the progress.
* @param params.infoListener Callback function to fetch the info.
* @returns this
*/
addEntry: function(params) {
this.circles.push(new Circle({
canvas: this.canvas,
context: this.context,
centerX: this.centerX,
centerY: this.centerY,
innerRadius: this.minRadius + this.circles.length *
(this.gapWidth + this.arcWidth),
arcWidth: this.arcWidth,
infoLineLength: this.infoLineLength,
horizLineLength: this.horizLineLength,
id: this.circles.length,
fillColor: params.fillColor,
outlineColor: params.outlineColor,
progressListener: params.progressListener,
infoListener: params.infoListener,
infoLineAngle: this.infoLineBaseAngle +
this.circles.length * this.infoLineAngleInterval,
}));
return this;
},
/**
* @method Starts the monitor and updates with the given interval.
* @param interval Interval between updates, in millisecond.
* @returns this
*/
start: function(interval) {
var self = this;
this.timer = setInterval(function() {
self._update();
}, interval || 33);
return this;
},
/**
* @method Stop the animation.
*/
stop: function() {
clearTimeout(this.timer);
},
/**
* @private
* @method Call update on each circle and redraw them.
* @returns this
*/
_update: function() {
this._clear();
this.circles.forEach(function(circle, idx, array) {
circle.update();
});
return this;
},
/**
* @private
* @method Clear the canvas.
* @returns this
*/
_clear: function() {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
return this;
},
};
/**
* @private
* @class Individual progress circle.
* @param params.canvas Canvas on which the circle will be drawn.
* @param params.context Context of the canvas.
* @param params.innerRadius Inner radius of the circle, in px.
* @param params.arcWidth Width of each arc(circle).
* @param params.gapWidth Distance between each arc.
* @param params.centerX X coordinate of the center of circles.
* @param params.centerY Y coordinate of the center of circles.
* @param params.fillColor Color to fill in the circle.
* @param params.outlineColor Color to outline the circle.
* @param params.progressListener Callback function to fetch the progress.
* @param params.infoListener Callback function to fetch the info.
* @param params.infoLineAngle Angle of info line.
*/
var Circle = function(params) {
this.id = params.id;
this.canvas = params.canvas;
this.context = params.context;
this.centerX = params.centerX;
this.centerY = params.centerY;
this.arcWidth = params.arcWidth;
this.innerRadius = params.innerRadius || 0;
this.fillColor = params.fillColor || '#fff';
this.outlineColor = params.outlineColor || this.fillColor;
this.progressListener = params.progressListener;
this.infoLineLength = params.infoLineLength || 250;
this.horizLineLength = params.horizLineLength || 50;
this.infoListener = params.infoListener;
this.infoLineAngle = params.infoLineAngle;
this.outerRadius = this.innerRadius + this.arcWidth;
// If the info listener is not registered, then don't calculate
// the related coordinates
if (!this.infoListener) return;
// calculate the info-line turning points
var angle = this.infoLineAngle,
arcDistance = (this.innerRadius + this.outerRadius) / 2,
sinA = Math.sin(angle),
cosA = Math.cos(angle);
this.infoLineStartX = this.centerX + sinA * arcDistance;
this.infoLineStartY = this.centerY - cosA * arcDistance;
this.infoLineMidX = this.centerX + sinA * this.infoLineLength;
this.infoLineMidY = this.centerY - cosA * this.infoLineLength;
this.infoLineEndX = this.infoLineMidX +
(sinA < 0 ? -this.horizLineLength : this.horizLineLength);
this.infoLineEndY = this.infoLineMidY;
var infoText = document.createElement('div'),
style = infoText.style;
style.color = this.fillColor;
style.position = 'absolute';
style.left = this.infoLineEndX + absPos(this.canvas)[0] + 'px';
// style.top will be calculated in the `drawInfo` method. Since
// user may want to change the size of the font, so the top offset
// must be updated in each loop.
infoText.className = 'ProgressCircleInfo'; // For css styling
infoText.id = 'progress_circle_info_' + this.id;
document.body.appendChild(infoText);
this.infoText = infoText;
};
Circle.prototype = {
constructor: Circle,
update: function() {
this.progress = this.progressListener();
this._draw();
if (this.infoListener) {
this.info = this.infoListener();
this._drawInfo();
}
},
/**
* @private
* @method Draw the circle on the canvas.
* @returns this
*/
_draw: function() {
var ctx = this.context,
ANGLE_OFFSET = -Math.PI / 2,
startAngle = 0 + ANGLE_OFFSET,
endAngle= startAngle + this.progress * Math.PI * 2,
x = this.centerX,
y = this.centerY,
innerRadius = this.innerRadius - this.arcWidth - 1,
outerRadius = this.outerRadius - this.arcWidth - 1;
if ( innerRadius < 0 )
return;
ctx.fillStyle = this.fillColor;
ctx.strokeStyle = this.outlineColor;
ctx.beginPath();
ctx.arc(x, y, innerRadius, startAngle, endAngle, false);
ctx.arc(x, y, outerRadius, endAngle, startAngle, true);
ctx.closePath();
ctx.stroke();
ctx.fill();
return this;
},
/**
* @private
* @method Draw the info lines and info text.
* @returns this
*/
_drawInfo: function() {
var pointList, lineHeight;
pointList = [
[this.infoLineStartX, this.infoLineStartY],
[this.infoLineMidX, this.infoLineMidY],
[this.infoLineEndX, this.infoLineEndY],
];
this._drawSegments(pointList, false);
this.infoText.innerHTML = this.info;
lineHeight = this.infoText.offsetHeight;
this.infoText.style.top = this.infoLineEndY +
absPos(this.canvas)[1] - lineHeight / 2 + 'px';
return this;
},
/**
* @private
* @method Helper function to draw the segments
* @param pointList An array of points in the form of [x, y].
* @param close Whether to connect the first and last point.
*/
_drawSegments: function(pointList, close) {
var ctx = this.context;
ctx.beginPath();
ctx.moveTo(pointList[0][0], pointList[0][1]);
for (var i = 1; i < pointList.length; ++i) {
ctx.lineTo(pointList[i][0], pointList[i][1]);
}
if (close) {
ctx.closePath();
}
ctx.stroke();
},
};
window.ProgressCircle = ProgressCircle;
})(window, document);
/* =========================================================
* jquery.vc_chart.js v1.0
* =========================================================
* Copyright 2013 Wpbakery
*
* Jquery chart plugin for the Visual Composer.
* ========================================================= */
(function($){
/**
* Pie chart animated.
* @param element - DOM element
* @param options - settings object.
* @constructor
*/
var VcChart = function(element, options) {
this.el = element;
this.$el = $(this.el);
var $this = this;
$this.options = $.extend({
color: 'wpb_button',
units: '',
width: '',
label_selector: '.vc_pie_chart_value',
back_selector: '.vc_pie_chart_back',
responsive: true
}, options);
$this.init();
};
VcChart.prototype = {
constructor: VcChart,
_progress_v: 0,
animated: false,
colors: {
'wpb_button': 'rgba(247, 247, 247, 1)',
'btn-primary': 'rgba(0, 136, 204, 1)',
'btn-info': 'rgba(88, 185, 218, 1)',
'btn-success': 'rgba(106, 177, 101, 1)',
'btn-warning': 'rgba(255, 153, 0, 1)',
'btn-danger': 'rgba(255, 103, 91, 1)',
'btn-inverse': 'rgba(85, 85, 85, 1)'
},
init: function() {
this.setupColor();
this.value = this.$el.data('pie-value')/100;
this.label_value = this.$el.data('pie-label-value') || this.$el.data('pie-value');
this.$wrapper = $('.vc_pie_wrapper', this.$el);
this.$label = $(this.options.label_selector, this.$el);
this.$back = $(this.options.back_selector, this.$el);
this.$canvas = this.$el.find('canvas');
this.arcWidth = this.$el.data('pie-width') * 2;
this.draw();
this.setWayPoint();
if(this.options.responsive === true) this.setResponsive();
if (UNCODE.isMobile) this._progress_v = this.value;
},
setupColor: function() {
// if(typeof this.colors[this.options.color] !== 'undefined') {
// this.color = this.colors[this.options.color];
// } else if(typeof this.options.color === 'string' && this.options.color.match(/^rgba?\([^\)]+\)/)) {
// this.color = this.options.color;
// } else {
// this.color = 'rgba(247, 247, 247, 0.2)';
// }
if(typeof this.options.color !== 'undefined') {
this.color = this.options.color;
} else this.color = 'rgba(247, 247, 247, 0.2)';
},
setResponsive: function() {
var that = this;
if (!UNCODE.isMobile) {
$(window).resize(function(){
if(that.animated === true) that.circle.stop();
that.draw(true);
});
}
},
draw: function(redraw) {
var w = this.$el.addClass('vc_ready').width() * 2,
border_w = this.arcWidth,
radius;
if(!w) w = this.$el.parents(':visible').first().width()-2;
//w = Math.round(w/100*80);
//if (w < 250) w = 250;
radius = w/2;
this.$wrapper.css({"width" : (w / 2) + "px"});
this.$label.css({"width" : (w / 2), "height" : (w / 2), "line-height" : (w / 2)+"px"});
this.$back.css({"width" : (w / 2), "height" : (w / 2)});
this.$canvas.attr({"width" : w + "px", "height" : w + "px"});
this.$el.addClass('vc_ready');
this.circle = new ProgressCircle({
canvas: this.$canvas.get(0),
minRadius: radius,
arcWidth: border_w
});
if(redraw === true && this.animated === true) {
this._progress_v = this.value;
this.circle.addEntry({
fillColor: this.color,
progressListener: $.proxy(this.setProgress, this)
}).start();
}
},
setProgress: function() {
if (this._progress_v >= this.value) {
this.circle.stop();
this.animated = true;
this.$label.html(this.label_value + this.options.units);
return this._progress_v;
}
this._progress_v += 0.01;
if (!isNaN(this.label_value)) {
var label_value = this._progress_v/this.value*this.label_value;
var val = Math.round(label_value) + this.options.units;
this.$label.html(val);
} else this.$label.html(this.label_value + this.options.units);
return this._progress_v;
},
animate: function() {
if(this.animated !== true) {
this.circle.addEntry({
fillColor: this.color,
progressListener: $.proxy(this.setProgress, this)
}).start(10);
}
},
setWayPoint: function() {
if (typeof $.fn.waypoint !== 'undefined' && !UNCODE.isMobile) {
this.$el.waypoint($.proxy(this.animate, this), { offset: '85%' });
} else {
this.animate();
}
}
};
/**
* jQuery plugin
* @param option - object with settings
* @return {*}
*/
$.fn.vcChat = function(option, value) {
return this.each(function () {
var $this = $(this),
data = $this.data('vc_chart'),
options = typeof option === 'object' ? option : {
color: $this.data('pie-color'),
units: $this.data('pie-units')
};
if (typeof option == 'undefined') $this.data('vc_chart', (data = new VcChart(this, options)));
if (typeof option == 'string') data[option](value);
});
};
/**
* Allows users to rewrite function inside theme.
*/
if ( typeof window['vc_pieChart'] !== 'function' ) {
window.vc_pieChart = function() {
$('.vc_pie_chart:visible:not(.vc_ready)').vcChat();
}
}
$(document).ready(function(){
!window.vc_iframe && vc_pieChart();
});
})(window.jQuery);
/* Progress bar
---------------------------------------------------------- */
function uncode_progress_bar() {Â Â Â Â
jQuery.each(jQuery('.vc_progress_bar'), function(index, val) {
if (!UNCODE.isMobile) {
new Waypoint({
element: val,
handler: function() {
var element = jQuery(this.element);
element.find('.vc_single_bar').each(function(index) {Â Â Â Â Â Â Â Â Â Â
var $this = jQuery(this),
            bar = $this.find('.vc_bar'),
            val = bar.data('percentage-value');         Â
setTimeout(function() {Â Â Â Â Â Â Â Â Â Â Â Â
bar.css({
"width": val + '%'
});Â Â Â Â Â Â Â Â Â Â
}, index * 200);Â Â Â Â Â Â Â Â
});
},
offset: '80%'
});
} else {
var element = jQuery(val);
element.find('.vc_single_bar').each(function(index) {Â Â Â Â Â Â Â Â Â Â
var $this = jQuery(this),
            bar = $this.find('.vc_bar'),
            val = bar.data('percentage-value');         Â
setTimeout(function() {Â Â Â Â Â Â Â Â Â Â Â Â
bar.css({
"width": val + '%'
});Â Â Â Â Â Â Â Â Â Â
}, index * 200);Â Â Â Â Â Â Â Â
});
}
});
};
uncode_progress_bar();
/*!
* jquery.counterup.js 1.0
*
* Copyright 2013, Benjamin Intal http://gambit.ph @bfintal
* Released under the GPL v2 License
*
* Date: Nov 26, 2013
*/
(function($) {
"use strict";
$.fn.counterUp = function(options) {
// Defaults
var settings = $.extend({
'time': 400,
'delay': 10
}, options);
return this.each(function() {
// Store the object
var $this = $(this);
var $settings = settings;
var counterUpper = function() {
var nums = [];
var divisions = $settings.time / $settings.delay;
var numReal = $this.attr('data-val'),
num = numReal;
var isComma = /[0-9]+,[0-9]+/.test(num);
num = num.replace(/,/g, '');
var isInt = /^[0-9]+$/.test(num);
var isFloat = /^[0-9]+\.[0-9]+$/.test(num);
var decimalPlaces = isFloat ? (num.split('.')[1] || []).length : 0;
// Generate list of incremental numbers to display
for (var i = divisions; i >= 1; i--) {
// Preserve as int if input was int
var newNum = parseInt(num / divisions * i);
// Preserve float if input was float
if (isFloat) {
newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces);
}
// Preserve commas if input had commas
if (isComma) {
while (/(\d+)(\d{3})/.test(newNum.toString())) {
newNum = newNum.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
}
}
nums.unshift(newNum);
}
nums.push(numReal);
$this.data('counterup-nums', nums);
$this.text('0');
// Updates the number until we're done
var f = function() {
if ($this.data('counterup-nums') != null) {
$this.text($this.data('counterup-nums').shift());
if ($this.data('counterup-nums').length) {
setTimeout($this.data('counterup-func'), $settings.delay);
} else {
delete $this.data('counterup-nums');
$this.data('counterup-nums', null);
$this.data('counterup-func', null);
}
}
};
$this.data('counterup-func', f);
// Start the count up
setTimeout($this.data('counterup-func'), $settings.delay);
};
// Perform counts when the element gets into view
new Waypoint({
element: this,
handler: function() {
counterUpper();
this.destroy();
},
offset: '100%'
});
});
};
})(jQuery);
/*!
* The Final Countdown for jQuery v2.0.4 (http://hilios.github.io/jQuery.countdown/)
* Copyright (c) 2014 Edson Hilios
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function(factory) {
"use strict";
if (typeof define === "function" && define.amd) {
define([ "jquery" ], factory);
} else {
factory(jQuery);
}
})(function($) {
"use strict";
var PRECISION = 100;
var instances = [], matchers = [];
matchers.push(/^[0-9]*$/.source);
matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source);
matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source);
matchers = new RegExp(matchers.join("|"));
function parseDateString(dateString) {
if (dateString instanceof Date) {
return dateString;
}
if (String(dateString).match(matchers)) {
if (String(dateString).match(/^[0-9]*$/)) {
dateString = Number(dateString);
}
if (String(dateString).match(/\-/)) {
dateString = String(dateString).replace(/\-/g, "/");
}
return new Date(dateString);
} else {
throw new Error("Couldn't cast `" + dateString + "` to a date object.");
}
}
var DIRECTIVE_KEY_MAP = {
Y: "years",
m: "months",
w: "weeks",
d: "days",
D: "totalDays",
H: "hours",
M: "minutes",
S: "seconds"
};
function strftime(offsetObject) {
return function(format) {
var directives = format.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);
if (directives) {
for (var i = 0, len = directives.length; i < len; ++i) {
var directive = directives[i].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/), regexp = new RegExp(directive[0]), modifier = directive[1] || "", plural = directive[3] || "", value = null;
directive = directive[2];
if (DIRECTIVE_KEY_MAP.hasOwnProperty(directive)) {
value = DIRECTIVE_KEY_MAP[directive];
value = Number(offsetObject[value]);
}
if (value !== null) {
if (modifier === "!") {
value = pluralize(plural, value);
}
if (modifier === "") {
if (value < 10) {
value = "0" + value.toString();
}
}
format = format.replace(regexp, value.toString());
}
}
}
format = format.replace(/%%/, "%");
return format;
};
}
function pluralize(format, count) {
var plural = "s", singular = "";
if (format) {
format = format.replace(/(:|;|\s)/gi, "").split(/\,/);
if (format.length === 1) {
plural = format[0];
} else {
singular = format[0];
plural = format[1];
}
}
if (Math.abs(count) === 1) {
return singular;
} else {
return plural;
}
}
var Countdown = function(el, finalDate, callback) {
this.el = el;
this.$el = $(el);
this.interval = null;
this.offset = {};
this.instanceNumber = instances.length;
instances.push(this);
this.$el.data("countdown-instance", this.instanceNumber);
if (callback) {
this.$el.on("update.countdown", callback);
this.$el.on("stoped.countdown", callback);
this.$el.on("finish.countdown", callback);
}
this.setFinalDate(finalDate);
this.start();
};
$.extend(Countdown.prototype, {
start: function() {
if (this.interval !== null) {
clearInterval(this.interval);
}
var self = this;
this.update();
this.interval = setInterval(function() {
self.update.call(self);
}, PRECISION);
},
stop: function() {
clearInterval(this.interval);
this.interval = null;
this.dispatchEvent("stoped");
},
pause: function() {
this.stop.call(this);
},
resume: function() {
this.start.call(this);
},
remove: function() {
this.stop();
instances[this.instanceNumber] = null;
delete this.$el.data().countdownInstance;
},
setFinalDate: function(value) {
this.finalDate = parseDateString(value);
},
update: function() {
if (this.$el.closest("html").length === 0) {
this.remove();
return;
}
this.totalSecsLeft = this.finalDate.getTime() - new Date().getTime();
this.totalSecsLeft = Math.ceil(this.totalSecsLeft / 1e3);
this.totalSecsLeft = this.totalSecsLeft < 0 ? 0 : this.totalSecsLeft;
this.offset = {
seconds: this.totalSecsLeft % 60,
minutes: Math.floor(this.totalSecsLeft / 60) % 60,
hours: Math.floor(this.totalSecsLeft / 60 / 60) % 24,
days: Math.floor(this.totalSecsLeft / 60 / 60 / 24) % 7,
totalDays: Math.floor(this.totalSecsLeft / 60 / 60 / 24),
weeks: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 7),
months: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 30),
years: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 365)
};
if (this.totalSecsLeft === 0) {
this.stop();
this.dispatchEvent("finish");
} else {
this.dispatchEvent("update");
}
},
dispatchEvent: function(eventName) {
var event = $.Event(eventName + ".countdown");
event.finalDate = this.finalDate;
event.offset = $.extend({}, this.offset);
event.strftime = strftime(this.offset);
this.$el.trigger(event);
}
});
$.fn.countdown = function() {
var argumentsArray = Array.prototype.slice.call(arguments, 0);
return this.each(function() {
var instanceNumber = $(this).data("countdown-instance");
if (instanceNumber !== undefined) {
var instance = instances[instanceNumber], method = argumentsArray[0];
if (Countdown.prototype.hasOwnProperty(method)) {
instance[method].apply(instance, argumentsArray.slice(1));
} else if (String(method).match(/^[$A-Z_][0-9A-Z_$]*$/i) === null) {
instance.setFinalDate.call(instance, method);
instance.start();
} else {
$.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi, method));
}
} else {
new Countdown(this, argumentsArray[0], argumentsArray[1]);
}
});
};
});
/*! waitForImages jQuery Plugin - v2.0.2 - 2015-05-05
* https://github.com/alexanderdickson/waitForImages
* Copyright (c) 2015 Alex Dickson; Licensed MIT */
;(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS / nodejs module
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
// Namespace all events.
var eventNamespace = 'waitForImages';
// CSS properties which contain references to images.
$.waitForImages = {
hasImageProperties: [
'backgroundImage',
'listStyleImage',
'borderImage',
'borderCornerImage',
'cursor'
],
hasImageAttributes: ['srcset']
};
// Custom selector to find `img` elements that have a valid `src`
// attribute and have not already loaded.
$.expr[':'].uncached = function (obj) {
// Ensure we are dealing with an `img` element with a valid
// `src` attribute.
if (!$(obj).is('img[src][src!=""]')) {
return false;
}
return !obj.complete;
};
$.fn.waitForImages = function () {
var allImgsLength = 0;
var allImgsLoaded = 0;
var deferred = $.Deferred();
var finishedCallback;
var eachCallback;
var waitForAll;
// Handle options object (if passed).
if ($.isPlainObject(arguments[0])) {
waitForAll = arguments[0].waitForAll;
eachCallback = arguments[0].each;
finishedCallback = arguments[0].finished;
} else {
// Handle if using deferred object and only one param was passed in.
if (arguments.length === 1 && $.type(arguments[0]) === 'boolean') {
waitForAll = arguments[0];
} else {
finishedCallback = arguments[0];
eachCallback = arguments[1];
waitForAll = arguments[2];
}
}
// Handle missing callbacks.
finishedCallback = finishedCallback || $.noop;
eachCallback = eachCallback || $.noop;
// Convert waitForAll to Boolean
waitForAll = !! waitForAll;
// Ensure callbacks are functions.
if (!$.isFunction(finishedCallback) || !$.isFunction(eachCallback)) {
throw new TypeError('An invalid callback was supplied.');
}
this.each(function () {
// Build a list of all imgs, dependent on what images will
// be considered.
var obj = $(this);
var allImgs = [];
// CSS properties which may contain an image.
var hasImgProperties = $.waitForImages.hasImageProperties || [];
// Element attributes which may contain an image.
var hasImageAttributes = $.waitForImages.hasImageAttributes || [];
// To match `url()` references.
// Spec: http://www.w3.org/TR/CSS2/syndata.html#value-def-uri
var matchUrl = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
if (waitForAll) {
// Get all elements (including the original), as any one of
// them could have a background image.
obj.find('*').addBack().each(function () {
var element = $(this);
// If an `img` element, add it. But keep iterating in
// case it has a background image too.
if (element.is('img:uncached')) {
allImgs.push({
src: element.attr('src'),
element: element[0]
});
}
$.each(hasImgProperties, function (i, property) {
var propertyValue = element.css(property);
var match;
// If it doesn't contain this property, skip.
if (!propertyValue) {
return true;
}
// Get all url() of this element.
while (match = matchUrl.exec(propertyValue)) {
allImgs.push({
src: match[2],
element: element[0]
});
}
});
$.each(hasImageAttributes, function (i, attribute) {
var attributeValue = element.attr(attribute);
var attributeValues;
// If it doesn't contain this property, skip.
if (!attributeValue) {
return true;
}
// Check for multiple comma separated images
attributeValues = attributeValue.split(',');
$.each(attributeValues, function(i, value) {
// Trim value and get string before first
// whitespace (for use with srcset).
value = $.trim(value).split(' ')[0];
allImgs.push({
src: value,
element: element[0]
});
});
});
});
} else {
// For images only, the task is simpler.
obj.find('img:uncached')
.each(function () {
allImgs.push({
src: this.src,
element: this
});
});
}
allImgsLength = allImgs.length;
allImgsLoaded = 0;
// If no images found, don't bother.
if (allImgsLength === 0) {
finishedCallback.call(obj[0]);
deferred.resolveWith(obj[0]);
}
$.each(allImgs, function (i, img) {
var image = new Image();
var events =
'load.' + eventNamespace + ' error.' + eventNamespace;
// Handle the image loading and error with the same callback.
$(image).one(events, function me (event) {
// If an error occurred with loading the image, set the
// third argument accordingly.
var eachArguments = [
allImgsLoaded,
allImgsLength,
event.type == 'load'
];
allImgsLoaded++;
eachCallback.apply(img.element, eachArguments);
deferred.notifyWith(img.element, eachArguments);
// Unbind the event listeners. I use this in addition to
// `one` as one of those events won't be called (either
// 'load' or 'error' will be called).
$(this).off(events, me);
if (allImgsLoaded == allImgsLength) {
finishedCallback.call(obj[0]);
deferred.resolveWith(obj[0]);
return false;
}
});
image.src = img.src;
});
});
return deferred.promise();
};
}));
/**
* @preserve textfill
* @name jquery.textfill.js
* @author Russ Painter
* @author Yu-Jie Lin
* @author Alexandre Dantas
* @version 0.6.0
* @date 2014-08-19
* @copyright (c) 2014 Alexandre Dantas
* @copyright (c) 2012-2013 Yu-Jie Lin
* @copyright (c) 2009 Russ Painter
* @license MIT License
* @homepage https://github.com/jquery-textfill/jquery-textfill
* @example http://jquery-textfill.github.io/jquery-textfill/index.html
*/
; (function($) {
/**
* Resizes an inner element's font so that the
* inner element completely fills the outer element.
*
* @param {Object} options User options that take
* higher precedence when
* merging with the default ones.
*
* @return All outer elements processed
*/
$.fn.textfill = function(options) {
// ______ _______ _______ _______ _ _ _______ _______
// | \ |______ |______ |_____| | | | | |______
// |_____/ |______ | | | |_____| |_____ | ______|
//
// Merging user options with the default values
var defaults = {
debug : false,
maxFontPixels : 40,
minFontPixels : 4,
innerTag : 'span',
widthOnly : false,
success : null, // callback when a resizing is done
callback : null, // callback when a resizing is done (deprecated, use success)
fail : null, // callback when a resizing is failed
complete : null, // callback when all is done
explicitWidth : null,
explicitHeight : null,
changeLineHeight : false
};
var Opts = $.extend(defaults, options);
// _______ _ _ __ _ _______ _______ _____ _____ __ _ _______
// |______ | | | \ | | | | | | | \ | |______
// | |_____| | \_| |_____ | __|__ |_____| | \_| ______|
//
// Predefining the awesomeness
// Output arguments to the Debug console
// if "Debug Mode" is enabled
function _debug() {
if (!Opts.debug
|| typeof console == 'undefined'
|| typeof console.debug == 'undefined') {
return;
}
console.debug.apply(console, arguments);
}
// Output arguments to the Warning console
function _warn() {
if (typeof console == 'undefined' ||
typeof console.warn == 'undefined') {
return;
}
console.warn.apply(console, arguments);
}
// Outputs all information on the current sizing
// of the font.
function _debug_sizing(prefix, ourText, maxHeight, maxWidth, minFontPixels, maxFontPixels) {
function _m(v1, v2) {
var marker = ' / ';
if (v1 > v2)
marker = ' > ';
else if (v1 == v2)
marker = ' = ';
return marker;
}
_debug(
'[TextFill] ' + prefix + ' { ' +
'font-size: ' + ourText.css('font-size') + ',' +
'Height: ' + ourText.height() + 'px ' + _m(ourText.height(), maxHeight) + maxHeight + 'px,' +
'Width: ' + ourText.width() + _m(ourText.width() , maxWidth) + maxWidth + ',' +
'minFontPixels: ' + minFontPixels + 'px, ' +
'maxFontPixels: ' + maxFontPixels + 'px }'
);
}
/**
* Calculates which size the font can get resized,
* according to constrains.
*
* @param {String} prefix Gets shown on the console before
* all the arguments, if debug mode is on.
* @param {Object} ourText The DOM element to resize,
* that contains the text.
* @param {function} func Function called on `ourText` that's
* used to compare with `max`.
* @param {number} max Maximum value, that gets compared with
* `func` called on `ourText`.
* @param {number} minFontPixels Minimum value the font can
* get resized to (in pixels).
* @param {number} maxFontPixels Maximum value the font can
* get resized to (in pixels).
*
* @return Size (in pixels) that the font can be resized.
*/
function _sizing(prefix, ourText, func, max, maxHeight, maxWidth, minFontPixels, maxFontPixels) {
_debug_sizing(
prefix, ourText,
maxHeight, maxWidth,
minFontPixels, maxFontPixels
);
// The kernel of the whole plugin, take most attention
// on this part.
//
// This is a loop that keeps increasing the `font-size`
// until it fits the parent element.
//
// - Start from the minimal allowed value (`minFontPixels`)
// - Guesses an average font size (in pixels) for the font,
// - Resizes the text and sees if its size is within the
// boundaries (`minFontPixels` and `maxFontPixels`).
// - If so, keep guessing until we break.
// - If not, return the last calculated size.
//
// I understand this is not optimized and we should
// consider implementing something akin to
// Daniel Hoffmann's answer here:
//
// http://stackoverflow.com/a/17433451/1094964
//
while (minFontPixels < (maxFontPixels - 1)) {
var fontSize = Math.floor((minFontPixels + maxFontPixels) / 2);
ourText.css('font-size', fontSize);
if (func.call(ourText) <= max) {
minFontPixels = fontSize;
if (func.call(ourText) == max)
break;
}
else
maxFontPixels = fontSize;
_debug_sizing(
prefix, ourText,
maxHeight, maxWidth,
minFontPixels, maxFontPixels
);
}
ourText.css('font-size', maxFontPixels);
if (func.call(ourText) <= max) {
minFontPixels = maxFontPixels;
_debug_sizing(
prefix + '* ', ourText,
maxHeight, maxWidth,
minFontPixels, maxFontPixels
);
}
return minFontPixels;
}
// _______ _______ _______ ______ _______
// |______ | |_____| |_____/ |
// ______| | | | | \_ |
//
// Let's get it started (yeah)!
_debug('[TextFill] Start Debug');
this.each(function() {
// Contains the child element we will resize.
// $(this) means the parent container
var ourText = $(Opts.innerTag + ':visible:first', this);
// Will resize to this dimensions.
// Use explicit dimensions when specified
var maxHeight = Opts.explicitHeight || $(this).height();
var maxWidth = Opts.explicitWidth || $(this).width();
var oldFontSize = ourText.css('font-size');
var lineHeight = parseFloat(ourText.css('line-height')) / parseFloat(oldFontSize);
_debug('[TextFill] Inner text: ' + ourText.text());
_debug('[TextFill] All options: ', Opts);
_debug('[TextFill] Maximum sizes: { ' +
'Height: ' + maxHeight + 'px, ' +
'Width: ' + maxWidth + 'px' + ' }'
);
var minFontPixels = Opts.minFontPixels;
// Remember, if this `maxFontPixels` is negative,
// the text will resize to as long as the container
// can accomodate
var maxFontPixels = (Opts.maxFontPixels <= 0 ?
maxHeight :
Opts.maxFontPixels);
// Let's start it all!
// 1. Calculate which `font-size` would
// be best for the Height
var fontSizeHeight = undefined;
if (! Opts.widthOnly)
fontSizeHeight = _sizing(
'Height', ourText,
$.fn.height, maxHeight,
maxHeight, maxWidth,
minFontPixels, maxFontPixels
);
// 2. Calculate which `font-size` would
// be best for the Width
var fontSizeWidth = undefined;
fontSizeWidth = _sizing(
'Width', ourText,
$.fn.width, maxWidth,
maxHeight, maxWidth,
minFontPixels, maxFontPixels
);
// 3. Actually resize the text!
if (Opts.widthOnly) {
ourText.css({
'font-size' : fontSizeWidth,
'white-space': 'nowrap'
});
if (Opts.changeLineHeight)
ourText.parent().css(
'line-height',
(lineHeight * fontSizeWidth + 'px')
);
}
else {
var fontSizeFinal = Math.min(fontSizeHeight, fontSizeWidth);
ourText.css('font-size', fontSizeFinal);
if (Opts.changeLineHeight)
ourText.parent().css(
'line-height',
(lineHeight * fontSizeFinal) + 'px'
);
}
_debug(
'[TextFill] Finished { ' +
'Old font-size: ' + oldFontSize + ', ' +
'New font-size: ' + ourText.css('font-size') + ' }'
);
// Oops, something wrong happened!
// We weren't supposed to exceed the original size
if ((ourText.width() > maxWidth) ||
(ourText.height() > maxHeight && !Opts.widthOnly)) {
ourText.css('font-size', oldFontSize);
// Failure callback
if (Opts.fail)
Opts.fail(this);
_debug(
'[TextFill] Failure { ' +
'Current Width: ' + ourText.width() + ', ' +
'Maximum Width: ' + maxWidth + ', ' +
'Current Height: ' + ourText.height() + ', ' +
'Maximum Height: ' + maxHeight + ' }'
);
}
else if (Opts.success) {
Opts.success(this);
}
else if (Opts.callback) {
_warn('callback is deprecated, use success, instead');
// Success callback
Opts.callback(this);
}
});
// Complete callback
if (Opts.complete)
Opts.complete(this);
_debug('[TextFill] End Debug');
return this;
};
})(window.jQuery);
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Share=e()}}(function(){var define,module,exports;
function getStyles(config){
// return ""+config.selector+"{width:92px;height:20px;-webkit-touch-callout:none;-khtml-user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}"+config.selector+" [class*=social-]:before{font-family:'uncodeicon'}"+config.selector+" label{font-size:16px;cursor:pointer;margin:0;padding:5px 10px;border-radius:5px;background:#a29baa;-webkit-transition:all .3s ease-in-out;transition:all .3s ease-in-out}"+config.selector+" label:hover{opacity:.8}"+config.selector+" label span{text-transform:uppercase;font-size:.9em;font-family:Lato,sans-serif;font-weight:700;-webkit-font-smoothing:antialiased;padding-left:6px}"+config.selector+" .social{opacity:0;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out;margin-left:-15px;visibility:hidden}"+config.selector+" .social.top{-webkit-transform-origin:0 0;-ms-transform-origin:0 0;transform-origin:0 0;margin-top:-80px}"+config.selector+" .social.bottom{-webkit-transform-origin:0 0;-ms-transform-origin:0 0;transform-origin:0 0;margin-top:5px}"+config.selector+" .social.middle{margin-top:-34px}"+config.selector+" .social.middle.right{-webkit-transform-origin:5% 50%;-ms-transform-origin:5% 50%;transform-origin:5% 50%;margin-left:105px}"+config.selector+" .social.middle.left{-webkit-transform-origin:5% 50%;-ms-transform-origin:5% 50%;transform-origin:5% 50%}"+config.selector+" .social.right{margin-left:14px}"+config.selector+" .social.load{-webkit-transition:none!important;transition:none!important}"+config.selector+" .social.networks-1{width:60px}"+config.selector+" .social.networks-1.center,"+config.selector+" .social.networks-1.left{margin-left:14px}"+config.selector+" .social.networks-1.middle.left{margin-left:-70px}"+config.selector+" .social.networks-1 ul{width:60px}"+config.selector+" .social.networks-2{width:120px}"+config.selector+" .social.networks-2.center{margin-left:-13px}"+config.selector+" .social.networks-2.left{margin-left:-44px}"+config.selector+" .social.networks-2.middle.left{margin-left:-130px}"+config.selector+" .social.networks-2 ul{width:120px}"+config.selector+" .social.networks-3{width:180px}"+config.selector+" .social.networks-3.center{margin-left:-45px}"+config.selector+" .social.networks-3.left{margin-left:-102px}"+config.selector+" .social.networks-3.middle.left{margin-left:-190px}"+config.selector+" .social.networks-3 ul{width:180px}"+config.selector+" .social.networks-4{width:240px}"+config.selector+" .social.networks-4.center{margin-left:-75px}"+config.selector+" .social.networks-4.left{margin-left:162px}"+config.selector+" .social.networks-4.middle.left{margin-left:-250px}"+config.selector+" .social.networks-4 ul{width:240px}"+config.selector+" .social.networks-5{width:300px}"+config.selector+" .social.networks-5.center{margin-left:-105px}"+config.selector+" .social.networks-5.left{margin-left:-225px}"+config.selector+" .social.networks-5.middle.left{margin-left:-320px}"+config.selector+" .social.networks-5 ul{width:300px}"+config.selector+" .social.active{opacity:1;-webkit-transition:all .2s ease-in-out;transition:all .2s ease-in-out;visibility:visible}"+config.selector+" .social.active.top{-webkit-transform:scale(1) translateY(-20px);-ms-transform:scale(1) translateY(-20px);transform:scale(1) translateY(-20px)}"+config.selector+" .social.active.bottom{-webkit-transform:scale(1) translateY(15px);-ms-transform:scale(1) translateY(15px);transform:scale(1) translateY(15px)}"+config.selector+" .social.active.middle.right{-webkit-transform:scale(1) translateX(10px);-ms-transform:scale(1) translateX(10px);transform:scale(1) translateX(10px)}"+config.selector+" .social.active.middle.left{-webkit-transform:scale(1) translateX(-20px);-ms-transform:scale(1) translateX(-20px);transform:scale(1) translateX(-20px)}"+config.selector+" .social ul{position:relative;left:0;right:0;height:46px;color:#fff;margin:auto;padding:0;list-style:none}"+config.selector+" .social ul li{font-size:20px;cursor:pointer;width:60px;margin:0;padding:12px 0;text-align:center;float:left;display:none;height:22px;position:relative;z-index:2;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-transition:all .3s ease-in-out;transition:all .3s ease-in-out}"+config.selector+" .social ul li:hover{}"+config.selector+" .social li[class*=facebook]{display:"+config.networks.facebook.display+"}"+config.selector+" .social li[class*=twitter]{display:"+config.networks.twitter.display+"}"+config.selector+" .social li[class*=gplus]{display:"+config.networks.google_plus.display+"}"+config.selector+" .social li[class*=pinterest]{display:"+config.networks.pinterest.display+"}"+config.selector+" .social li[class*=paper-plane]{display:"+config.networks.email.display+"}"
};
var ShareUtils;
if ((!("classList" in document.documentElement)) && Object.defineProperty && typeof HTMLElement !== "undefined") {
Object.defineProperty(HTMLElement.prototype, "classList", {
get: function() {
var ret, self, update;
update = function(fn) {
return function(value) {
var classes, index;
classes = self.className.split(/\s+/);
index = classes.indexOf(value);
fn(classes, index, value);
self.className = classes.join(" ");
};
};
self = this;
ret = {
add: update(function(classes, index, value) {
~index || classes.push(value);
}),
remove: update(function(classes, index) {
~index && classes.splice(index, 1);
}),
toggle: update(function(classes, index, value) {
if (~index) {
classes.splice(index, 1);
} else {
classes.push(value);
}
}),
contains: function(value) {
return !!~self.className.split(/\s+/).indexOf(value);
},
item: function(i) {
return self.className.split(/\s+/)[i] || null;
}
};
Object.defineProperty(ret, "length", {
get: function() {
return self.className.split(/\s+/).length;
}
});
return ret;
}
});
}
String.prototype.to_rfc3986 = function() {
var tmp;
tmp = encodeURIComponent(this);
return tmp.replace(/[!'()*]/g, function(c) {
return "%" + c.charCodeAt(0).toString(16);
});
};
ShareUtils = (function() {
function ShareUtils() {}
ShareUtils.prototype.extend = function(to, from, overwrite) {
var hasProp, prop;
for (prop in from) {
hasProp = to[prop] !== undefined;
if (hasProp && typeof from[prop] === "object") {
this.extend(to[prop], from[prop], overwrite);
} else {
if (overwrite || !hasProp) {
to[prop] = from[prop];
}
}
}
};
ShareUtils.prototype.hide = function(el) {
return el.style.display = "none";
};
ShareUtils.prototype.show = function(el) {
return el.style.display = "block";
};
ShareUtils.prototype.has_class = function(el, class_name) {
return el.classList.contains(class_name);
};
ShareUtils.prototype.add_class = function(el, class_name) {
return el.classList.add(class_name);
};
ShareUtils.prototype.remove_class = function(el, class_name) {
return el.classList.remove(class_name);
};
ShareUtils.prototype.is_encoded = function(str) {
str = str.to_rfc3986();
return decodeURIComponent(str) !== str;
};
ShareUtils.prototype.encode = function(str) {
if (typeof str === "undefined" || this.is_encoded(str)) {
return str;
} else {
return str.to_rfc3986();
}
};
ShareUtils.prototype.popup = function(url, params) {
var k, popup, qs, v;
if (params == null) {
params = {};
}
popup = {
width: 500,
height: 350
};
popup.top = (screen.height / 2) - (popup.height / 2);
popup.left = (screen.width / 2) - (popup.width / 2);
qs = ((function() {
var _results;
_results = [];
for (k in params) {
v = params[k];
_results.push("" + k + "=" + (this.encode(v)));
}
return _results;
}).call(this)).join('&');
if (qs) {
qs = "?" + qs;
}
return window.open(url + qs, 'targetWindow', "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=" + popup.left + ",top=" + popup.top + ",width=" + popup.width + ",height=" + popup.height);
};
return ShareUtils;
})();
var Share,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Share = (function(_super) {
__extends(Share, _super);
function Share(element, options) {
this.element = element;
this.el = {
head: document.getElementsByTagName('head')[0],
body: document.getElementsByTagName('body')[0]
};
this.config = {
enabled_networks: 0,
protocol: ['http', 'https'].indexOf(window.location.href.split(':')[0]) === -1 ? 'https://' : '//',
url: window.location.href.replace("&", "%26"),
caption: null,
title: this.default_title(),
image: this.default_image(),
description: this.default_description(),
ui: {
flyout: 'top center',
button_text: 'Share',
button_font: true,
icon_font: true
},
networks: {
google_plus: {
enabled: true,
url: null
},
twitter: {
enabled: true,
url: null,
title: null,
description: null
},
facebook: {
enabled: true,
load_sdk: true,
url: null,
app_id: null,
title: null,
caption: null,
description: null,
image: null
},
pinterest: {
enabled: true,
url: null,
image: null,
description: null
},
reddit: {
enabled: true,
url: null,
title: null
},
linkedin: {
enabled: true,
url: null,
title: null,
description: null
},
xing: {
enabled: true,
url: null,
title: null,
image: null,
description: null
},
whatsapp: {
enabled: true,
description: null,
url: null
},
email: {
enabled: true,
title: null,
description: null,
url: null
}
}
};
this.setup(element, options);
return this;
}
Share.prototype.setup = function(element, opts) {
var index, instance, instances, _i, _len;
instances = document.querySelectorAll(element);
this.extend(this.config, opts, true);
this.set_global_configuration();
this.normalize_network_configuration();
if (this.config.ui.icon_font) {
this.inject_icons();
}
if (this.config.ui.button_font) {
this.inject_fonts();
}
if (this.config.networks.facebook.enabled && this.config.networks.facebook.load_sdk) {
this.inject_facebook_sdk();
}
for (index = _i = 0, _len = instances.length; _i < _len; index = ++_i) {
instance = instances[index];
this.setup_instance(element, index);
}
};
Share.prototype.setup_instance = function(element, index) {
var button, instance, label, network, networks, _i, _len, _results,
_this = this;
instance = document.querySelectorAll(element)[index];
this.hide(instance);
this.add_class(instance, "sharer-" + index);
instance = document.querySelectorAll(element)[index];
this.inject_css(instance);
this.inject_html(instance);
this.show(instance);
label = instance.getElementsByTagName("label")[0];
button = instance.getElementsByClassName("social")[0];
networks = instance.getElementsByTagName('li');
this.add_class(button, "networks-" + this.config.enabled_networks);
label.addEventListener("click", function() {
return _this.event_toggle(button);
});
_this = this;
_results = [];
for (index = _i = 0, _len = networks.length; _i < _len; index = ++_i) {
network = networks[index];
_results.push(network.addEventListener("click", function() {
_this.event_network(instance, this);
return _this.event_close(button);
}));
}
return _results;
};
Share.prototype.event_toggle = function(button) {
if (this.has_class(button, "active")) {
return this.event_close(button);
} else {
return this.event_open(button);
}
};
Share.prototype.event_open = function(button) {
if (this.has_class(button, "load")) {
this.remove_class(button, "load");
}
return this.add_class(button, "active");
};
Share.prototype.event_close = function(button) {
return this.remove_class(button, "active");
};
Share.prototype.event_network = function(instance, network) {
var name;
name = network.getAttribute("data-network");
this.hook("before", name, instance);
this["network_" + name]();
return this.hook("after", name, instance);
};
Share.prototype.open = function() {
return this["public"]("open");
};
Share.prototype.close = function() {
return this["public"]("close");
};
Share.prototype.toggle = function() {
return this["public"]("toggle");
};
Share.prototype["public"] = function(action) {
var button, index, instance, _i, _len, _ref, _results;
_ref = document.querySelectorAll(this.element);
_results = [];
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
instance = _ref[index];
button = instance.getElementsByClassName("social")[0];
_results.push(this["event_" + action](button));
}
return _results;
};
Share.prototype.network_facebook = function() {
if (this.config.networks.facebook.load_sdk) {
if (!window.FB) {
return console.error("The Facebook JS SDK hasn't loaded yet.");
}
return FB.ui({
method: 'feed',
name: this.config.networks.facebook.title,
link: this.config.networks.facebook.url,
picture: this.config.networks.facebook.image,
caption: this.config.networks.facebook.caption,
description: this.config.networks.facebook.description
});
} else {
return this.popup('https://www.facebook.com/sharer/sharer.php', {
u: this.config.networks.facebook.url
});
}
};
Share.prototype.network_twitter = function() {
return this.popup('https://twitter.com/intent/tweet', {
text: this.config.networks.twitter.title,
url: this.config.networks.twitter.url
});
};
Share.prototype.network_google_plus = function() {
return this.popup('https://plus.google.com/share', {
url: this.config.networks.google_plus.url
});
};
Share.prototype.network_pinterest = function() {
return this.popup('https://www.pinterest.com/pin/create/button', {
url: this.config.networks.pinterest.url,
media: this.config.networks.pinterest.image,
description: this.config.networks.pinterest.description
});
};
Share.prototype.network_linkedin = function() {
return this.popup('https://www.linkedin.com/shareArticle', {
url: this.config.networks.linkedin.url,
title: this.config.networks.linkedin.title,
summary: this.config.networks.linkedin.description
});
}
Share.prototype.network_xing = function() {
return this.popup('https://www.xing.com/spi/shares/new', {
url: this.config.networks.xing.url,
image: this.config.networks.xing.image,
title: this.config.networks.xing.title,
summary: this.config.networks.xing.description
});
}
Share.prototype.network_email = function() {
return this.popup('mailto:', {
subject: this.config.networks.email.title,
body: this.config.networks.email.url + '%0A%0A' + this.config.networks.email.description,
});
};
Share.prototype.inject_icons = function() {
// return this.inject_stylesheet("https://www.sharebutton.co/fonts/v2/entypo.min.css");
};
Share.prototype.inject_fonts = function() {
// return this.inject_stylesheet("http://fonts.googleapis.com/css?family=Lato:900&text=" + this.config.ui.button_text);
};
Share.prototype.inject_stylesheet = function(url) {
var link;
if (!this.el.head.querySelector("link[href=\"" + url + "\"]")) {
link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", url);
return this.el.head.appendChild(link);
}
};
Share.prototype.inject_css = function(instance) {
var css, meta, selector, style;
selector = "." + (instance.getAttribute('class').split(" ").join("."));
if (!this.el.head.querySelector("meta[name='sharer" + selector + "']")) {
this.config.selector = selector;
css = getStyles(this.config);
style = document.createElement("style");
style.type = "text/css";
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
this.el.head.appendChild(style);
delete this.config.selector;
meta = document.createElement("meta");
meta.setAttribute("name", "sharer" + selector);
return this.el.head.appendChild(meta);
}
};
Share.prototype.inject_html = function(instance) {
//return instance.innerHTML = "<label class='social-export'><span>" + this.config.ui.button_text + "</span></label><div class='social load " + this.config.ui.flyout + "'><ul><li class='social-facebook' data-network='facebook' tabindex='0'></li><li class='social-twitter' data-network='twitter' tabindex='0'></li><li class='social-gplus' data-network='google_plus' tabindex='0'></li><li class='social-pinterest' data-network='pinterest' tabindex='0'></li><li class='social-linkedin' data-network='linkedin' tabindex='0'></li><li class='social-xing' data-network='xing' tabindex='0'></li><li class='social-paper-plane' data-network='email' tabindex='0'></li></ul></div>";
return instance.innerHTML = "<label class='social-export'><span>" + this.config.ui.button_text + "</span></label><div class='social load " + this.config.ui.flyout + "'><ul><li class='social-facebook' data-network='facebook' tabindex='0'></li><li class='social-twitter' data-network='twitter' tabindex='0'></li><li class='social-pinterest' data-network='pinterest' tabindex='0'></li><li class='social-linkedin' data-network='linkedin' tabindex='0'></li><li class='social-xing' data-network='xing' tabindex='0'></li><li class='social-paper-plane' data-network='email' tabindex='0'></li></ul></div>";
};
Share.prototype.inject_facebook_sdk = function() {
var fb_root, script;
if (!window.FB && this.config.networks.facebook.app_id && !this.el.body.querySelector('#fb-root')) {
script = document.createElement("script");
script.text = "window.fbAsyncInit=function(){FB.init({appId:'" + this.config.networks.facebook.app_id + "',status:true,xfbml:true})};(function(e,t,n){var r,i=e.getElementsByTagName(t)[0];if(e.getElementById(n)){return}r=e.createElement(t);r.id=n;r.src='" + this.config.protocol + "connect.facebook.net/en_US/all.js';i.parentNode.insertBefore(r,i)})(document,'script','facebook-jssdk')";
fb_root = document.createElement("div");
fb_root.id = "fb-root";
this.el.body.appendChild(fb_root);
return this.el.body.appendChild(script);
}
};
Share.prototype.hook = function(type, network, instance) {
var fn, opts;
fn = this.config.networks[network][type];
if (typeof fn === "function") {
opts = fn.call(this.config.networks[network], instance);
if (opts !== void 0) {
opts = this.normalize_filter_config_updates(opts);
this.extend(this.config.networks[network], opts, true);
this.normalize_network_configuration();
}
}
};
Share.prototype.default_title = function() {
var content;
if (content = document.querySelector('meta[property="og:title"]') || document.querySelector('meta[name="twitter:title"]')) {
return encodeURIComponent(content.getAttribute('content'));
} else if (content = document.querySelector('title')) {
return encodeURIComponent(content.innerText);
}
};
Share.prototype.default_image = function() {
var content;
if (content = document.querySelector('meta[property="og:image"]') || document.querySelector('meta[name="twitter:image"]')) {
return content.getAttribute('content');
}
};
Share.prototype.default_description = function() {
var content;
if (content = document.querySelector('meta[property="og:description"]') || document.querySelector('meta[name="twitter:description"]') || document.querySelector('meta[name="description"]')) {
return encodeURIComponent(content.getAttribute('content'));
} else {
return '';
}
};
Share.prototype.set_global_configuration = function() {
var display, network, option, options, _ref, _results;
_ref = this.config.networks;
_results = [];
for (network in _ref) {
options = _ref[network];
for (option in options) {
if (this.config.networks[network][option] == null) {
this.config.networks[network][option] = this.config[option];
}
}
if (this.config.networks[network].enabled) {
display = 'block';
this.config.enabled_networks += 1;
} else {
display = 'none';
}
_results.push(this.config.networks[network].display = display);
}
return _results;
};
Share.prototype.normalize_network_configuration = function() {
if (!this.config.networks.facebook.app_id) {
this.config.networks.facebook.load_sdk = false;
}
if (!this.is_encoded(this.config.networks.twitter.description)) {
this.config.networks.twitter.description = encodeURIComponent(this.config.networks.twitter.description);
}
if (typeof this.config.networks.facebook.app_id === 'number') {
return this.config.networks.facebook.app_id = this.config.networks.facebook.app_id.toString();
}
};
Share.prototype.normalize_filter_config_updates = function(opts) {
if (this.config.networks.facebook.app_id !== opts.app_id) {
console.warn("You are unable to change the Facebook app_id after the button has been initialized. Please-in-out update your Facebook filters accordingly.");
delete opts.app_id;
}
if (this.config.networks.facebook.load_sdk !== opts.load_sdk) {
console.warn("You are unable to change the Facebook load_sdk option after the button has been initialized. Please-in-out update your Facebook filters accordingly.");
delete opts.app_id;
}
return opts;
};
return Share;
})(ShareUtils);
return Share;
});
// Generated by CoffeeScript 1.9.2
// @license Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net
(function() {
var $, win;
$ = this.jQuery || window.jQuery;
win = $(window);
$.fn.stick_in_parent = function(opts) {
var doc, elm, enable_bottoming, fn, i, inner_scrolling, len, manual_spacer, offset_top, outer_width, parent_selector, recalc_every, sticky_class;
if (opts == null) {
opts = {};
}
sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, recalc_every = opts.recalc_every, parent_selector = opts.parent, offset_top = opts.offset_top, manual_spacer = opts.spacer, enable_bottoming = opts.bottoming;
if (offset_top == null) {
offset_top = 0;
}
if (parent_selector == null) {
parent_selector = void 0;
}
if (inner_scrolling == null) {
inner_scrolling = true;
}
if (sticky_class == null) {
sticky_class = "is_stuck";
}
doc = $(document);
if (enable_bottoming == null) {
enable_bottoming = true;
}
outer_width = function(el) {
var _el, computed, w;
if (window.getComputedStyle) {
_el = el[0];
computed = window.getComputedStyle(el[0]);
w = parseFloat(computed.getPropertyValue("width")) + parseFloat(computed.getPropertyValue("margin-left")) + parseFloat(computed.getPropertyValue("margin-right"));
if (computed.getPropertyValue("box-sizing") !== "border-box") {
w += parseFloat(computed.getPropertyValue("border-left-width")) + parseFloat(computed.getPropertyValue("border-right-width")) + parseFloat(computed.getPropertyValue("padding-left")) + parseFloat(computed.getPropertyValue("padding-right"));
}
return w;
} else {
return el.outerWidth(true);
}
};
fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) {
var bottomed, detach, fixed, last_pos, last_scroll_height, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick;
if (elm.data("sticky_kit")) {
return;
}
elm.data("sticky_kit", true);
last_scroll_height = doc.height();
parent = elm.parent();
if (parent_selector != null) {
parent = parent.closest(parent_selector);
}
if (!parent.length) {
throw "failed to find stick parent";
}
fixed = false;
bottomed = false;
spacer = manual_spacer != null ? manual_spacer && elm.closest(manual_spacer) : $("<div />");
if (spacer) {
spacer.css('position', elm.css('position'));
}
recalc = function() {
var border_top, padding_top, restore;
if (detached) {
return;
}
last_scroll_height = doc.height();
border_top = parseInt(parent.css("border-top-width"), 10);
padding_top = parseInt(parent.css("padding-top"), 10);
padding_bottom = parseInt(parent.css("padding-bottom"), 10);
parent_top = parent.offset().top + border_top + padding_top;
parent_height = parent.height();
if (fixed) {
fixed = false;
bottomed = false;
if (manual_spacer == null) {
elm.insertAfter(spacer);
spacer.detach();
}
elm.css({
position: "",
top: "",
width: "",
bottom: ""
}).removeClass(sticky_class);
restore = true;
}
top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) || 0) - offset_top;
height = elm.outerHeight(true);
el_float = elm.css("float");
if (spacer) {
spacer.css({
width: outer_width(elm),
height: height,
display: elm.css("display"),
"vertical-align": elm.css("vertical-align"),
"float": el_float
});
}
if (restore) {
return tick();
}
};
recalc();
if (height === parent_height) {
return;
}
last_pos = void 0;
offset = offset_top;
recalc_counter = recalc_every;
tick = function() {
var css, delta, recalced, scroll, will_bottom, win_height;
if (detached) {
return;
}
recalced = false;
if (recalc_counter != null) {
recalc_counter -= 1;
if (recalc_counter <= 0) {
recalc_counter = recalc_every;
recalc();
recalced = true;
}
}
if (!recalced && doc.height() !== last_scroll_height) {
recalc();
recalced = true;
}
scroll = win.scrollTop();
if (last_pos != null) {
delta = scroll - last_pos;
}
last_pos = scroll;
if (fixed) {
if (enable_bottoming) {
will_bottom = scroll + height + offset > parent_height + parent_top;
if (bottomed && !will_bottom) {
bottomed = false;
elm.css({
position: "fixed",
bottom: "",
top: offset
}).trigger("sticky_kit:unbottom");
}
}
if (scroll < top) {
fixed = false;
offset = offset_top;
if (manual_spacer == null) {
if (el_float === "left" || el_float === "right") {
elm.insertAfter(spacer);
}
spacer.detach();
}
css = {
position: "",
width: "",
top: ""
};
elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick");
}
if (inner_scrolling) {
win_height = win.height();
if (height + offset_top > win_height) {
if (!bottomed) {
offset -= delta;
offset = Math.max(win_height - height, offset);
offset = Math.min(offset_top, offset);
if (fixed) {
elm.css({
top: offset + "px"
});
}
}
}
}
} else {
if (scroll > top) {
fixed = true;
css = {
position: "fixed",
top: offset
};
css.width = elm.css("box-sizing") === "border-box" ? elm.outerWidth() + "px" : elm.width() + "px";
elm.css(css).addClass(sticky_class);
if (manual_spacer == null) {
elm.after(spacer);
if (el_float === "left" || el_float === "right") {
spacer.append(elm);
}
}
elm.trigger("sticky_kit:stick");
}
}
if (fixed && enable_bottoming) {
if (will_bottom == null) {
will_bottom = scroll + height + offset > parent_height + parent_top;
}
if (!bottomed && will_bottom) {
bottomed = true;
if (parent.css("position") === "static") {
parent.css({
position: "relative"
});
}
return elm.css({
position: "absolute",
bottom: padding_bottom,
top: "auto"
}).trigger("sticky_kit:bottom");
}
}
};
recalc_and_tick = function() {
recalc();
return tick();
};
detach = function() {
detached = true;
win.off("touchmove", tick);
win.off("scroll", tick);
win.off("resize", recalc_and_tick);
$(document.body).off("sticky_kit:recalc", recalc_and_tick);
elm.off("sticky_kit:detach", detach);
elm.removeData("sticky_kit");
elm.css({
position: "",
bottom: "",
top: "",
width: ""
});
parent.position("position", "");
if (fixed) {
if (manual_spacer == null) {
if (el_float === "left" || el_float === "right") {
elm.insertAfter(spacer);
}
spacer.remove();
}
return elm.removeClass(sticky_class);
}
};
win.on("touchmove", tick);
win.on("scroll", tick);
win.on("resize", recalc_and_tick);
$(document.body).on("sticky_kit:recalc", recalc_and_tick);
elm.on("sticky_kit:detach", detach);
return setTimeout(tick, 0);
};
for (i = 0, len = this.length; i < len; i++) {
elm = this[i];
fn($(elm));
}
return this;
};
}).call(this);
/* ==========================================================================
* bootstrap-tab-history.js
* Author: Michael Narayan <mnarayan01@gmail.com>
* Repository: https://github.com/mnarayan01/bootstrap-tab-history/
* ==========================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
* ========================================================================== */
/* ========================================================================== */
/* JSHint directives */
/* */
/* global BootstrapTabHistory: true */
/* */
/* global document */
/* global jQuery */
/* global history */
/* global window */
/* ========================================================================== */
/**
* Integrate [HTML5 history state tracking](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history)
* with [`bootstrap/tab.js`](http://getbootstrap.com/javascript/#tabs). To enable tracking on a tab element, simply set
* the `data-tab-history` attribute to true (or a string denoting a tab grouping).
*
* See the README for additional information.
*
* Functionality based upon bootstrap/tab.js v3.1.0; reference it when making any changes.
*/
BootstrapTabHistory = {
options: {
/**
* When the anchor portion of the URI is used to activate a tab, scroll down to the given offset, rather than the
* element with the given `id` attribute. Set to null to disable. Only relevant if showTabsBasedOnAnchor is true.
*
* May be overriden on a per-element basis by the attribute `data-tab-history-anchor-y-offset`.
*
* @public
* @type {?number}
*/
defaultAnchorYOffset: 0,
/**
* Either 'push' or 'replace', for whether to use `history.pushState` or `history.replaceState`, resp.
*
* May be overriden on a per-element basis by the attribute `data-tab-history-changer`.
*
* @public
* @type {string}
*/
defaultChanger: 'replace',
/**
* If true, update the URL in onShownTab in the calls to `history.pushState` and `history.replaceState`. Otherwise,
* `null` is passed as the third parameter to these calls.
*
* May be overriden on a per-element basis by the attribute `data-tab-history-update-url`.
*
* @public
* @type {boolean}
*/
defaultUpdateURL: false,
/**
* Should the anchor portion of the loaded URI be used to activate a single tab if no history was present on page
* load.
*
* @public
* @type {boolean}
*/
showTabsBasedOnAnchor: true
}
};
(function () {
'use strict';
jQuery(function () {
if(history && history.pushState && history.replaceState) {
var bootstrapTabHistory = history.state && history.state.bootstrapTabHistory;
if(bootstrapTabHistory) {
showTabsBasedOnState(bootstrapTabHistory);
} else {
showTabsBasedOnAnchor();
}
backfillHistoryState();
jQuery(document).on('shown.bs.tab show.bs.collapse', onShownTab);
jQuery(window).on('popstate', onPopState);
} else {
showTabsBasedOnAnchor();
}
});
/**
* Used to prevent onShownTab from registering shown events that we triggered via showTabsBasedOnState.
*
* @type {boolean}
*/
var showingTabsBasedOnState = false;
/**
* Used to update `history.state` to reflect the default active tabs on initial page load. This supports proper
* `history.back` handling when `data-tab-history-update-url` is true.
*/
function backfillHistoryState() {
var newState = null;
jQuery('li.active > [data-tab-history], .panel-title.active [data-tab-history]').each(function () {//edited by Uncode
var $activeTabElement = jQuery(this);
var selector = getTabSelector($activeTabElement);
if(selector) {
var tabGroup = getTabGroup($activeTabElement);
if(tabGroup) {
newState = createNewHistoryState(newState || history.state, tabGroup, selector);
}
}
});
if(newState) {
history.replaceState(newState, '', null);
}
}
/**
* Clone the existing state, ensure its bootstrapTabHistory attribute is an Object, and add the provided tabGroup to
* said bootstrapTabHistory attribute.
*
* @param {?object} existingState
* @param {!string} tabGroup
* @param {!string} selector
* @returns {!object}
*/
function createNewHistoryState(existingState, tabGroup, selector) {
// Clone history.state and ensure it has a bootstrapTabHistory entry.
var newState = jQuery.extend(true, {}, existingState, {
bootstrapTabHistory: {}
});
newState.bootstrapTabHistory[tabGroup] = selector;
return newState;
}
/**
* @param {jQuery} $tab
* @returns {?string}
*/
function getTabGroup($tab) {
return parseTruthyAttributeValue($tab.data('tab-history'));
}
/**
* @param {jQuery} $tab
* @returns {?string}
*/
function getTabSelector($tab) {
return $tab.data('target') || $tab.attr('href');
}
/**
* Receives the `shown.bs.tab` event. Updates `history.state` as appropriate.
*
* @param {jQuery.Event} shownEvt
*/
function onShownTab(shownEvt) {
if(!showingTabsBasedOnState) {
var $activatedTab = jQuery(shownEvt.target);
if ( $activatedTab.hasClass('panel-collapse') )
$activatedTab = $activatedTab.closest('.panel').find('a');
var selector = getTabSelector($activatedTab);
if(selector) {
var tabGroup = getTabGroup($activatedTab);
if(tabGroup) {
var historyChanger = $activatedTab.data('tab-history-changer') || BootstrapTabHistory.options.defaultChanger;
var newState = createNewHistoryState(history.state, tabGroup, selector);
var updateURL = (function ($activatedTab) {
if(selector[0] === '#') {
var elementUpdateURLOption = parseTruthyAttributeValue($activatedTab.data('tab-history-update-url'));
if(elementUpdateURLOption === undefined) {
return BootstrapTabHistory.options.defaultUpdateURL;
} else {
return elementUpdateURLOption;
}
} else {
return false;
}
})($activatedTab);
switch(historyChanger) {
case 'push':
history.pushState(newState, '', updateURL ? selector : null);
break;
case 'replace':
history.replaceState(newState, '', updateURL ? selector : null);
break;
default:
throw new Error('Unknown tab-history-changer: ' + historyChanger);
}
}
}
}
}
/**
* Receives the `popstate` event. Shows tabs based on the value of `history.state` as appropriate.
*/
function onPopState() {
var bootstrapTabHistory = history.state && history.state.bootstrapTabHistory;
if(bootstrapTabHistory) {
showTabsBasedOnState(bootstrapTabHistory);
}
}
/**
* Returns the given value, _unless_ that value is an empty string, in which case `true` is returned.
*
* Rationale: HAML data attributes which are set to `true` are rendered as a blank string.
*
* @param {*} value
* @returns {*}
*/
function parseTruthyAttributeValue(value) {
if(value) {
return value;
} else if(value === '') {
return true;
} else {
return value;
}
}
/**
* Show tabs based upon the anchor component of `window.location`.
*/
function showTabsBasedOnAnchor() {
if(BootstrapTabHistory.options.showTabsBasedOnAnchor) {
var anchor = window.location && window.location.hash;
if(anchor) {
var $tabElement = showTabForSelector(anchor);
if($tabElement && window.addEventListener && window.removeEventListener) {
var anchorYOffset = (function ($tabElement) {
var elementSetting = $tabElement.data('tab-history-anchor-y-offset');
if(elementSetting === undefined) {
return BootstrapTabHistory.options.defaultAnchorYOffset;
} else {
return elementSetting;
}
})($tabElement);
// HACK: This prevents scrolling to the tab on page load. This relies on the fact that we should never get
// here on `history.forward`, `history.back`, or `location.reload`, since in all those situations the
// `history.state` object should have been used (unless the browser did not support the modern History API).
if(anchorYOffset || anchorYOffset === 0) {
var scrollListener = function resetAnchorScroll () {
window.removeEventListener('scroll', scrollListener);
window.scrollTo(0, anchorYOffset);
};
window.addEventListener('scroll', scrollListener);
}
}
}
}
}
/**
* Show a tab which corresponds to the provided selector.
*
* @param {string} selector - A CSS selector.
* @returns {?jQuery} - The tab which was found to show (even if said tab was already active).
*/
function showTabForSelector(selector) {
var $tabElement = (function (selector) {
var $ret = null;
jQuery('[data-toggle="tab"], [data-toggle="pill"], [data-toggle="collapse"]').each(function () {
var $potentialTab = jQuery(this);
if(($potentialTab.attr('href') === selector || $potentialTab.data('target') === selector ) && getTabGroup($potentialTab)) {
$ret = $potentialTab;
return false;
} else {
return null;
}
});
return $ret;
})(selector);
if($tabElement) {
$tabElement.trigger('click');
//$tabElement.tab('show');
}
return $tabElement;
}
/**
* Iterate through the provided set of tab tab groups, showing the tabs based on the stored selectors.
*
* @param {object} bootstrapTabHistory - Each of the values is passed to showTabForSelector; the keys are actually irrelevant.
*/
function showTabsBasedOnState(bootstrapTabHistory) {
showingTabsBasedOnState = true;
try {
for(var k in bootstrapTabHistory) {
if(bootstrapTabHistory.hasOwnProperty(k)) {
showTabForSelector(bootstrapTabHistory[k]);
}
}
} finally {
showingTabsBasedOnState = false;
}
}
})();
/*!
* Justified Gallery - v3.6.3
* http://miromannino.github.io/Justified-Gallery/
* Copyright (c) 2016 Miro Mannino
* Licensed under the MIT license.
*/
(function($) {
function hasScrollBar() {
return $("body").height() > $(window).height();
}
/**
* Justified Gallery controller constructor
*
* @param $gallery the gallery to build
* @param settings the settings (the defaults are in $.fn.justifiedGallery.defaults)
* @constructor
*/
var JustifiedGallery = function ($gallery, settings) {
this.settings = settings;
this.checkSettings();
this.imgAnalyzerTimeout = null;
this.entries = null;
this.buildingRow = {
entriesBuff : [],
width : 0,
height : 0,
aspectRatio : 0
};
this.lastFetchedEntry = null;
this.lastAnalyzedIndex = -1;
this.yield = {
every : 2, // do a flush every n flushes (must be greater than 1)
flushed : 0 // flushed rows without a yield
};
this.border = settings.border >= 0 ? settings.border : settings.margins;
this.maxRowHeight = this.retrieveMaxRowHeight();
this.suffixRanges = this.retrieveSuffixRanges();
this.offY = this.border;
this.rows = 0;
this.spinner = {
phase : 0,
timeSlot : 150,
$el : $('<div class="spinner"><span></span><span></span><span></span></div>'),
intervalId : null
};
this.checkWidthIntervalId = null;
this.galleryWidth = $gallery.width();
this.$gallery = $gallery;
};
/** @returns {String} the best suffix given the width and the height */
JustifiedGallery.prototype.getSuffix = function (width, height) {
var longestSide, i;
longestSide = (width > height) ? width : height;
for (i = 0; i < this.suffixRanges.length; i++) {
if (longestSide <= this.suffixRanges[i]) {
return this.settings.sizeRangeSuffixes[this.suffixRanges[i]];
}
}
return this.settings.sizeRangeSuffixes[this.suffixRanges[i - 1]];
};
/**
* Remove the suffix from the string
*
* @returns {string} a new string without the suffix
*/
JustifiedGallery.prototype.removeSuffix = function (str, suffix) {
return str.substring(0, str.length - suffix.length);
};
/**
* @returns {boolean} a boolean to say if the suffix is contained in the str or not
*/
JustifiedGallery.prototype.endsWith = function (str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
};
/**
* Get the used suffix of a particular url
*
* @param str
* @returns {String} return the used suffix
*/
JustifiedGallery.prototype.getUsedSuffix = function (str) {
for (var si in this.settings.sizeRangeSuffixes) {
if (this.settings.sizeRangeSuffixes.hasOwnProperty(si)) {
if (this.settings.sizeRangeSuffixes[si].length === 0) continue;
if (this.endsWith(str, this.settings.sizeRangeSuffixes[si])) return this.settings.sizeRangeSuffixes[si];
}
}
return '';
};
/**
* Given an image src, with the width and the height, returns the new image src with the
* best suffix to show the best quality thumbnail.
*
* @returns {String} the suffix to use
*/
JustifiedGallery.prototype.newSrc = function (imageSrc, imgWidth, imgHeight, image) {
var newImageSrc;
if (this.settings.thumbnailPath) {
newImageSrc = this.settings.thumbnailPath(imageSrc, imgWidth, imgHeight, image);
} else {
var matchRes = imageSrc.match(this.settings.extension);
var ext = (matchRes !== null) ? matchRes[0] : '';
newImageSrc = imageSrc.replace(this.settings.extension, '');
newImageSrc = this.removeSuffix(newImageSrc, this.getUsedSuffix(newImageSrc));
newImageSrc += this.getSuffix(imgWidth, imgHeight) + ext;
}
return newImageSrc;
};
/**
* Shows the images that is in the given entry
*
* @param $entry the entry
* @param callback the callback that is called when the show animation is finished
*/
JustifiedGallery.prototype.showImg = function ($entry, callback) {
if (this.settings.cssAnimation) {
$entry.addClass('entry-visible');
if (callback) callback();
} else {
$entry.stop().fadeTo(this.settings.imagesAnimationDuration, 1.0, callback);
$entry.find('> img, > a > img').stop().fadeTo(this.settings.imagesAnimationDuration, 1.0, callback);
}
};
/**
* Extract the image src form the image, looking from the 'safe-src', and if it can't be found, from the
* 'src' attribute. It saves in the image data the 'jg.originalSrc' field, with the extracted src.
*
* @param $image the image to analyze
* @returns {String} the extracted src
*/
JustifiedGallery.prototype.extractImgSrcFromImage = function ($image) {
var imageSrc = (typeof $image.data('safe-src') !== 'undefined') ? $image.data('safe-src') : $image.attr('src');
$image.data('jg.originalSrc', imageSrc);
return imageSrc;
};
/** @returns {jQuery} the image in the given entry */
JustifiedGallery.prototype.imgFromEntry = function ($entry) {
var $img = $entry.find('> img');
if ($img.length === 0) $img = $entry.find('> a > img');
if ($img.length === 0) $img = $entry.find('.t-entry-visual-cont img');//hacked by Uncode
return $img.length === 0 ? null : $img;
};
/** @returns {jQuery} the caption in the given entry */
JustifiedGallery.prototype.captionFromEntry = function ($entry) {
var $caption = $entry.find('> .caption');
return $caption.length === 0 ? null : $caption;
};
/**
* Display the entry
*
* @param {jQuery} $entry the entry to display
* @param {int} x the x position where the entry must be positioned
* @param y the y position where the entry must be positioned
* @param imgWidth the image width
* @param imgHeight the image height
* @param rowHeight the row height of the row that owns the entry
*/
JustifiedGallery.prototype.displayEntry = function ($entry, x, y, imgWidth, imgHeight, rowHeight) {
$entry.width(imgWidth);
$entry.height(Math.floor(rowHeight));//hacked by Uncode
$entry.css('top', Math.floor(y));//hacked by Uncode
$entry.css('left', x);
var $image = this.imgFromEntry($entry);
if ($image !== null) {
$image.css('width', imgWidth);
$image.css('height', imgHeight);
$image.css('margin-left', - imgWidth / 2);
$image.css('margin-top', - imgHeight / 2);
// Image reloading for an high quality of thumbnails
var imageSrc = $image.attr('src');
var newImageSrc = this.newSrc(imageSrc, imgWidth, imgHeight, $image[0]);
$image.one('error', function () {
$image.attr('src', $image.data('jg.originalSrc')); //revert to the original thumbnail, we got it.
});
var loadNewImage = function () {
if (imageSrc !== newImageSrc) { //load the new image after the fadeIn
$image.attr('src', newImageSrc);
}
};
if ($entry.data('jg.loaded') === 'skipped') {
this.onImageEvent(imageSrc, $.proxy(function() {
this.showImg($entry, loadNewImage);
$entry.data('jg.loaded', true);
}, this));
} else {
this.showImg($entry, loadNewImage);
}
} else {
this.showImg($entry);
}
this.displayEntryCaption($entry);
};
/**
* Display the entry caption. If the caption element doesn't exists, it creates the caption using the 'alt'
* or the 'title' attributes.
*
* @param {jQuery} $entry the entry to process
*/
JustifiedGallery.prototype.displayEntryCaption = function ($entry) {
var $image = this.imgFromEntry($entry);
if ($image !== null && this.settings.captions) {
var $imgCaption = this.captionFromEntry($entry);
// Create it if it doesn't exists
if ($imgCaption === null) {
var caption = $image.attr('alt');
if (!this.isValidCaption(caption)) caption = $entry.attr('title');
if (this.isValidCaption(caption)) { // Create only we found something
$imgCaption = $('<div class="caption">' + caption + '</div>');
$entry.append($imgCaption);
$entry.data('jg.createdCaption', true);
}
}
// Create events (we check again the $imgCaption because it can be still inexistent)
if ($imgCaption !== null) {
if (!this.settings.cssAnimation) $imgCaption.stop().fadeTo(0, this.settings.captionSettings.nonVisibleOpacity);
this.addCaptionEventsHandlers($entry);
}
} else {
this.removeCaptionEventsHandlers($entry);
}
};
/**
* Validates the caption
*
* @param caption The caption that should be validated
* @return {boolean} Validation result
*/
JustifiedGallery.prototype.isValidCaption = function (caption) {
return (typeof caption !== 'undefined' && caption.length > 0);
};
/**
* The callback for the event 'mouseenter'. It assumes that the event currentTarget is an entry.
* It shows the caption using jQuery (or using CSS if it is configured so)
*
* @param {Event} eventObject the event object
*/
JustifiedGallery.prototype.onEntryMouseEnterForCaption = function (eventObject) {
var $caption = this.captionFromEntry($(eventObject.currentTarget));
if (this.settings.cssAnimation) {
$caption.addClass('caption-visible').removeClass('caption-hidden');
} else {
$caption.stop().fadeTo(this.settings.captionSettings.animationDuration,
this.settings.captionSettings.visibleOpacity);
}
};
/**
* The callback for the event 'mouseleave'. It assumes that the event currentTarget is an entry.
* It hides the caption using jQuery (or using CSS if it is configured so)
*
* @param {Event} eventObject the event object
*/
JustifiedGallery.prototype.onEntryMouseLeaveForCaption = function (eventObject) {
var $caption = this.captionFromEntry($(eventObject.currentTarget));
if (this.settings.cssAnimation) {
$caption.removeClass('caption-visible').removeClass('caption-hidden');
} else {
$caption.stop().fadeTo(this.settings.captionSettings.animationDuration,
this.settings.captionSettings.nonVisibleOpacity);
}
};
/**
* Add the handlers of the entry for the caption
*
* @param $entry the entry to modify
*/
JustifiedGallery.prototype.addCaptionEventsHandlers = function ($entry) {
var captionMouseEvents = $entry.data('jg.captionMouseEvents');
if (typeof captionMouseEvents === 'undefined') {
captionMouseEvents = {
mouseenter: $.proxy(this.onEntryMouseEnterForCaption, this),
mouseleave: $.proxy(this.onEntryMouseLeaveForCaption, this)
};
$entry.on('mouseenter', undefined, undefined, captionMouseEvents.mouseenter);
$entry.on('mouseleave', undefined, undefined, captionMouseEvents.mouseleave);
$entry.data('jg.captionMouseEvents', captionMouseEvents);
}
};
/**
* Remove the handlers of the entry for the caption
*
* @param $entry the entry to modify
*/
JustifiedGallery.prototype.removeCaptionEventsHandlers = function ($entry) {
var captionMouseEvents = $entry.data('jg.captionMouseEvents');
if (typeof captionMouseEvents !== 'undefined') {
$entry.off('mouseenter', undefined, captionMouseEvents.mouseenter);
$entry.off('mouseleave', undefined, captionMouseEvents.mouseleave);
$entry.removeData('jg.captionMouseEvents');
}
};
/**
* Justify the building row, preparing it to
*
* @param isLastRow
* @returns a boolean to know if the row has been justified or not
*/
JustifiedGallery.prototype.prepareBuildingRow = function (isLastRow) {
var i, $entry, imgAspectRatio, newImgW, newImgH, justify = true;
var minHeight = 0;
var availableWidth = this.galleryWidth - 2 * this.border - (
(this.buildingRow.entriesBuff.length - 1) * this.settings.margins);
var rowHeight = Math.floor( availableWidth / this.buildingRow.aspectRatio );//hacked by Uncode
var defaultRowHeight = this.settings.rowHeight;
var justifiable = this.buildingRow.width / availableWidth > this.settings.justifyThreshold;
//Skip the last row if we can't justify it and the lastRow == 'hide'
if (isLastRow && this.settings.lastRow === 'hide' && !justifiable) {
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
if (this.settings.cssAnimation)
$entry.removeClass('entry-visible');
else {
$entry.stop().fadeTo(0, 0.1);
$entry.find('> img, > a > img').fadeTo(0, 0);
}
}
return -1;
}
// With lastRow = nojustify, justify if is justificable (the images will not become too big)
if (isLastRow && !justifiable && this.settings.lastRow !== 'justify' && this.settings.lastRow !== 'hide') {
justify = false;
if (this.rows > 0) {
defaultRowHeight = (this.offY - this.border - this.settings.margins * this.rows) / this.rows;
justify = defaultRowHeight * this.buildingRow.aspectRatio / availableWidth > this.settings.justifyThreshold;
}
}
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
imgAspectRatio = $entry.data('jg.width') / $entry.data('jg.height');
if (justify) {
newImgW = (i === this.buildingRow.entriesBuff.length - 1) ? availableWidth : rowHeight * imgAspectRatio;
newImgH = rowHeight;
} else {
newImgW = defaultRowHeight * imgAspectRatio;
newImgH = defaultRowHeight;
}
availableWidth -= Math.round(newImgW);
$entry.data('jg.jwidth', Math.round(newImgW));
$entry.data('jg.jheight', Math.ceil(newImgH));
if (i === 0 || minHeight > newImgH) minHeight = newImgH;
}
this.buildingRow.height = minHeight;
return justify;
};
/**
* Clear the building row data to be used for a new row
*/
JustifiedGallery.prototype.clearBuildingRow = function () {
this.buildingRow.entriesBuff = [];
this.buildingRow.aspectRatio = 0;
this.buildingRow.width = 0;
};
/**
* Flush a row: justify it, modify the gallery height accordingly to the row height
*
* @param isLastRow
*/
JustifiedGallery.prototype.flushRow = function (isLastRow) {
var settings = this.settings;
var $entry, buildingRowRes, offX = this.border, i;
buildingRowRes = this.prepareBuildingRow(isLastRow);
if (isLastRow && settings.lastRow === 'hide' && buildingRowRes === -1) {
this.clearBuildingRow();
return;
}
if (this.maxRowHeight) {
if (this.maxRowHeight.isPercentage && this.maxRowHeight.value * settings.rowHeight < this.buildingRow.height) {
this.buildingRow.height = this.maxRowHeight.value * settings.rowHeight;
} else if (this.maxRowHeight.value >= settings.rowHeight && this.maxRowHeight.value < this.buildingRow.height) {
this.buildingRow.height = this.maxRowHeight.value;
}
}
//Align last (unjustified) row
if (settings.lastRow === 'center' || settings.lastRow === 'right') {
var availableWidth = this.galleryWidth - 2 * this.border - (this.buildingRow.entriesBuff.length - 1) * settings.margins;
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
availableWidth -= $entry.data('jg.jwidth');
}
if (settings.lastRow === 'center')
offX += availableWidth / 2;
else if (settings.lastRow === 'right')
offX += availableWidth;
}
for (i = 0; i < this.buildingRow.entriesBuff.length; i++) {
$entry = this.buildingRow.entriesBuff[i];
this.displayEntry($entry, offX, this.offY, $entry.data('jg.jwidth'), $entry.data('jg.jheight'), this.buildingRow.height);
offX += $entry.data('jg.jwidth') + settings.margins;
}
//Gallery Height
this.galleryHeightToSet = this.offY + this.buildingRow.height + this.border;
this.$gallery.height(this.galleryHeightToSet + this.getSpinnerHeight());
if (!isLastRow || (this.buildingRow.height <= settings.rowHeight && buildingRowRes)) {
//Ready for a new row
this.offY += this.buildingRow.height + settings.margins;
this.rows += 1;
this.clearBuildingRow();
this.$gallery.trigger('jg.rowflush');
}
};
/**
* Checks the width of the gallery container, to know if a new justification is needed
*/
var scrollBarOn = false;
JustifiedGallery.prototype.checkWidth = function () {
this.checkWidthIntervalId = setInterval($.proxy(function () {
var galleryWidth = parseFloat(this.$gallery.width());
if (hasScrollBar() === scrollBarOn) {
if (Math.abs(galleryWidth - this.galleryWidth) > this.settings.refreshSensitivity) {
this.galleryWidth = galleryWidth;
this.rewind();
// Restart to analyze
this.startImgAnalyzer(true);
}
} else {
scrollBarOn = hasScrollBar();
this.galleryWidth = galleryWidth;
}
}, this), this.settings.refreshTime);
};
/**
* @returns {boolean} a boolean saying if the spinner is active or not
*/
JustifiedGallery.prototype.isSpinnerActive = function () {
return this.spinner.intervalId !== null;
};
/**
* @returns {int} the spinner height
*/
JustifiedGallery.prototype.getSpinnerHeight = function () {
return this.spinner.$el.innerHeight();
};
/**
* Stops the spinner animation and modify the gallery height to exclude the spinner
*/
JustifiedGallery.prototype.stopLoadingSpinnerAnimation = function () {
clearInterval(this.spinner.intervalId);
this.spinner.intervalId = null;
this.$gallery.height(this.$gallery.height() - this.getSpinnerHeight());
this.spinner.$el.detach();
};
/**
* Starts the spinner animation
*/
JustifiedGallery.prototype.startLoadingSpinnerAnimation = function () {
var spinnerContext = this.spinner;
var $spinnerPoints = spinnerContext.$el.find('span');
clearInterval(spinnerContext.intervalId);
this.$gallery.append(spinnerContext.$el);
this.$gallery.height(this.offY + this.buildingRow.height + this.getSpinnerHeight());
spinnerContext.intervalId = setInterval(function () {
if (spinnerContext.phase < $spinnerPoints.length) {
$spinnerPoints.eq(spinnerContext.phase).fadeTo(spinnerContext.timeSlot, 1);
} else {
$spinnerPoints.eq(spinnerContext.phase - $spinnerPoints.length).fadeTo(spinnerContext.timeSlot, 0);
}
spinnerContext.phase = (spinnerContext.phase + 1) % ($spinnerPoints.length * 2);
}, spinnerContext.timeSlot);
};
/**
* Rewind the image analysis to start from the first entry.
*/
JustifiedGallery.prototype.rewind = function () {
this.lastFetchedEntry = null;
this.lastAnalyzedIndex = -1;
this.offY = this.border;
this.rows = 0;
this.clearBuildingRow();
};
/**
* Update the entries searching it from the justified gallery HTML element
*
* @param norewind if norewind only the new entries will be changed (i.e. randomized, sorted or filtered)
* @returns {boolean} true if some entries has been founded
*/
JustifiedGallery.prototype.updateEntries = function (norewind) {
var newEntries;
if (norewind && this.lastFetchedEntry != null) {
newEntries = $(this.lastFetchedEntry).nextAll(this.settings.selector).toArray();
} else {
this.entries = [];
newEntries = this.$gallery.children(this.settings.selector).toArray();
}
if (newEntries.length > 0) {
// Sort or randomize
if ($.isFunction(this.settings.sort)) {
newEntries = this.sortArray(newEntries);
} else if (this.settings.randomize) {
newEntries = this.shuffleArray(newEntries);
}
this.lastFetchedEntry = newEntries[newEntries.length - 1];
// Filter
if (this.settings.filter) {
newEntries = this.filterArray(newEntries);
} else {
this.resetFilters(newEntries);
}
}
this.entries = this.entries.concat(newEntries);
return true;
};
/**
* Apply the entries order to the DOM, iterating the entries and appending the images
*
* @param entries the entries that has been modified and that must be re-ordered in the DOM
*/
JustifiedGallery.prototype.insertToGallery = function (entries) {
var that = this;
$.each(entries, function () {
$(this).appendTo(that.$gallery);
});
};
/**
* Shuffle the array using the Fisher-Yates shuffle algorithm
*
* @param a the array to shuffle
* @return the shuffled array
*/
JustifiedGallery.prototype.shuffleArray = function (a) {
var i, j, temp;
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
this.insertToGallery(a);
return a;
};
/**
* Sort the array using settings.comparator as comparator
*
* @param a the array to sort (it is sorted)
* @return the sorted array
*/
JustifiedGallery.prototype.sortArray = function (a) {
a.sort(this.settings.sort);
this.insertToGallery(a);
return a;
};
/**
* Reset the filters removing the 'jg-filtered' class from all the entries
*
* @param a the array to reset
*/
JustifiedGallery.prototype.resetFilters = function (a) {
for (var i = 0; i < a.length; i++) $(a[i]).removeClass('jg-filtered');
};
/**
* Filter the entries considering theirs classes (if a string has been passed) or using a function for filtering.
*
* @param a the array to filter
* @return the filtered array
*/
JustifiedGallery.prototype.filterArray = function (a) {
var settings = this.settings;
if ($.type(settings.filter) === 'string') {
// Filter only keeping the entries passed in the string
return a.filter(function (el) {
var $el = $(el);
if ($el.is(settings.filter)) {
$el.removeClass('jg-filtered');
return true;
} else {
$el.addClass('jg-filtered').removeClass('jg-visible');
return false;
}
});
} else if ($.isFunction(settings.filter)) {
// Filter using the passed function
var filteredArr = a.filter(settings.filter);
for (var i = 0; i < a.length; i++) {
if (filteredArr.indexOf(a[i]) == -1) {
$(a[i]).addClass('jg-filtered').removeClass('jg-visible');
} else {
$(a[i]).removeClass('jg-filtered');
}
}
return filteredArr;
}
};
/**
* Destroy the Justified Gallery instance.
*
* It clears all the css properties added in the style attributes. We doesn't backup the original
* values for those css attributes, because it costs (performance) and because in general one
* shouldn't use the style attribute for an uniform set of images (where we suppose the use of
* classes). Creating a backup is also difficult because JG could be called multiple times and
* with different style attributes.
*/
JustifiedGallery.prototype.destroy = function () {
clearInterval(this.checkWidthIntervalId);
$.each(this.entries, $.proxy(function(_, entry) {
var $entry = $(entry);
// Reset entry style
$entry.css('width', '');
$entry.css('height', '');
$entry.css('top', '');
$entry.css('left', '');
$entry.data('jg.loaded', undefined);
$entry.removeClass('jg-entry');
// Reset image style
var $img = this.imgFromEntry($entry);
$img.css('width', '');
$img.css('height', '');
$img.css('margin-left', '');
$img.css('margin-top', '');
$img.attr('src', $img.data('jg.originalSrc'));
$img.data('jg.originalSrc', undefined);
// Remove caption
this.removeCaptionEventsHandlers($entry);
var $caption = this.captionFromEntry($entry);
if ($entry.data('jg.createdCaption')) {
// remove also the caption element (if created by jg)
$entry.data('jg.createdCaption', undefined);
if ($caption !== null) $caption.remove();
} else {
if ($caption !== null) $caption.fadeTo(0, 1);
}
}, this));
this.$gallery.css('height', '');
this.$gallery.removeClass('justified-gallery');
this.$gallery.data('jg.controller', undefined);
};
/**
* Analyze the images and builds the rows. It returns if it found an image that is not loaded.
*
* @param isForResize if the image analyzer is called for resizing or not, to call a different callback at the end
*/
JustifiedGallery.prototype.analyzeImages = function (isForResize) {
for (var i = this.lastAnalyzedIndex + 1; i < this.entries.length; i++) {
var $entry = $(this.entries[i]);
if ($entry.data('jg.loaded') === true || $entry.data('jg.loaded') === 'skipped') {
var availableWidth = this.galleryWidth - 2 * this.border - (
(this.buildingRow.entriesBuff.length - 1) * this.settings.margins);
var imgAspectRatio = $entry.data('jg.width') / $entry.data('jg.height');
if (availableWidth / (this.buildingRow.aspectRatio + imgAspectRatio) < this.settings.rowHeight) {
this.flushRow(false);
if(++this.yield.flushed >= this.yield.every) {
this.startImgAnalyzer(isForResize);
return;
}
}
this.buildingRow.entriesBuff.push($entry);
this.buildingRow.aspectRatio += imgAspectRatio;
this.buildingRow.width += imgAspectRatio * this.settings.rowHeight;
this.lastAnalyzedIndex = i;
} else if ($entry.data('jg.loaded') !== 'error') {
return;
}
}
// Last row flush (the row is not full)
if (this.buildingRow.entriesBuff.length > 0) this.flushRow(true);
if (this.isSpinnerActive()) {
this.stopLoadingSpinnerAnimation();
}
/* Stop, if there is, the timeout to start the analyzeImages.
This is because an image can be set loaded, and the timeout can be set,
but this image can be analyzed yet.
*/
this.stopImgAnalyzerStarter();
//On complete callback
this.$gallery.trigger(isForResize ? 'jg.resize' : 'jg.complete');
this.$gallery.height(this.galleryHeightToSet);
};
/**
* Stops any ImgAnalyzer starter (that has an assigned timeout)
*/
JustifiedGallery.prototype.stopImgAnalyzerStarter = function () {
this.yield.flushed = 0;
if (this.imgAnalyzerTimeout !== null) clearTimeout(this.imgAnalyzerTimeout);
};
/**
* Starts the image analyzer. It is not immediately called to let the browser to update the view
*
* @param isForResize specifies if the image analyzer must be called for resizing or not
*/
JustifiedGallery.prototype.startImgAnalyzer = function (isForResize) {
var that = this;
this.stopImgAnalyzerStarter();
this.imgAnalyzerTimeout = setTimeout(function () {
that.analyzeImages(isForResize);
}, 0.001); // we can't start it immediately due to a IE different behaviour
};
/**
* Checks if the image is loaded or not using another image object. We cannot use the 'complete' image property,
* because some browsers, with a 404 set complete = true.
*
* @param imageSrc the image src to load
* @param onLoad callback that is called when the image has been loaded
* @param onError callback that is called in case of an error
*/
JustifiedGallery.prototype.onImageEvent = function (imageSrc, onLoad, onError) {
if (!onLoad && !onError) return;
var memImage = new Image();
var $memImage = $(memImage);
if (onLoad) {
$memImage.one('load', function () {
$memImage.off('load error');
onLoad(memImage);
});
}
if (onError) {
$memImage.one('error', function() {
$memImage.off('load error');
onError(memImage);
});
}
memImage.src = imageSrc;
};
/**
* Init of Justified Gallery controlled
* It analyzes all the entries starting theirs loading and calling the image analyzer (that works with loaded images)
*/
JustifiedGallery.prototype.init = function () {
var imagesToLoad = false, skippedImages = false, that = this;
$.each(this.entries, function (index, entry) {
var $entry = $(entry);
var $image = that.imgFromEntry($entry);
$entry.addClass('jg-entry');
if ($entry.data('jg.loaded') !== true && $entry.data('jg.loaded') !== 'skipped') {
// Link Rel global overwrite
if (that.settings.rel !== null) $entry.attr('rel', that.settings.rel);
// Link Target global overwrite
if (that.settings.target !== null) $entry.attr('target', that.settings.target);
if ($image !== null) {
// Image src
var imageSrc = that.extractImgSrcFromImage($image);
$image.attr('src', imageSrc);
/* If we have the height and the width, we don't wait that the image is loaded, but we start directly
* with the justification */
if (that.settings.waitThumbnailsLoad === false) {
var width = parseFloat($image.attr('width'));
var height = parseFloat($image.attr('height'));
if (!isNaN(width) && !isNaN(height)) {
$entry.data('jg.width', width);
$entry.data('jg.height', height);
$entry.data('jg.loaded', 'skipped');
skippedImages = true;
that.startImgAnalyzer(false);
return true; // continue
}
}
$entry.data('jg.loaded', false);
imagesToLoad = true;
// Spinner start
if (!that.isSpinnerActive()) that.startLoadingSpinnerAnimation();
that.onImageEvent(imageSrc, function (loadImg) { // image loaded
$entry.data('jg.width', loadImg.width);
$entry.data('jg.height', loadImg.height);
$entry.data('jg.loaded', true);
that.startImgAnalyzer(false);
}, function () { // image load error
$entry.data('jg.loaded', 'error');
that.startImgAnalyzer(false);
});
} else {
$entry.data('jg.loaded', true);
$entry.data('jg.width', $entry.width() | parseFloat($entry.css('width')) | 1);
$entry.data('jg.height', $entry.height() | parseFloat($entry.css('height')) | 1);
}
}
});
if (!imagesToLoad && !skippedImages) this.startImgAnalyzer(false);
this.checkWidth();
};
/**
* Checks that it is a valid number. If a string is passed it is converted to a number
*
* @param settingContainer the object that contains the setting (to allow the conversion)
* @param settingName the setting name
*/
JustifiedGallery.prototype.checkOrConvertNumber = function (settingContainer, settingName) {
if ($.type(settingContainer[settingName]) === 'string') {
settingContainer[settingName] = parseFloat(settingContainer[settingName]);
}
if ($.type(settingContainer[settingName]) === 'number') {
if (isNaN(settingContainer[settingName])) throw 'invalid number for ' + settingName;
} else {
throw settingName + ' must be a number';
}
};
/**
* Checks the sizeRangeSuffixes and, if necessary, converts
* its keys from string (e.g. old settings with 'lt100') to int.
*/
JustifiedGallery.prototype.checkSizeRangesSuffixes = function () {
if ($.type(this.settings.sizeRangeSuffixes) !== 'object') {
throw 'sizeRangeSuffixes must be defined and must be an object';
}
var suffixRanges = [];
for (var rangeIdx in this.settings.sizeRangeSuffixes) {
if (this.settings.sizeRangeSuffixes.hasOwnProperty(rangeIdx)) suffixRanges.push(rangeIdx);
}
var newSizeRngSuffixes = {0: ''};
for (var i = 0; i < suffixRanges.length; i++) {
if ($.type(suffixRanges[i]) === 'string') {
try {
var numIdx = parseInt(suffixRanges[i].replace(/^[a-z]+/, ''), 10);
newSizeRngSuffixes[numIdx] = this.settings.sizeRangeSuffixes[suffixRanges[i]];
} catch (e) {
throw 'sizeRangeSuffixes keys must contains correct numbers (' + e + ')';
}
} else {
newSizeRngSuffixes[suffixRanges[i]] = this.settings.sizeRangeSuffixes[suffixRanges[i]];
}
}
this.settings.sizeRangeSuffixes = newSizeRngSuffixes;
};
/**
* check and convert the maxRowHeight setting
*/
JustifiedGallery.prototype.retrieveMaxRowHeight = function () {
var newMaxRowHeight = { };
if ($.type(this.settings.maxRowHeight) === 'string') {
if (this.settings.maxRowHeight.match(/^[0-9]+%$/)) {
newMaxRowHeight.value = parseFloat(this.settings.maxRowHeight.match(/^([0-9]+)%$/)[1]) / 100;
newMaxRowHeight.isPercentage = false;
} else {
newMaxRowHeight.value = parseFloat(this.settings.maxRowHeight);
newMaxRowHeight.isPercentage = true;
}
} else if ($.type(this.settings.maxRowHeight) === 'number') {
newMaxRowHeight.value = this.settings.maxRowHeight;
newMaxRowHeight.isPercentage = false;
} else if (this.settings.maxRowHeight === false ||
this.settings.maxRowHeight === null ||
typeof this.settings.maxRowHeight == 'undefined') {
return null;
} else {
throw 'maxRowHeight must be a number or a percentage';
}
// check if the converted value is not a number
if (isNaN(newMaxRowHeight.value)) throw 'invalid number for maxRowHeight';
// check values
if (newMaxRowHeight.isPercentage) {
if (newMaxRowHeight.value < 100) newMaxRowHeight.value = 100;
}
return newMaxRowHeight;
};
/**
* Checks the settings
*/
JustifiedGallery.prototype.checkSettings = function () {
this.checkSizeRangesSuffixes();
this.checkOrConvertNumber(this.settings, 'rowHeight');
this.checkOrConvertNumber(this.settings, 'margins');
this.checkOrConvertNumber(this.settings, 'border');
var lastRowModes = [
'justify',
'nojustify',
'left',
'center',
'right',
'hide'
];
if (lastRowModes.indexOf(this.settings.lastRow) === -1) {
throw 'lastRow must be one of: ' + lastRowModes.join(', ');
}
this.checkOrConvertNumber(this.settings, 'justifyThreshold');
if (this.settings.justifyThreshold < 0 || this.settings.justifyThreshold > 1) {
throw 'justifyThreshold must be in the interval [0,1]';
}
if ($.type(this.settings.cssAnimation) !== 'boolean') {
throw 'cssAnimation must be a boolean';
}
if ($.type(this.settings.captions) !== 'boolean') throw 'captions must be a boolean';
this.checkOrConvertNumber(this.settings.captionSettings, 'animationDuration');
this.checkOrConvertNumber(this.settings.captionSettings, 'visibleOpacity');
if (this.settings.captionSettings.visibleOpacity < 0 ||
this.settings.captionSettings.visibleOpacity > 1) {
throw 'captionSettings.visibleOpacity must be in the interval [0, 1]';
}
this.checkOrConvertNumber(this.settings.captionSettings, 'nonVisibleOpacity');
if (this.settings.captionSettings.nonVisibleOpacity < 0 ||
this.settings.captionSettings.nonVisibleOpacity > 1) {
throw 'captionSettings.nonVisibleOpacity must be in the interval [0, 1]';
}
this.checkOrConvertNumber(this.settings, 'imagesAnimationDuration');
this.checkOrConvertNumber(this.settings, 'refreshTime');
this.checkOrConvertNumber(this.settings, 'refreshSensitivity');
if ($.type(this.settings.randomize) !== 'boolean') throw 'randomize must be a boolean';
if ($.type(this.settings.selector) !== 'string') throw 'selector must be a string';
if (this.settings.sort !== false && !$.isFunction(this.settings.sort)) {
throw 'sort must be false or a comparison function';
}
if (this.settings.filter !== false && !$.isFunction(this.settings.filter) &&
$.type(this.settings.filter) !== 'string') {
throw 'filter must be false, a string or a filter function';
}
};
/**
* It brings all the indexes from the sizeRangeSuffixes and it orders them. They are then sorted and returned.
* @returns {Array} sorted suffix ranges
*/
JustifiedGallery.prototype.retrieveSuffixRanges = function () {
var suffixRanges = [];
for (var rangeIdx in this.settings.sizeRangeSuffixes) {
if (this.settings.sizeRangeSuffixes.hasOwnProperty(rangeIdx)) suffixRanges.push(parseInt(rangeIdx, 10));
}
suffixRanges.sort(function (a, b) { return a > b ? 1 : a < b ? -1 : 0; });
return suffixRanges;
};
/**
* Update the existing settings only changing some of them
*
* @param newSettings the new settings (or a subgroup of them)
*/
JustifiedGallery.prototype.updateSettings = function (newSettings) {
// In this case Justified Gallery has been called again changing only some options
this.settings = $.extend({}, this.settings, newSettings);
this.checkSettings();
// As reported in the settings: negative value = same as margins, 0 = disabled
this.border = this.settings.border >= 0 ? this.settings.border : this.settings.margins;
this.maxRowHeight = this.retrieveMaxRowHeight();
this.suffixRanges = this.retrieveSuffixRanges();
};
/**
* Justified Gallery plugin for jQuery
*
* Events
* - jg.complete : called when all the gallery has been created
* - jg.resize : called when the gallery has been resized
* - jg.rowflush : when a new row appears
*
* @param arg the action (or the settings) passed when the plugin is called
* @returns {*} the object itself
*/
$.fn.justifiedGallery = function (arg) {
return this.each(function (index, gallery) {
var $gallery = $(gallery);
$gallery.addClass('justified-gallery');
var controller = $gallery.data('jg.controller');
if (typeof controller === 'undefined') {
// Create controller and assign it to the object data
if (typeof arg !== 'undefined' && arg !== null && $.type(arg) !== 'object') {
if (arg === 'destroy') return; // Just a call to an unexisting object
throw 'The argument must be an object';
}
controller = new JustifiedGallery($gallery, $.extend({}, $.fn.justifiedGallery.defaults, arg));
$gallery.data('jg.controller', controller);
} else if (arg === 'norewind') {
// In this case we don't rewind: we analyze only the latest images (e.g. to complete the last unfinished row
// ... left to be more readable
} else if (arg === 'destroy') {
controller.destroy();
return;
} else {
// In this case Justified Gallery has been called again changing only some options
controller.updateSettings(arg);
controller.rewind();
}
// Update the entries list
if (!controller.updateEntries(arg === 'norewind')) return;
// Init justified gallery
controller.init();
});
};
// Default options
$.fn.justifiedGallery.defaults = {
sizeRangeSuffixes: { }, /* e.g. Flickr configuration
{
100: '_t', // used when longest is less than 100px
240: '_m', // used when longest is between 101px and 240px
320: '_n', // ...
500: '',
640: '_z',
1024: '_b' // used as else case because it is the last
}
*/
thumbnailPath: undefined, /* If defined, sizeRangeSuffixes is not used, and this function is used to determine the
path relative to a specific thumbnail size. The function should accept respectively three arguments:
current path, width and height */
rowHeight: 120,
maxRowHeight: false, // false or negative value to deactivate. Positive number to express the value in pixels,
// A string '[0-9]+%' to express in percentage (e.g. 300% means that the row height
// can't exceed 3 * rowHeight)
margins: 1,
border: -1, // negative value = same as margins, 0 = disabled, any other value to set the border
lastRow: 'nojustify', // … which is the same as 'left', or can be 'justify', 'center', 'right' or 'hide'
justifyThreshold: 0.90, /* if row width / available space > 0.90 it will be always justified
* (i.e. lastRow setting is not considered) */
waitThumbnailsLoad: true,
captions: true,
cssAnimation: true,
imagesAnimationDuration: 500, // ignored with css animations
captionSettings: { // ignored with css animations
animationDuration: 500,
visibleOpacity: 0.7,
nonVisibleOpacity: 0.0
},
rel: null, // rewrite the rel of each analyzed links
target: null, // rewrite the target of all links
extension: /\.[^.\\/]+$/, // regexp to capture the extension of an image
refreshTime: 200, // time interval (in ms) to check if the page changes its width
refreshSensitivity: 0, // change in width allowed (in px) without re-building the gallery
randomize: false,
sort: false, /*
- false: to do not sort
- function: to sort them using the function as comparator (see Array.prototype.sort())
*/
filter: false, /*
- false, null or undefined: for a disabled filter
- a string: an entry is kept if entry.is(filter string) returns true
see jQuery's .is() function for further information
- a function: invoked with arguments (entry, index, array). Return true to keep the entry, false otherwise.
It follows the specifications of the Array.prototype.filter() function of JavaScript.
*/
selector: 'a, div:not(.spinner)' // The selector that is used to know what are the entries of the gallery
};
}(jQuery));
/*!
* Customized version of iScroll.js 0.0.1
* It fixes bugs affecting its integration with fullpage.js
*/
/*! iScroll v5.2.0 ~ (c) 2008-2016 Matteo Spinelli ~ http://cubiq.org/license */
(function (window, document, Math) {
var rAF = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) { window.setTimeout(callback, 1000 / 60); };
var utils = (function () {
var me = {};
var _elementStyle = document.createElement('div').style;
var _vendor = (function () {
var vendors = ['t', 'webkitT', 'MozT', 'msT', 'OT'],
transform,
i = 0,
l = vendors.length;
for ( ; i < l; i++ ) {
transform = vendors[i] + 'ransform';
if ( transform in _elementStyle ) return vendors[i].substr(0, vendors[i].length-1);
}
return false;
})();
function _prefixStyle (style) {
if ( _vendor === false ) return false;
if ( _vendor === '' ) return style;
return _vendor + style.charAt(0).toUpperCase() + style.substr(1);
}
me.getTime = Date.now || function getTime () { return new Date().getTime(); };
me.extend = function (target, obj) {
for ( var i in obj ) {
target[i] = obj[i];
}
};
me.addEvent = function (el, type, fn, capture) {
el.addEventListener(type, fn, !!capture);
};
me.removeEvent = function (el, type, fn, capture) {
el.removeEventListener(type, fn, !!capture);
};
me.prefixPointerEvent = function (pointerEvent) {
return window.MSPointerEvent ?
'MSPointer' + pointerEvent.charAt(7).toUpperCase() + pointerEvent.substr(8):
pointerEvent;
};
me.momentum = function (current, start, time, lowerMargin, wrapperSize, deceleration) {
var distance = current - start,
speed = Math.abs(distance) / time,
destination,
duration;
deceleration = deceleration === undefined ? 0.0006 : deceleration;
destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
duration = speed / deceleration;
if ( destination < lowerMargin ) {
destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
distance = Math.abs(destination - current);
duration = distance / speed;
} else if ( destination > 0 ) {
destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
distance = Math.abs(current) + destination;
duration = distance / speed;
}
return {
destination: Math.round(destination),
duration: duration
};
};
var _transform = _prefixStyle('transform');
me.extend(me, {
hasTransform: _transform !== false,
hasPerspective: _prefixStyle('perspective') in _elementStyle,
hasTouch: 'ontouchstart' in window,
hasPointer: !!(window.PointerEvent || window.MSPointerEvent), // IE10 is prefixed
hasTransition: _prefixStyle('transition') in _elementStyle
});
/*
This should find all Android browsers lower than build 535.19 (both stock browser and webview)
- galaxy S2 is ok
- 2.3.6 : `AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1`
- 4.0.4 : `AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
- galaxy S3 is badAndroid (stock brower, webview)
`AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
- galaxy S4 is badAndroid (stock brower, webview)
`AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30`
- galaxy S5 is OK
`AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
- galaxy S6 is OK
`AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36 (Chrome/)`
*/
me.isBadAndroid = (function() {
var appVersion = window.navigator.appVersion;
// Android browser is not a chrome browser.
if (/Android/.test(appVersion) && !(/Chrome\/\d/.test(appVersion))) {
var safariVersion = appVersion.match(/Safari\/(\d+.\d)/);
if(safariVersion && typeof safariVersion === "object" && safariVersion.length >= 2) {
return parseFloat(safariVersion[1]) < 535.19;
} else {
return true;
}
} else {
return false;
}
})();
me.extend(me.style = {}, {
transform: _transform,
transitionTimingFunction: _prefixStyle('transitionTimingFunction'),
transitionDuration: _prefixStyle('transitionDuration'),
transitionDelay: _prefixStyle('transitionDelay'),
transformOrigin: _prefixStyle('transformOrigin')
});
me.hasClass = function (e, c) {
var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
return re.test(e.className);
};
me.addClass = function (e, c) {
if ( me.hasClass(e, c) ) {
return;
}
var newclass = e.className.split(' ');
newclass.push(c);
e.className = newclass.join(' ');
};
me.removeClass = function (e, c) {
if ( !me.hasClass(e, c) ) {
return;
}
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g');
e.className = e.className.replace(re, ' ');
};
me.offset = function (el) {
var left = -el.offsetLeft,
top = -el.offsetTop;
// jshint -W084
while (el = el.offsetParent) {
left -= el.offsetLeft;
top -= el.offsetTop;
}
// jshint +W084
return {
left: left,
top: top
};
};
me.preventDefaultException = function (el, exceptions) {
for ( var i in exceptions ) {
if ( exceptions[i].test(el[i]) ) {
return true;
}
}
return false;
};
me.extend(me.eventType = {}, {
touchstart: 1,
touchmove: 1,
touchend: 1,
mousedown: 2,
mousemove: 2,
mouseup: 2,
pointerdown: 3,
pointermove: 3,
pointerup: 3,
MSPointerDown: 3,
MSPointerMove: 3,
MSPointerUp: 3
});
me.extend(me.ease = {}, {
quadratic: {
style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
fn: function (k) {
return k * ( 2 - k );
}
},
circular: {
style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1)
fn: function (k) {
return Math.sqrt( 1 - ( --k * k ) );
}
},
back: {
style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)',
fn: function (k) {
var b = 4;
return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1;
}
},
bounce: {
style: '',
fn: function (k) {
if ( ( k /= 1 ) < ( 1 / 2.75 ) ) {
return 7.5625 * k * k;
} else if ( k < ( 2 / 2.75 ) ) {
return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
} else if ( k < ( 2.5 / 2.75 ) ) {
return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
} else {
return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
}
}
},
elastic: {
style: '',
fn: function (k) {
var f = 0.22,
e = 0.4;
if ( k === 0 ) { return 0; }
if ( k == 1 ) { return 1; }
return ( e * Math.pow( 2, - 10 * k ) * Math.sin( ( k - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 );
}
}
});
me.tap = function (e, eventName) {
var ev = document.createEvent('Event');
ev.initEvent(eventName, true, true);
ev.pageX = e.pageX;
ev.pageY = e.pageY;
e.target.dispatchEvent(ev);
};
me.click = function (e) {
var target = e.target,
ev;
if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent
// initMouseEvent is deprecated.
ev = document.createEvent(window.MouseEvent ? 'MouseEvents' : 'Event');
ev.initEvent('click', true, true);
ev.view = e.view || window;
ev.detail = 1;
ev.screenX = target.screenX || 0;
ev.screenY = target.screenY || 0;
ev.clientX = target.clientX || 0;
ev.clientY = target.clientY || 0;
ev.ctrlKey = !!e.ctrlKey;
ev.altKey = !!e.altKey;
ev.shiftKey = !!e.shiftKey;
ev.metaKey = !!e.metaKey;
ev.button = 0;
ev.relatedTarget = null;
ev._constructed = true;
target.dispatchEvent(ev);
}
};
return me;
})();
function IScroll (el, options) {
this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
this.scroller = this.wrapper.children[0];
this.scrollerStyle = this.scroller.style; // cache style for better performance
this.options = {
resizeScrollbars: true,
mouseWheelSpeed: 20,
snapThreshold: 0.334,
// INSERT POINT: OPTIONS
disablePointer : !utils.hasPointer,
disableTouch : utils.hasPointer || !utils.hasTouch,
disableMouse : utils.hasPointer || utils.hasTouch,
startX: 0,
startY: 0,
scrollY: true,
directionLockThreshold: 5,
momentum: true,
bounce: true,
bounceTime: 600,
bounceEasing: '',
preventDefault: true,
preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|LABEL)$/ },
HWCompositing: true,
useTransition: true,
useTransform: true,
bindToWrapper: typeof window.onmousedown === "undefined"
};
for ( var i in options ) {
this.options[i] = options[i];
}
// Normalize options
this.translateZ = this.options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : '';
this.options.useTransition = utils.hasTransition && this.options.useTransition;
this.options.useTransform = utils.hasTransform && this.options.useTransform;
this.options.eventPassthrough = this.options.eventPassthrough === true ? 'vertical' : this.options.eventPassthrough;
this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault;
// If you want eventPassthrough I have to lock one of the axes
this.options.scrollY = this.options.eventPassthrough == 'vertical' ? false : this.options.scrollY;
this.options.scrollX = this.options.eventPassthrough == 'horizontal' ? false : this.options.scrollX;
// With eventPassthrough we also need lockDirection mechanism
this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough;
this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold;
this.options.bounceEasing = typeof this.options.bounceEasing == 'string' ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing;
this.options.resizePolling = this.options.resizePolling === undefined ? 60 : this.options.resizePolling;
if ( this.options.tap === true ) {
this.options.tap = 'tap';
}
// https://github.com/cubiq/iscroll/issues/1029
if (!this.options.useTransition && !this.options.useTransform) {
if(!(/relative|absolute/i).test(this.scrollerStyle.position)) {
this.scrollerStyle.position = "relative";
}
}
if ( this.options.shrinkScrollbars == 'scale' ) {
this.options.useTransition = false;
}
this.options.invertWheelDirection = this.options.invertWheelDirection ? -1 : 1;
// INSERT POINT: NORMALIZATION
// Some defaults
this.x = 0;
this.y = 0;
this.directionX = 0;
this.directionY = 0;
this._events = {};
// INSERT POINT: DEFAULTS
this._init();
this.refresh();
this.scrollTo(this.options.startX, this.options.startY);
this.enable();
}
IScroll.prototype = {
version: '5.2.0',
_init: function () {
this._initEvents();
if ( this.options.scrollbars || this.options.indicators ) {
this._initIndicators();
}
if ( this.options.mouseWheel ) {
this._initWheel();
}
if ( this.options.snap ) {
this._initSnap();
}
if ( this.options.keyBindings ) {
this._initKeys();
}
// INSERT POINT: _init
},
destroy: function () {
this._initEvents(true);
clearTimeout(this.resizeTimeout);
this.resizeTimeout = null;
this._execEvent('destroy');
},
_transitionEnd: function (e) {
if ( e.target != this.scroller || !this.isInTransition ) {
return;
}
this._transitionTime();
if ( !this.resetPosition(this.options.bounceTime) ) {
this.isInTransition = false;
this._execEvent('scrollEnd');
}
},
_start: function (e) {
// React to left mouse button only
if ( utils.eventType[e.type] != 1 ) {
// for button property
// http://unixpapa.com/js/mouse.html
var button;
if (!e.which) {
/* IE case */
button = (e.button < 2) ? 0 :
((e.button == 4) ? 1 : 2);
} else {
/* All others */
button = e.button;
}
if ( button !== 0 ) {
return;
}
}
if ( !this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated) ) {
return;
}
if ( this.options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
e.preventDefault();
}
var point = e.touches ? e.touches[0] : e,
pos;
this.initiated = utils.eventType[e.type];
this.moved = false;
this.distX = 0;
this.distY = 0;
this.directionX = 0;
this.directionY = 0;
this.directionLocked = 0;
this.startTime = utils.getTime();
if ( this.options.useTransition && this.isInTransition ) {
this._transitionTime();
this.isInTransition = false;
pos = this.getComputedPosition();
this._translate(Math.round(pos.x), Math.round(pos.y));
this._execEvent('scrollEnd');
} else if ( !this.options.useTransition && this.isAnimating ) {
this.isAnimating = false;
this._execEvent('scrollEnd');
}
this.startX = this.x;
this.startY = this.y;
this.absStartX = this.x;
this.absStartY = this.y;
this.pointX = point.pageX;
this.pointY = point.pageY;
this._execEvent('beforeScrollStart');
},
_move: function (e) {
if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) {
return;
}
if ( this.options.preventDefault ) { // increases performance on Android? TODO: check!
e.preventDefault();
}
var point = e.touches ? e.touches[0] : e,
deltaX = point.pageX - this.pointX,
deltaY = point.pageY - this.pointY,
timestamp = utils.getTime(),
newX, newY,
absDistX, absDistY;
this.pointX = point.pageX;
this.pointY = point.pageY;
this.distX += deltaX;
this.distY += deltaY;
absDistX = Math.abs(this.distX);
absDistY = Math.abs(this.distY);
// We need to move at least 10 pixels for the scrolling to initiate
if ( timestamp - this.endTime > 300 && (absDistX < 10 && absDistY < 10) ) {
return;
}
// If you are scrolling in one direction lock the other
if ( !this.directionLocked && !this.options.freeScroll ) {
if ( absDistX > absDistY + this.options.directionLockThreshold ) {
this.directionLocked = 'h'; // lock horizontally
} else if ( absDistY >= absDistX + this.options.directionLockThreshold ) {
this.directionLocked = 'v'; // lock vertically
} else {
this.directionLocked = 'n'; // no lock
}
}
if ( this.directionLocked == 'h' ) {
if ( this.options.eventPassthrough == 'vertical' ) {
e.preventDefault();
} else if ( this.options.eventPassthrough == 'horizontal' ) {
this.initiated = false;
return;
}
deltaY = 0;
} else if ( this.directionLocked == 'v' ) {
if ( this.options.eventPassthrough == 'horizontal' ) {
e.preventDefault();
} else if ( this.options.eventPassthrough == 'vertical' ) {
this.initiated = false;
return;
}
deltaX = 0;
}
deltaX = this.hasHorizontalScroll ? deltaX : 0;
deltaY = this.hasVerticalScroll ? deltaY : 0;
newX = this.x + deltaX;
newY = this.y + deltaY;
// Slow down if outside of the boundaries
if ( newX > 0 || newX < this.maxScrollX ) {
newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX;
}
if ( newY > 0 || newY < this.maxScrollY ) {
newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY;
}
this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
if ( !this.moved ) {
this._execEvent('scrollStart');
}
this.moved = true;
this._translate(newX, newY);
/* REPLACE START: _move */
if ( timestamp - this.startTime > 300 ) {
this.startTime = timestamp;
this.startX = this.x;
this.startY = this.y;
}
/* REPLACE END: _move */
},
_end: function (e) {
if ( !this.enabled || utils.eventType[e.type] !== this.initiated ) {
return;
}
if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
e.preventDefault();
}
var point = e.changedTouches ? e.changedTouches[0] : e,
momentumX,
momentumY,
duration = utils.getTime() - this.startTime,
newX = Math.round(this.x),
newY = Math.round(this.y),
distanceX = Math.abs(newX - this.startX),
distanceY = Math.abs(newY - this.startY),
time = 0,
easing = '';
this.isInTransition = 0;
this.initiated = 0;
this.endTime = utils.getTime();
// reset if we are outside of the boundaries
if ( this.resetPosition(this.options.bounceTime) ) {
return;
}
this.scrollTo(newX, newY); // ensures that the last position is rounded
// we scrolled less than 10 pixels
if ( !this.moved ) {
if ( this.options.tap ) {
utils.tap(e, this.options.tap);
}
if ( this.options.click ) {
utils.click(e);
}
this._execEvent('scrollCancel');
return;
}
if ( this._events.flick && duration < 200 && distanceX < 100 && distanceY < 100 ) {
this._execEvent('flick');
return;
}
// start momentum animation if needed
if ( this.options.momentum && duration < 300 ) {
momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : { destination: newX, duration: 0 };
momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : { destination: newY, duration: 0 };
newX = momentumX.destination;
newY = momentumY.destination;
time = Math.max(momentumX.duration, momentumY.duration);
this.isInTransition = 1;
}
if ( this.options.snap ) {
var snap = this._nearestSnap(newX, newY);
this.currentPage = snap;
time = this.options.snapSpeed || Math.max(
Math.max(
Math.min(Math.abs(newX - snap.x), 1000),
Math.min(Math.abs(newY - snap.y), 1000)
), 300);
newX = snap.x;
newY = snap.y;
this.directionX = 0;
this.directionY = 0;
easing = this.options.bounceEasing;
}
// INSERT POINT: _end
if ( newX != this.x || newY != this.y ) {
// change easing function when scroller goes out of the boundaries
if ( newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY ) {
easing = utils.ease.quadratic;
}
this.scrollTo(newX, newY, time, easing);
return;
}
this._execEvent('scrollEnd');
},
_resize: function () {
var that = this;
clearTimeout(this.resizeTimeout);
this.resizeTimeout = setTimeout(function () {
that.refresh();
}, this.options.resizePolling);
},
resetPosition: function (time) {
var x = this.x,
y = this.y;
time = time || 0;
if ( !this.hasHorizontalScroll || this.x > 0 ) {
x = 0;
} else if ( this.x < this.maxScrollX ) {
x = this.maxScrollX;
}
if ( !this.hasVerticalScroll || this.y > 0 ) {
y = 0;
} else if ( this.y < this.maxScrollY ) {
y = this.maxScrollY;
}
if ( x == this.x && y == this.y ) {
return false;
}
this.scrollTo(x, y, time, this.options.bounceEasing);
return true;
},
disable: function () {
this.enabled = false;
},
enable: function () {
this.enabled = true;
},
refresh: function () {
var rf = this.wrapper.offsetHeight; // Force reflow
this.wrapperWidth = this.wrapper.clientWidth;
this.wrapperHeight = this.wrapper.clientHeight;
/* REPLACE START: refresh */
this.scrollerWidth = this.scroller.offsetWidth;
this.scrollerHeight = this.scroller.offsetHeight;
this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
this.maxScrollY = this.wrapperHeight - this.scrollerHeight;
/* REPLACE END: refresh */
this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0;
this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0;
if ( !this.hasHorizontalScroll ) {
this.maxScrollX = 0;
this.scrollerWidth = this.wrapperWidth;
}
if ( !this.hasVerticalScroll ) {
this.maxScrollY = 0;
this.scrollerHeight = this.wrapperHeight;
}
this.endTime = 0;
this.directionX = 0;
this.directionY = 0;
this.wrapperOffset = utils.offset(this.wrapper);
this._execEvent('refresh');
this.resetPosition();
// INSERT POINT: _refresh
},
on: function (type, fn) {
if ( !this._events[type] ) {
this._events[type] = [];
}
this._events[type].push(fn);
},
off: function (type, fn) {
if ( !this._events[type] ) {
return;
}
var index = this._events[type].indexOf(fn);
if ( index > -1 ) {
this._events[type].splice(index, 1);
}
},
_execEvent: function (type) {
if ( !this._events[type] ) {
return;
}
var i = 0,
l = this._events[type].length;
if ( !l ) {
return;
}
for ( ; i < l; i++ ) {
this._events[type][i].apply(this, [].slice.call(arguments, 1));
}
},
scrollBy: function (x, y, time, easing) {
x = this.x + x;
y = this.y + y;
time = time || 0;
this.scrollTo(x, y, time, easing);
},
scrollTo: function (x, y, time, easing) {
easing = easing || utils.ease.circular;
this.isInTransition = this.options.useTransition && time > 0;
var transitionType = this.options.useTransition && easing.style;
if ( !time || transitionType ) {
if(transitionType) {
this._transitionTimingFunction(easing.style);
this._transitionTime(time);
}
this._translate(x, y);
} else {
this._animate(x, y, time, easing.fn);
}
},
scrollToElement: function (el, time, offsetX, offsetY, easing) {
el = el.nodeType ? el : this.scroller.querySelector(el);
if ( !el ) {
return;
}
var pos = utils.offset(el);
pos.left -= this.wrapperOffset.left;
pos.top -= this.wrapperOffset.top;
// if offsetX/Y are true we center the element to the screen
if ( offsetX === true ) {
offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2);
}
if ( offsetY === true ) {
offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2);
}
pos.left -= offsetX || 0;
pos.top -= offsetY || 0;
pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left;
pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top;
time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time;
this.scrollTo(pos.left, pos.top, time, easing);
},
_transitionTime: function (time) {
if (!this.options.useTransition) {
return;
}
time = time || 0;
var durationProp = utils.style.transitionDuration;
if(!durationProp) {
return;
}
this.scrollerStyle[durationProp] = time + 'ms';
if ( !time && utils.isBadAndroid ) {
this.scrollerStyle[durationProp] = '0.0001ms';
// remove 0.0001ms
var self = this;
rAF(function() {
if(self.scrollerStyle[durationProp] === '0.0001ms') {
self.scrollerStyle[durationProp] = '0s';
}
});
}
if ( this.indicators ) {
for ( var i = this.indicators.length; i--; ) {
this.indicators[i].transitionTime(time);
}
}
// INSERT POINT: _transitionTime
},
_transitionTimingFunction: function (easing) {
this.scrollerStyle[utils.style.transitionTimingFunction] = easing;
if ( this.indicators ) {
for ( var i = this.indicators.length; i--; ) {
this.indicators[i].transitionTimingFunction(easing);
}
}
// INSERT POINT: _transitionTimingFunction
},
_translate: function (x, y) {
//Uncode addition
if ( (" " + this.wrapper.className + " ").replace(/[\n\t]/g, " ").indexOf(" no-scrolloverflow ") > -1 )
return false;
if ( this.options.useTransform ) {
/* REPLACE START: _translate */
this.scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ;
/* REPLACE END: _translate */
} else {
x = Math.round(x);
y = Math.round(y);
this.scrollerStyle.left = x + 'px';
this.scrollerStyle.top = y + 'px';
}
this.x = x;
this.y = y;
if ( this.indicators ) {
for ( var i = this.indicators.length; i--; ) {
this.indicators[i].updatePosition();
}
}
//Uncode addition
var uncodevent = new CustomEvent('fp-slide-scroll');
window.dispatchEvent(uncodevent);
// INSERT POINT: _translate
},
_initEvents: function (remove) {
var eventType = remove ? utils.removeEvent : utils.addEvent,
target = this.options.bindToWrapper ? this.wrapper : window;
eventType(window, 'orientationchange', this);
eventType(window, 'resize', this);
if ( this.options.click ) {
eventType(this.wrapper, 'click', this, true);
}
if ( !this.options.disableMouse ) {
eventType(this.wrapper, 'mousedown', this);
eventType(target, 'mousemove', this);
eventType(target, 'mousecancel', this);
eventType(target, 'mouseup', this);
}
if ( utils.hasPointer && !this.options.disablePointer ) {
eventType(this.wrapper, utils.prefixPointerEvent('pointerdown'), this);
eventType(target, utils.prefixPointerEvent('pointermove'), this);
eventType(target, utils.prefixPointerEvent('pointercancel'), this);
eventType(target, utils.prefixPointerEvent('pointerup'), this);
}
if ( utils.hasTouch && !this.options.disableTouch ) {
eventType(this.wrapper, 'touchstart', this);
eventType(target, 'touchmove', this);
eventType(target, 'touchcancel', this);
eventType(target, 'touchend', this);
}
eventType(this.scroller, 'transitionend', this);
eventType(this.scroller, 'webkitTransitionEnd', this);
eventType(this.scroller, 'oTransitionEnd', this);
eventType(this.scroller, 'MSTransitionEnd', this);
},
getComputedPosition: function () {
var matrix = window.getComputedStyle(this.scroller, null),
x, y;
if ( this.options.useTransform ) {
matrix = matrix[utils.style.transform].split(')')[0].split(', ');
x = +(matrix[12] || matrix[4]);
y = +(matrix[13] || matrix[5]);
} else {
x = +matrix.left.replace(/[^-\d.]/g, '');
y = +matrix.top.replace(/[^-\d.]/g, '');
}
return { x: x, y: y };
},
_initIndicators: function () {
var interactive = this.options.interactiveScrollbars,
customStyle = typeof this.options.scrollbars != 'string',
indicators = [],
indicator;
var that = this;
this.indicators = [];
if ( this.options.scrollbars ) {
// Vertical scrollbar
if ( this.options.scrollY ) {
indicator = {
el: createDefaultScrollbar('v', interactive, this.options.scrollbars),
interactive: interactive,
defaultScrollbars: true,
customStyle: customStyle,
resize: this.options.resizeScrollbars,
shrink: this.options.shrinkScrollbars,
fade: this.options.fadeScrollbars,
listenX: false
};
this.wrapper.appendChild(indicator.el);
indicators.push(indicator);
}
// Horizontal scrollbar
if ( this.options.scrollX ) {
indicator = {
el: createDefaultScrollbar('h', interactive, this.options.scrollbars),
interactive: interactive,
defaultScrollbars: true,
customStyle: customStyle,
resize: this.options.resizeScrollbars,
shrink: this.options.shrinkScrollbars,
fade: this.options.fadeScrollbars,
listenY: false
};
this.wrapper.appendChild(indicator.el);
indicators.push(indicator);
}
}
if ( this.options.indicators ) {
// TODO: check concat compatibility
indicators = indicators.concat(this.options.indicators);
}
for ( var i = indicators.length; i--; ) {
this.indicators.push( new Indicator(this, indicators[i]) );
}
// TODO: check if we can use array.map (wide compatibility and performance issues)
function _indicatorsMap (fn) {
if (that.indicators) {
for ( var i = that.indicators.length; i--; ) {
fn.call(that.indicators[i]);
}
}
}
if ( this.options.fadeScrollbars ) {
this.on('scrollEnd', function () {
_indicatorsMap(function () {
this.fade();
});
});
this.on('scrollCancel', function () {
_indicatorsMap(function () {
this.fade();
});
});
this.on('scrollStart', function () {
_indicatorsMap(function () {
this.fade(1);
});
});
this.on('beforeScrollStart', function () {
_indicatorsMap(function () {
this.fade(1, true);
});
});
}
this.on('refresh', function () {
_indicatorsMap(function () {
this.refresh();
});
});
this.on('destroy', function () {
_indicatorsMap(function () {
this.destroy();
});
delete this.indicators;
});
},
_initWheel: function () {
utils.addEvent(this.wrapper, 'wheel', this);
utils.addEvent(this.wrapper, 'mousewheel', this);
utils.addEvent(this.wrapper, 'DOMMouseScroll', this);
this.on('destroy', function () {
clearTimeout(this.wheelTimeout);
this.wheelTimeout = null;
utils.removeEvent(this.wrapper, 'wheel', this);
utils.removeEvent(this.wrapper, 'mousewheel', this);
utils.removeEvent(this.wrapper, 'DOMMouseScroll', this);
});
},
_wheel: function (e) {
if ( !this.enabled ) {
return;
}
var wheelDeltaX, wheelDeltaY,
newX, newY,
that = this;
if ( this.wheelTimeout === undefined ) {
that._execEvent('scrollStart');
}
// Execute the scrollEnd event after 400ms the wheel stopped scrolling
clearTimeout(this.wheelTimeout);
this.wheelTimeout = setTimeout(function () {
if(!that.options.snap) {
that._execEvent('scrollEnd');
}
that.wheelTimeout = undefined;
}, 400);
if ( 'deltaX' in e ) {
if (e.deltaMode === 1) {
wheelDeltaX = -e.deltaX * this.options.mouseWheelSpeed;
wheelDeltaY = -e.deltaY * this.options.mouseWheelSpeed;
} else {
wheelDeltaX = -e.deltaX;
wheelDeltaY = -e.deltaY;
}
} else if ( 'wheelDeltaX' in e ) {
wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed;
wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed;
} else if ( 'wheelDelta' in e ) {
wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed;
} else if ( 'detail' in e ) {
wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed;
} else {
return;
}
wheelDeltaX *= this.options.invertWheelDirection;
wheelDeltaY *= this.options.invertWheelDirection;
if ( !this.hasVerticalScroll ) {
wheelDeltaX = wheelDeltaY;
wheelDeltaY = 0;
}
if ( this.options.snap ) {
newX = this.currentPage.pageX;
newY = this.currentPage.pageY;
if ( wheelDeltaX > 0 ) {
newX--;
} else if ( wheelDeltaX < 0 ) {
newX++;
}
if ( wheelDeltaY > 0 ) {
newY--;
} else if ( wheelDeltaY < 0 ) {
newY++;
}
this.goToPage(newX, newY);
return;
}
newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0);
newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0);
this.directionX = wheelDeltaX > 0 ? -1 : wheelDeltaX < 0 ? 1 : 0;
this.directionY = wheelDeltaY > 0 ? -1 : wheelDeltaY < 0 ? 1 : 0;
if ( newX > 0 ) {
newX = 0;
} else if ( newX < this.maxScrollX ) {
newX = this.maxScrollX;
}
if ( newY > 0 ) {
newY = 0;
} else if ( newY < this.maxScrollY ) {
newY = this.maxScrollY;
}
this.scrollTo(newX, newY, 0);
// INSERT POINT: _wheel
},
_initSnap: function () {
this.currentPage = {};
if ( typeof this.options.snap == 'string' ) {
this.options.snap = this.scroller.querySelectorAll(this.options.snap);
}
this.on('refresh', function () {
var i = 0, l,
m = 0, n,
cx, cy,
x = 0, y,
stepX = this.options.snapStepX || this.wrapperWidth,
stepY = this.options.snapStepY || this.wrapperHeight,
el;
this.pages = [];
if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) {
return;
}
if ( this.options.snap === true ) {
cx = Math.round( stepX / 2 );
cy = Math.round( stepY / 2 );
while ( x > -this.scrollerWidth ) {
this.pages[i] = [];
l = 0;
y = 0;
while ( y > -this.scrollerHeight ) {
this.pages[i][l] = {
x: Math.max(x, this.maxScrollX),
y: Math.max(y, this.maxScrollY),
width: stepX,
height: stepY,
cx: x - cx,
cy: y - cy
};
y -= stepY;
l++;
}
x -= stepX;
i++;
}
} else {
el = this.options.snap;
l = el.length;
n = -1;
for ( ; i < l; i++ ) {
if ( i === 0 || el[i].offsetLeft <= el[i-1].offsetLeft ) {
m = 0;
n++;
}
if ( !this.pages[m] ) {
this.pages[m] = [];
}
x = Math.max(-el[i].offsetLeft, this.maxScrollX);
y = Math.max(-el[i].offsetTop, this.maxScrollY);
cx = x - Math.round(el[i].offsetWidth / 2);
cy = y - Math.round(el[i].offsetHeight / 2);
this.pages[m][n] = {
x: x,
y: y,
width: el[i].offsetWidth,
height: el[i].offsetHeight,
cx: cx,
cy: cy
};
if ( x > this.maxScrollX ) {
m++;
}
}
}
this.goToPage(this.currentPage.pageX || 0, this.currentPage.pageY || 0, 0);
// Update snap threshold if needed
if ( this.options.snapThreshold % 1 === 0 ) {
this.snapThresholdX = this.options.snapThreshold;
this.snapThresholdY = this.options.snapThreshold;
} else {
this.snapThresholdX = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].width * this.options.snapThreshold);
this.snapThresholdY = Math.round(this.pages[this.currentPage.pageX][this.currentPage.pageY].height * this.options.snapThreshold);
}
});
this.on('flick', function () {
var time = this.options.snapSpeed || Math.max(
Math.max(
Math.min(Math.abs(this.x - this.startX), 1000),
Math.min(Math.abs(this.y - this.startY), 1000)
), 300);
this.goToPage(
this.currentPage.pageX + this.directionX,
this.currentPage.pageY + this.directionY,
time
);
});
},
_nearestSnap: function (x, y) {
if ( !this.pages.length ) {
return { x: 0, y: 0, pageX: 0, pageY: 0 };
}
var i = 0,
l = this.pages.length,
m = 0;
// Check if we exceeded the snap threshold
if ( Math.abs(x - this.absStartX) < this.snapThresholdX &&
Math.abs(y - this.absStartY) < this.snapThresholdY ) {
return this.currentPage;
}
if ( x > 0 ) {
x = 0;
} else if ( x < this.maxScrollX ) {
x = this.maxScrollX;
}
if ( y > 0 ) {
y = 0;
} else if ( y < this.maxScrollY ) {
y = this.maxScrollY;
}
for ( ; i < l; i++ ) {
if ( x >= this.pages[i][0].cx ) {
x = this.pages[i][0].x;
break;
}
}
l = this.pages[i].length;
for ( ; m < l; m++ ) {
if ( y >= this.pages[0][m].cy ) {
y = this.pages[0][m].y;
break;
}
}
if ( i == this.currentPage.pageX ) {
i += this.directionX;
if ( i < 0 ) {
i = 0;
} else if ( i >= this.pages.length ) {
i = this.pages.length - 1;
}
x = this.pages[i][0].x;
}
if ( m == this.currentPage.pageY ) {
m += this.directionY;
if ( m < 0 ) {
m = 0;
} else if ( m >= this.pages[0].length ) {
m = this.pages[0].length - 1;
}
y = this.pages[0][m].y;
}
return {
x: x,
y: y,
pageX: i,
pageY: m
};
},
goToPage: function (x, y, time, easing) {
easing = easing || this.options.bounceEasing;
if ( x >= this.pages.length ) {
x = this.pages.length - 1;
} else if ( x < 0 ) {
x = 0;
}
if ( y >= this.pages[x].length ) {
y = this.pages[x].length - 1;
} else if ( y < 0 ) {
y = 0;
}
var posX = this.pages[x][y].x,
posY = this.pages[x][y].y;
time = time === undefined ? this.options.snapSpeed || Math.max(
Math.max(
Math.min(Math.abs(posX - this.x), 1000),
Math.min(Math.abs(posY - this.y), 1000)
), 300) : time;
this.currentPage = {
x: posX,
y: posY,
pageX: x,
pageY: y
};
this.scrollTo(posX, posY, time, easing);
},
next: function (time, easing) {
var x = this.currentPage.pageX,
y = this.currentPage.pageY;
x++;
if ( x >= this.pages.length && this.hasVerticalScroll ) {
x = 0;
y++;
}
this.goToPage(x, y, time, easing);
},
prev: function (time, easing) {
var x = this.currentPage.pageX,
y = this.currentPage.pageY;
x--;
if ( x < 0 && this.hasVerticalScroll ) {
x = 0;
y--;
}
this.goToPage(x, y, time, easing);
},
_initKeys: function (e) {
// default key bindings
var keys = {
pageUp: 33,
pageDown: 34,
end: 35,
home: 36,
left: 37,
up: 38,
right: 39,
down: 40
};
var i;
// if you give me characters I give you keycode
if ( typeof this.options.keyBindings == 'object' ) {
for ( i in this.options.keyBindings ) {
if ( typeof this.options.keyBindings[i] == 'string' ) {
this.options.keyBindings[i] = this.options.keyBindings[i].toUpperCase().charCodeAt(0);
}
}
} else {
this.options.keyBindings = {};
}
for ( i in keys ) {
this.options.keyBindings[i] = this.options.keyBindings[i] || keys[i];
}
utils.addEvent(window, 'keydown', this);
this.on('destroy', function () {
utils.removeEvent(window, 'keydown', this);
});
},
_key: function (e) {
if ( !this.enabled ) {
return;
}
var snap = this.options.snap, // we are using this alot, better to cache it
newX = snap ? this.currentPage.pageX : this.x,
newY = snap ? this.currentPage.pageY : this.y,
now = utils.getTime(),
prevTime = this.keyTime || 0,
acceleration = 0.250,
pos;
if ( this.options.useTransition && this.isInTransition ) {
pos = this.getComputedPosition();
this._translate(Math.round(pos.x), Math.round(pos.y));
this.isInTransition = false;
}
this.keyAcceleration = now - prevTime < 200 ? Math.min(this.keyAcceleration + acceleration, 50) : 0;
switch ( e.keyCode ) {
case this.options.keyBindings.pageUp:
if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) {
newX += snap ? 1 : this.wrapperWidth;
} else {
newY += snap ? 1 : this.wrapperHeight;
}
break;
case this.options.keyBindings.pageDown:
if ( this.hasHorizontalScroll && !this.hasVerticalScroll ) {
newX -= snap ? 1 : this.wrapperWidth;
} else {
newY -= snap ? 1 : this.wrapperHeight;
}
break;
case this.options.keyBindings.end:
newX = snap ? this.pages.length-1 : this.maxScrollX;
newY = snap ? this.pages[0].length-1 : this.maxScrollY;
break;
case this.options.keyBindings.home:
newX = 0;
newY = 0;
break;
case this.options.keyBindings.left:
newX += snap ? -1 : 5 + this.keyAcceleration>>0;
break;
case this.options.keyBindings.up:
newY += snap ? 1 : 5 + this.keyAcceleration>>0;
break;
case this.options.keyBindings.right:
newX -= snap ? -1 : 5 + this.keyAcceleration>>0;
break;
case this.options.keyBindings.down:
newY -= snap ? 1 : 5 + this.keyAcceleration>>0;
break;
default:
return;
}
if ( snap ) {
this.goToPage(newX, newY);
return;
}
if ( newX > 0 ) {
newX = 0;
this.keyAcceleration = 0;
} else if ( newX < this.maxScrollX ) {
newX = this.maxScrollX;
this.keyAcceleration = 0;
}
if ( newY > 0 ) {
newY = 0;
this.keyAcceleration = 0;
} else if ( newY < this.maxScrollY ) {
newY = this.maxScrollY;
this.keyAcceleration = 0;
}
this.scrollTo(newX, newY, 0);
this.keyTime = now;
},
_animate: function (destX, destY, duration, easingFn) {
var that = this,
startX = this.x,
startY = this.y,
startTime = utils.getTime(),
destTime = startTime + duration;
function step () {
var now = utils.getTime(),
newX, newY,
easing;
if ( now >= destTime ) {
that.isAnimating = false;
that._translate(destX, destY);
if ( !that.resetPosition(that.options.bounceTime) ) {
that._execEvent('scrollEnd');
}
return;
}
now = ( now - startTime ) / duration;
easing = easingFn(now);
newX = ( destX - startX ) * easing + startX;
newY = ( destY - startY ) * easing + startY;
that._translate(newX, newY);
if ( that.isAnimating ) {
rAF(step);
}
}
this.isAnimating = true;
step();
},
handleEvent: function (e) {
switch ( e.type ) {
case 'touchstart':
case 'pointerdown':
case 'MSPointerDown':
case 'mousedown':
this._start(e);
break;
case 'touchmove':
case 'pointermove':
case 'MSPointerMove':
case 'mousemove':
this._move(e);
break;
case 'touchend':
case 'pointerup':
case 'MSPointerUp':
case 'mouseup':
case 'touchcancel':
case 'pointercancel':
case 'MSPointerCancel':
case 'mousecancel':
this._end(e);
break;
case 'orientationchange':
case 'resize':
this._resize();
break;
case 'transitionend':
case 'webkitTransitionEnd':
case 'oTransitionEnd':
case 'MSTransitionEnd':
this._transitionEnd(e);
break;
case 'wheel':
case 'DOMMouseScroll':
case 'mousewheel':
this._wheel(e);
break;
case 'keydown':
this._key(e);
break;
case 'click':
if ( this.enabled && !e._constructed ) {
e.preventDefault();
e.stopPropagation();
}
break;
}
}
};
function createDefaultScrollbar (direction, interactive, type) {
var scrollbar = document.createElement('div'),
indicator = document.createElement('div');
if ( type === true ) {
scrollbar.style.cssText = 'position:absolute;z-index:9999';
indicator.style.cssText = '-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:absolute;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);border-radius:3px';
}
indicator.className = 'iScrollIndicator';
if ( direction == 'h' ) {
if ( type === true ) {
scrollbar.style.cssText += ';height:7px;left:2px;right:2px;bottom:0';
indicator.style.height = '100%';
}
scrollbar.className = 'iScrollHorizontalScrollbar';
} else {
if ( type === true ) {
scrollbar.style.cssText += ';width:7px;bottom:2px;top:2px;right:1px';
indicator.style.width = '100%';
}
scrollbar.className = 'iScrollVerticalScrollbar';
}
scrollbar.style.cssText += ';overflow:hidden';
if ( !interactive ) {
scrollbar.style.pointerEvents = 'none';
}
scrollbar.appendChild(indicator);
return scrollbar;
}
function Indicator (scroller, options) {
this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el;
this.wrapperStyle = this.wrapper.style;
this.indicator = this.wrapper.children[0];
this.indicatorStyle = this.indicator.style;
this.scroller = scroller;
this.options = {
listenX: true,
listenY: true,
interactive: false,
resize: true,
defaultScrollbars: false,
shrink: false,
fade: false,
speedRatioX: 0,
speedRatioY: 0
};
for ( var i in options ) {
this.options[i] = options[i];
}
this.sizeRatioX = 1;
this.sizeRatioY = 1;
this.maxPosX = 0;
this.maxPosY = 0;
if ( this.options.interactive ) {
if ( !this.options.disableTouch ) {
utils.addEvent(this.indicator, 'touchstart', this);
utils.addEvent(window, 'touchend', this);
}
if ( !this.options.disablePointer ) {
utils.addEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
utils.addEvent(window, utils.prefixPointerEvent('pointerup'), this);
}
if ( !this.options.disableMouse ) {
utils.addEvent(this.indicator, 'mousedown', this);
utils.addEvent(window, 'mouseup', this);
}
}
if ( this.options.fade ) {
this.wrapperStyle[utils.style.transform] = this.scroller.translateZ;
var durationProp = utils.style.transitionDuration;
if(!durationProp) {
return;
}
this.wrapperStyle[durationProp] = utils.isBadAndroid ? '0.0001ms' : '0ms';
// remove 0.0001ms
var self = this;
if(utils.isBadAndroid) {
rAF(function() {
if(self.wrapperStyle[durationProp] === '0.0001ms') {
self.wrapperStyle[durationProp] = '0s';
}
});
}
this.wrapperStyle.opacity = '0';
}
}
Indicator.prototype = {
handleEvent: function (e) {
switch ( e.type ) {
case 'touchstart':
case 'pointerdown':
case 'MSPointerDown':
case 'mousedown':
this._start(e);
break;
case 'touchmove':
case 'pointermove':
case 'MSPointerMove':
case 'mousemove':
this._move(e);
break;
case 'touchend':
case 'pointerup':
case 'MSPointerUp':
case 'mouseup':
case 'touchcancel':
case 'pointercancel':
case 'MSPointerCancel':
case 'mousecancel':
this._end(e);
break;
}
},
destroy: function () {
if ( this.options.fadeScrollbars ) {
clearTimeout(this.fadeTimeout);
this.fadeTimeout = null;
}
if ( this.options.interactive ) {
utils.removeEvent(this.indicator, 'touchstart', this);
utils.removeEvent(this.indicator, utils.prefixPointerEvent('pointerdown'), this);
utils.removeEvent(this.indicator, 'mousedown', this);
utils.removeEvent(window, 'touchmove', this);
utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this);
utils.removeEvent(window, 'mousemove', this);
utils.removeEvent(window, 'touchend', this);
utils.removeEvent(window, utils.prefixPointerEvent('pointerup'), this);
utils.removeEvent(window, 'mouseup', this);
}
if ( this.options.defaultScrollbars ) {
this.wrapper.parentNode.removeChild(this.wrapper);
}
},
_start: function (e) {
var point = e.touches ? e.touches[0] : e;
e.preventDefault();
e.stopPropagation();
this.transitionTime();
this.initiated = true;
this.moved = false;
this.lastPointX = point.pageX;
this.lastPointY = point.pageY;
this.startTime = utils.getTime();
if ( !this.options.disableTouch ) {
utils.addEvent(window, 'touchmove', this);
}
if ( !this.options.disablePointer ) {
utils.addEvent(window, utils.prefixPointerEvent('pointermove'), this);
}
if ( !this.options.disableMouse ) {
utils.addEvent(window, 'mousemove', this);
}
this.scroller._execEvent('beforeScrollStart');
},
_move: function (e) {
var point = e.touches ? e.touches[0] : e,
deltaX, deltaY,
newX, newY,
timestamp = utils.getTime();
if ( !this.moved ) {
this.scroller._execEvent('scrollStart');
}
this.moved = true;
deltaX = point.pageX - this.lastPointX;
this.lastPointX = point.pageX;
deltaY = point.pageY - this.lastPointY;
this.lastPointY = point.pageY;
newX = this.x + deltaX;
newY = this.y + deltaY;
this._pos(newX, newY);
// INSERT POINT: indicator._move
e.preventDefault();
e.stopPropagation();
},
_end: function (e) {
if ( !this.initiated ) {
return;
}
this.initiated = false;
e.preventDefault();
e.stopPropagation();
utils.removeEvent(window, 'touchmove', this);
utils.removeEvent(window, utils.prefixPointerEvent('pointermove'), this);
utils.removeEvent(window, 'mousemove', this);
if ( this.scroller.options.snap ) {
var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y);
var time = this.options.snapSpeed || Math.max(
Math.max(
Math.min(Math.abs(this.scroller.x - snap.x), 1000),
Math.min(Math.abs(this.scroller.y - snap.y), 1000)
), 300);
if ( this.scroller.x != snap.x || this.scroller.y != snap.y ) {
this.scroller.directionX = 0;
this.scroller.directionY = 0;
this.scroller.currentPage = snap;
this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing);
}
}
if ( this.moved ) {
this.scroller._execEvent('scrollEnd');
}
},
transitionTime: function (time) {
time = time || 0;
var durationProp = utils.style.transitionDuration;
if(!durationProp) {
return;
}
this.indicatorStyle[durationProp] = time + 'ms';
if ( !time && utils.isBadAndroid ) {
this.indicatorStyle[durationProp] = '0.0001ms';
// remove 0.0001ms
var self = this;
rAF(function() {
if(self.indicatorStyle[durationProp] === '0.0001ms') {
self.indicatorStyle[durationProp] = '0s';
}
});
}
},
transitionTimingFunction: function (easing) {
this.indicatorStyle[utils.style.transitionTimingFunction] = easing;
},
refresh: function () {
this.transitionTime();
if ( this.options.listenX && !this.options.listenY ) {
this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none';
} else if ( this.options.listenY && !this.options.listenX ) {
this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none';
} else {
this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none';
}
if ( this.scroller.hasHorizontalScroll && this.scroller.hasVerticalScroll ) {
utils.addClass(this.wrapper, 'iScrollBothScrollbars');
utils.removeClass(this.wrapper, 'iScrollLoneScrollbar');
if ( this.options.defaultScrollbars && this.options.customStyle ) {
if ( this.options.listenX ) {
this.wrapper.style.right = '8px';
} else {
this.wrapper.style.bottom = '8px';
}
}
} else {
utils.removeClass(this.wrapper, 'iScrollBothScrollbars');
utils.addClass(this.wrapper, 'iScrollLoneScrollbar');
if ( this.options.defaultScrollbars && this.options.customStyle ) {
if ( this.options.listenX ) {
this.wrapper.style.right = '2px';
} else {
this.wrapper.style.bottom = '2px';
}
}
}
var r = this.wrapper.offsetHeight; // force refresh
if ( this.options.listenX ) {
this.wrapperWidth = this.wrapper.clientWidth;
if ( this.options.resize ) {
this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
this.indicatorStyle.width = this.indicatorWidth + 'px';
} else {
this.indicatorWidth = this.indicator.clientWidth;
}
this.maxPosX = this.wrapperWidth - this.indicatorWidth;
if ( this.options.shrink == 'clip' ) {
this.minBoundaryX = -this.indicatorWidth + 8;
this.maxBoundaryX = this.wrapperWidth - 8;
} else {
this.minBoundaryX = 0;
this.maxBoundaryX = this.maxPosX;
}
this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX));
}
if ( this.options.listenY ) {
this.wrapperHeight = this.wrapper.clientHeight;
if ( this.options.resize ) {
this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8);
this.indicatorStyle.height = this.indicatorHeight + 'px';
} else {
this.indicatorHeight = this.indicator.clientHeight;
}
this.maxPosY = this.wrapperHeight - this.indicatorHeight;
if ( this.options.shrink == 'clip' ) {
this.minBoundaryY = -this.indicatorHeight + 8;
this.maxBoundaryY = this.wrapperHeight - 8;
} else {
this.minBoundaryY = 0;
this.maxBoundaryY = this.maxPosY;
}
this.maxPosY = this.wrapperHeight - this.indicatorHeight;
this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY));
}
this.updatePosition();
},
updatePosition: function () {
var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0,
y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0;
if ( !this.options.ignoreBoundaries ) {
if ( x < this.minBoundaryX ) {
if ( this.options.shrink == 'scale' ) {
this.width = Math.max(this.indicatorWidth + x, 8);
this.indicatorStyle.width = this.width + 'px';
}
x = this.minBoundaryX;
} else if ( x > this.maxBoundaryX ) {
if ( this.options.shrink == 'scale' ) {
this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8);
this.indicatorStyle.width = this.width + 'px';
x = this.maxPosX + this.indicatorWidth - this.width;
} else {
x = this.maxBoundaryX;
}
} else if ( this.options.shrink == 'scale' && this.width != this.indicatorWidth ) {
this.width = this.indicatorWidth;
this.indicatorStyle.width = this.width + 'px';
}
if ( y < this.minBoundaryY ) {
if ( this.options.shrink == 'scale' ) {
this.height = Math.max(this.indicatorHeight + y * 3, 8);
this.indicatorStyle.height = this.height + 'px';
}
y = this.minBoundaryY;
} else if ( y > this.maxBoundaryY ) {
if ( this.options.shrink == 'scale' ) {
this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8);
this.indicatorStyle.height = this.height + 'px';
y = this.maxPosY + this.indicatorHeight - this.height;
} else {
y = this.maxBoundaryY;
}
} else if ( this.options.shrink == 'scale' && this.height != this.indicatorHeight ) {
this.height = this.indicatorHeight;
this.indicatorStyle.height = this.height + 'px';
}
}
this.x = x;
this.y = y;
if ( this.scroller.options.useTransform ) {
this.indicatorStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.scroller.translateZ;
} else {
this.indicatorStyle.left = x + 'px';
this.indicatorStyle.top = y + 'px';
}
},
_pos: function (x, y) {
if ( x < 0 ) {
x = 0;
} else if ( x > this.maxPosX ) {
x = this.maxPosX;
}
if ( y < 0 ) {
y = 0;
} else if ( y > this.maxPosY ) {
y = this.maxPosY;
}
x = this.options.listenX ? Math.round(x / this.sizeRatioX) : this.scroller.x;
y = this.options.listenY ? Math.round(y / this.sizeRatioY) : this.scroller.y;
this.scroller.scrollTo(x, y);
},
fade: function (val, hold) {
if ( hold && !this.visible ) {
return;
}
clearTimeout(this.fadeTimeout);
this.fadeTimeout = null;
var time = val ? 250 : 500,
delay = val ? 0 : 300;
val = val ? '1' : '0';
this.wrapperStyle[utils.style.transitionDuration] = time + 'ms';
this.fadeTimeout = setTimeout((function (val) {
this.wrapperStyle.opacity = val;
this.visible = +val;
}).bind(this, val), delay);
}
};
IScroll.utils = utils;
if ( typeof module != 'undefined' && module.exports ) {
module.exports = IScroll;
} else if ( typeof define == 'function' && define.amd ) {
define( function () { return IScroll; } );
} else {
window.IScroll = IScroll;
}
})(window, document, Math);
/*!
* fullPage 2.9.4
* https://github.com/alvarotrigo/fullPage.js
* @license MIT licensed
*
* Copyright (C) 2015 alvarotrigo.com - A project by Alvaro Trigo
*/
(function(global, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define(['jquery'], function($) {
return factory($, global, global.document, global.Math);
});
} else if (typeof exports === "object" && exports) {
module.exports = factory(require('jquery'), global, global.document, global.Math);
} else {
factory(jQuery, global, global.document, global.Math);
}
})(typeof window !== 'undefined' ? window : this, function($, window, document, Math, undefined) {
'use strict';
// keeping central set of classnames and selectors
var WRAPPER = 'fullpage-wrapper';
var WRAPPER_SEL = '.' + WRAPPER;
// slimscroll
var SCROLLABLE = 'fp-scrollable';
var SCROLLABLE_SEL = '.' + SCROLLABLE;
// util
var RESPONSIVE = 'fp-responsive';
var NO_TRANSITION = 'fp-notransition';
var DESTROYED = 'fp-destroyed';
var ENABLED = 'fp-enabled';
var VIEWING_PREFIX = 'fp-viewing';
var ACTIVE = 'active';
var ACTIVE_SEL = '.' + ACTIVE;
var COMPLETELY = 'fp-completely';
var COMPLETELY_SEL = '.' + COMPLETELY;
// section
var SECTION_DEFAULT_SEL = '.section';
var SECTION = 'fp-section';
var SECTION_SEL = '.' + SECTION;
var SECTION_ACTIVE_SEL = SECTION_SEL + ACTIVE_SEL;
var SECTION_FIRST_SEL = SECTION_SEL + ':first';
var SECTION_LAST_SEL = SECTION_SEL + ':last';
var TABLE_CELL = 'fp-tableCell';
var TABLE_CELL_SEL = '.' + TABLE_CELL;
var AUTO_HEIGHT = 'fp-auto-height';
var AUTO_HEIGHT_SEL = '.fp-auto-height';
var NORMAL_SCROLL = 'fp-normal-scroll';
var NORMAL_SCROLL_SEL = '.fp-normal-scroll';
// section nav
var SECTION_NAV = 'fp-nav';
var SECTION_NAV_SEL = '#' + SECTION_NAV;
var SECTION_NAV_TOOLTIP = 'fp-tooltip';
var SECTION_NAV_TOOLTIP_SEL='.'+SECTION_NAV_TOOLTIP;
var SHOW_ACTIVE_TOOLTIP = 'fp-show-active';
// slide
var SLIDE_DEFAULT_SEL = '.slide';
var SLIDE = 'fp-slide';
var SLIDE_SEL = '.' + SLIDE;
var SLIDE_ACTIVE_SEL = SLIDE_SEL + ACTIVE_SEL;
var SLIDES_WRAPPER = 'fp-slides';
var SLIDES_WRAPPER_SEL = '.' + SLIDES_WRAPPER;
var SLIDES_CONTAINER = 'fp-slidesContainer';
var SLIDES_CONTAINER_SEL = '.' + SLIDES_CONTAINER;
var TABLE = 'fp-table';
// slide nav
var SLIDES_NAV = 'fp-slidesNav';
var SLIDES_NAV_SEL = '.' + SLIDES_NAV;
var SLIDES_NAV_LINK_SEL = SLIDES_NAV_SEL + ' a';
var SLIDES_ARROW = 'fp-controlArrow';
var SLIDES_ARROW_SEL = '.' + SLIDES_ARROW;
var SLIDES_PREV = 'fp-prev';
var SLIDES_PREV_SEL = '.' + SLIDES_PREV;
var SLIDES_ARROW_PREV = SLIDES_ARROW + ' ' + SLIDES_PREV;
var SLIDES_ARROW_PREV_SEL = SLIDES_ARROW_SEL + SLIDES_PREV_SEL;
var SLIDES_NEXT = 'fp-next';
var SLIDES_NEXT_SEL = '.' + SLIDES_NEXT;
var SLIDES_ARROW_NEXT = SLIDES_ARROW + ' ' + SLIDES_NEXT;
var SLIDES_ARROW_NEXT_SEL = SLIDES_ARROW_SEL + SLIDES_NEXT_SEL;
var $window = $(window);
var $document = $(document);
// Default options for iScroll.js used when using scrollOverflow
var iscrollOptions = {
scrollbars: true,
mouseWheel: true,
hideScrollbars: false,
fadeScrollbars: false,
disableMouse: true,
interactiveScrollbars: true,
bounce: false,
};
$.fn.fullpage = function(options) {
//only once my friend!
if($('html').hasClass(ENABLED)){ displayWarnings(); return; }
// common jQuery objects
var $htmlBody = $('html, body');
var $body = $('body');
var FP = $.fn.fullpage;
// Creating some defaults, extending them with any options that were provided
options = $.extend({
//navigation
menu: false,
anchors:[],
lockAnchors: false,
navigation: false,
navigationPosition: 'right',
navigationTooltips: [],
showActiveTooltip: false,
slidesNavigation: false,
slidesNavPosition: 'bottom',
scrollBar: false,
hybrid: false,
//scrolling
css3: true,
scrollingSpeed: 700,
autoScrolling: true,
fitToSection: true,
fitToSectionDelay: 1000,
easing: 'easeInOutCubic',
easingcss3: 'ease',
loopBottom: false,
loopTop: false,
loopHorizontal: true,
continuousVertical: false,
continuousHorizontal: false,
scrollHorizontally: false,
interlockedSlides: false,
dragAndMove: false,
offsetSections: false,
resetSliders: false,
fadingEffect: false,
normalScrollElements: null,
scrollOverflow: false,
scrollOverflowReset: false,
scrollOverflowHandler: iscrollHandler,
scrollOverflowOptions: null,
touchSensitivity: 5,
normalScrollElementTouchThreshold: 5,
bigSectionsDestination: null,
//Accessibility
keyboardScrolling: true,
animateAnchor: true,
recordHistory: true,
//design
controlArrows: true,
controlArrowColor: '#fff',
verticalCentered: true,
sectionsColor : [],
paddingTop: 0,
paddingBottom: 0,
fixedElements: null,
responsive: 0, //backwards compabitility with responsiveWiddth
responsiveWidth: 0,
responsiveHeight: 0,
responsiveSlides: false,
parallax: false,
parallaxOptions: {
type: 'reveal',
percentage: 62,
property: 'translate'
},
//Custom selectors
sectionSelector: SECTION_DEFAULT_SEL,
slideSelector: SLIDE_DEFAULT_SEL,
//events
afterLoad: null,
onLeave: null,
afterRender: null,
afterResize: null,
afterReBuild: null,
afterSlideLoad: null,
onSlideLeave: null,
afterResponsive: null,
lazyLoading: true
}, options);
//flag to avoid very fast sliding for landscape sliders
var slideMoving = false;
var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/);
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
var container = $(this);
var windowsHeight = $window.height();
var isResizing = false;
var isWindowFocused = true;
var lastScrolledDestiny;
var lastScrolledSlide;
var canScroll = true;
var scrollings = [];
var controlPressed;
var startingSection;
var isScrollAllowed = {};
isScrollAllowed.m = { 'up':true, 'down':true, 'left':true, 'right':true };
isScrollAllowed.k = $.extend(true,{}, isScrollAllowed.m);
var MSPointer = getMSPointer();
var events = {
touchmove: 'ontouchmove' in window ? 'touchmove' : MSPointer.move,
touchstart: 'ontouchstart' in window ? 'touchstart' : MSPointer.down
};
//cheks for passive event support
//added by Uncode from new fullPage updates
var g_supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
g_supportsPassive = true;
}
});
window.addEventListener("testPassive", null, opts);
window.removeEventListener("testPassive", null, opts);
} catch (e) {}
//timeouts
var resizeId;
var afterSectionLoadsId;
var afterSlideLoadsId;
var scrollId;
var scrollId2;
var keydownId;
var originals = $.extend(true, {}, options); //deep copy
//Uncode addition
var $masthead = $('#masthead');
var hideMenu = !$('body').hasClass('vmenu') && $('body').hasClass('uncode-fp-menu-hide') ? true : false;
var menuHeight = $masthead.hasClass('menu-transparent') || hideMenu ? 0 : UNCODE.menuHeight;
var bodyBorder = UNCODE.bodyBorder;
var adminBarHeight = UNCODE.adminBarHeight;
displayWarnings();
//fixing bug in iScroll with links: https://github.com/cubiq/iscroll/issues/783
iscrollOptions.click = isTouch; // see #2035
//extending iScroll options with the user custom ones
iscrollOptions = $.extend(iscrollOptions, options.scrollOverflowOptions);
//easeInOutCubic animation included in the plugin
$.extend($.easing,{ easeInOutCubic: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t*t + b;return c/2*((t-=2)*t*t + 2) + b;}});
/**
* Sets the autoScroll option.
* It changes the scroll bar visibility and the history of the site as a result.
*/
function setAutoScrolling(value, type){
//removing the transformation
if(!value){
silentScroll(0);
}
setVariableState('autoScrolling', value, type);
var element = $(SECTION_ACTIVE_SEL);
if(options.autoScrolling && !options.scrollBar){
$htmlBody.css({
'overflow' : 'hidden !important',
'height' : '100%'
});
//Uncode addition
//setRecordHistory(originals.recordHistory, 'internal');
//for IE touch devices
container.css({
'-ms-touch-action': 'none',
'touch-action': 'none'
});
if(element.length){
//moving the container up
silentScroll(element.position().top);
}
}else{
$htmlBody.css({
'overflow' : 'visible !important',
'height' : 'initial'
});
//Uncode addition
//setRecordHistory(false, 'internal');
//for IE touch devices
container.css({
'-ms-touch-action': '',
'touch-action': ''
});
//scrolling the page to the section with no animation
if (element.length) {
$htmlBody.scrollTop(element.position().top);
}
}
}
/**
* Defines wheter to record the history for each hash change in the URL.
*/
function setRecordHistory(value, type){
setVariableState('recordHistory', value, type);
}
/**
* Defines the scrolling speed
*/
function setScrollingSpeed(value, type){
setVariableState('scrollingSpeed', value, type);
}
/**
* Sets fitToSection
*/
function setFitToSection(value, type){
setVariableState('fitToSection', value, type);
}
/**
* Sets lockAnchors
*/
function setLockAnchors(value){
options.lockAnchors = value;
}
/**
* Adds or remove the possiblity of scrolling through sections by using the mouse wheel or the trackpad.
*/
function setMouseWheelScrolling(value){
if(value){
addMouseWheelHandler();
addMiddleWheelHandler();
}else{
removeMouseWheelHandler();
removeMiddleWheelHandler();
}
}
/**
* Adds or remove the possibility of scrolling through sections by using the mouse wheel/trackpad or touch gestures.
* Optionally a second parameter can be used to specify the direction for which the action will be applied.
*
* @param directions string containing the direction or directions separated by comma.
*/
function setAllowScrolling(value, directions){
if(typeof directions !== 'undefined'){
directions = directions.replace(/ /g,'').split(',');
$.each(directions, function (index, direction){
setIsScrollAllowed(value, direction, 'm');
});
}
else if(value){
setMouseWheelScrolling(true);
addTouchHandler();
}else{
setMouseWheelScrolling(false);
removeTouchHandler();
}
}
/**
* Adds or remove the possibility of scrolling through sections by using the keyboard arrow keys
*/
function setKeyboardScrolling(value, directions){
if(typeof directions !== 'undefined'){
directions = directions.replace(/ /g,'').split(',');
$.each(directions, function (index, direction){
setIsScrollAllowed(value, direction, 'k');
});
}else{
options.keyboardScrolling = value;
}
}
/**
* Moves the page up one section.
*/
function moveSectionUp(){
var prev = $(SECTION_ACTIVE_SEL).prev(SECTION_SEL);
//looping to the bottom if there's no more sections above
if (!prev.length && (options.loopTop || options.continuousVertical)) {
prev = $(SECTION_SEL).last();
}
if (prev.length) {
scrollPage(prev, null, true);
}
}
/**
* Moves the page down one section.
*/
function moveSectionDown(){
var next = $(SECTION_ACTIVE_SEL).next(SECTION_SEL);
//looping to the top if there's no more sections below
if(!next.length &&
(options.loopBottom || options.continuousVertical)){
next = $(SECTION_SEL).first();
}
if(next.length){
scrollPage(next, null, false);
}
}
/**
* Moves the page to the given section and slide with no animation.
* Anchors or index positions can be used as params.
*/
function silentMoveTo(sectionAnchor, slideAnchor){
setScrollingSpeed (0, 'internal');
moveTo(sectionAnchor, slideAnchor);
setScrollingSpeed (originals.scrollingSpeed, 'internal');
}
/**
* Moves the page to the given section and slide.
* Anchors or index positions can be used as params.
*/
function moveTo(sectionAnchor, slideAnchor){
var destiny = getSectionByAnchor(sectionAnchor);
if (typeof slideAnchor !== 'undefined'){
scrollPageAndSlide(sectionAnchor, slideAnchor);
}else if(destiny.length > 0){
scrollPage(destiny);
}
}
/**
* Slides right the slider of the active section.
* Optional `section` param.
*/
function moveSlideRight(section){
moveSlide('right', section);
}
/**
* Slides left the slider of the active section.
* Optional `section` param.
*/
function moveSlideLeft(section){
moveSlide('left', section);
}
/**
* When resizing is finished, we adjust the slides sizes and positions
*/
function reBuild(resizing){
if(container.hasClass(DESTROYED)){ return; } //nothing to do if the plugin was destroyed
isResizing = true;
windowsHeight = $window.height(); //updating global var
$(SECTION_SEL).each(function(){
var slidesWrap = $(this).find(SLIDES_WRAPPER_SEL);
var slides = $(this).find(SLIDE_SEL);
//adjusting the height of the table-cell for IE and Firefox
if(options.verticalCentered){
$(this).find(TABLE_CELL_SEL).css('height', getTableHeight($(this)) + 'px');
}
$(this).css('height', windowsHeight + 'px');
//resizing the scrolling divs
if(options.scrollOverflow){
if(slides.length){
slides.each(function(){
createScrollBar($(this));
});
}else{
createScrollBar($(this));
}
}
//adjusting the position fo the FULL WIDTH slides...
if (slides.length > 1) {
landscapeScroll(slidesWrap, slidesWrap.find(SLIDE_ACTIVE_SEL));
}
});
var activeSection = $(SECTION_ACTIVE_SEL);
var sectionIndex = activeSection.index(SECTION_SEL);
//isn't it the first section?
if(sectionIndex){
//adjusting the position for the current section
silentMoveTo(sectionIndex + 1);
}
isResizing = false;
$.isFunction( options.afterResize ) && resizing && options.afterResize.call(container);
$.isFunction( options.afterReBuild ) && !resizing && options.afterReBuild.call(container);
}
/**
* Turns fullPage.js to normal scrolling mode when the viewport `width` or `height`
* are smaller than the set limit values.
*/
function setResponsive(active){
var isResponsive = $body.hasClass(RESPONSIVE);
if(active){
if(!isResponsive){
setAutoScrolling(false, 'internal');
setFitToSection(false, 'internal');
$(SECTION_NAV_SEL).hide();
$body.addClass(RESPONSIVE);
$.isFunction( options.afterResponsive ) && options.afterResponsive.call( container, active);
}
}
else if(isResponsive){
setAutoScrolling(originals.autoScrolling, 'internal');
setFitToSection(originals.autoScrolling, 'internal');
$(SECTION_NAV_SEL).show();
$body.removeClass(RESPONSIVE);
$.isFunction( options.afterResponsive ) && options.afterResponsive.call( container, active);
}
}
if($(this).length){
//public functions
FP.setAutoScrolling = setAutoScrolling;
FP.setRecordHistory = setRecordHistory;
FP.setScrollingSpeed = setScrollingSpeed;
FP.setFitToSection = setFitToSection;
FP.setLockAnchors = setLockAnchors;
FP.setMouseWheelScrolling = setMouseWheelScrolling;
FP.setAllowScrolling = setAllowScrolling;
FP.setKeyboardScrolling = setKeyboardScrolling;
FP.moveSectionUp = moveSectionUp;
FP.moveSectionDown = moveSectionDown;
FP.silentMoveTo = silentMoveTo;
FP.moveTo = moveTo;
FP.moveSlideRight = moveSlideRight;
FP.moveSlideLeft = moveSlideLeft;
FP.fitToSection = fitToSection;
FP.reBuild = reBuild;
FP.setResponsive = setResponsive;
FP.destroy = destroy;
init();
bindEvents();
}
function init(){
//if css3 is not supported, it will use jQuery animations
if(options.css3){
options.css3 = support3d();
}
options.scrollBar = options.scrollBar || options.hybrid;
setOptionsFromDOM();
prepareDom();
setAllowScrolling(true);
setAutoScrolling(options.autoScrolling, 'internal');
responsive();
//setting the class for the body element
setBodyClass();
//Uncode addition
// if(document.readyState === 'complete'){
// scrollToAnchor();
// }
// $window.on('load', scrollToAnchor);
}
function bindEvents(){
$window
//when scrolling...
//.on('scroll', scrollHandler)
//detecting any change on the URL to scroll to the given anchor link
//(a way to detect back history button as we play with the hashes on the URL)
.on('hashchange', hashChangeHandler)
//when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
.blur(blurHandler)
//when resizing the site, we adjust the heights of the sections, slimScroll...
.resize(resizeHandler);
$document
//Sliding with arrow keys, both, vertical and horizontal
.keydown(keydownHandler)
//to prevent scrolling while zooming
.keyup(keyUpHandler)
//Scrolls to the section when clicking the navigation bullet
.on('click touchstart', SECTION_NAV_SEL + ' a', sectionBulletHandler)
//Scrolls the slider to the given slide destination for the given section
.on('click touchstart', SLIDES_NAV_LINK_SEL, slideBulletHandler)
.on('click', SECTION_NAV_TOOLTIP_SEL, tooltipTextHandler);
//Scrolling horizontally when clicking on the slider controls.
$(SECTION_SEL).on('click touchstart', SLIDES_ARROW_SEL, slideArrowHandler);
/**
* Applying normalScroll elements.
* Ignoring the scrolls over the specified selectors.
*/
if(options.normalScrollElements){
$document.on('mouseenter', options.normalScrollElements, function () {
setMouseWheelScrolling(false);
});
$document.on('mouseleave', options.normalScrollElements, function(){
setMouseWheelScrolling(true);
});
}
}
/**
* Setting options from DOM elements if they are not provided.
*/
function setOptionsFromDOM(){
var sections = container.find(options.sectionSelector);
//no anchors option? Checking for them in the DOM attributes
if(!options.anchors.length){
options.anchors = sections.filter('[data-anchor]').map(function(){
return $(this).data('anchor').toString();
}).get();
}
//no tooltips option? Checking for them in the DOM attributes
if(!options.navigationTooltips.length){
options.navigationTooltips = sections.filter('[data-tooltip]').map(function(){
return $(this).data('tooltip').toString();
}).get();
}
}
/**
* Works over the DOM structure to set it up for the current fullpage options.
*/
function prepareDom(){
container.css({
'height': '100%',
'position': 'relative'
});
//adding a class to recognize the container internally in the code
container.addClass(WRAPPER);
$('html').addClass(ENABLED);
windowsHeight = $window.height();
container.removeClass(DESTROYED); //in case it was destroyed before initializing it again
addInternalSelectors();
//styling the sections / slides / menu
$(SECTION_SEL).each(function(index){
var section = $(this);
var slides = section.find(SLIDE_SEL);
var numSlides = slides.length;
styleSection(section, index);
styleMenu(section, index);
// if there's any slide
if (numSlides > 0) {
styleSlides(section, slides, numSlides);
}else{
if(options.verticalCentered){
addTableClass(section);
}
}
});
//fixed elements need to be moved out of the plugin container due to problems with CSS3.
if(options.fixedElements && options.css3){
$(options.fixedElements).appendTo($body);
}
//vertical centered of the navigation + active bullet
if(options.navigation){
addVerticalNavigation();
}
enableYoutubeAPI();
if(options.scrollOverflow){
if(document.readyState === 'complete'){
createScrollBarHandler();
}
//after DOM and images are loaded
$window.on('load', createScrollBarHandler);
}else{
afterRenderActions();
}
}
/**
* Styles the horizontal slides for a section.
*/
function styleSlides(section, slides, numSlides){
var sliderWidth = numSlides * 100;
var slideWidth = 100 / numSlides;
slides.wrapAll('<div class="' + SLIDES_CONTAINER + '" />');
slides.parent().wrap('<div class="' + SLIDES_WRAPPER + '" />');
section.find(SLIDES_CONTAINER_SEL).css('width', sliderWidth + '%');
if(numSlides > 1){
if(options.controlArrows){
createSlideArrows(section);
}
if(options.slidesNavigation){
addSlidesNavigation(section, numSlides);
}
}
slides.each(function(index) {
$(this).css('width', slideWidth + '%');
if(options.verticalCentered){
addTableClass($(this));
}
});
var startingSlide = section.find(SLIDE_ACTIVE_SEL);
//if the slide won't be an starting point, the default will be the first one
//the active section isn't the first one? Is not the first slide of the first section? Then we load that section/slide by default.
if( startingSlide.length && ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) !== 0 || ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) === 0 && startingSlide.index() !== 0))){
silentLandscapeScroll(startingSlide, 'internal');
}else{
slides.eq(0).addClass(ACTIVE);
}
}
/**
* Styling vertical sections
*/
function styleSection(section, index){
//if no active section is defined, the 1st one will be the default one
if(!index && $(SECTION_ACTIVE_SEL).length === 0) {
section.addClass(ACTIVE);
}
startingSection = $(SECTION_ACTIVE_SEL);
section.css('height', windowsHeight + 'px');
if(options.paddingTop){
section.css('padding-top', options.paddingTop);
}
if(options.paddingBottom){
section.css('padding-bottom', options.paddingBottom);
}
if (typeof options.sectionsColor[index] !== 'undefined') {
section.css('background-color', options.sectionsColor[index]);
}
if (typeof options.anchors[index] !== 'undefined') {
section.attr('data-anchor', options.anchors[index]);
}
}
/**
* Sets the data-anchor attributes to the menu elements and activates the current one.
*/
function styleMenu(section, index){
if (typeof options.anchors[index] !== 'undefined') {
//activating the menu / nav element on load
if(section.hasClass(ACTIVE)){
activateMenuAndNav(options.anchors[index], index);
}
}
//moving the menu outside the main container if it is inside (avoid problems with fixed positions when using CSS3 tranforms)
if(options.menu && options.css3 && $(options.menu).closest(WRAPPER_SEL).length){
$(options.menu).appendTo($body);
}
}
/**
* Adds internal classes to be able to provide customizable selectors
* keeping the link with the style sheet.
*/
function addInternalSelectors(){
container.find(options.sectionSelector).addClass(SECTION);
container.find(options.slideSelector).addClass(SLIDE);
}
/**
* Creates the control arrows for the given section
*/
function createSlideArrows(section){
section.find(SLIDES_WRAPPER_SEL).after('<div class="' + SLIDES_ARROW_PREV + '"></div><div class="' + SLIDES_ARROW_NEXT + '"></div>');
if(options.controlArrowColor!='#fff'){
section.find(SLIDES_ARROW_NEXT_SEL).css('border-color', 'transparent transparent transparent '+options.controlArrowColor);
section.find(SLIDES_ARROW_PREV_SEL).css('border-color', 'transparent '+ options.controlArrowColor + ' transparent transparent');
}
if(!options.loopHorizontal){
section.find(SLIDES_ARROW_PREV_SEL).hide();
}
}
/**
* Creates a vertical navigation bar.
*/
function addVerticalNavigation(){
$body.append('<div id="' + SECTION_NAV + '"><ul></ul></div>');
var nav = $(SECTION_NAV_SEL);
nav.addClass(function() {
return options.showActiveTooltip ? SHOW_ACTIVE_TOOLTIP + ' ' + options.navigationPosition : options.navigationPosition;
});
for (var i = 0; i < $(SECTION_SEL).length; i++) {
var link = '';
if (options.anchors.length) {
link = options.anchors[i];
}
var li = '<li><a href="#' + link + '"><span></span></a>';
// Only add tooltip if needed (defined by user)
var tooltip = options.navigationTooltips[i];
if (typeof tooltip !== 'undefined' && tooltip !== '') {
li += '<div class="' + SECTION_NAV_TOOLTIP + ' ' + options.navigationPosition + '">' + tooltip + '</div>';
}
li += '</li>';
nav.find('ul').append(li);
}
//centering it vertically
$(SECTION_NAV_SEL).css('margin-top', '-' + ($(SECTION_NAV_SEL).height()/2) + 'px');
//activating the current active section
$(SECTION_NAV_SEL).find('li').eq($(SECTION_ACTIVE_SEL).index(SECTION_SEL)).find('a').addClass(ACTIVE);
}
/**
* Creates the slim scroll scrollbar for the sections and slides inside them.
*/
function createScrollBarHandler(){
$(SECTION_SEL).each(function(){
var slides = $(this).find(SLIDE_SEL);
if(slides.length){
slides.each(function(){
createScrollBar($(this));
});
}else{
createScrollBar($(this));
}
});
afterRenderActions();
}
/*
* Enables the Youtube videos API so we can control their flow if necessary.
*/
function enableYoutubeAPI(){
container.find('iframe[src*="youtube.com/embed/"]').each(function(){
addURLParam($(this), 'enablejsapi=1');
});
}
/**
* Adds a new parameter and its value to the `src` of a given element
*/
function addURLParam(element, newParam){
var originalSrc = element.attr('src');
element.attr('src', originalSrc + getUrlParamSign(originalSrc) + newParam);
}
/*
* Returns the prefix sign to use for a new parameter in an existen URL.
*
* @return {String} ? | &
*/
function getUrlParamSign(url){
return ( !/\?/.test( url ) ) ? '?' : '&';
}
/**
* Actions and callbacks to fire afterRender
*/
function afterRenderActions(){
var section = $(SECTION_ACTIVE_SEL);
section.addClass(COMPLETELY);
if(options.scrollOverflowHandler.afterRender){
options.scrollOverflowHandler.afterRender(section);
}
lazyLoad(section);
playMedia(section);
options.scrollOverflowHandler.afterLoad();
if(isDestinyTheStartingSection()){
$.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1));
}
$.isFunction( options.afterRender ) && options.afterRender.call(container);
}
/**
* Determines if the URL anchor destiny is the starting section (the one using 'active' class before initialization)
*/
function isDestinyTheStartingSection(){
var anchors = window.location.hash.replace('#', '').split('/');
var destinationSection = getSectionByAnchor(decodeURIComponent(anchors[0]));
return !destinationSection.length || destinationSection.length && destinationSection.index() === startingSection.index();
}
var isScrolling = false;
var lastScroll = 0;
//when scrolling...
function scrollHandler(){
var currentSection;
if(!options.autoScrolling || options.scrollBar){
var currentScroll = $window.scrollTop();
var scrollDirection = getScrollDirection(currentScroll);
var visibleSectionIndex = 0;
var screen_mid = currentScroll + ($window.height() / 2.0);
var isAtBottom = $body.height() - $window.height() === currentScroll;
var sections = document.querySelectorAll(SECTION_SEL);
//when using `auto-height` for a small last section it won't be centered in the viewport
if(isAtBottom){
visibleSectionIndex = sections.length - 1;
}
//is at top? when using `auto-height` for a small first section it won't be centered in the viewport
else if(!currentScroll){
visibleSectionIndex = 0;
}
//taking the section which is showing more content in the viewport
else{
for (var i = 0; i < sections.length; ++i) {
var section = sections[i];
// Pick the the last section which passes the middle line of the screen.
if (section.offsetTop <= screen_mid)
{
visibleSectionIndex = i;
}
}
}
if(isCompletelyInViewPort(scrollDirection)){
if(!$(SECTION_ACTIVE_SEL).hasClass(COMPLETELY)){
$(SECTION_ACTIVE_SEL).addClass(COMPLETELY).siblings().removeClass(COMPLETELY);
}
}
//geting the last one, the current one on the screen
currentSection = $(sections).eq(visibleSectionIndex);
//setting the visible section as active when manually scrolling
//executing only once the first time we reach the section
if(!currentSection.hasClass(ACTIVE)){
isScrolling = true;
var leavingSection = $(SECTION_ACTIVE_SEL);
var leavingSectionIndex = leavingSection.index(SECTION_SEL) + 1;
var yMovement = getYmovement(currentSection);
var anchorLink = currentSection.data('anchor');
var sectionIndex = currentSection.index(SECTION_SEL) + 1;
var activeSlide = currentSection.find(SLIDE_ACTIVE_SEL);
var slideIndex;
var slideAnchorLink;
if(activeSlide.length){
slideAnchorLink = activeSlide.data('anchor');
slideIndex = activeSlide.index();
}
if(canScroll){
currentSection.addClass(ACTIVE).siblings().removeClass(ACTIVE);
$.isFunction( options.onLeave ) && options.onLeave.call( leavingSection, leavingSectionIndex, sectionIndex, yMovement);
$.isFunction( options.afterLoad ) && options.afterLoad.call( currentSection, anchorLink, sectionIndex);
stopMedia(leavingSection);
lazyLoad(currentSection);
playMedia(currentSection);
activateMenuAndNav(anchorLink, sectionIndex - 1);
if(options.anchors.length){
//needed to enter in hashChange event when using the menu with anchor links
lastScrolledDestiny = anchorLink;
}
setState(slideIndex, slideAnchorLink, anchorLink, sectionIndex);
}
//small timeout in order to avoid entering in hashChange event when scrolling is not finished yet
clearTimeout(scrollId);
scrollId = setTimeout(function(){
isScrolling = false;
}, 100);
}
if(options.fitToSection){
//for the auto adjust of the viewport to fit a whole section
clearTimeout(scrollId2);
scrollId2 = setTimeout(function(){
//checking it again in case it changed during the delay
if(options.fitToSection){
fitToSection();
}
}, options.fitToSectionDelay);
}
}
}
/**
* Fits the site to the nearest active section
*/
function fitToSection(){
//checking fitToSection again in case it was set to false before the timeout delay
if(canScroll){
//allows to scroll to an active section and
//if the section is already active, we prevent firing callbacks
isResizing = true;
scrollPage($(SECTION_ACTIVE_SEL));
isResizing = false;
}
}
/**
* Determines whether the active section has seen in its whole or not.
*/
function isCompletelyInViewPort(movement){
var top = $(SECTION_ACTIVE_SEL).position().top;
var bottom = top + $window.height();
if(movement == 'up'){
return bottom >= ($window.scrollTop() + $window.height());
}
return top <= $window.scrollTop();
}
/**
* Gets the directon of the the scrolling fired by the scroll event.
*/
function getScrollDirection(currentScroll){
var direction = currentScroll > lastScroll ? 'down' : 'up';
lastScroll = currentScroll;
//needed for auto-height sections to determine if we want to scroll to the top or bottom of the destination
previousDestTop = currentScroll;
return direction;
}
/**
* Determines the way of scrolling up or down:
* by 'automatically' scrolling a section or by using the default and normal scrolling.
*/
function scrolling(type, scrollable){
if (!isScrollAllowed.m[type]){
return;
}
var check = (type === 'down') ? 'bottom' : 'top';
var scrollSection = (type === 'down') ? moveSectionDown : moveSectionUp;
if(scrollable.length > 0 ){
//is the scrollbar at the start/end of the scroll?
if(options.scrollOverflowHandler.isScrolled(check, scrollable)){
scrollSection();
}else{
return true;
}
}else{
// moved up/down
scrollSection();
}
}
/*
* Preventing bouncing in iOS #2285
*/
function preventBouncing(event){
var e = event.originalEvent;
if(!checkParentForNormalScrollElement(event.target) && options.autoScrolling && isReallyTouch(e) && isScrollAllowed.m.up){
//preventing the easing on iOS devices
event.preventDefault();
}
}
var touchStartY = 0;
var touchStartX = 0;
var touchEndY = 0;
var touchEndX = 0;
/* Detecting touch events
* As we are changing the top property of the page on scrolling, we can not use the traditional way to detect it.
* This way, the touchstart and the touch moves shows an small difference between them which is the
* used one to determine the direction.
*/
function touchMoveHandler(event){
var e = event.originalEvent;
var activeSection = $(e.target).closest(SECTION_SEL);
// additional: if one of the normalScrollElements isn't within options.normalScrollElementTouchThreshold hops up the DOM chain
if (!checkParentForNormalScrollElement(event.target) && isReallyTouch(e) ) {
if(options.autoScrolling){
//preventing the easing on iOS devices
event.preventDefault();
}
var scrollable = options.scrollOverflowHandler.scrollable(activeSection);
var touchEvents = getEventsPage(e);
touchEndY = touchEvents.y;
touchEndX = touchEvents.x;
//if movement in the X axys is greater than in the Y and the currect section has slides...
if (activeSection.find(SLIDES_WRAPPER_SEL).length && Math.abs(touchStartX - touchEndX) > (Math.abs(touchStartY - touchEndY))) {
//is the movement greater than the minimum resistance to scroll?
if (!slideMoving && Math.abs(touchStartX - touchEndX) > ($window.outerWidth() / 100 * options.touchSensitivity)) {
if (touchStartX > touchEndX) {
if(isScrollAllowed.m.right){
moveSlideRight(activeSection); //next
}
} else {
if(isScrollAllowed.m.left){
moveSlideLeft(activeSection); //prev
}
}
}
}
//vertical scrolling (only when autoScrolling is enabled)
else if(options.autoScrolling && canScroll){
//is the movement greater than the minimum resistance to scroll?
if (Math.abs(touchStartY - touchEndY) > ($window.height() / 100 * options.touchSensitivity)) {
if (touchStartY > touchEndY) {
scrolling('down', scrollable);
} else if (touchEndY > touchStartY) {
scrolling('up', scrollable);
}
}
}
}
}
/**
* recursive function to loop up the parent nodes to check if one of them exists in options.normalScrollElements
* Currently works well for iOS - Android might need some testing
* @param {Element} el target element / jquery selector (in subsequent nodes)
* @param {int} hop current hop compared to options.normalScrollElementTouchThreshold
* @return {boolean} true if there is a match to options.normalScrollElements
*/
function checkParentForNormalScrollElement (el, hop) {
hop = hop || 0;
var parent = $(el).parent();
if (hop < options.normalScrollElementTouchThreshold &&
parent.is(options.normalScrollElements) ) {
return true;
} else if (hop == options.normalScrollElementTouchThreshold) {
return false;
} else {
return checkParentForNormalScrollElement(parent, ++hop);
}
}
/**
* As IE >= 10 fires both touch and mouse events when using a mouse in a touchscreen
* this way we make sure that is really a touch event what IE is detecting.
*/
function isReallyTouch(e){
//if is not IE || IE is detecting `touch` or `pen`
return typeof e.pointerType === 'undefined' || e.pointerType != 'mouse';
}
/**
* Handler for the touch start event.
*/
function touchStartHandler(event){
var e = event.originalEvent;
//stopping the auto scroll to adjust to a section
if(options.fitToSection){
$htmlBody.stop();
}
if(isReallyTouch(e)){
var touchEvents = getEventsPage(e);
touchStartY = touchEvents.y;
touchStartX = touchEvents.x;
}
}
/**
* Gets the average of the last `number` elements of the given array.
*/
function getAverage(elements, number){
var sum = 0;
//taking `number` elements from the end to make the average, if there are not enought, 1
var lastElements = elements.slice(Math.max(elements.length - number, 1));
for(var i = 0; i < lastElements.length; i++){
sum = sum + lastElements[i];
}
return Math.ceil(sum/number);
}
/**
* Detecting mousewheel scrolling
*
* http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html
* http://www.sitepoint.com/html5-javascript-mouse-wheel/
*/
var prevTime = new Date().getTime();
function MouseWheelHandler(e) {
var curTime = new Date().getTime();
var isNormalScroll = $(COMPLETELY_SEL).hasClass(NORMAL_SCROLL);
//autoscrolling and not zooming?
if(options.autoScrolling && !controlPressed && !isNormalScroll){
// cross-browser wheel delta
e = e || window.event;
var value = e.wheelDelta || -e.deltaY || -e.detail;
var delta = Math.max(-1, Math.min(1, value));
var horizontalDetection = typeof e.wheelDeltaX !== 'undefined' || typeof e.deltaX !== 'undefined';
var isScrollingVertically = (Math.abs(e.wheelDeltaX) < Math.abs(e.wheelDelta)) || (Math.abs(e.deltaX ) < Math.abs(e.deltaY) || !horizontalDetection);
//Limiting the array to 150 (lets not waste memory!)
if(scrollings.length > 149){
scrollings.shift();
}
//keeping record of the previous scrollings
scrollings.push(Math.abs(value));
//preventing to scroll the site on mouse wheel when scrollbar is present
if(options.scrollBar){
e.preventDefault ? e.preventDefault() : e.returnValue = false;
}
var activeSection = $(SECTION_ACTIVE_SEL);
var scrollable = options.scrollOverflowHandler.scrollable(activeSection);
//time difference between the last scroll and the current one
var timeDiff = curTime-prevTime;
prevTime = curTime;
//haven't they scrolled in a while?
//(enough to be consider a different scrolling action to scroll another section)
if(timeDiff > 200){
//emptying the array, we dont care about old scrollings for our averages
scrollings = [];
}
if(canScroll){
var averageEnd = getAverage(scrollings, 10);
var averageMiddle = getAverage(scrollings, 70);
var isAccelerating = averageEnd >= averageMiddle;
//to avoid double swipes...
if(isAccelerating && isScrollingVertically){
//scrolling down?
if (delta < 0) {
scrolling('down', scrollable);
//scrolling up?
}else {
scrolling('up', scrollable);
}
}
}
return false;
}
if(options.fitToSection){
//stopping the auto scroll to adjust to a section
$htmlBody.stop();
}
}
/**
* Slides a slider to the given direction.
* Optional `section` param.
*/
function moveSlide(direction, section){
var activeSection = typeof section === 'undefined' ? $(SECTION_ACTIVE_SEL) : section;
var slides = activeSection.find(SLIDES_WRAPPER_SEL);
var numSlides = slides.find(SLIDE_SEL).length;
// more than one slide needed and nothing should be sliding
if (!slides.length || slideMoving || numSlides < 2) {
return;
}
var currentSlide = slides.find(SLIDE_ACTIVE_SEL);
var destiny = null;
if(direction === 'left'){
destiny = currentSlide.prev(SLIDE_SEL);
}else{
destiny = currentSlide.next(SLIDE_SEL);
}
//isn't there a next slide in the secuence?
if(!destiny.length){
//respect loopHorizontal settin
if (!options.loopHorizontal) return;
if(direction === 'left'){
destiny = currentSlide.siblings(':last');
}else{
destiny = currentSlide.siblings(':first');
}
}
slideMoving = true;
landscapeScroll(slides, destiny, direction);
}
/**
* Maintains the active slides in the viewport
* (Because the `scroll` animation might get lost with some actions, such as when using continuousVertical)
*/
function keepSlidesPosition(){
$(SLIDE_ACTIVE_SEL).each(function(){
silentLandscapeScroll($(this), 'internal');
});
}
var previousDestTop = 0;
/**
* Returns the destination Y position based on the scrolling direction and
* the height of the section.
*/
function getDestinationPosition(element){
var elemPosition = element.position();
//top of the desination will be at the top of the viewport
var position = elemPosition.top;
var isScrollingDown = elemPosition.top > previousDestTop;
var sectionBottom = position - windowsHeight + element.outerHeight();
var bigSectionsDestination = options.bigSectionsDestination;
//Uncode addition
var containerH = container.outerHeight();
var containerPosition = container.offset();
//########### Commented by Uncode - START ###########
//is the destination element bigger than the viewport?
// if(element.outerHeight() > windowsHeight){
// //scrolling up?
// if(!isScrollingDown && !bigSectionsDestination || bigSectionsDestination === 'bottom' ){
// position = sectionBottom;
// }
// }
// //sections equal or smaller than the viewport height && scrolling down? || is resizing and its in the last section
// else if(isScrollingDown || (isResizing && element.is(':last-child')) ){
// //The bottom of the destination will be at the bottom of the viewport
// position = sectionBottom;
// }
//########### Commented by Uncode - END ###########
//Uncode addition
if ( !$masthead.hasClass('menu-transparent') && $('body').hasClass('uncode-fp-menu-shrink') && !element.is(':first-child') )
position += 18;
if ( ( containerH + menuHeight + bodyBorder + adminBarHeight - windowsHeight ) < position || ( isResizing && element.is(':last-child') ) ) {
position = sectionBottom + menuHeight + bodyBorder*2 + adminBarHeight;
}
/*
Keeping record of the last scrolled position to determine the scrolling direction.
No conventional methods can be used as the scroll bar might not be present
AND the section might not be active if it is auto-height and didnt reach the middle
of the viewport.
*/
previousDestTop = position;
return position;
}
/**
* Scrolls the site to the given element and scrolls to the slide if a callback is given.
*/
function scrollPage(element, callback, isMovementUp){
if(typeof element === 'undefined'){ return; } //there's no element to scroll, leaving the function
var dtop = getDestinationPosition(element);
var slideAnchorLink;
var slideIndex;
//local variables
var v = {
element: element,
callback: callback,
isMovementUp: isMovementUp,
dtop: dtop,
yMovement: getYmovement(element),
anchorLink: element.data('anchor'),
sectionIndex: element.index(SECTION_SEL),
activeSlide: element.find(SLIDE_ACTIVE_SEL),
activeSection: $(SECTION_ACTIVE_SEL),
leavingSection: $(SECTION_ACTIVE_SEL).index(SECTION_SEL) + 1,
//caching the value of isResizing at the momment the function is called
//because it will be checked later inside a setTimeout and the value might change
localIsResizing: isResizing
};
//quiting when destination scroll is the same as the current one
if((v.activeSection.is(element) && !isResizing) || (options.scrollBar && $window.scrollTop() === v.dtop && !element.hasClass(AUTO_HEIGHT) )){ return; }
if(v.activeSlide.length){
slideAnchorLink = v.activeSlide.data('anchor');
slideIndex = v.activeSlide.index();
}
// If continuousVertical && we need to wrap around
if (options.autoScrolling && options.continuousVertical && typeof (v.isMovementUp) !== "undefined" &&
((!v.isMovementUp && v.yMovement == 'up') || // Intending to scroll down but about to go up or
(v.isMovementUp && v.yMovement == 'down'))) { // intending to scroll up but about to go down
v = createInfiniteSections(v);
}
//callback (onLeave) if the site is not just resizing and readjusting the slides
if($.isFunction(options.onLeave) && !v.localIsResizing){
if(options.onLeave.call(v.activeSection, v.leavingSection, (v.sectionIndex + 1), v.yMovement) === false){
return;
}
}
//pausing media of the leaving section (if we are not just resizing, as destinatino will be the same one)
if(!v.localIsResizing){
stopMedia(v.activeSection);
}
options.scrollOverflowHandler.beforeLeave();
element.addClass(ACTIVE).siblings().removeClass(ACTIVE);
lazyLoad(element);
options.scrollOverflowHandler.onLeave();
//preventing from activating the MouseWheelHandler event
//more than once if the page is scrolling
canScroll = false;
setState(slideIndex, slideAnchorLink, v.anchorLink, v.sectionIndex);
performMovement(v);
//flag to avoid callingn `scrollPage()` twice in case of using anchor links
lastScrolledDestiny = v.anchorLink;
//avoid firing it twice (as it does also on scroll)
activateMenuAndNav(v.anchorLink, v.sectionIndex);
}
/**
* Performs the vertical movement (by CSS3 or by jQuery)
*/
function performMovement(v){
// using CSS3 translate functionality
if (options.css3 && options.autoScrolling && !options.scrollBar) {
// The first section can have a negative value in iOS 10. Not quite sure why: -0.0142822265625
// that's why we round it to 0.
var translate3d = 'translate3d(0px, -' + Math.round(v.dtop) + 'px, 0px)';
transformContainer(translate3d, true);
//even when the scrollingSpeed is 0 there's a little delay, which might cause the
//scrollingSpeed to change in case of using silentMoveTo();
if(options.scrollingSpeed){
clearTimeout(afterSectionLoadsId);
afterSectionLoadsId = setTimeout(function () {
afterSectionLoads(v);
}, options.scrollingSpeed);
}else{
afterSectionLoads(v);
}
}
// using jQuery animate
else{
var scrollSettings = getScrollSettings(v);
$(scrollSettings.element).animate(
scrollSettings.options,
options.scrollingSpeed, options.easing).promise().done(function () { //only one single callback in case of animating `html, body`
if(options.scrollBar){
/* Hack!
The timeout prevents setting the most dominant section in the viewport as "active" when the user
scrolled to a smaller section by using the mousewheel (auto scrolling) rather than draging the scroll bar.
When using scrollBar:true It seems like the scroll events still getting propagated even after the scrolling animation has finished.
*/
setTimeout(function(){
afterSectionLoads(v);
},30);
}else{
afterSectionLoads(v);
}
});
}
}
/**
* Gets the scrolling settings depending on the plugin autoScrolling option
*/
function getScrollSettings(v){
var scroll = {};
if(options.autoScrolling && !options.scrollBar){
scroll.options = { 'top': -v.dtop};
scroll.element = WRAPPER_SEL;
}else{
scroll.options = { 'scrollTop': v.dtop};
scroll.element = 'html, body';
}
return scroll;
}
/**
* Adds sections before or after the current one to create the infinite effect.
*/
function createInfiniteSections(v){
// Scrolling down
if (!v.isMovementUp) {
// Move all previous sections to after the active section
$(SECTION_ACTIVE_SEL).after(v.activeSection.prevAll(SECTION_SEL).get().reverse());
}
else { // Scrolling up
// Move all next sections to before the active section
$(SECTION_ACTIVE_SEL).before(v.activeSection.nextAll(SECTION_SEL));
}
// Maintain the displayed position (now that we changed the element order)
silentScroll($(SECTION_ACTIVE_SEL).position().top);
// Maintain the active slides visible in the viewport
keepSlidesPosition();
// save for later the elements that still need to be reordered
v.wrapAroundElements = v.activeSection;
// Recalculate animation variables
v.dtop = v.element.position().top;
v.yMovement = getYmovement(v.element);
return v;
}
/**
* Fix section order after continuousVertical changes have been animated
*/
function continuousVerticalFixSectionOrder (v) {
// If continuousVertical is in effect (and autoScrolling would also be in effect then),
// finish moving the elements around so the direct navigation will function more simply
if (!v.wrapAroundElements || !v.wrapAroundElements.length) {
return;
}
if (v.isMovementUp) {
$(SECTION_FIRST_SEL).before(v.wrapAroundElements);
}
else {
$(SECTION_LAST_SEL).after(v.wrapAroundElements);
}
silentScroll($(SECTION_ACTIVE_SEL).position().top);
// Maintain the active slides visible in the viewport
keepSlidesPosition();
}
/**
* Actions to do once the section is loaded.
*/
function afterSectionLoads (v){
continuousVerticalFixSectionOrder(v);
//callback (afterLoad) if the site is not just resizing and readjusting the slides
$.isFunction(options.afterLoad) && !v.localIsResizing && options.afterLoad.call(v.element, v.anchorLink, (v.sectionIndex + 1));
options.scrollOverflowHandler.afterLoad();
if(!v.localIsResizing){
playMedia(v.element);
}
v.element.addClass(COMPLETELY).siblings().removeClass(COMPLETELY);
canScroll = true;
$.isFunction(v.callback) && v.callback.call(this);
}
/**
* Sets the value for the given attribute from the `data-` attribute with the same suffix
* ie: data-srcset ==> srcset | data-src ==> src
*/
function setSrc(element, attribute){
element
.attr(attribute, element.data(attribute))
.removeAttr('data-' + attribute);
}
/**
* Lazy loads image, video and audio elements.
*/
function lazyLoad(destiny){
if (!options.lazyLoading){
return;
}
var panel = getSlideOrSection(destiny);
var element;
panel.find('img[data-src], img[data-srcset], source[data-src], audio[data-src], iframe[data-src]').each(function(){
element = $(this);
$.each(['src', 'srcset'], function(index, type){
var attribute = element.attr('data-' + type);
if(typeof attribute !== 'undefined' && attribute){
setSrc(element, type);
}
});
if(element.is('source')){
element.closest('video').get(0).load();
}
});
}
/**
* Plays video and audio elements.
*/
function playMedia(destiny){
var panel = getSlideOrSection(destiny);
//playing HTML5 media elements
panel.find('video, audio').each(function(){
var element = $(this).get(0);
if( element.hasAttribute('data-autoplay') && typeof element.play === 'function' ) {
element.play();
}
});
//youtube videos
panel.find('iframe[src*="youtube.com/embed/"]').each(function(){
var element = $(this).get(0);
if ( element.hasAttribute('data-autoplay') ){
playYoutube(element);
}
//in case the URL was not loaded yet. On page load we need time for the new URL (with the API string) to load.
element.onload = function() {
if ( element.hasAttribute('data-autoplay') ){
playYoutube(element);
}
};
});
}
/**
* Plays a youtube video
*/
function playYoutube(element){
element.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
}
/**
* Stops video and audio elements.
*/
function stopMedia(destiny){
var panel = getSlideOrSection(destiny);
//stopping HTML5 media elements
panel.find('video, audio').each(function(){
var element = $(this).get(0);
if( !element.hasAttribute('data-keepplaying') && typeof element.pause === 'function' ) {
element.pause();
}
});
//youtube videos
panel.find('iframe[src*="youtube.com/embed/"]').each(function(){
var element = $(this).get(0);
if( /youtube\.com\/embed\//.test($(this).attr('src')) && !element.hasAttribute('data-keepplaying')){
$(this).get(0).contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}','*');
}
});
}
/**
* Gets the active slide (or section) for the given section
*/
function getSlideOrSection(destiny){
var slide = destiny.find(SLIDE_ACTIVE_SEL);
if( slide.length ) {
destiny = $(slide);
}
return destiny;
}
/**
* Scrolls to the anchor in the URL when loading the site
*/
function scrollToAnchor(){
//getting the anchor link in the URL and deleting the `#`
var value = window.location.hash.replace('#', '').split('/');
var sectionAnchor = decodeURIComponent(value[0]);
var slideAnchor = decodeURIComponent(value[1]);
if(sectionAnchor){ //if theres any #
if(options.animateAnchor){
scrollPageAndSlide(sectionAnchor, slideAnchor);
}else{
silentMoveTo(sectionAnchor, slideAnchor);
}
}
}
/**
* Detecting any change on the URL to scroll to the given anchor link
* (a way to detect back history button as we play with the hashes on the URL)
*/
function hashChangeHandler(){
if(!isScrolling && !options.lockAnchors){
var value = window.location.hash.replace('#', '').split('/');
var sectionAnchor = decodeURIComponent(value[0]);
var slideAnchor = decodeURIComponent(value[1]);
//when moving to a slide in the first section for the first time (first time to add an anchor to the URL)
var isFirstSlideMove = (typeof lastScrolledDestiny === 'undefined');
var isFirstScrollMove = (typeof lastScrolledDestiny === 'undefined' && typeof slideAnchor === 'undefined' && !slideMoving);
if(sectionAnchor.length){
/*in order to call scrollpage() only once for each destination at a time
It is called twice for each scroll otherwise, as in case of using anchorlinks `hashChange`
event is fired on every scroll too.*/
if ((sectionAnchor && sectionAnchor !== lastScrolledDestiny) && !isFirstSlideMove || isFirstScrollMove || (!slideMoving && lastScrolledSlide != slideAnchor )) {
scrollPageAndSlide(sectionAnchor, slideAnchor);
}
}
}
}
//Sliding with arrow keys, both, vertical and horizontal
function keydownHandler(e) {
clearTimeout(keydownId);
var activeElement = $(':focus');
if(!activeElement.is('textarea') && !activeElement.is('input') && !activeElement.is('select') &&
activeElement.attr('contentEditable') !== "true" && activeElement.attr('contentEditable') !== '' &&
options.keyboardScrolling && options.autoScrolling){
var keyCode = e.which;
//preventing the scroll with arrow keys & spacebar & Page Up & Down keys
var keyControls = [40, 38, 32, 33, 34];
if($.inArray(keyCode, keyControls) > -1){
e.preventDefault();
}
controlPressed = e.ctrlKey;
keydownId = setTimeout(function(){
onkeydown(e);
},150);
}
}
function tooltipTextHandler(){
$(this).prev().trigger('click');
}
//to prevent scrolling while zooming
function keyUpHandler(e){
if(isWindowFocused){ //the keyup gets fired on new tab ctrl + t in Firefox
controlPressed = e.ctrlKey;
}
}
//binding the mousemove when the mouse's middle button is released
function mouseDownHandler(e){
//middle button
if (e.which == 2){
oldPageY = e.pageY;
container.on('mousemove', mouseMoveHandler);
}
}
//unbinding the mousemove when the mouse's middle button is released
function mouseUpHandler(e){
//middle button
if (e.which == 2){
container.off('mousemove');
}
}
//Scrolling horizontally when clicking on the slider controls.
function slideArrowHandler(){
var section = $(this).closest(SECTION_SEL);
if ($(this).hasClass(SLIDES_PREV)) {
if(isScrollAllowed.m.left){
moveSlideLeft(section);
}
} else {
if(isScrollAllowed.m.right){
moveSlideRight(section);
}
}
}
//when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
function blurHandler(){
isWindowFocused = false;
controlPressed = false;
}
//Scrolls to the section when clicking the navigation bullet
function sectionBulletHandler(e){
e.preventDefault();
var index = $(this).parent().index();
scrollPage($(SECTION_SEL).eq(index));
}
//Scrolls the slider to the given slide destination for the given section
function slideBulletHandler(e){
e.preventDefault();
var slides = $(this).closest(SECTION_SEL).find(SLIDES_WRAPPER_SEL);
var destiny = slides.find(SLIDE_SEL).eq($(this).closest('li').index());
landscapeScroll(slides, destiny);
}
/**
* Keydown event
*/
function onkeydown(e){
var shiftPressed = e.shiftKey;
//do nothing if we can not scroll or we are not using horizotnal key arrows.
if(!canScroll && [37,39].indexOf(e.which) < 0){
return;
}
switch (e.which) {
//up
case 38:
case 33:
if(isScrollAllowed.k.up){
moveSectionUp();
}
break;
//down
case 32: //spacebar
if(shiftPressed && isScrollAllowed.k.up){
moveSectionUp();
break;
}
/* falls through */
case 40:
case 34:
if(isScrollAllowed.k.down){
moveSectionDown();
}
break;
//Home
case 36:
if(isScrollAllowed.k.up){
moveTo(1);
}
break;
//End
case 35:
if(isScrollAllowed.k.down){
moveTo( $(SECTION_SEL).length );
}
break;
//left
case 37:
if(isScrollAllowed.k.left){
moveSlideLeft();
}
break;
//right
case 39:
if(isScrollAllowed.k.right){
moveSlideRight();
}
break;
default:
return; // exit this handler for other keys
}
}
/**
* Detecting the direction of the mouse movement.
* Used only for the middle button of the mouse.
*/
var oldPageY = 0;
function mouseMoveHandler(e){
if(canScroll){
// moving up
if (e.pageY < oldPageY && isScrollAllowed.m.up){
moveSectionUp();
}
// moving down
else if(e.pageY > oldPageY && isScrollAllowed.m.down){
moveSectionDown();
}
}
oldPageY = e.pageY;
}
/**
* Scrolls horizontal sliders.
*/
function landscapeScroll(slides, destiny, direction){
var section = slides.closest(SECTION_SEL);
var v = {
slides: slides,
destiny: destiny,
direction: direction,
destinyPos: destiny.position(),
slideIndex: destiny.index(),
section: section,
sectionIndex: section.index(SECTION_SEL),
anchorLink: section.data('anchor'),
slidesNav: section.find(SLIDES_NAV_SEL),
slideAnchor: getAnchor(destiny),
prevSlide: section.find(SLIDE_ACTIVE_SEL),
prevSlideIndex: section.find(SLIDE_ACTIVE_SEL).index(),
//caching the value of isResizing at the momment the function is called
//because it will be checked later inside a setTimeout and the value might change
localIsResizing: isResizing
};
v.xMovement = getXmovement(v.prevSlideIndex, v.slideIndex);
v.direction = v.direction ? v.direction : v.xMovement;
//important!! Only do it when not resizing
if(!v.localIsResizing){
//preventing from scrolling to the next/prev section when using scrollHorizontally
canScroll = false;
}
if(options.onSlideLeave){
//if the site is not just resizing and readjusting the slides
if(!v.localIsResizing && v.xMovement!=='none'){
if($.isFunction( options.onSlideLeave )){
if(options.onSlideLeave.call( v.prevSlide, v.anchorLink, (v.sectionIndex + 1), v.prevSlideIndex, v.xMovement, v.slideIndex ) === false){
slideMoving = false;
return;
}
}
}
}
destiny.addClass(ACTIVE).siblings().removeClass(ACTIVE);
if(!v.localIsResizing){
stopMedia(v.prevSlide);
lazyLoad(destiny);
}
if(!options.loopHorizontal && options.controlArrows){
//hidding it for the fist slide, showing for the rest
section.find(SLIDES_ARROW_PREV_SEL).toggle(v.slideIndex!==0);
//hidding it for the last slide, showing for the rest
section.find(SLIDES_ARROW_NEXT_SEL).toggle(!destiny.is(':last-child'));
}
//only changing the URL if the slides are in the current section (not for resize re-adjusting)
if(section.hasClass(ACTIVE) && !v.localIsResizing){
setState(v.slideIndex, v.slideAnchor, v.anchorLink, v.sectionIndex);
}
performHorizontalMove(slides, v, true);
}
function afterSlideLoads(v){
activeSlidesNavigation(v.slidesNav, v.slideIndex);
//if the site is not just resizing and readjusting the slides
if(!v.localIsResizing){
$.isFunction( options.afterSlideLoad ) && options.afterSlideLoad.call( v.destiny, v.anchorLink, (v.sectionIndex + 1), v.slideAnchor, v.slideIndex);
//needs to be inside the condition to prevent problems with continuousVertical and scrollHorizontally
//and to prevent double scroll right after a windows resize
canScroll = true;
playMedia(v.destiny);
}
//letting them slide again
slideMoving = false;
}
/**
* Performs the horizontal movement. (CSS3 or jQuery)
*
* @param fireCallback {Bool} - determines whether or not to fire the callback
*/
function performHorizontalMove(slides, v, fireCallback){
var destinyPos = v.destinyPos;
if(options.css3){
var translate3d = 'translate3d(-' + Math.round(destinyPos.left) + 'px, 0px, 0px)';
addAnimation(slides.find(SLIDES_CONTAINER_SEL)).css(getTransforms(translate3d), v);
afterSlideLoadsId = setTimeout(function(){
fireCallback && afterSlideLoads(v);
}, options.scrollingSpeed, options.easing);
}else{
slides.animate({
scrollLeft : Math.round(destinyPos.left)
}, options.scrollingSpeed, options.easing, function() {
fireCallback && afterSlideLoads(v);
});
}
}
/**
* Sets the state for the horizontal bullet navigations.
*/
function activeSlidesNavigation(slidesNav, slideIndex){
slidesNav.find(ACTIVE_SEL).removeClass(ACTIVE);
slidesNav.find('li').eq(slideIndex).find('a').addClass(ACTIVE);
}
var previousHeight = windowsHeight;
//when resizing the site, we adjust the heights of the sections, slimScroll...
function resizeHandler(){
//checking if it needs to get responsive
responsive();
// rebuild immediately on touch devices
if (isTouchDevice) {
var activeElement = $(document.activeElement);
//if the keyboard is NOT visible
if (!activeElement.is('textarea') && !activeElement.is('input') && !activeElement.is('select')) {
var currentHeight = $window.height();
//making sure the change in the viewport size is enough to force a rebuild. (20 % of the window to avoid problems when hidding scroll bars)
if( Math.abs(currentHeight - previousHeight) > (20 * Math.max(previousHeight, currentHeight) / 100) ){
reBuild(true);
previousHeight = currentHeight;
}
}
}else{
//in order to call the functions only when the resize is finished
//http://stackoverflow.com/questions/4298612/jquery-how-to-call-resize-event-only-once-its-finished-resizing
clearTimeout(resizeId);
resizeId = setTimeout(function(){
reBuild(true);
}, 350);
}
}
/**
* Checks if the site needs to get responsive and disables autoScrolling if so.
* A class `fp-responsive` is added to the plugin's container in case the user wants to use it for his own responsive CSS.
*/
function responsive(){
var widthLimit = options.responsive || options.responsiveWidth; //backwards compatiblity
var heightLimit = options.responsiveHeight;
//only calculating what we need. Remember its called on the resize event.
var isBreakingPointWidth = widthLimit && $window.outerWidth() < widthLimit;
var isBreakingPointHeight = heightLimit && $window.height() < heightLimit;
if(widthLimit && heightLimit){
setResponsive(isBreakingPointWidth || isBreakingPointHeight);
}
else if(widthLimit){
setResponsive(isBreakingPointWidth);
}
else if(heightLimit){
setResponsive(isBreakingPointHeight);
}
}
/**
* Adds transition animations for the given element
*/
function addAnimation(container, element){
var transition = 'all ' + options.scrollingSpeed + 'ms ' + options.easingcss3;
container.removeClass(NO_TRANSITION);
return container.css({
'-webkit-transition': transition,
'transition': transition
});
}
/**
* Remove transition animations for the given element
*/
function removeAnimation(element){
return element.addClass(NO_TRANSITION);
}
/**
* Activating the vertical navigation bullets according to the given slide name.
*/
function activateNavDots(name, sectionIndex){
if(options.navigation){
$(SECTION_NAV_SEL).find(ACTIVE_SEL).removeClass(ACTIVE);
if(name){
$(SECTION_NAV_SEL).find('a[href="#' + name + '"]').addClass(ACTIVE);
}else{
$(SECTION_NAV_SEL).find('li').eq(sectionIndex).find('a').addClass(ACTIVE);
}
}
}
/**
* Activating the website main menu elements according to the given slide name.
*/
function activateMenuElement(name){
if(options.menu){
$(options.menu).find(ACTIVE_SEL).removeClass(ACTIVE);
$(options.menu).find('[data-menuanchor="'+name+'"]').addClass(ACTIVE);
}
}
/**
* Sets to active the current menu and vertical nav items.
*/
function activateMenuAndNav(anchor, index){
activateMenuElement(anchor);
activateNavDots(anchor, index);
}
/**
* Retuns `up` or `down` depending on the scrolling movement to reach its destination
* from the current section.
*/
function getYmovement(destiny){
var fromIndex = $(SECTION_ACTIVE_SEL).index(SECTION_SEL);
var toIndex = destiny.index(SECTION_SEL);
if( fromIndex == toIndex){
return 'none';
}
if(fromIndex > toIndex){
return 'up';
}
return 'down';
}
/**
* Retuns `right` or `left` depending on the scrolling movement to reach its destination
* from the current slide.
*/
function getXmovement(fromIndex, toIndex){
if( fromIndex == toIndex){
return 'none';
}
if(fromIndex > toIndex){
return 'left';
}
return 'right';
}
/**
* Checks if the element needs scrollbar and if the user wants to apply it.
* If so it creates it.
*
* @param {Object} element jQuery object of the section or slide
*/
function createScrollBar(element){
//User doesn't want scrollbar here? Sayonara baby!
if(element.hasClass('fp-noscroll')) return;
//needed to make `scrollHeight` work under Opera 12
element.css('overflow', 'hidden');
var scrollOverflowHandler = options.scrollOverflowHandler;
var wrap = scrollOverflowHandler.wrapContent();
//in case element is a slide
var section = element.closest(SECTION_SEL);
var scrollable = scrollOverflowHandler.scrollable(element);
var contentHeight;
//if there was scroll, the contentHeight will be the one in the scrollable section
if(scrollable.length){
contentHeight = scrollOverflowHandler.scrollHeight(element);
}else{
contentHeight = element.get(0).scrollHeight;
if(options.verticalCentered){
contentHeight = element.find(TABLE_CELL_SEL).get(0).scrollHeight;
}
}
var scrollHeight = windowsHeight - parseInt(section.css('padding-bottom')) - parseInt(section.css('padding-top'));
//needs scroll?
if ( contentHeight > scrollHeight) {
//did we already have an scrollbar ? Updating it
if(scrollable.length){
scrollOverflowHandler.update(element, scrollHeight);
}
//creating the scrolling
else{
if(options.verticalCentered){
element.find(TABLE_CELL_SEL).wrapInner(wrap);
}else{
element.wrapInner(wrap);
}
scrollOverflowHandler.create(element, scrollHeight);
}
}
//removing the scrolling when it is not necessary anymore
else{
scrollOverflowHandler.remove(element);
}
//undo
element.css('overflow', '');
}
function addTableClass(element){
//In case we are styling for the 2nd time as in with reponsiveSlides
if(!element.hasClass(TABLE)){
element.addClass(TABLE).wrapInner('<div class="' + TABLE_CELL + '" style="height:' + getTableHeight(element) + 'px;" />');
}
}
function getTableHeight(element){
var sectionHeight = windowsHeight;
if(options.paddingTop || options.paddingBottom){
var section = element;
if(!section.hasClass(SECTION)){
section = element.closest(SECTION_SEL);
}
var paddings = parseInt(section.css('padding-top')) + parseInt(section.css('padding-bottom'));
sectionHeight = (windowsHeight - paddings);
}
return sectionHeight;
}
/**
* Adds a css3 transform property to the container class with or without animation depending on the animated param.
*/
function transformContainer(translate3d, animated){
if(animated){
addAnimation(container);
}else{
removeAnimation(container);
}
container.css(getTransforms(translate3d));
//syncronously removing the class after the animation has been applied.
setTimeout(function(){
container.removeClass(NO_TRANSITION);
},10);
}
/**
* Gets a section by its anchor / index
*/
function getSectionByAnchor(sectionAnchor){
if(!sectionAnchor) return [];
var section = container.find(SECTION_SEL + '[data-anchor="'+sectionAnchor+'"]');
if(!section.length){
section = $(SECTION_SEL).eq( sectionAnchor -1);
}
return section;
}
/**
* Gets a slide inside a given section by its anchor / index
*/
function getSlideByAnchor(slideAnchor, section){
var slides = section.find(SLIDES_WRAPPER_SEL);
var slide = slides.find(SLIDE_SEL + '[data-anchor="'+slideAnchor+'"]');
if(!slide.length){
slide = slides.find(SLIDE_SEL).eq(slideAnchor);
}
return slide;
}
/**
* Scrolls to the given section and slide anchors
*/
function scrollPageAndSlide(destiny, slide){
var section = getSectionByAnchor(destiny);
//do nothing if there's no section with the given anchor name
if(!section.length) return;
//default slide
if (typeof slide === 'undefined') {
slide = 0;
}
//we need to scroll to the section and then to the slide
if (destiny !== lastScrolledDestiny && !section.hasClass(ACTIVE)){
scrollPage(section, function(){
scrollSlider(section, slide);
});
}
//if we were already in the section
else{
scrollSlider(section, slide);
}
}
/**
* Scrolls the slider to the given slide destination for the given section
*/
function scrollSlider(section, slideAnchor){
if(typeof slideAnchor !== 'undefined'){
var slides = section.find(SLIDES_WRAPPER_SEL);
var destiny = getSlideByAnchor(slideAnchor, section);
if(destiny.length){
landscapeScroll(slides, destiny);
}
}
}
/**
* Creates a landscape navigation bar with dots for horizontal sliders.
*/
function addSlidesNavigation(section, numSlides){
section.append('<div class="' + SLIDES_NAV + '"><ul></ul></div>');
var nav = section.find(SLIDES_NAV_SEL);
//top or bottom
nav.addClass(options.slidesNavPosition);
for(var i=0; i< numSlides; i++){
nav.find('ul').append('<li><a href="#"><span></span></a></li>');
}
//centering it
nav.css('margin-left', '-' + (nav.width()/2) + 'px');
nav.find('li').first().find('a').addClass(ACTIVE);
}
/**
* Sets the state of the website depending on the active section/slide.
* It changes the URL hash when needed and updates the body class.
*/
function setState(slideIndex, slideAnchor, anchorLink, sectionIndex){
var sectionHash = '';
if(options.anchors.length && !options.lockAnchors){
//isn't it the first slide?
if(slideIndex){
if(typeof anchorLink !== 'undefined'){
sectionHash = anchorLink;
}
//slide without anchor link? We take the index instead.
if(typeof slideAnchor === 'undefined'){
slideAnchor = slideIndex;
}
lastScrolledSlide = slideAnchor;
setUrlHash(sectionHash + '/' + slideAnchor);
//first slide won't have slide anchor, just the section one
}else if(typeof slideIndex !== 'undefined'){
lastScrolledSlide = slideAnchor;
setUrlHash(anchorLink);
}
//section without slides
else{
setUrlHash(anchorLink);
}
}
setBodyClass();
}
/**
* Sets the URL hash.
*/
function setUrlHash(url){
//Uncode addition
if ( typeof SiteParameters.slide_footer != 'undefined' && url == SiteParameters.slide_footer )
return false;
if(options.recordHistory){
location.hash = url;
}else{
//Uncode addition
//Mobile Chrome doesn't work the normal way, so... lets use HTML5 for phones :)
// if(isTouchDevice || isTouch){
// window.history.replaceState(undefined, undefined, '#' + url);
// }else{
// var baseUrl = window.location.href.split('#')[0];
// window.location.replace( baseUrl + '#' + url );
// }
return false;
}
}
/**
* Gets the anchor for the given slide / section. Its index will be used if there's none.
*/
function getAnchor(element){
var anchor = element.data('anchor');
var index = element.index();
//Slide without anchor link? We take the index instead.
if(typeof anchor === 'undefined'){
anchor = index;
}
return anchor;
}
/**
* Sets a class for the body of the page depending on the active section / slide
*/
function setBodyClass(){
var section = $(SECTION_ACTIVE_SEL);
var slide = section.find(SLIDE_ACTIVE_SEL);
var sectionAnchor = getAnchor(section);
var slideAnchor = getAnchor(slide);
var text = String(sectionAnchor);
if(slide.length){
text = text + '-' + slideAnchor;
}
//changing slash for dash to make it a valid CSS style
text = text.replace('/', '-').replace('#','');
//removing previous anchor classes
var classRe = new RegExp('\\b\\s?' + VIEWING_PREFIX + '-[^\\s]+\\b', "g");
$body[0].className = $body[0].className.replace(classRe, '');
//adding the current anchor
$body.addClass(VIEWING_PREFIX + '-' + text);
}
/**
* Checks for translate3d support
* @return boolean
* http://stackoverflow.com/questions/5661671/detecting-transform-translate3d-support
*/
function support3d() {
var el = document.createElement('p'),
has3d,
transforms = {
'webkitTransform':'-webkit-transform',
'OTransform':'-o-transform',
'msTransform':'-ms-transform',
'MozTransform':'-moz-transform',
'transform':'transform'
};
// Add it to the body to get the computed style.
document.body.insertBefore(el, null);
for (var t in transforms) {
if (el.style[t] !== undefined) {
el.style[t] = 'translate3d(1px,1px,1px)';
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
}
}
document.body.removeChild(el);
return (has3d !== undefined && has3d.length > 0 && has3d !== 'none');
}
/**
* Removes the auto scrolling action fired by the mouse wheel and trackpad.
* After this function is called, the mousewheel and trackpad movements won't scroll through sections.
*/
function removeMouseWheelHandler(){
if (document.addEventListener) {
document.removeEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
document.removeEventListener('wheel', MouseWheelHandler, false); //Firefox
document.removeEventListener('MozMousePixelScroll', MouseWheelHandler, false); //old Firefox
} else {
document.detachEvent('onmousewheel', MouseWheelHandler); //IE 6/7/8
}
}
/**
* Adds the auto scrolling action for the mouse wheel and trackpad.
* After this function is called, the mousewheel and trackpad movements will scroll through sections
* https://developer.mozilla.org/en-US/docs/Web/Events/wheel
*/
function addMouseWheelHandler(){
var prefix = '';
var _addEventListener;
if (window.addEventListener){
_addEventListener = "addEventListener";
}else{
_addEventListener = "attachEvent";
prefix = 'on';
}
// detect available wheel event
var support = 'onwheel' in document.createElement('div') ? 'wheel' : // Modern browsers support "wheel"
document.onmousewheel !== undefined ? 'mousewheel' : // Webkit and IE support at least "mousewheel"
'DOMMouseScroll'; // let's assume that remaining browsers are older Firefox
var passiveEvent = g_supportsPassive ? {passive: false }: false;
if(support == 'DOMMouseScroll'){
document[ _addEventListener ](prefix + 'MozMousePixelScroll', MouseWheelHandler, passiveEvent);
}
//handle MozMousePixelScroll in older Firefox
else{
document[ _addEventListener ](prefix + support, MouseWheelHandler, passiveEvent);
}
}
/**
* Binding the mousemove when the mouse's middle button is pressed
*/
function addMiddleWheelHandler(){
container
.on('mousedown', mouseDownHandler)
.on('mouseup', mouseUpHandler);
}
/**
* Unbinding the mousemove when the mouse's middle button is released
*/
function removeMiddleWheelHandler(){
container
.off('mousedown', mouseDownHandler)
.off('mouseup', mouseUpHandler);
}
/**
* Adds the possibility to auto scroll through sections on touch devices.
*/
function addTouchHandler(){
if(isTouchDevice || isTouch){
if(options.autoScrolling){
$body.off(events.touchmove).on(events.touchmove, preventBouncing);
}
$(WRAPPER_SEL)
.off(events.touchstart).on(events.touchstart, touchStartHandler)
.off(events.touchmove).on(events.touchmove, touchMoveHandler);
}
}
/**
* Removes the auto scrolling for touch devices.
*/
function removeTouchHandler(){
if(isTouchDevice || isTouch){
$(WRAPPER_SEL)
.off(events.touchstart)
.off(events.touchmove);
}
}
/*
* Returns and object with Microsoft pointers (for IE<11 and for IE >= 11)
* http://msdn.microsoft.com/en-us/library/ie/dn304886(v=vs.85).aspx
*/
function getMSPointer(){
var pointer;
//IE >= 11 & rest of browsers
if(window.PointerEvent){
pointer = { down: 'pointerdown', move: 'pointermove'};
}
//IE < 11
else{
pointer = { down: 'MSPointerDown', move: 'MSPointerMove'};
}
return pointer;
}
/**
* Gets the pageX and pageY properties depending on the browser.
* https://github.com/alvarotrigo/fullPage.js/issues/194#issuecomment-34069854
*/
function getEventsPage(e){
var events = [];
events.y = (typeof e.pageY !== 'undefined' && (e.pageY || e.pageX) ? e.pageY : e.touches[0].pageY);
events.x = (typeof e.pageX !== 'undefined' && (e.pageY || e.pageX) ? e.pageX : e.touches[0].pageX);
//in touch devices with scrollBar:true, e.pageY is detected, but we have to deal with touch events. #1008
if(isTouch && isReallyTouch(e) && options.scrollBar){
events.y = e.touches[0].pageY;
events.x = e.touches[0].pageX;
}
return events;
}
/**
* Slides silently (with no animation) the active slider to the given slide.
* @param noCallback {bool} true or defined -> no callbacks
*/
function silentLandscapeScroll(activeSlide, noCallbacks){
setScrollingSpeed (0, 'internal');
if(typeof noCallbacks !== 'undefined'){
//preventing firing callbacks afterSlideLoad etc.
isResizing = true;
}
landscapeScroll(activeSlide.closest(SLIDES_WRAPPER_SEL), activeSlide);
if(typeof noCallbacks !== 'undefined'){
isResizing = false;
}
setScrollingSpeed(originals.scrollingSpeed, 'internal');
}
/**
* Scrolls silently (with no animation) the page to the given Y position.
*/
function silentScroll(top){
// The first section can have a negative value in iOS 10. Not quite sure why: -0.0142822265625
// that's why we round it to 0.
var roundedTop = Math.round(top);
if (options.css3 && options.autoScrolling && !options.scrollBar){
var translate3d = 'translate3d(0px, -' + roundedTop + 'px, 0px)';
transformContainer(translate3d, false);
}
else if(options.autoScrolling && !options.scrollBar){
container.css('top', -roundedTop);
}
else{
$htmlBody.scrollTop(roundedTop);
}
}
/**
* Returns the cross-browser transform string.
*/
function getTransforms(translate3d){
return {
'-webkit-transform': translate3d,
'-moz-transform': translate3d,
'-ms-transform':translate3d,
'transform': translate3d
};
}
/**
* Allowing or disallowing the mouse/swipe scroll in a given direction. (not for keyboard)
* @type m (mouse) or k (keyboard)
*/
function setIsScrollAllowed(value, direction, type){
switch (direction){
case 'up': isScrollAllowed[type].up = value; break;
case 'down': isScrollAllowed[type].down = value; break;
case 'left': isScrollAllowed[type].left = value; break;
case 'right': isScrollAllowed[type].right = value; break;
case 'all':
if(type == 'm'){
setAllowScrolling(value);
}else{
setKeyboardScrolling(value);
}
}
}
/*
* Destroys fullpage.js plugin events and optinally its html markup and styles
*/
function destroy(all){
setAutoScrolling(false, 'internal');
setAllowScrolling(false);
setKeyboardScrolling(false);
container.addClass(DESTROYED);
clearTimeout(afterSlideLoadsId);
clearTimeout(afterSectionLoadsId);
clearTimeout(resizeId);
clearTimeout(scrollId);
clearTimeout(scrollId2);
$window
.off('scroll', scrollHandler)
.off('hashchange', hashChangeHandler)
.off('resize', resizeHandler);
$document
.off('click touchstart', SECTION_NAV_SEL + ' a')
.off('mouseenter', SECTION_NAV_SEL + ' li')
.off('mouseleave', SECTION_NAV_SEL + ' li')
.off('click touchstart', SLIDES_NAV_LINK_SEL)
.off('mouseover', options.normalScrollElements)
.off('mouseout', options.normalScrollElements);
$(SECTION_SEL)
.off('click touchstart', SLIDES_ARROW_SEL);
clearTimeout(afterSlideLoadsId);
clearTimeout(afterSectionLoadsId);
//lets make a mess!
if(all){
destroyStructure();
}
}
/*
* Removes inline styles added by fullpage.js
*/
function destroyStructure(){
//reseting the `top` or `translate` properties to 0
silentScroll(0);
//loading all the lazy load content
container.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){
setSrc($(this), 'src');
});
container.find('img[data-srcset]').each(function(){
setSrc($(this), 'srcset');
});
$(SECTION_NAV_SEL + ', ' + SLIDES_NAV_SEL + ', ' + SLIDES_ARROW_SEL).remove();
//removing inline styles
$(SECTION_SEL).css( {
'height': '',
'background-color' : '',
'padding': ''
});
$(SLIDE_SEL).css( {
'width': ''
});
container.css({
'height': '',
'position': '',
'-ms-touch-action': '',
'touch-action': ''
});
$htmlBody.css({
'overflow': '',
'height': ''
});
// remove .fp-enabled class
$('html').removeClass(ENABLED);
// remove .fp-responsive class
$body.removeClass(RESPONSIVE);
// remove all of the .fp-viewing- classes
$.each($body.get(0).className.split(/\s+/), function (index, className) {
if (className.indexOf(VIEWING_PREFIX) === 0) {
$body.removeClass(className);
}
});
//removing added classes
$(SECTION_SEL + ', ' + SLIDE_SEL).each(function(){
options.scrollOverflowHandler.remove($(this));
$(this).removeClass(TABLE + ' ' + ACTIVE);
});
removeAnimation(container);
//Unwrapping content
container.find(TABLE_CELL_SEL + ', ' + SLIDES_CONTAINER_SEL + ', ' + SLIDES_WRAPPER_SEL).each(function(){
//unwrap not being use in case there's no child element inside and its just text
$(this).replaceWith(this.childNodes);
});
//removing the applied transition from the fullpage wrapper
container.css({
'-webkit-transition': 'none',
'transition': 'none'
});
//scrolling the page to the top with no animation
$htmlBody.scrollTop(0);
//removing selectors
var usedSelectors = [SECTION, SLIDE, SLIDES_CONTAINER];
$.each(usedSelectors, function(index, value){
$('.' + value).removeClass(value);
});
}
/*
* Sets the state for a variable with multiple states (original, and temporal)
* Some variables such as `autoScrolling` or `recordHistory` might change automatically its state when using `responsive` or `autoScrolling:false`.
* This function is used to keep track of both states, the original and the temporal one.
* If type is not 'internal', then we assume the user is globally changing the variable.
*/
function setVariableState(variable, value, type){
options[variable] = value;
if(type !== 'internal'){
originals[variable] = value;
}
}
/**
* Displays warnings
*/
function displayWarnings(){
var extensions = ['fadingEffect', 'continuousHorizontal', 'scrollHorizontally', 'interlockedSlides', 'resetSliders', 'responsiveSlides', 'offsetSections', 'dragAndMove', 'scrollOverflowReset', 'parallax'];
//UNCODE.addition
// if($('html').hasClass(ENABLED)){
// showError('error', 'Fullpage.js can only be initialized once and you are doing it multiple times!');
// return;
// }
// Disable mutually exclusive settings
//UNCODE.addition
// if (options.continuousVertical &&
// (options.loopTop || options.loopBottom)) {
// options.continuousVertical = false;
// showError('warn', 'Option `loopTop/loopBottom` is mutually exclusive with `continuousVertical`; `continuousVertical` disabled');
// }
// if(options.scrollBar && options.scrollOverflow){
// showError('warn', 'Option `scrollBar` is mutually exclusive with `scrollOverflow`. Sections with scrollOverflow might not work well in Firefox');
// }
// if(options.continuousVertical && (options.scrollBar || !options.autoScrolling)){
// options.continuousVertical = false;
// showError('warn', 'Scroll bars (`scrollBar:true` or `autoScrolling:false`) are mutually exclusive with `continuousVertical`; `continuousVertical` disabled');
// }
//using extensions? Wrong file!
$.each(extensions, function(index, extension){
//is the option set to true?
if(options[extension]){
showError('warn', 'fullpage.js extensions require jquery.fullpage.extensions.min.js file instead of the usual jquery.fullpage.js. Requested: '+ extension);
}
});
//anchors can not have the same value as any element ID or NAME
$.each(options.anchors, function(index, name){
//case insensitive selectors (http://stackoverflow.com/a/19465187/1081396)
var nameAttr = $document.find('[name]').filter(function() {
return $(this).attr('name') && $(this).attr('name').toLowerCase() == name.toLowerCase();
});
var idAttr = $document.find('[id]').filter(function() {
return $(this).attr('id') && $(this).attr('id').toLowerCase() == name.toLowerCase();
});
if(idAttr.length || nameAttr.length ){
showError('error', 'data-anchor tags can not have the same value as any `id` element on the site (or `name` element for IE).');
idAttr.length && showError('error', '"' + name + '" is is being used by another element `id` property');
nameAttr.length && showError('error', '"' + name + '" is is being used by another element `name` property');
}
});
}
/**
* Shows a message in the console of the given type.
*/
function showError(type, text){
console && console[type] && console[type]('fullPage: ' + text);
}
}; //end of $.fn.fullpage
if(typeof IScroll !== 'undefined'){
/*
* Turns iScroll `mousewheel` option off dynamically
* https://github.com/cubiq/iscroll/issues/1036
*/
IScroll.prototype.wheelOn = function () {
this.wrapper.addEventListener('wheel', this);
this.wrapper.addEventListener('mousewheel', this);
this.wrapper.addEventListener('DOMMouseScroll', this);
};
/*
* Turns iScroll `mousewheel` option on dynamically
* https://github.com/cubiq/iscroll/issues/1036
*/
IScroll.prototype.wheelOff = function () {
this.wrapper.removeEventListener('wheel', this);
this.wrapper.removeEventListener('mousewheel', this);
this.wrapper.removeEventListener('DOMMouseScroll', this);
};
}
/**
* An object to handle overflow scrolling.
* This uses jquery.slimScroll to accomplish overflow scrolling.
* It is possible to pass in an alternate scrollOverflowHandler
* to the fullpage.js option that implements the same functions
* as this handler.
*
* @type {Object}
*/
var iscrollHandler = {
refreshId: null,
iScrollInstances: [],
// Enables or disables the mouse wheel for the active section or all slides in it
toggleWheel: function(value){
var scrollable = $(SECTION_ACTIVE_SEL).find(SCROLLABLE_SEL);
scrollable.each(function(){
var iScrollInstance = $(this).data('iscrollInstance');
if(typeof iScrollInstance !== 'undefined' && iScrollInstance){
if(value){
iScrollInstance.wheelOn();
}
else{
iScrollInstance.wheelOff();
}
}
});
},
/**
* Turns off iScroll for the destination section.
* When scrolling very fast on some trackpads (and Apple laptops) the inertial scrolling would
* scroll the destination section/slide before the sections animations ends.
*/
onLeave: function(){
iscrollHandler.toggleWheel(false);
},
// Turns off iScroll for the leaving section
beforeLeave: function(){
iscrollHandler.onLeave()
},
// Turns on iScroll on section load
afterLoad: function(){
iscrollHandler.toggleWheel(true);
},
/**
* Called when overflow scrolling is needed for a section.
*
* @param {Object} element jQuery object containing current section
* @param {Number} scrollHeight Current window height in pixels
*/
create: function(element, scrollHeight) {
var scrollable = element.find(SCROLLABLE_SEL);
scrollable.height(scrollHeight);
scrollable.each(function() {
var $this = $(this);
var iScrollInstance = $this.data('iscrollInstance');
if (iScrollInstance) {
$.each(iscrollHandler.iScrollInstances, function(){
$(this).destroy();
});
}
iScrollInstance = new IScroll($this.get(0), iscrollOptions);
iscrollHandler.iScrollInstances.push(iScrollInstance);
//off by default until the section gets active
iScrollInstance.wheelOff();
$this.data('iscrollInstance', iScrollInstance);
});
},
/**
* Return a boolean depending on whether the scrollable element is a
* the end or at the start of the scrolling depending on the given type.
*
* @param {String} type Either 'top' or 'bottom'
* @param {Object} scrollable jQuery object for the scrollable element
* @return {Boolean}
*/
isScrolled: function(type, scrollable) {
var scroller = scrollable.data('iscrollInstance');
//no scroller?
if (!scroller) {
return true;
}
if (type === 'top') {
return scroller.y >= 0 && !scrollable.scrollTop();
} else if (type === 'bottom') {
return (0 - scroller.y) + scrollable.scrollTop() + 1 + scrollable.innerHeight() >= scrollable[0].scrollHeight;
}
},
/**
* Returns the scrollable element for the given section.
* If there are landscape slides, will only return a scrollable element
* if it is in the active slide.
*
* @param {Object} activeSection jQuery object containing current section
* @return {Boolean}
*/
scrollable: function(activeSection){
// if there are landscape slides, we check if the scrolling bar is in the current one or not
if (activeSection.find(SLIDES_WRAPPER_SEL).length) {
return activeSection.find(SLIDE_ACTIVE_SEL).find(SCROLLABLE_SEL);
}
return activeSection.find(SCROLLABLE_SEL);
},
/**
* Returns the scroll height of the wrapped content.
* If this is larger than the window height minus section padding,
* overflow scrolling is needed.
*
* @param {Object} element jQuery object containing current section
* @return {Number}
*/
scrollHeight: function(element) {
return element.find(SCROLLABLE_SEL).children().first().get(0).scrollHeight;
},
/**
* Called when overflow scrolling is no longer needed for a section.
*
* @param {Object} element jQuery object containing current section
*/
remove: function(element) {
var scrollable = element.find(SCROLLABLE_SEL);
if (scrollable.length) {
var iScrollInstance = scrollable.data('iscrollInstance');
iScrollInstance.destroy();
scrollable.data('iscrollInstance', null);
}
element.find(SCROLLABLE_SEL).children().first().children().first().unwrap().unwrap();
},
/**
* Called when overflow scrolling has already been setup but the
* window height has potentially changed.
*
* @param {Object} element jQuery object containing current section
* @param {Number} scrollHeight Current window height in pixels
*/
update: function(element, scrollHeight) {
//using a timeout in order to execute the refresh function only once when `update` is called multiple times in a
//short period of time.
//it also comes on handy because iScroll requires the use of timeout when using `refresh`.
clearTimeout(iscrollHandler.refreshId);
iscrollHandler.refreshId = setTimeout(function(){
$.each(iscrollHandler.iScrollInstances, function(){
$(this).get(0).refresh();
});
}, 150);
//updating the wrappers height
element.find(SCROLLABLE_SEL).css('height', scrollHeight + 'px').parent().css('height', scrollHeight + 'px');
},
/**
* Called to get any additional elements needed to wrap the section
* content in order to facilitate overflow scrolling.
*
* @return {String|Object} Can be a string containing HTML,
* a DOM element, or jQuery object.
*/
wrapContent: function() {
return '<div class="' + SCROLLABLE + '"><div class="fp-scroller"></div></div>';
}
};
});
/* ========================================================================
* Bootstrap: collapse.js v3.1.1
* http://getbootstrap.com/javascript/#collapse
* ========================================================================
* Copyright 2011-2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// COLLAPSE PUBLIC CLASS DEFINITION
// ================================
var Collapse = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, Collapse.DEFAULTS, options)
this.transitioning = null
if (this.options.parent) this.$parent = $(this.options.parent)
if (this.options.toggle) this.toggle()
}
Collapse.DEFAULTS = {
toggle: true
}
Collapse.prototype.dimension = function () {
var hasWidth = this.$element.hasClass('width')
return hasWidth ? 'width' : 'height'
}
Collapse.prototype.show = function () {
if (this.transitioning || this.$element.hasClass('in')) return
var startEvent = $.Event('show.bs.collapse')
this.$element.trigger(startEvent)
if (startEvent.isDefaultPrevented()) return
var actives = this.$parent && this.$parent.find('> .panel > .in')
if (actives && actives.length) {
var hasData = actives.data('bs.collapse')
if (hasData && hasData.transitioning) return
actives.collapse('hide')
hasData || actives.data('bs.collapse', null)
}
var dimension = this.dimension()
this.$element
.removeClass('collapse')
.addClass('collapsing')[dimension](0)
this.transitioning = 1
var complete = function (e) {
if (e && e.target != this.$element[0]) return
this.$element
.removeClass('collapsing')
.addClass('collapse in')[dimension]('auto')
this.transitioning = 0
this.$element.trigger('shown.bs.collapse')
}
if (!$.support.transition) return complete.call(this)
var scrollSize = $.camelCase(['scroll', dimension].join('-'))
this.$element
.one($.support.transition.end, $.proxy(complete, this))
.emulateTransitionEnd(350)[dimension](this.$element[0][scrollSize])
}
Collapse.prototype.hide = function () {
if (this.transitioning || !this.$element.hasClass('in')) return
var startEvent = $.Event('hide.bs.collapse')
this.$element.trigger(startEvent)
if (startEvent.isDefaultPrevented()) return
var dimension = this.dimension()
this.$element[dimension](this.$element[dimension]())[0].offsetHeight
this.$element
.addClass('collapsing')
.removeClass('collapse')
.removeClass('in')
this.transitioning = 1
var complete = function (e) {
if (e && e.target != this.$element[0]) return
this.transitioning = 0
this.$element
.trigger('hidden.bs.collapse')
.removeClass('collapsing')
.addClass('collapse')
}
if (!$.support.transition) return complete.call(this)
this.$element
[dimension](0)
.one($.support.transition.end, $.proxy(complete, this))
.emulateTransitionEnd(350)
}
Collapse.prototype.toggle = function () {
this[this.$element.hasClass('in') ? 'hide' : 'show']()
}
// COLLAPSE PLUGIN DEFINITION
// ==========================
var old = $.fn.collapse
$.fn.collapse = function (option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.collapse')
var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
if (!data && options.toggle && option == 'show') option = !option
if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.collapse.Constructor = Collapse
// COLLAPSE NO CONFLICT
// ====================
$.fn.collapse.noConflict = function () {
$.fn.collapse = old
return this
}
// COLLAPSE DATA-API
// =================
$(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) {
var $this = $(this), href
var target = $this.attr('data-target')
|| e.preventDefault()
|| (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
//Edited by Uncode to replace ID in panel [START]
var _target = href.replace(/^#/, "");
if ( $('[data-id="' + _target + '"]').length ) {
var $target = $('[data-id="' + _target + '"]')
} else {
var $target = $(target)
}
//Edited by Uncode to replace ID in panel [END]
var data = $target.data('bs.collapse')
var option = data ? 'toggle' : $this.data()
var parent = $this.attr('data-parent')
var $parent = parent && $(parent)
if (!data || !data.transitioning) {
if ($parent) $parent.find('[data-toggle="collapse"][data-parent="' + parent + '"]').not($this).addClass('collapsed')
$this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
}
$target.collapse(option)
})
}(jQuery);
/* ========================================================================
* Bootstrap: tab.js v3.1.1
* http://getbootstrap.com/javascript/#tabs
* ========================================================================
* Copyright 2011-2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// TAB CLASS DEFINITION
// ====================
var Tab = function (element) {
this.element = $(element)
}
Tab.prototype.show = function () {
var $this = this.element
var $ul = $this.closest('ul:not(.dropdown-menu)')
var selector = $this.data('target')
if (!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
}
if ($this.parent('li').hasClass('active')) return
var previous = $ul.find('.active:last a')[0]
var e = $.Event('show.bs.tab', {
relatedTarget: previous
})
$this.trigger(e)
if (e.isDefaultPrevented()) return
//Edited by Uncode to replace ID in panel [START]
var _target = selector.replace(/^#/, "");
if ( $('[data-id="' + _target + '"]').length )
var $target = $('[data-id="' + _target + '"]')
else
var $target = $(selector)
//Edited by Uncode to replace ID in panel [END]
this.activate($this.parent('li'), $ul)
this.activate($target, $target.parent(), function () {
$this.trigger({
type: 'shown.bs.tab',
relatedTarget: previous
})
})
}
Tab.prototype.activate = function (element, container, callback) {
var $active = container.find('> .active')
var transition = callback
&& $.support.transition
&& $active.hasClass('fade')
function next() {
$active
.removeClass('active')
.find('> .dropdown-menu > .active')
.removeClass('active')
element.addClass('active')
if (transition) {
element[0].offsetWidth // reflow for transition
element.addClass('in')
} else {
element.removeClass('fade')
}
if (element.parent('.dropdown-menu')) {
element.closest('li.dropdown').addClass('active')
}
callback && callback()
}
transition ?
$active
.one($.support.transition.end, next)
.emulateTransitionEnd(150) :
next()
$active.removeClass('in')
}
// TAB PLUGIN DEFINITION
// =====================
var old = $.fn.tab
$.fn.tab = function ( option ) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.tab')
if (!data) $this.data('bs.tab', (data = new Tab(this)))
if (typeof option == 'string') data[option]()
})
}
$.fn.tab.Constructor = Tab
// TAB NO CONFLICT
// ===============
$.fn.tab.noConflict = function () {
$.fn.tab = old
return this
}
// TAB DATA-API
// ============
$(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
e.preventDefault()
$(this).tab('show')
})
}(jQuery);
/* ========================================================================
* Bootstrap: tooltip.js v3.1.1
* http://getbootstrap.com/javascript/#tooltip
* Inspired by the original jQuery.tipsy by Jason Frame
* ========================================================================
* Copyright 2011-2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// TOOLTIP PUBLIC CLASS DEFINITION
// ===============================
var Tooltip = function (element, options) {
this.type =
this.options =
this.enabled =
this.timeout =
this.hoverState =
this.$element = null
this.init('tooltip', element, options)
}
Tooltip.DEFAULTS = {
animation: true,
placement: 'top',
selector: false,
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
trigger: 'hover focus',
title: '',
delay: 0,
html: false,
container: false,
viewport: {
selector: 'body',
padding: 0
}
}
Tooltip.prototype.init = function (type, element, options) {
this.enabled = true
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport)
var triggers = this.options.trigger.split(' ')
for (var i = triggers.length; i--;) {
var trigger = triggers[i]
if (trigger == 'click') {
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (trigger != 'manual') {
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin'
var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
}
}
this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
this.fixTitle()
}
Tooltip.prototype.getDefaults = function () {
return Tooltip.DEFAULTS
}
Tooltip.prototype.getOptions = function (options) {
options = $.extend({}, this.getDefaults(), this.$element.data(), options)
if (options.delay && typeof options.delay == 'number') {
options.delay = {
show: options.delay,
hide: options.delay
}
}
return options
}
Tooltip.prototype.getDelegateOptions = function () {
var options = {}
var defaults = this.getDefaults()
this._options && $.each(this._options, function (key, value) {
if (defaults[key] != value) options[key] = value
})
return options
}
Tooltip.prototype.enter = function (obj) {
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
clearTimeout(self.timeout)
self.hoverState = 'in'
if (!self.options.delay || !self.options.delay.show) return self.show()
self.timeout = setTimeout(function () {
if (self.hoverState == 'in') self.show()
}, self.options.delay.show)
}
Tooltip.prototype.leave = function (obj) {
var self = obj instanceof this.constructor ?
obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
clearTimeout(self.timeout)
self.hoverState = 'out'
if (!self.options.delay || !self.options.delay.hide) return self.hide()
self.timeout = setTimeout(function () {
if (self.hoverState == 'out') self.hide()
}, self.options.delay.hide)
}
Tooltip.prototype.show = function () {
var e = $.Event('show.bs.' + this.type)
if (this.hasContent() && this.enabled) {
this.$element.trigger(e)
if (e.isDefaultPrevented()) return
var that = this;
var $tip = this.tip()
this.setContent()
if (this.options.animation) $tip.addClass('fade')
var placement = typeof this.options.placement == 'function' ?
this.options.placement.call(this, $tip[0], this.$element[0]) :
this.options.placement
var autoToken = /\s?auto?\s?/i
var autoPlace = autoToken.test(placement)
if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
$tip
.detach()
.css({ top: 0, left: 0, display: 'block' })
.addClass(placement)
this.options.container ? $tip.appendTo($(document).find(this.options.container)) : $tip.insertAfter(this.$element)
var pos = this.getPosition()
var actualWidth = $tip[0].offsetWidth
var actualHeight = $tip[0].offsetHeight
if (autoPlace) {
var orgPlacement = placement
var $parent = this.$element.parent()
var parentDim = this.getPosition($parent)
placement = placement == 'bottom' && pos.top + pos.height + actualHeight - parentDim.scroll > parentDim.height ? 'top' :
placement == 'top' && pos.top - parentDim.scroll - actualHeight < 0 ? 'bottom' :
placement == 'right' && pos.right + actualWidth > parentDim.width ? 'left' :
placement == 'left' && pos.left - actualWidth < parentDim.left ? 'right' :
placement
$tip
.removeClass(orgPlacement)
.addClass(placement)
}
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
this.applyPlacement(calculatedOffset, placement)
this.hoverState = null
var complete = function() {
that.$element.trigger('shown.bs.' + that.type)
}
$.support.transition && this.$tip.hasClass('fade') ?
$tip
.one($.support.transition.end, complete)
.emulateTransitionEnd(150) :
complete()
}
}
Tooltip.prototype.applyPlacement = function (offset, placement) {
var $tip = this.tip()
var width = $tip[0].offsetWidth
var height = $tip[0].offsetHeight
// manually read margins because getBoundingClientRect includes difference
var marginTop = parseInt($tip.css('margin-top'), 10)
var marginLeft = parseInt($tip.css('margin-left'), 10)
// we must check for NaN for ie 8/9
if (isNaN(marginTop)) marginTop = 0
if (isNaN(marginLeft)) marginLeft = 0
offset.top = offset.top + marginTop
offset.left = offset.left + marginLeft
// $.fn.offset doesn't round pixel values
// so we use setOffset directly with our own function B-0
$.offset.setOffset($tip[0], $.extend({
using: function (props) {
$tip.css({
top: Math.round(props.top),
left: Math.round(props.left)
})
}
}, offset), 0)
$tip.addClass('in')
// check to see if placing tip in new offset caused the tip to resize itself
var actualWidth = $tip[0].offsetWidth
var actualHeight = $tip[0].offsetHeight
if (placement == 'top' && actualHeight != height) {
offset.top = offset.top + height - actualHeight
}
var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
if (delta.left) offset.left += delta.left
else offset.top += delta.top
var arrowDelta = delta.left ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
var arrowPosition = delta.left ? 'left' : 'top'
var arrowOffsetPosition = delta.left ? 'offsetWidth' : 'offsetHeight'
$tip.offset(offset)
this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], arrowPosition)
}
Tooltip.prototype.replaceArrow = function (delta, dimension, position) {
this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + '%') : '')
}
Tooltip.prototype.setContent = function () {
var $tip = this.tip()
var title = this.getTitle()
$tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
$tip.removeClass('fade in top bottom left right')
}
Tooltip.prototype.hide = function () {
var that = this
var $tip = this.tip()
var e = $.Event('hide.bs.' + this.type)
function complete() {
if (that.hoverState != 'in') $tip.detach()
that.$element.trigger('hidden.bs.' + that.type)
}
this.$element.trigger(e)
if (e.isDefaultPrevented()) return
$tip.removeClass('in')
$.support.transition && this.$tip.hasClass('fade') ?
$tip
.one($.support.transition.end, complete)
.emulateTransitionEnd(150) :
complete()
this.hoverState = null
return this
}
Tooltip.prototype.fixTitle = function () {
var $e = this.$element
if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
$e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
}
}
Tooltip.prototype.hasContent = function () {
return this.getTitle()
}
Tooltip.prototype.getPosition = function ($element) {
$element = $element || this.$element
var el = $element[0]
var isBody = el.tagName == 'BODY'
return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : null, {
scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop(),
width: isBody ? $(window).width() : $element.outerWidth(),
height: isBody ? $(window).height() : $element.outerHeight()
}, isBody ? {top: 0, left: 0} : $element.offset())
}
Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
/* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
}
Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
var delta = { top: 0, left: 0 }
if (!this.$viewport) return delta
var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
var viewportDimensions = this.getPosition(this.$viewport)
if (/right|left/.test(placement)) {
var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll
var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
if (topEdgeOffset < viewportDimensions.top) { // top overflow
delta.top = viewportDimensions.top - topEdgeOffset
} else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
}
} else {
var leftEdgeOffset = pos.left - viewportPadding
var rightEdgeOffset = pos.left + viewportPadding + actualWidth
if (leftEdgeOffset < viewportDimensions.left) { // left overflow
delta.left = viewportDimensions.left - leftEdgeOffset
} else if (rightEdgeOffset > viewportDimensions.width) { // right overflow
delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
}
}
return delta
}
Tooltip.prototype.getTitle = function () {
var title
var $e = this.$element
var o = this.options
title = $e.attr('data-original-title')
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
return title
}
Tooltip.prototype.tip = function () {
return this.$tip = this.$tip || $(this.options.template)
}
Tooltip.prototype.arrow = function () {
return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')
}
Tooltip.prototype.validate = function () {
if (!this.$element[0].parentNode) {
this.hide()
this.$element = null
this.options = null
}
}
Tooltip.prototype.enable = function () {
this.enabled = true
}
Tooltip.prototype.disable = function () {
this.enabled = false
}
Tooltip.prototype.toggleEnabled = function () {
this.enabled = !this.enabled
}
Tooltip.prototype.toggle = function (e) {
var self = e ? $(e.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) : this
self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
}
Tooltip.prototype.destroy = function () {
clearTimeout(this.timeout)
this.hide().$element.off('.' + this.type).removeData('bs.' + this.type)
}
// TOOLTIP PLUGIN DEFINITION
// =========================
var old = $.fn.tooltip
$.fn.tooltip = function (option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.tooltip')
var options = typeof option == 'object' && option
if (!data && option == 'destroy') return
if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.tooltip.Constructor = Tooltip
// TOOLTIP NO CONFLICT
// ===================
$.fn.tooltip.noConflict = function () {
$.fn.tooltip = old
return this
}
}(jQuery);
/* ========================================================================
* Bootstrap: transition.js v3.1.1
* http://getbootstrap.com/javascript/#transitions
* ========================================================================
* Copyright 2011-2014 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
// ============================================================
function transitionEnd() {
var el = document.createElement('bootstrap')
var transEndEventNames = {
WebkitTransition : 'webkitTransitionEnd',
MozTransition : 'transitionend',
OTransition : 'oTransitionEnd otransitionend',
transition : 'transitionend'
}
for (var name in transEndEventNames) {
if (el.style[name] !== undefined) {
return { end: transEndEventNames[name] }
}
}
return false // explicit for ie8 ( ._.)
}
// http://blog.alexmaccaw.com/css-transitions
$.fn.emulateTransitionEnd = function (duration) {
var called = false, $el = this
$(this).one($.support.transition.end, function () { called = true })
var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
setTimeout(callback, duration)
return this
}
$(function () {
$.support.transition = transitionEnd()
})
}(jQuery);