com web/php: Merged and optimized JavaScript. Also removed jQuery UI dependency. Users are reporting slow load-times; this is an effort to improve the
situation. Missing features include auto-complete and highlighting a user note when clicking on a link to it.: include/footer.inc include/header.inc
js/common.js js/jquery.scrollto.min.js js/usernotes.js

From: Date: Wed, 24 Jul 2013 22:03:00 +0000
Subject: com web/php: Merged and optimized JavaScript. Also removed jQuery UI dependency. Users are reporting slow load-times; this is an effort to improve the
situation. Missing features include auto-complete and highlighting a user note when clicking on a link to it.: include/footer.inc include/header.inc
js/common.js js/jquery.scrollto.min.js js/usernotes.js
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-16373@lists.php.net to get a copy of this message
Commit: 613a15b4954034a65072cd78d007072221779998 Author: Levi Morrison <levim@php.net> Wed, 24 Jul 2013 16:03:00 -0600 Parents: c9ee02900ed89e5de45bec513c1ce3b27e758758 Branches: responsive Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=613a15b4954034a65072cd78d007072221779998 Log: Merged and optimized JavaScript. Also removed jQuery UI dependency. Users are reporting slow load-times; this is an effort to improve the situation. Missing features include auto-complete and highlighting a user note when clicking on a link to it. Changed paths: M include/footer.inc M include/header.inc M js/common.js D js/jquery.scrollto.min.js D js/usernotes.js

diff --git a/include/footer.inc b/include/footer.inc index 9258d2c..fd635c4 100644 --- a/include/footer.inc +++ b/include/footer.inc @@ -42,8 +42,10 @@ } ?> - <script type="text/javascript" src="/js/jquery.scrollto.min.js"></script> + <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> + <script type="text/javascript" src="/js/common.js<?php echo $v?>"></script> + <?php include 'uservoice.inc' ?> </body> </html> diff --git a/include/header.inc b/include/header.inc index 7101fd2..f3b507c 100644 --- a/include/header.inc +++ b/include/header.inc @@ -42,7 +42,6 @@ if (isset($shortname) && $shortname) { <link rel="stylesheet" type="text/css" href="<?php echo $STATIC_ROOT ?>styles/bootstrap.css<?php echo $v?>" media="all" /> <link rel="stylesheet" type="text/css" href="<?php echo $STATIC_ROOT ?>styles/theme.css<?php echo $v?>" media="screen" /> <link rel="stylesheet" type="text/css" href="<?php echo $STATIC_ROOT ?>styles/doc.css<?php echo $v?>" media="screen" /> - <link rel="stylesheet" type="text/css" href="<?php echo $STATIC_ROOT ?>styles/dynamic.php<?php echo $v?>" media="screen" /> <?php if(isset($config['css']) && is_array($config['css'])): @@ -66,17 +65,6 @@ if (isset($shortname) && $shortname) { <script type="text/javascript" src="<?php echo $STATIC_ROOT ?>js/ext/html5.js<?php echo $v?>"></script> <![endif]--> - <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> - <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script> - <script type="text/javascript"> - if (typeof jQuery == 'undefined') { - document.write('<script type="text/javascript" src="<?php echo $STATIC_ROOT ?>js/ext/jquery-1.7.2.min.js"><' + '/script>'); - document.write('<script type="text/javascript" src="<?php echo $STATIC_ROOT ?>js/ext/jquery-ui-1.8.7.min.js"><' + '/script>'); - } - </script> - <script type="text/javascript" src="<?php echo $STATIC_ROOT ?>js/ext/jquery.ui.totop.js"></script> - <script type="text/javascript" src="<?php echo $STATIC_ROOT ?>js/common.js<?php echo $v?>"></script> - <script type="text/javascript" src="<?php echo $STATIC_ROOT ?>js/usernotes.js"></script> <?php if (!empty($_SERVER["BASE_HREF"])): ?> <base href="<?php echo $_SERVER["BASE_HREF"] ?>" /> <?php endif ?> @@ -110,13 +98,6 @@ if (isset($shortname) && $shortname) { </div> </nav> -<div id='mega-drop-down'> - <div id='menu-container'> - </div> -</div> - -<?php include 'uservoice.inc' ?> - <?php if (!empty($config['intro'])):?> <div id="intro"> <div class="container"> diff --git a/js/common.js b/js/common.js index 2153f8a..e9e8106 100644 --- a/js/common.js +++ b/js/common.js @@ -1,6 +1,19 @@ +/* Plugins, etc, are on top. */ + +/** {{{ + * jQuery.ScrollTo - Easy element scrolling using jQuery. + * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com + * Dual licensed under MIT and GPL. + * Date: 5/25/2009 + * @author Ariel Flesler + * @version 1.4.2 + * + * http://flesler.blogspot.com/2007/10/jqueryscrollto.html + */ +;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery); +/*}}}*/ $(document).ready(function() { - // Ugh, cookie handling. var cookies = document.cookie.split(";"); var showBetaWarning = true; @@ -34,102 +47,6 @@ $(document).ready(function() { }); } - // load the search index and enable auto-complete. - jQuery.getScript("/search-index.php?lang=" + getLanguage(), function(){ - var haveDesc = 0; - jQuery.getScript("/search-index.php?lang=" + getLanguage() + "&description=1", function(){ - haveDesc = 1; - }); - $.widget("custom.catcomplete", $.ui.autocomplete, { - /* - // Print out category headers rather then in () after the match - _renderMenu: function(ul, items) { - var self = this, currentCategory = ""; - $.each(items, function(index, item) { - if (item.category != currentCategory) { - var cat = self._resolveIndexName(item.category); - ul.append("<li class='ui-autocomplete-category'>" + cat + "</li>"); - currentCategory = item.category; - } - - self._renderItem(ul, item); - }); - }, - */ - _renderItem: function(ul, item) { - var n = $("<li></li>").data("item.autocomplete", item); - var cat = this._resolveIndexName(item.category); - if (item.desc) { - n.append("<a><span class='search-item-label'>" + item.label + " <span class='search-item-category'>(" + cat + ")</span></span><span class='search-item-description'>" + item.desc + "</span></a>"); - } - else { - n.append("<a>" + item.label + " (" + cat + ") </a>"); - } - - return n.appendTo(ul); - }, - // Resolve the element names to human understandable things - _resolveIndexName: function(key) { - var indexes = { - 'phpdoc:varentry': 'Variables', - 'phpdoc:classref': 'Classes', - 'phpdoc:exceptionref': 'Exceptions', - 'refentry': 'Functions' - }; - return indexes[key] || key; - } - }); - $('#headsearch-keywords').catcomplete({ - delay: 50, - minScore: 50, - maxResults: 20, - source: function(request, response){ - var term = request.term; - var minScore = this.options.minScore; - - // Score an possible match - var score = function(item){ - var match = item.search(new RegExp(term, "i")); - if (match < 0) return 0; - return 100 - (match * 2) - (item.length - term.length); - }; - - var results = []; - $.each(searchIndex, function(idx, item) { - var itemScore = score(item[0]); - if (item && itemScore > minScore) { - results.push({ - label: item[0], - value: item[1], - desc: haveDesc ? descriptionIndex[item[1]] : '', - category: item[2], - score: itemScore - }); - } - }); - - // Only sort the matches - results.sort(function(a, b){ - return b.score - a.score; - }); - - // Return at most maxResults - response(results.slice(0, this.options.maxResults)); - }, - focus: function(event, ui) { - $('#headsearch-keywords').val(ui.item.label); - return false; - }, - select: function(event, ui){ - event.preventDefault(); - $('#headsearch-keywords').val(ui.item.label); - if (ui.item.value) { - window.location = '/manual/' + getLanguage() + '/' + ui.item.value + '.php'; - } - } - }); - }); - var $docs = $('.docs'); var $refsect1 = $docs.find('.refentry .refsect1'); var $docsDivWithId = $docs.find('div[id]'); @@ -226,9 +143,102 @@ $(document).ready(function() { $this.remove(); } }); - - $().UItoTop({ easingType: 'easeOutQuart' }); - + +/*{{{ Scroll to top */ + (function() { + var settings = { + text: 'To Top', + min: 200, + inDelay:600, + outDelay:400, + containerID: 'toTop', + containerHoverID: 'toTopHover', + scrollSpeed: 400, + easingType: 'linear' + }; + var containerIDhash = '#' + settings.containerID; + var containerHoverIDHash = '#'+settings.containerHoverID; + + $('body').append('<a href="#" id="'+settings.containerID+'" onclick="return false;">'+settings.text+'</a>'); + $(containerIDhash).hide().click(function(){ + $('html, body').animate({scrollTop:0}, settings.scrollSpeed, settings.easingType); + $('#'+settings.containerHoverID, this).stop().animate({'opacity': 0 }, settings.inDelay, settings.easingType); + return false; + }) + .prepend('<span id="'+settings.containerHoverID+'"></span>') + .hover(function() { + $(containerHoverIDHash, this).stop().animate({ + 'opacity': 1 + }, 600, 'linear'); + }, function() { + $(containerHoverIDHash, this).stop().animate({ + 'opacity': 0 + }, 700, 'linear'); + }); + + $(window).scroll(function() { + var sd = $(window).scrollTop(); + if (typeof document.body.style.maxHeight === "undefined") { + $(containerIDhash).css({ + 'position': 'absolute', + 'top': $(window).scrollTop() + $(window).height() - 50 + }); + } + if ( sd > settings.min ) { + $(containerIDhash).fadeIn(settings.inDelay); + } else { + $(containerIDhash).fadeOut(settings.outDelay); + } + }); + + })(); +/*}}}*/ + +/*{{{User Notes*/ + $("#usernotes a.usernotes-voteu, #usernotes a.usernotes-voted").each( + function () { + $(this).click( + function (event) { + event.preventDefault(); + var url = $(this).attr("href"); + var id = url.match(/\?id=(\d+)/)[1]; + var request = $.ajax({ + type: "POST", + url: url, + dataType: "json", + headers: {"X-Json": "On" }, + beforeSend: function() { + $("#Vu"+id).hide(); + $("#Vd"+id).hide(); + $("#V"+id).html("<img src=\"/images/working.gif\" alt=\"Working...\" border=\"0\" title=\"Working...\" />"); + } + }); + request.done(function(data) { + if(data.success != null && data.success == true) { + $("#V"+id).html("<div style=\"float: left; width: 16px; height: 16px; background-image: url(/images/notes-features.png); background-position:-32px 16px; margin-right: 8px; overflow: hidden;\" border=\"0\" alt=\"success\" title=\"Thank you for voting!\"></div>" + data.update); + } + else { + var responsedata = "Error :("; + if (data.msg != null) { + responsedata = data.msg; + } + $("#V"+id).html("<div style=\"float: left; width: 16px; height: 16px; background-image: url(/images/notes-features.png); background-position:-32px 0px; margin-right: 8px; overflow: hidden;\" border=\"0\" alt=\"fail\" title=\"" + responsedata + "\"></div>"); + } + }); + request.fail(function(jqXHR, textStatus) { + $("#Vu"+id).show(); + $("#Vd"+id).show(); + $("#V"+id).html("<div style=\"float: left; width: 16px; height: 16px; background-image: url(/images/notes-features.png); background-position:-32px 0px; margin-right: 8px; overflow: hidden;\" border=\"0\" alt=\"fail\" title=\"Error :(\"></div>"); + }); + request.always(function(data) { + $("#V"+id).fadeIn(500, "linear"); + }); + } + ); + } + ); +/*}}}*/ + }); /** diff --git a/js/jquery.scrollto.min.js b/js/jquery.scrollto.min.js deleted file mode 100644 index f242cb9..0000000 --- a/js/jquery.scrollto.min.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * jQuery.ScrollTo - Easy element scrolling using jQuery. - * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com - * Dual licensed under MIT and GPL. - * Date: 5/25/2009 - * @author Ariel Flesler - * @version 1.4.2 - * - * http://flesler.blogspot.com/2007/10/jqueryscrollto.html - */ -;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery); diff --git a/js/usernotes.js b/js/usernotes.js deleted file mode 100644 index 83804ea..0000000 --- a/js/usernotes.js +++ /dev/null @@ -1,49 +0,0 @@ -$(document).ready(function() { - $("a").each( - function () { - if ($(this).is("a:.usernotes-voteu") || $(this).is("a:.usernotes-voted")) $(this).click( - function (event) { - event.preventDefault(); - var url = $(this).attr("href"); - var id = url.match(/\?id=(\d+)/)[1]; - var request = $.ajax({ - type: "POST", - url: url, - dataType: "json", - headers: {"X-Json": "On" }, - beforeSend: function() { - $("#Vu"+id).hide(); - $("#Vd"+id).hide(); - $("#V"+id).html("<img src=\"/images/working.gif\" alt=\"Working...\" border=\"0\" title=\"Working...\" />"); - } - }); - request.done(function(data) { - if(data.success != null && data.success == true) { - $("#V"+id).html("<div style=\"float: left; width: 16px; height: 16px; background-image: url(/images/notes-features.png); background-position:-32px 16px; margin-right: 8px; overflow: hidden;\" border=\"0\" alt=\"success\" title=\"Thank you for voting!\"></div>" + data.update); - } - else { - var responsedata = "Error :("; - if (data.msg != null) { - responsedata = data.msg; - } - $("#V"+id).html("<div style=\"float: left; width: 16px; height: 16px; background-image: url(/images/notes-features.png); background-position:-32px 0px; margin-right: 8px; overflow: hidden;\" border=\"0\" alt=\"fail\" title=\"" + responsedata + "\"></div>"); - } - }); - request.fail(function(jqXHR, textStatus) { - $("#Vu"+id).show(); - $("#Vd"+id).show(); - $("#V"+id).html("<div style=\"float: left; width: 16px; height: 16px; background-image: url(/images/notes-features.png); background-position:-32px 0px; margin-right: 8px; overflow: hidden;\" border=\"0\" alt=\"fail\" title=\"Error :(\"></div>"); - }); - request.always(function(data) { - $("#V"+id).fadeIn(500, "linear"); - }); - } - ); - } - ); - if (window.location.href.match(/#\d+$/)) { - var highlightId = window.location.href.match(/#(\d+)$/); - highlightId = highlightId[1]; - $("#Hcom"+highlightId).effect("highlight", {}, 3000); - } -});
« previous php.webmaster (#16373) next »