diff options
-rw-r--r-- | templates/web/base/common_header_tags.html | 13 | ||||
-rw-r--r-- | templates/web/base/common_scripts.html | 41 | ||||
-rw-r--r-- | templates/web/base/front/javascript.html | 12 | ||||
-rw-r--r-- | templates/web/base/index.html | 2 | ||||
-rw-r--r-- | templates/web/base/report/photo-js.html | 3 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/footer_extra_js.html | 7 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/front/javascript.html | 12 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/header_extra.html | 4 | ||||
-rw-r--r-- | web/cobrands/fixmystreet-uk-councils/js.js | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet.com/js.js | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 6 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/front.js | 12 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/prefetch-polyfill.js | 28 | ||||
-rw-r--r-- | web/vendor/yepnope.js | 1 |
14 files changed, 89 insertions, 58 deletions
diff --git a/templates/web/base/common_header_tags.html b/templates/web/base/common_header_tags.html index 321e45649..1dad1cfa0 100644 --- a/templates/web/base/common_header_tags.html +++ b/templates/web/base/common_header_tags.html @@ -33,3 +33,16 @@ [% "$title :: " | html IF title %] [% site_name -%] </title> + +[% IF bodyclass.match('frontpage') %] + <link rel="prefetch" href="[% version('/js/validation_rules.js') %]"> + <link rel="prefetch" href="[% version('/vendor/jquery.validate.min.js') %]"> +[% END %] +[% IF NOT bodyclass.match('mappage') %] + [% FOR script IN map_js %] + <link rel="prefetch" href="[% IF script.match('^/'); version(script); ELSE; script; END %]"> + [% END %] + <link rel="prefetch" href="[% version('/cobrands/fixmystreet/map.js') %]"> + <link rel="prefetch" href="[% version('/vendor/dropzone.min.js') %]"> + <link rel="prefetch" href="[% version('/vendor/fancybox/jquery.fancybox-1.3.4.pack.js') %]"> +[% END %] diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html index 82f33569d..cecf9da5b 100644 --- a/templates/web/base/common_scripts.html +++ b/templates/web/base/common_scripts.html @@ -8,13 +8,21 @@ scripts = []; scripts.push( start _ "/js/translation_strings." _ lang_code _ ".js?" _ Math.int( date.now / 3600 ), version('/jslib/jquery-1.7.2.min.js'), - version('/js/validation_rules.js'), - version('/vendor/jquery.validate.min.js'), - version('/vendor/dropzone.min.js'), version('/js/jquery.multi-select.js'), version('/cobrands/fixmystreet/fixmystreet.js'), ); +IF NOT bodyclass.match('frontpage'); + scripts.push( + version('/js/validation_rules.js'), + version('/vendor/jquery.validate.min.js'), + ); +END; + +FOR script IN extra_js; + scripts.push(script); +END; + IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); scripts.push( version('/cobrands/fixmystreet/staff.js') @@ -26,14 +34,25 @@ IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); END; END; -FOR script IN map_js; - scripts.push(script); +IF bodyclass.match('mappage'); + FOR script IN map_js; + IF script.match('^/'); + scripts.push(version(script)); + ELSE; + scripts.push(script); + END; + END; + scripts.push( + version('/cobrands/fixmystreet/map.js'), + version('/vendor/dropzone.min.js'), + version('/vendor/fancybox/jquery.fancybox-1.3.4.pack.js'), + ); +ELSE; + scripts.push( + version('/cobrands/fixmystreet/prefetch-polyfill.js'), + ); END; -scripts.push( - version('/cobrands/fixmystreet/map.js'), -); - IF admin; scripts.push( version('/vendor/jquery-ui/js/jquery-ui-1.10.3.custom.min.js'), @@ -41,10 +60,6 @@ IF admin; ); END; -FOR script IN extra_js; - scripts.push(script); -END; - TRY; PROCESS 'footer_extra_js.html'; CATCH file; diff --git a/templates/web/base/front/javascript.html b/templates/web/base/front/javascript.html deleted file mode 100644 index 69eb626f7..000000000 --- a/templates/web/base/front/javascript.html +++ /dev/null @@ -1,12 +0,0 @@ -[% -# Assume using OpenStreetMap maps -map_js = [ - version('/vendor/yepnope.js'), - [ version('/cobrands/fixmystreet/front.js'), { - id = 'script_front', - 'data-scripts' = version('/vendor/OpenLayers/OpenLayers.fixmystreet.js') _ ',' _ - version('/js/map-OpenLayers.js') _ ',' _ - version('/js/map-OpenStreetMap.js') - } ], -] -%] diff --git a/templates/web/base/index.html b/templates/web/base/index.html index 5a064ecb6..620c1a2be 100644 --- a/templates/web/base/index.html +++ b/templates/web/base/index.html @@ -1,5 +1,3 @@ -[% PROCESS 'front/javascript.html' %] - [% pre_container_extra = PROCESS 'around/postcode_form.html' %] [% SET bodyclass = 'frontpage fullwidthpage' %] [% INCLUDE 'header.html', title = '', inline_css = 1 %] diff --git a/templates/web/base/report/photo-js.html b/templates/web/base/report/photo-js.html index 8c8c91669..6f3dd55d1 100644 --- a/templates/web/base/report/photo-js.html +++ b/templates/web/base/report/photo-js.html @@ -1,6 +1,3 @@ [% extra_css = BLOCK %] <link rel="stylesheet" href="[% version('/vendor/fancybox/jquery.fancybox-1.3.4.css') %]"> [% END %] -[% extra_js = [ - version('/vendor/fancybox/jquery.fancybox-1.3.4.pack.js') -] %] diff --git a/templates/web/fixmystreet.com/footer_extra_js.html b/templates/web/fixmystreet.com/footer_extra_js.html index 67f1dbb6a..1b140822e 100644 --- a/templates/web/fixmystreet.com/footer_extra_js.html +++ b/templates/web/fixmystreet.com/footer_extra_js.html @@ -1,4 +1,9 @@ +[% +IF bodyclass.match('mappage'); + scripts.push( + version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), + ); +END ~%] [% scripts.push( - version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), version('/cobrands/fixmystreet.com/js.js'), ) %] diff --git a/templates/web/fixmystreet.com/front/javascript.html b/templates/web/fixmystreet.com/front/javascript.html deleted file mode 100644 index 4bf586b70..000000000 --- a/templates/web/fixmystreet.com/front/javascript.html +++ /dev/null @@ -1,12 +0,0 @@ -[% -map_js = [ - version('/vendor/yepnope.js'), - [ version('/cobrands/fixmystreet/front.js'), { - id = "script_front", - 'data-scripts' = version('/vendor/OpenLayers/OpenLayers.fixmystreet.js') _ ',' _ - version('/js/map-OpenLayers.js') _ ',' _ - version('/js/map-bing-ol.js') _ ',' _ - version('/js/map-fms.js') - } ], -] -%] diff --git a/templates/web/fixmystreet.com/header_extra.html b/templates/web/fixmystreet.com/header_extra.html index f05aeed43..588c72650 100644 --- a/templates/web/fixmystreet.com/header_extra.html +++ b/templates/web/fixmystreet.com/header_extra.html @@ -1,3 +1,7 @@ +[% IF NOT bodyclass.match('mappage') %] +<link rel="prefetch" href="[% version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js') %]"> +[% END %] + [% IF c.req.uri.host == 'osm.fixmystreet.com' %] <link rel="canonical" href="https://www.fixmystreet.com[% c.req.uri.path_query %]"> [% END %] diff --git a/web/cobrands/fixmystreet-uk-councils/js.js b/web/cobrands/fixmystreet-uk-councils/js.js index 6066db9c5..7c4f7a9ed 100644 --- a/web/cobrands/fixmystreet-uk-councils/js.js +++ b/web/cobrands/fixmystreet-uk-councils/js.js @@ -1,4 +1,7 @@ (function(){ + if (!jQuery.validator) { + return; + } var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; function valid_name(value, element) { return this.optional(element) || value.length > 5 && value.match( /\S/ ) && value.match( /\s/ ) && !value.match( validNamePat ); diff --git a/web/cobrands/fixmystreet.com/js.js b/web/cobrands/fixmystreet.com/js.js index 0ac533be1..087d5d15f 100644 --- a/web/cobrands/fixmystreet.com/js.js +++ b/web/cobrands/fixmystreet.com/js.js @@ -1,4 +1,7 @@ (function(){ + if (!jQuery.validator) { + return; + } var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; function valid_name_factory(single) { return function(value, element) { diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 17748444a..1333517ac 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -303,8 +303,10 @@ $.extend(fixmystreet.set_up, { form_validation: function() { // FIXME - needs to use translated string - jQuery.validator.addMethod('validCategory', function(value, element) { - return this.optional(element) || value != '-- Pick a category --'; }, translation_strings.category ); + if (jQuery.validator) { + jQuery.validator.addMethod('validCategory', function(value, element) { + return this.optional(element) || value != '-- Pick a category --'; }, translation_strings.category ); + } var submitted = false; diff --git a/web/cobrands/fixmystreet/front.js b/web/cobrands/fixmystreet/front.js deleted file mode 100644 index a5e3bac98..000000000 --- a/web/cobrands/fixmystreet/front.js +++ /dev/null @@ -1,12 +0,0 @@ -yepnope.addPrefix( 'preload', function ( resource ) { - resource.noexec = true; - return resource; -}); - -(function(){ - var scripts = document.getElementById('script_front').getAttribute('data-scripts').split(','); - for (var i=0; i<scripts.length; i++) { - scripts[i] = 'preload!' + scripts[i]; - } - yepnope({ load: scripts }); -})(); diff --git a/web/cobrands/fixmystreet/prefetch-polyfill.js b/web/cobrands/fixmystreet/prefetch-polyfill.js new file mode 100644 index 000000000..a8b0f3dbf --- /dev/null +++ b/web/cobrands/fixmystreet/prefetch-polyfill.js @@ -0,0 +1,28 @@ +(function(){ + function has_prefetch() { + // IE11 + Edge support prefetch, but do not support relList.supports, sigh + var ua = navigator.userAgent; + if (ua.indexOf('Edge/') > -1 || ua.indexOf('Trident/7') > -1) { + return true; + } + // e.g. Firefox + Chrome will pass this test, and Safari will fail. + var l = document.createElement("link"), + rl = l.relList; + if (rl && rl.supports) { + return rl.supports('prefetch'); + } + } + + // If we don't support the <link rel="prefetch">s in the header, manually + // prefetch them by storing them in images. + if (!has_prefetch()) { + var links = document.getElementsByTagName('link'), + llen = links.length; + for (var x = 0; x < llen; x++) { + var link = links[x]; + if (link.nodeName === "LINK" && link.rel && link.rel === 'prefetch') { + (new Image()).src = link.href; + } + } + } +})(); diff --git a/web/vendor/yepnope.js b/web/vendor/yepnope.js deleted file mode 100644 index d48d17427..000000000 --- a/web/vendor/yepnope.js +++ /dev/null @@ -1 +0,0 @@ -(function(e,t,n){function r(e){return"[object Function]"==y.call(e)}function o(e){return"string"==typeof e}function a(){}function i(e){return!e||"loaded"==e||"complete"==e||"uninitialized"==e}function c(){var e=v.shift();g=1,e?e.t?m(function(){("c"==e.t?f.injectCss:f.injectJs)(e.s,0,e.a,e.x,e.e,1)},0):(e(),c()):g=0}function l(e,n,r,o,a,l,s){function u(t){if(!p&&i(d.readyState)&&(b.r=p=1,!g&&c(),d.onload=d.onreadystatechange=null,t)){"img"!=e&&m(function(){C.removeChild(d)},50);for(var r in M[n])M[n].hasOwnProperty(r)&&M[n][r].onload()}}var s=s||f.errorTimeout,d=t.createElement(e),p=0,y=0,b={t:r,s:n,e:a,a:l,x:s};1===M[n]&&(y=1,M[n]=[]),"object"==e?d.data=n:(d.src=n,d.type=e),d.width=d.height="0",d.onerror=d.onload=d.onreadystatechange=function(){u.call(this,y)},v.splice(o,0,b),"img"!=e&&(y||2===M[n]?(C.insertBefore(d,E?null:h),m(u,s)):M[n].push(d))}function s(e,t,n,r,a){return g=0,t=t||"j",o(e)?l("c"==t?w:S,e,t,this.i++,n,r,a):(v.splice(this.i++,0,e),1==v.length&&c()),this}function u(){var e=f;return e.loader={load:s,i:0},e}var d,f,p=t.documentElement,m=e.setTimeout,h=t.getElementsByTagName("script")[0],y={}.toString,v=[],g=0,b="MozAppearance"in p.style,E=b&&!!t.createRange().compareNode,C=E?p:h.parentNode,p=e.opera&&"[object Opera]"==y.call(e.opera),p=!!t.attachEvent&&!p,S=b?"object":p?"script":"img",w=p?"script":S,j=Array.isArray||function(e){return"[object Array]"==y.call(e)},F=[],M={},N={timeout:function(e,t){return t.length&&(e.timeout=t[0]),e}};f=function(e){function t(e){var t,n,r,e=e.split("!"),o=F.length,a=e.pop(),i=e.length,a={url:a,origUrl:a,prefixes:e};for(n=0;i>n;n++)r=e[n].split("="),(t=N[r.shift()])&&(a=t(a,r));for(n=0;o>n;n++)a=F[n](a);return a}function i(e,o,a,i,c){var l=t(e),s=l.autoCallback;l.url.split(".").pop().split("?").shift(),l.bypass||(o&&(o=r(o)?o:o[e]||o[i]||o[e.split("/").pop().split("?")[0]]),l.instead?l.instead(e,o,a,i,c):(M[l.url]?l.noexec=!0:M[l.url]=1,a.load(l.url,l.forceCSS||!l.forceJS&&"css"==l.url.split(".").pop().split("?").shift()?"c":n,l.noexec,l.attrs,l.timeout),(r(o)||r(s))&&a.load(function(){u(),o&&o(l.origUrl,c,i),s&&s(l.origUrl,c,i),M[l.url]=2})))}function c(e,t){function n(e,n){if(e){if(o(e))n||(d=function(){var e=[].slice.call(arguments);f.apply(this,e),p()}),i(e,d,t,0,s);else if(Object(e)===e)for(l in c=function(){var t,n=0;for(t in e)e.hasOwnProperty(t)&&n++;return n}(),e)e.hasOwnProperty(l)&&(!n&&!--c&&(r(d)?d=function(){var e=[].slice.call(arguments);f.apply(this,e),p()}:d[l]=function(e){return function(){var t=[].slice.call(arguments);e&&e.apply(this,t),p()}}(f[l])),i(e[l],d,t,l,s))}else!n&&p()}var c,l,s=!!e.test,u=e.load||e.both,d=e.callback||a,f=d,p=e.complete||a;n(s?e.yep:e.nope,!!u),u&&n(u)}var l,s,d=this.yepnope.loader;if(o(e))i(e,0,d,0);else if(j(e))for(l=0;l<e.length;l++)s=e[l],o(s)?i(s,0,d,0):j(s)?f(s):Object(s)===s&&c(s,d);else Object(e)===e&&c(e,d)},f.addPrefix=function(e,t){N[e]=t},f.addFilter=function(e){F.push(e)},f.errorTimeout=1e4,null==t.readyState&&t.addEventListener&&(t.readyState="loading",t.addEventListener("DOMContentLoaded",d=function(){t.removeEventListener("DOMContentLoaded",d,0),t.readyState="complete"},0)),e.yepnope=u(),e.yepnope.executeStack=c,e.yepnope.injectJs=function(e,n,r,o,l,s){var u,d,p=t.createElement("script"),o=o||f.errorTimeout;p.src=e;for(d in r)p.setAttribute(d,r[d]);n=s?c:n||a,p.onreadystatechange=p.onload=function(){!u&&i(p.readyState)&&(u=1,n(),p.onload=p.onreadystatechange=null)},m(function(){u||(u=1,n(1))},o),l?p.onload():h.parentNode.insertBefore(p,h)},e.yepnope.injectCss=function(e,n,r,o,i,l){var s,o=t.createElement("link"),n=l?c:n||a;o.href=e,o.rel="stylesheet",o.type="text/css";for(s in r)o.setAttribute(s,r[s]);i||(h.parentNode.insertBefore(o,h),m(n,0))}})(this,document); |