From e6bf89d5cec8e27d3b65f3d12b61e16887675cdf Mon Sep 17 00:00:00 2001 From: david Date: Fri, 31 Aug 2012 15:58:19 +0000 Subject: [PATCH] Tarea #1054 -> Mejorar el rendimiento de la web git-svn-id: https://192.168.0.254/svn/Proyectos.ASong2U_Web/trunk@163 cd1a4ea2-8c7f-e448-aada-19d1fee9e1d6 --- wp-content/themes/score/footer.php | 2 +- wp-content/themes/score/functions.php | 8 +- wp-content/themes/score/header.php | 2 +- .../themes/score/lib/scripts/asong2u.js | 31 +- .../themes/score/lib/scripts/asong2u.min.js | 2 +- .../themes/score/lib/scripts/custom-ajax.js | 2 - .../themes/score/lib/scripts/custom.php | 9 +- .../lib/scripts/videoslider/js/froogaloop.js | 288 ++++++++++++++++++ .../scripts/videoslider/js/froogaloop.min.js | 8 +- .../videoslider/js/jquery.apVimeoPlayer.js | 5 +- wp-content/themes/score/video-slider.php | 6 +- 11 files changed, 328 insertions(+), 35 deletions(-) create mode 100644 wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.js diff --git a/wp-content/themes/score/footer.php b/wp-content/themes/score/footer.php index 9e0e83f..f64a046 100644 --- a/wp-content/themes/score/footer.php +++ b/wp-content/themes/score/footer.php @@ -73,6 +73,6 @@ - + \ No newline at end of file diff --git a/wp-content/themes/score/functions.php b/wp-content/themes/score/functions.php index 245b820..171e5f5 100644 --- a/wp-content/themes/score/functions.php +++ b/wp-content/themes/score/functions.php @@ -232,11 +232,13 @@ function gp_enqueue_scripts() { //wp_enqueue_script('prettyphoto', get_template_directory_uri() . '/lib/scripts/prettyPhoto/js/jquery.prettyPhoto.js', array('jquery')); - //wp_enqueue_script('jqtransform', get_template_directory_uri() . '/lib/scripts/jquery.jqtransform.js', array('jquery')); + wp_enqueue_script('jqtransform', get_template_directory_uri() . '/lib/scripts/jquery.jqtransform.js', array('jquery')); - //wp_enqueue_script('jqueryeasing', get_template_directory_uri() . '/lib/scripts/videoslider/js/jquery.easing.1.3.js', array('jquery')); + wp_enqueue_script('jqueryeasing', get_template_directory_uri() . '/lib/scripts/videoslider/js/jquery.easing.1.3.js', array('jquery')); - //wp_enqueue_script('froogaloop', get_template_directory_uri() . '/lib/scripts/videoslider/js/froogaloop.min.js', array('jquery')); + // Para Vimeo; + wp_enqueue_script('froogaloop', get_template_directory_uri() . '/lib/scripts/videoslider/js/froogaloop.min.js', array('jquery')); + //wp_enqueue_script('froogaloop', get_template_directory_uri() . '/lib/scripts/videoslider/js/froogaloop.js', array('jquery')); wp_enqueue_script('apPlaylistManager', get_template_directory_uri() . '/lib/scripts/videoslider/js/jquery.apPlaylistManager.min.js', array('jquery')); //wp_enqueue_script('apPlaylistManager', get_template_directory_uri() . '/lib/scripts/videoslider/js/jquery.apPlaylistManager.js', array('jquery')); diff --git a/wp-content/themes/score/header.php b/wp-content/themes/score/header.php index 509ce32..b4fc519 100644 --- a/wp-content/themes/score/header.php +++ b/wp-content/themes/score/header.php @@ -11,7 +11,7 @@ - + diff --git a/wp-content/themes/score/lib/scripts/asong2u.js b/wp-content/themes/score/lib/scripts/asong2u.js index 3d6dd46..fc33514 100644 --- a/wp-content/themes/score/lib/scripts/asong2u.js +++ b/wp-content/themes/score/lib/scripts/asong2u.js @@ -210,21 +210,23 @@ function shrinkTitle() textH1.style.fontSize -= 10+"px"; } -jQuery(window).ready(function() { - jQuery('#content-wrapper .post-loop .post-thumbnail a').live('click', function(e) { - e.preventDefault(); - var nParent = (jQuery(this).parent().parent()); - var classList = jQuery(nParent).attr('class').split(' '); - jQuery(classList).each(function(index, item) { - var id = item.replace('post-',''); - if (jQuery.isNumeric(id)) { - loadVideo(id); - jQuery('html, body').animate({ scrollTop: 0 }, 600); - return false; - } +jQuery(window).ready(function() { + if (jQuery('#slider-wrapper').length > 0 ) { + jQuery('#content-wrapper .post-loop .post-thumbnail a').live('click', function(e) { + e.preventDefault(); + var nParent = (jQuery(this).parent().parent()); + var classList = jQuery(nParent).attr('class').split(' '); + jQuery(classList).each(function(index, item) { + var id = item.replace('post-',''); + if (jQuery.isNumeric(id)) { + loadVideo(id); + jQuery('html, body').animate({ scrollTop: 0 }, 600); + return false; + } + }); + return false; }); - return false; - }); + } }); jQuery(document).ready(function(){ @@ -242,7 +244,6 @@ jQuery(document).ready(function(){ }); }); - jQuery(document).ready(function(){ setTimeout(function() { jQuery("#content-wrapper #message.updated").toggle('slow'); diff --git a/wp-content/themes/score/lib/scripts/asong2u.min.js b/wp-content/themes/score/lib/scripts/asong2u.min.js index e7da862..1b85857 100644 --- a/wp-content/themes/score/lib/scripts/asong2u.min.js +++ b/wp-content/themes/score/lib/scripts/asong2u.min.js @@ -11,6 +11,6 @@ b=oUrl+"id/"+b;jQuery("#dedicate_this_song_button").attr("href",b);jQuery("#fsbb jQuery("#dedication-data-panel").hide("fast");jQuery("#dedication-data-panel").slideUp("fast",function(){jQuery("#dedication-data-panel").html(c);jQuery("#dedicationTitle-data-panel").html(c)});jQuery("#dedication-data-panel").slideDown();jQuery("#dedicationFooter_container").slideUp("fast",function(){jQuery("#dedicationArtits").html(f);jQuery("#dedicationSong").html(g)});jQuery("#dedicationFooter_container").slideDown("fast",function(){});jQuery("#dedicationTitle").html(e);shrinkTitle();jQuery("#dedicationTitle a").jTypeWriter(); jQuery("#dedicationComments_container").slideUp("fast",function(){jQuery("#dedicationComments_container").load(h+" #comments","",function(){init_comments();jQuery("#dedicationComments_container").on("submit","#commentform",function(){prepare_new_comment_home();return!1})})});jQuery("#dedicationComments_container").slideDown();0b.offsetWidth;)size=parseInt(a.style.fontSize.replace("px","")),size-=1,a.style.fontSize=size+"px";a.style.fontSize-=NaN} -jQuery(window).ready(function(){jQuery("#content-wrapper .post-loop .post-thumbnail a").live("click",function(a){a.preventDefault();a=jQuery(this).parent().parent();a=jQuery(a).attr("class").split(" ");jQuery(a).each(function(a,e){var c=e.replace("post-","");if(jQuery.isNumeric(c))return loadVideo(c),jQuery("html, body").animate({scrollTop:0},600),!1});return!1})}); +jQuery(window).ready(function(){0/lib/scripts/videoslider/data/icons/thumb_backward_on.png', iconThumbBackwardVOn: '/lib/scripts/videoslider/data/icons/thumb_backward_v_on.png', videoGalleryPlayMedia: function(){ updateInfo(); }, + videoGallerySetupDone: function(){ }, videoGalleryPlaylistEnd: function(){ - loadVideo(0); + + loadVideo(0); + + redirect(); + } }); }; diff --git a/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.js b/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.js new file mode 100644 index 0000000..9090ea4 --- /dev/null +++ b/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.js @@ -0,0 +1,288 @@ +// Init style shamelessly stolen from jQuery http://jquery.com +var Froogaloop = (function(){ + // Define a local copy of Froogaloop + function Froogaloop(iframe) { + // The Froogaloop object is actually just the init constructor + return new Froogaloop.fn.init(iframe); + } + + var eventCallbacks = {}, + hasWindowEvent = false, + isReady = false, + slice = Array.prototype.slice, + playerDomain = ''; + + Froogaloop.fn = Froogaloop.prototype = { + element: null, + + init: function(iframe) { + if (typeof iframe === "string") { + iframe = document.getElementById(iframe); + } + + this.element = iframe; + + // Register message event listeners + playerDomain = getDomainFromUrl(this.element.getAttribute('src')); + + return this; + }, + + /* + * Calls a function to act upon the player. + * + * @param {string} method The name of the Javascript API method to call. Eg: 'play'. + * @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method + * or callback function when the method returns a value. + */ + api: function(method, valueOrCallback) { + if (!this.element || !method) { + return false; + } + + var self = this, + element = self.element, + target_id = element.id !== '' ? element.id : null, + params = !isFunction(valueOrCallback) ? valueOrCallback : null, + callback = isFunction(valueOrCallback) ? valueOrCallback : null; + + // Store the callback for get functions + if (callback) { + storeCallback(method, callback, target_id); + } + + postMessage(method, params, element); + return self; + }, + + /* + * Registers an event listener and a callback function that gets called when the event fires. + * + * @param eventName (String): Name of the event to listen for. + * @param callback (Function): Function that should be called when the event fires. + */ + addEvent: function(eventName, callback) { + if (!this.element) { + return false; + } + + var self = this, + element = self.element, + target_id = element.id !== '' ? element.id : null; + + + storeCallback(eventName, callback, target_id); + + // The ready event is not registered via postMessage. It fires regardless. + if (eventName != 'ready') { + postMessage('addEventListener', eventName, element); + } + else if (eventName == 'ready' && isReady) { + callback.call(null, target_id); + } + + return self; + }, + + /* + * Unregisters an event listener that gets called when the event fires. + * + * @param eventName (String): Name of the event to stop listening for. + */ + removeEvent: function(eventName) { + if (!this.element) { + return false; + } + + var self = this, + element = self.element, + target_id = element.id !== '' ? element.id : null, + removed = removeCallback(eventName, target_id); + + // The ready event is not registered + if (eventName != 'ready' && removed) { + postMessage('removeEventListener', eventName, element); + } + } + }; + + /** + * Handles posting a message to the parent window. + * + * @param method (String): name of the method to call inside the player. For api calls + * this is the name of the api method (api_play or api_pause) while for events this method + * is api_addEventListener. + * @param params (Object or Array): List of parameters to submit to the method. Can be either + * a single param or an array list of parameters. + * @param target (HTMLElement): Target iframe to post the message to. + */ + function postMessage(method, params, target) { + if (!target.contentWindow.postMessage) { + return false; + } + + var url = target.getAttribute('src').split('?')[0], + data = JSON.stringify({ + method: method, + value: params + }); + + if (url.substr(0, 2) === '//') { + url = window.location.protocol + url; + } + + target.contentWindow.postMessage(data, url); + } + + /** + * Event that fires whenever the window receives a message from its parent + * via window.postMessage. + */ + function onMessageReceived(event) { + var data, method; + + try { + data = JSON.parse(event.data); + method = data.event || data.method; + } + catch(e) { + //fail silently... like a ninja! + } + + if (method == 'ready' && !isReady) { + isReady = true; + } + + // Handles messages from moogaloop only + if (event.origin != playerDomain) { + return false; + } + + var value = data.value, + eventData = data.data, + target_id = target_id === '' ? null : data.player_id, + + callback = getCallback(method, target_id), + params = []; + + if (!callback) { + return false; + } + + if (value !== undefined) { + params.push(value); + } + + if (eventData) { + params.push(eventData); + } + + if (target_id) { + params.push(target_id); + } + + return params.length > 0 ? callback.apply(null, params) : callback.call(); + } + + + /** + * Stores submitted callbacks for each iframe being tracked and each + * event for that iframe. + * + * @param eventName (String): Name of the event. Eg. api_onPlay + * @param callback (Function): Function that should get executed when the + * event is fired. + * @param target_id (String) [Optional]: If handling more than one iframe then + * it stores the different callbacks for different iframes based on the iframe's + * id. + */ + function storeCallback(eventName, callback, target_id) { + if (target_id) { + if (!eventCallbacks[target_id]) { + eventCallbacks[target_id] = {}; + } + eventCallbacks[target_id][eventName] = callback; + } + else { + eventCallbacks[eventName] = callback; + } + } + + /** + * Retrieves stored callbacks. + */ + function getCallback(eventName, target_id) { + if (target_id) { + return eventCallbacks[target_id][eventName]; + } + else { + return eventCallbacks[eventName]; + } + } + + function removeCallback(eventName, target_id) { + if (target_id && eventCallbacks[target_id]) { + if (!eventCallbacks[target_id][eventName]) { + return false; + } + eventCallbacks[target_id][eventName] = null; + } + else { + if (!eventCallbacks[eventName]) { + return false; + } + eventCallbacks[eventName] = null; + } + + return true; + } + + /** + * Returns a domain's root domain. + * Eg. returns http://vimeo.com when http://vimeo.com/channels is sbumitted + * + * @param url (String): Url to test against. + * @return url (String): Root domain of submitted url + */ + function getDomainFromUrl(url) { + if (url.substr(0, 2) === '//') { + url = window.location.protocol + url; + } + + var url_pieces = url.split('/'), + domain_str = ''; + + for(var i = 0, length = url_pieces.length; i < length; i++) { + if(i<3) {domain_str += url_pieces[i];} + else {break;} + if(i<2) {domain_str += '/';} + } + + return domain_str; + } + + function isFunction(obj) { + return !!(obj && obj.constructor && obj.call && obj.apply); + } + + function isArray(obj) { + return toString.call(obj) === '[object Array]'; + } + + // Give the init function the Froogaloop prototype for later instantiation + Froogaloop.fn.init.prototype = Froogaloop.fn; + + // Listens for the message event. + // W3C + if (window.addEventListener) { + window.addEventListener('message', onMessageReceived, false); + } + // IE + else { + window.attachEvent('onmessage', onMessageReceived); + } + + // Expose froogaloop to the global object + return (window.Froogaloop = window.$f = Froogaloop); + +})(); \ No newline at end of file diff --git a/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.min.js b/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.min.js index 792e3c5..2041626 100644 --- a/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.min.js +++ b/wp-content/themes/score/lib/scripts/videoslider/js/froogaloop.min.js @@ -1,4 +1,4 @@ -var Froogaloop=function(){function g(a){return new g.fn.init(a)}function h(a,b,c){if(!c.contentWindow.postMessage)return!1;var f=c.getAttribute("src").split("?")[0];a=JSON.stringify({method:a,value:b});c.contentWindow.postMessage(a,f)}function i(a){if(a.origin!=playerDomain)return!1;var b=JSON.parse(a.data);a=b.value;var c=b.data,f=f==""?null:b.player_id;b=f?d[f][b.event||b.method]:d[b.event||b.method];var e=[];if(!b)return!1;a!==void 0&&e.push(a);c&&e.push(c);f&&e.push(f);return e.length>0?b.apply(null, -e):b.call()}function j(a,b,c){c?(d[c]||(d[c]={}),d[c][a]=b):d[a]=b}var d={},k=!1;g.fn=g.prototype={playerDomain:"",element:null,init:function(a){typeof a==="string"&&(a=document.getElementById(a));this.element=a;return this},api:function(a,b){if(!this.element||!a)return!1;var c=this.element,f=c.id!=""?c.id:null,e=!b||!b.constructor||!b.call||!b.apply?b:null,d=b&&b.constructor&&b.call&&b.apply?b:null;d&&j(a,d,f);h(a,e,c);return this},addEvent:function(a,b){if(!this.element)return!1;var c=this.element; -j(a,b,c.id!=""?c.id:null);a!="ready"&&h("addEventListener",a,c);if(k)return this;c=c.getAttribute("src").split("/");for(var d="",e=0,g=c.length;eb)c+=a[b];else break;2>b&&(c+="/")}k=c;return this},api:function(a,c){if(!this.element|| +!a)return!1;var b=this.element,f=""!==b.id?b.id:null,d=!c||!c.constructor||!c.call||!c.apply?c:null,e=c&&c.constructor&&c.call&&c.apply?c:null;e&&l(a,e,f);h(a,d,b);return this},addEvent:function(a,c){if(!this.element)return!1;var b=this.element,d=""!==b.id?b.id:null;l(a,c,d);"ready"!=a?h("addEventListener",a,b):"ready"==a&&i&&c.call(null,d);return this},removeEvent:function(a){if(!this.element)return!1;var c=this.element,b;a:{if((b=""!==c.id?c.id:null)&&d[b]){if(!d[b][a]){b=!1;break a}d[b][a]=null}else{if(!d[a]){b= +!1;break a}d[a]=null}b=!0}"ready"!=a&&b&&h("removeEventListener",a,c)}};e.fn.init.prototype=e.fn;window.addEventListener?window.addEventListener("message",j,!1):window.attachEvent("onmessage",j);return window.Froogaloop=window.$f=e}(); \ No newline at end of file diff --git a/wp-content/themes/score/lib/scripts/videoslider/js/jquery.apVimeoPlayer.js b/wp-content/themes/score/lib/scripts/videoslider/js/jquery.apVimeoPlayer.js index 2c4e999..e235847 100644 --- a/wp-content/themes/score/lib/scripts/videoslider/js/jquery.apVimeoPlayer.js +++ b/wp-content/themes/score/lib/scripts/videoslider/js/jquery.apVimeoPlayer.js @@ -41,10 +41,8 @@ _vimeoHolder.css('display', 'block'); _vimeoHolder.append(_vimeoVideoIframe); - _player = Froogaloop(_vimeoVideoIframe[0]); _player.addEvent('ready', onVimeoReady); - }; ap_VimeoPlayer.prototype = { @@ -84,14 +82,13 @@ } function onVimeoReady(playerID) { - //console.log('this._onVimeoReady'); _player.api('setVolume', _defaultVolume); _player.addEvent('finish', onVimeoFinish); if(!_inited){ _inited=true; } - if(_autoPlay) _player.api('play'); + if(_autoPlay) { _player.api('play'); } } function onVimeoFinish() { diff --git a/wp-content/themes/score/video-slider.php b/wp-content/themes/score/video-slider.php index 3cf2c52..7851e39 100644 --- a/wp-content/themes/score/video-slider.php +++ b/wp-content/themes/score/video-slider.php @@ -89,9 +89,11 @@ if (have_posts()) {
-
controls_prev
-
+ +
controls_prev
controls_next
+ +