Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- $(function() {
- // Manages changes in responsive layout
- var layout = (function() {
- var callbacks = [];
- // Container for checking changes in layout width
- var $container = $('body > div:eq(0) .container');
- // Container width: screen width
- var steps = {
- 960: 960,
- 714: 768,
- 451: 480,
- 294: 320
- };
- var width = $container.width();
- // On each step call all callbacks
- $(window)
- .on('resize', function() {
- var current = $container.width();
- if (current != width) {
- width = current;
- $.each(callbacks, function(id, callback) {
- callback(steps[width]);
- });
- }
- })
- .trigger('resize');
- // Interface
- return {
- // Returns current step
- width: function() {
- return steps[width];
- },
- // Register callback
- change: function(callback) {
- callback(steps[width]);
- callbacks.push(callback);
- }
- };
- })();
- // Header slider
- var header = (function() {
- var $slider = $('#header');
- var $slides = $('li', $slider);
- var $arrows = $('.arrow', $slider);
- var $left = $arrows.filter('.left');
- var $right = $arrows.filter('.right');
- var last = $slides.length - 1;
- var current = 0;
- var interval = null;
- var enabled = false;
- var playing = false;
- var background = false;
- // Setup
- var setup = {
- interval: 4000,
- speed: 500
- };
- // Go to current slide with crossfade effect
- function refresh() {
- var $old = $slides.filter(':visible')
- var $current = $slides.eq(current);
- // Swap background
- if (!background) {
- var url = $current.data('background');
- if (url)
- $slider.css('background-image', 'url(' + url + ')');
- }
- // Transition
- if (!$old.filter($current).length) {
- $slides.stop();
- $old.fadeOut(setup.speed);
- $current.fadeIn(setup.speed);
- }
- // Pause videos
- $.each(youtube.get(), function() {
- this.pauseVideo();
- });
- $.each(vimeo.get(), function() {
- this.api('pause');
- });
- };
- // Interface
- var slider = {
- // Go to slide
- set: function(slide) {
- slide = Math.max(0, Math.min(last, slide));
- if (slide != current) {
- current = slide;
- refresh();
- }
- },
- // Get current slide
- get: function() {
- return current;
- },
- // Previous slide
- left: function() {
- this.set(current ? current - 1 : last);
- },
- // Next slide
- right: function() {
- this.set(current < last ? current + 1 : 0);
- },
- // Start autoslide
- start: function() {
- this.stop();
- interval = setInterval(function() {
- if (!playing)
- slider.right();
- }, setup.interval);
- },
- // Stop autoslide
- stop: function() {
- clearInterval(interval);
- interval = null;
- },
- // Disable slider
- disable: function() {
- $arrows.hide();
- enabled = false;
- this.stop();
- this.set(0);
- },
- // Enable slider
- enable: function() {
- if ($slides.length > 1) {
- this.start();
- enabled = true;
- $arrows.show();
- }
- },
- // Enable/disable slider or return current state
- enabled: function(value) {
- if (typeof value == 'undefined')
- return enabled;
- if (!!value)
- this.enable();
- else
- this.disable();
- },
- // Show/hide slider or return current state
- visible: function(value) {
- if (typeof value == 'undefined')
- return $slider.is(':visible');
- else
- $slider.toggle(value);
- },
- // Initialisation
- init: function(settings) {
- youtube.init();
- vimeo.init();
- background = $slider.css('background-image') != 'none';
- refresh();
- if ($slides.length <= 1)
- return;
- setup = $.extend(setup, settings);
- $('.arrow.left', $slider).on('click', function() {
- slider.left();
- });
- $('.arrow.right', $slider).on('click', function() {
- slider.right();
- });
- $slider.on({
- mouseenter: function() {
- if (enabled)
- slider.stop();
- },
- mouseleave: function() {
- if (enabled)
- slider.start();
- }
- });
- $(document).on('youtubePlayerStateChange vimeoPlayerStateChange', function(event, state) {
- playing = state;
- });
- this.enable();
- }
- };
- return slider;
- })();
- // Form validation
- var validation = {
- // Any value
- any: function(value) {
- return !!$.trim(value).length;
- },
- // E-mail
- email: function(email) {
- return /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email);
- },
- // Validate form before submit
- init: function(form) {
- var $form = $(form);
- $form.on('submit', function() {
- var errors = 0;
- $('[data-require]', $form).each(function() {
- var $input = $(this);
- var value = $.trim($input.val());
- value = value == $input.data('placeholder') ? '' : value;
- var type = $.trim($input.data('require'));
- if (validation[type]) {
- var valid = validation[type](value);
- $input.toggleClass('error', !valid);
- errors += valid ? 0 : 1;
- }
- });
- $('.error', form).effect('shake', {times: 2, distance: 4}, 1300);
- return !errors;
- });
- }
- };
- // Initialisation
- var init = {
- // Menu
- menu: function() {
- layout.change(function(width) {
- if( width < 960 ) {
- // Switch menu appearance between list and combo
- $('#menu').toggleClass('small', false);
- $('#menu .right').toggleClass('combo', false);
- var $menu = $('#menu ul');
- var height = $menu.height();
- var lines = !height ? 0 : Math.round(height / parseInt($menu.css('line-height')));
- $('#menu').toggleClass('small', lines > 1);
- $('#menu .right').toggleClass('combo', lines > 1);
- // Set body padding
- var padding = $('#menu').height();
- $('body').css('padding-top', width >= 768 ? padding - 2 : 0);
- // Combo
- layout.change(function(width) {
- var $list = $('#menu ul');
- if (width <= 480)
- $list.hide();
- else
- $list.removeAttr('style');
- });
- }
- else {
- $('#menu').toggleClass('small', false);
- $('#menu .right').toggleClass('combo', false);
- }
- });
- // Scroll to section
- $('#menu ul a[href*="#"]').on('click', function() {
- var $link = $(this);
- var top = $(this.hash).offset().top - $('#menu').height();
- $('html, body').animate({scrollTop: top}, 500, function() {
- $('#menu ul li').removeClass('active');
- $link.parent().addClass('active');
- });
- $('#menu .combo').trigger('click');
- return false;
- });
- },
- // Waypoints
- waypoints: function() {
- layout.change(function(width) {
- // Select current section during scrolling
- $('#header, #works, #services, #members, #contact').waypoint({
- handler: function(event, direction) {
- var $item = $('#menu ul li')
- .removeClass('active')
- .find('[href*="#' + $(this).attr('id') + '"]')
- .parent()
- .addClass('active');
- },
- offset: width >= 768 ? $('#menu').height() : 0
- });
- });
- },
- // Header
- header: function() {
- if (!$('#header').length)
- return;
- header.init();
- var $fallbacks = $('#header .fallback img');
- var $fallback = $([]);
- var $slide = $('#header li:eq(0)');
- var $content = $('> *', $slide);
- layout.change(function(width) {
- if ($fallback.length) {
- $fallback.remove();
- $content.appendTo($slide);
- }
- if (width == 960) {
- header.enabled(true);
- header.visible(true);
- }
- else {
- header.enabled(false);
- $fallback = $fallbacks.filter('[data-resolution="' + width + '"]');
- header.visible(!!$fallback.length);
- if ($fallback.length) {
- $content.detach();
- $fallback
- .appendTo($slide)
- .css({
- marginTop: Math.round(($slide.height() - $fallback.height()) / 2),
- marginLeft: Math.round(($slide.width() - $fallback.width()) / 2)
- });
- }
- }
- });
- },
- // Buttons
- buttons: function() {
- // Required elements
- $('a.button').each(function() {
- $(this)
- .wrapInner('<span class="text" />')
- .prepend([
- '<span class="normal"></span>',
- '<span class="hover"></span>'
- ].join(''));
- });
- // Hover effect
- $('body').on({
- mouseenter: function() {
- $('.hover', this).stop().fadeIn(250);
- },
- mouseleave: function() {
- $('.hover', this).stop().fadeOut(250);
- }
- }, 'a.button');
- },
- // Works list
- works: function() {
- if (!$('#works').length)
- return;
- var $list = $('#works .list');
- var $cache = $('li', $list.clone());
- var steps = {
- 960: 12,
- 768: 12, //9,
- 480: 6,
- 320: 3
- };
- var count = steps[layout.width()];
- var $all = $('#works .all');
- $('#works .menu').on('click', 'li a', function() {
- // Filter list by selected category
- var $link = $(this);
- var category = $link.attr('data-category');
- var $filter = $([]);
- if (category == 'all')
- $filter = $cache;
- else
- $cache.each(function() {
- var categories = $(this).attr('data-category').split(',');
- if ($.inArray(category, categories) != -1)
- $filter = $filter.add(this);
- });
- $all.toggle($filter.length > count);
- $filter = $filter.filter('li:lt(' + count + ')');
- $list.quicksand($filter);
- // Highlight current category in menu
- $link
- .closest('li')
- .addClass('active')
- .siblings()
- .removeClass('active');
- // Close combo
- $('#works .combo.open').trigger('click');
- return false;
- });
- layout.change(function(width) {
- // Switch menu appearance between list and combo
- $('#works .menu').toggleClass('combo', width <= 480);
- // Change count of visible works
- count = steps[width];
- $('li:gt(' + (count - 1) + ')', $list).hide();
- $('#works .menu .active a').trigger('click');
- $all.toggle(count < 12);
- });
- // Show all works
- $('a', $all).on('click', function() {
- count = 12;
- $('#works .menu .active a').trigger('click');
- $all.hide();
- return false;
- });
- // Hover
- $('#works .list').on({
- mouseenter: function() {
- var $hover = $('.hover', this);
- if (!$hover.length)
- $hover = $('<div class="hover" />').appendTo(this);
- $hover
- .stop()
- .hide()
- .fadeIn();
- },
- mouseleave: function() {
- var $hover = $('.hover', this);
- $hover
- .stop()
- .fadeOut(250, function() {
- $hover.remove();
- });
- }
- }, 'a');
- // Combo
- $('<p />')
- .text($('#works .menu li:eq(0)').text())
- .prependTo('#works .menu');
- $('#works .menu a').on('click', function() {
- $(this)
- .closest('.combo')
- .find('p')
- .text($(this).text());
- });
- layout.change(function(width) {
- var $list = $('#works .menu ul');
- if (width <= 480)
- $list.hide();
- else
- $list.removeAttr('style');
- });
- },
- // Combobox
- combo: function() {
- $(document).on('click', '.combo', function(event) {
- $('.combo.open')
- .not(this)
- .trigger('click');
- var $combo = $(this);
- var $list = $('ul', this);
- var open = $list.is(':visible');
- $list
- .stop(true, true)
- .fadeToggle(250);
- $combo.toggleClass('open', !open);
- return $(event.target).is('a');
- });
- $(document).on('click', function() {
- $('.combo.open').trigger('click');
- });
- },
- // Services
- services: function() {
- if (!$('#services').length)
- return;
- // Services carousel
- layout.change(function(width) {
- $('#services .list .items').carouFredSel(
- {
- width: '100%',
- height: 'auto',
- align: width <= 480 ? 'left' : 'center',
- prev: '#services .list .left',
- next: '#services .list .right',
- scroll: {
- items: 1,
- pauseOnHover: true
- },
- auto: {
- play: width <= 480
- },
- items: {
- visible: width <= 480 ? 1 : 4
- }
- },
- {
- wrapper: {
- classname: 'wrapper'
- }
- }
- );
- $('#services .list li').css('opacity', 1);
- });
- // Services slider
- $('#services .menu img').on('mouseenter', function() {
- var $item = $(this).closest('li');
- $item
- .siblings()
- .find('.spike:visible')
- .stop()
- .fadeOut(500);
- $item
- .find('.spike')
- .stop()
- .fadeIn(500);
- $('#services .list li')
- .filter(':visible')
- .stop()
- .animate({opacity: 0}, 500)
- .end()
- .eq($item.index())
- .stop()
- .animate({opacity: 1}, 500);
- });
- layout.change(function(width) {
- if (width == 768)
- $('#services .list li').removeAttr('style');
- });
- // Pricing table
- if ($('#services .pricing').length)
- layout.change(function(width) {
- $('#services .pricing .items').carouFredSel(
- {
- width: '100%',
- height: 'auto',
- align: width <= 480 ? 'left' : 'center',
- prev: '#services .pricing .left',
- next: '#services .pricing .right',
- scroll: {
- items: 1,
- pauseOnHover: true
- },
- auto: {
- play: width <= 480
- },
- items: {
- visible: width <= 480 ? 1 : 4
- }
- },
- {
- wrapper: {
- classname: 'wrapper'
- }
- }
- );
- });
- },
- // Team members slider
- members: function() {
- if (!$('#members').length)
- return;
- var items = $('#members li').length;
- layout.change(function(width) {
- $('#members .items').carouFredSel(
- {
- width: '100%',
- height: 'auto',
- align: width > 480 ? 'center' : (items == 1 ? 'center' : 'left'),
- prev: '#members .left',
- next: '#members .right',
- items: {
- visible: width == 320 ? 1 : 4
- },
- scroll: {
- items: 1,
- pauseOnHover: true
- },
- auto: {
- play: width == 320
- }
- },
- {
- wrapper: {
- classname: 'wrapper'
- }
- }
- );
- });
- },
- // Clients slider
- clients: function() {
- if (!$('#clients').length)
- return;
- layout.change(function(width) {
- $('#clients .items').carouFredSel({
- width: '100%',
- align: 'left',
- prev: '#clients .left',
- next: '#clients .right',
- items: {
- visible: width <= 480 ? 1 : '+1'
- },
- scroll: {
- items: 1,
- pauseOnHover: true
- }
- },
- {
- wrapper: {
- classname: 'carousel'
- }
- });
- });
- },
- // Contact form
- contact: function() {
- if (!$('#contact').length)
- return;
- // Validation
- validation.init('#contact form');
- // Scroll to contact
- $("#contact_us .button").on('click', function() {
- $('#menu a[href="#contact"]').trigger('click');
- return false;
- });
- // Submit form
- $('#contact form .submit').on('click', function() {
- $('#contact form').trigger('submit');
- return false;
- });
- // Get map position
- var $map = $('#contact .map');
- var latitude = parseFloat($map.attr('data-latitude').replace(',', '.'));
- var longtitude = parseFloat($map.attr('data-longtitude').replace(',', '.'));
- var center = new google.maps.LatLng(latitude - 0.003105999999997721, longtitude);
- // Render map
- var map = new google.maps.Map($map[0], {
- zoom: 16,
- scrollwheel: false,
- center: center,
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControl: false,
- panControlOptions: {
- position: google.maps.ControlPosition.LEFT_CENTER
- },
- zoomControlOptions: {
- position: google.maps.ControlPosition.LEFT_CENTER
- },
- scaleControlOptions: {
- position: google.maps.ControlPosition.LEFT_CENTER
- }
- });
- // Center map on window resize
- google.maps.event.addDomListener(window, 'resize', function() {
- map.setCenter(center);
- });
- // Custom marker
- new google.maps.Marker({
- draggable: false,
- map: map,
- shape: {
- coord: [63, 0, 68, 1, 72, 2, 75, 3, 77, 4, 80, 5, 81, 6, 83, 7, 85, 8, 86, 9, 88, 10, 89, 11, 90, 12, 91, 13, 93, 14, 94, 15, 95, 16, 95, 17, 96, 18, 97, 19, 98, 20, 99, 21, 99, 22, 100, 23, 101, 24, 101, 25, 102, 26, 103, 27, 103, 28, 104, 29, 104, 30, 104, 31, 105, 32, 105, 33, 106, 34, 106, 35, 106, 36, 107, 37, 107, 38, 107, 39, 107, 40, 108, 41, 108, 42, 108, 43, 108, 44, 108, 45, 109, 46, 109, 47, 109, 48, 109, 49, 109, 50, 109, 51, 109, 52, 109, 53, 109, 54, 109, 55, 109, 56, 109, 57, 109, 58, 109, 59, 109, 60, 109, 61, 109, 62, 109, 63, 108, 64, 108, 65, 108, 66, 108, 67, 108, 68, 107, 69, 107, 70, 107, 71, 107, 72, 106, 73, 106, 74, 106, 75, 105, 76, 105, 77, 104, 78, 104, 79, 104, 80, 103, 81, 103, 82, 102, 83, 101, 84, 101, 85, 100, 86, 99, 87, 99, 88, 98, 89, 97, 90, 96, 91, 95, 92, 95, 93, 94, 94, 93, 95, 91, 96, 90, 97, 89, 98, 88, 99, 86, 100, 85, 101, 83, 102, 82, 103, 80, 104, 77, 105, 75, 106, 72, 107, 68, 108, 63, 109, 46, 109, 41, 108, 37, 107, 34, 106, 32, 105, 29, 104, 27, 103, 26, 102, 24, 101, 23, 100, 21, 99, 20, 98, 19, 97, 18, 96, 16, 95, 15, 94, 14, 93, 14, 92, 13, 91, 12, 90, 11, 89, 10, 88, 10, 87, 9, 86, 8, 85, 8, 84, 7, 83, 6, 82, 6, 81, 5, 80, 5, 79, 5, 78, 4, 77, 4, 76, 3, 75, 3, 74, 3, 73, 2, 72, 2, 71, 2, 70, 2, 69, 1, 68, 1, 67, 1, 66, 1, 65, 1, 64, 0, 63, 0, 62, 0, 61, 0, 60, 0, 59, 0, 58, 0, 57, 0, 56, 0, 55, 0, 54, 0, 53, 0, 52, 0, 51, 0, 50, 0, 49, 0, 48, 0, 47, 0, 46, 1, 45, 1, 44, 1, 43, 1, 42, 1, 41, 2, 40, 2, 39, 2, 38, 2, 37, 3, 36, 3, 35, 3, 34, 4, 33, 4, 32, 5, 31, 5, 30, 5, 29, 6, 28, 6, 27, 7, 26, 8, 25, 8, 24, 9, 23, 10, 22, 10, 21, 11, 20, 12, 19, 13, 18, 14, 17, 14, 16, 15, 15, 16, 14, 18, 13, 19, 12, 20, 11, 21, 10, 23, 9, 24, 8, 26, 7, 28, 6, 29, 5, 32, 4, 34, 3, 37, 2, 41, 1, 46, 0, 63, 0],
- type: 'poly'
- },
- icon: new google.maps.MarkerImage(
- template_directory_uri + '/img/marker.png',
- new google.maps.Size(110, 110),
- new google.maps.Point(0, 0),
- new google.maps.Point(55, 110)
- ),
- position: new google.maps.LatLng(latitude, longtitude)
- });
- },
- // Input placeholders
- placeholders: function() {
- $(document).on({
- focus: function() {
- var $input = $(this);
- if ($.trim($input.val()) == $input.data('placeholder'))
- $input
- .val('')
- .removeClass('placeholder');
- },
- blur: function() {
- var $input = $(this);
- if (!$.trim($input.val()))
- $input
- .val($input.data('placeholder'))
- .addClass('placeholder');
- },
- change: function() {
- var $input = $(this);
- return $input.val() != $input.data('placeholder');
- },
- keydown: function(event) {
- if (event.which == 27)
- $(this)
- .val('')
- .trigger('keyup')
- .trigger('blur');
- }
- }, '[data-placeholder]');
- $('[data-placeholder]').each(function() {
- var $input = $(this);
- var value = $.trim($input.val());
- if (!value || value == $input.data('placeholder'))
- $input
- .val('')
- .trigger('blur');
- });
- },
- // Social ico hover
- social: function() {
- $('a.social').each(function() {
- $(this).append('<span class="hover" />');
- });
- $(document).on({
- mouseenter: function() {
- $('.hover', this).stop().fadeIn(250);
- },
- mouseleave: function() {
- $('.hover', this).stop().fadeOut(250);
- }
- }, 'a.social');
- },
- // Work detail page
- detail: function() {
- function refresh() {
- $('#slider .slider, #slider ul, #slider li').removeAttr('style');
- $('#slider ul').carouFredSel(
- {
- prev: '#slider .left',
- next: '#slider .right',
- responsive: true,
- align: 'center',
- items: {
- visible: 1,
- },
- scroll: {
- fx: 'crossfade',
- items: 1,
- pauseOnHover: true
- },
- // Workaround due to issues with height after window resize
- height: $('#slider li:eq(0) img').height()
- },
- {
- wrapper: {
- classname: 'slider'
- }
- }
- );
- }
- $('#slider img').imagesLoaded(function() {
- $('#slider').addClass('loaded');
- refresh();
- $(window).on('resize', refresh);
- });
- },
- blog: function() {
- // Navigation
- $('<p />')
- .text($('#navigation .menu li:eq(0)').text())
- .prependTo('#navigation .menu');
- $('#navigation .menu a').on('click', function() {
- $(this)
- .closest('.combo')
- .find('p')
- .text($(this).text());
- });
- // Switch menu appearance between list and combo
- layout.change(function(width) {
- $('#navigation .menu').toggleClass('combo', width <= 480);
- var $list = $('#navigation .menu ul');
- if (width <= 480)
- $list.hide();
- else
- $list.removeAttr('style');
- });
- // Validation
- validation.init('#commentform');
- // Reply
- $('#commentform .send').on('click', function() {
- $(this)
- .closest('form')
- .find('[type="submit"]')
- .trigger('click');
- });
- }
- };
- // Initialization
- switch ($('body').attr('id')) {
- // Home page
- case 'home':
- init.menu();
- init.waypoints();
- init.header();
- init.buttons();
- init.works();
- init.combo();
- init.services();
- init.members();
- init.clients();
- init.contact();
- init.placeholders();
- init.social();
- break;
- // Work detail page
- case 'detail':
- init.buttons();
- init.social();
- init.detail();
- break;
- // Blog
- case 'blog':
- init.menu();
- init.header();
- init.buttons();
- init.combo();
- init.placeholders();
- init.social();
- init.blog();
- }
- });
- })(jQuery);
- // Youtube videos
- var youtube = (function($) {
- // Youtube player references
- var players = [];
- var count = 0;
- // Loop through elements with video URL stored in attribute data-youtube and replace them with embedded videos
- function embed() {
- $('#header [data-youtube]').each(function() {
- var $placeholder = $(this);
- var playerId = 'youtubePlayer' + count++;
- var videoId = youtube.parse($placeholder.data('youtube'));
- $placeholder.attr('id', playerId);
- new YT.Player(playerId, {
- height: '100%',
- width: '100%',
- videoId: videoId,
- playerVars: {
- rel: 0
- },
- events: {
- onReady: ready,
- onStateChange: stateChange
- }
- });
- });
- }
- // Load youtube video API
- function loadApi() {
- var script = document.createElement('script');
- script.src = "//www.youtube.com/iframe_api";
- var firstScript = document.getElementsByTagName('script')[0];
- firstScript.parentNode.insertBefore(script, firstScript);
- }
- // Save referrence to youtube player
- function ready(event) {
- players.push(event.target);
- }
- // On state change trigger event on document object
- function stateChange(event) {
- var state = (event.data == YT.PlayerState.PLAYING);
- $(document).trigger('youtubePlayerStateChange', state);
- }
- // Interface
- return {
- // Get video id from youtube video URL
- parse: function(url) {
- var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
- var match = url.match(regExp);
- if (match && match[7].length == 11)
- return match[7];
- else
- throw 'youtube.parse: "Incorrect URL' + (url ? '(' + url + ')' : '') + '"';
- },
- // Get player instances
- get: function() {
- return players;
- },
- // Youtube videos initialisation
- init: function() {
- if ($('#header [data-youtube]').length) {
- window.onYouTubeIframeAPIReady = function() {
- embed();
- };
- loadApi();
- }
- }
- };
- })(jQuery);
- // Vimeo videos
- var vimeo = (function($) {
- // Vimeo player references
- var players = [];
- var count = 0;
- // Loop through elements with video URL stored in attribute data-vimeo and replace them with embedded videos
- function embed() {
- $('#header [data-vimeo]').each(function() {
- var $placeholder = $(this);
- var playerId = 'vimeoPlayer' + count++;
- var videoId = vimeo.parse($placeholder.data('vimeo'));
- $placeholder.attr('id', playerId);
- var $player = $('<iframe />').attr({
- src: 'http://player.vimeo.com/video/' + videoId + '?api=1&player_id=' + playerId,
- id: playerId,
- width: '100%',
- height: '100%',
- frameborder: 0,
- webkitAllowFullScreen: 'webkitAllowFullScreen',
- mozallowfullscreen: 'mozallowfullscreen',
- allowFullScreen: 'allowFullScreen'
- });
- $placeholder.replaceWith($player);
- var player = $f($player[0]);
- player.addEvent('ready', function() {
- ready(player);
- });
- });
- }
- // Load vimeo video API
- function loadApi(callback) {
- $.getScript('http://a.vimeocdn.com/js/froogaloop2.min.js', function() {
- callback();
- });
- }
- // Set events and save referrence to vimeo player
- function ready(player) {
- player.addEvent('play', function() {
- stateChange(true);
- });
- player.addEvent('pause', function() {
- stateChange(false);
- });
- player.addEvent('finish', function() {
- stateChange(false);
- });
- players.push(player);
- }
- // On state change trigger event on document object
- function stateChange(state) {
- $(document).trigger('vimeoPlayerStateChange', state);
- }
- // Interface
- return {
- // Get video id from vimeo video URL
- parse: function(url) {
- var regExp = /^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/;
- var match = regExp.exec(url);
- if (match && match[5].length == 8)
- return match[5];
- else
- throw 'vimeo.parse: "Incorrect URL' + (url ? '(' + url + ')' : '') + '"';
- },
- // Get player instances
- get: function() {
- return players;
- },
- // Vimeo videos initialisation
- init: function() {
- if ($('#header [data-vimeo]').length)
- loadApi(function() {
- embed();
- });
- }
- };
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement