diff --git a/addons/website_instantclick/__init__.py b/addons/website_instantclick/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/website_instantclick/__openerp__.py b/addons/website_instantclick/__openerp__.py new file mode 100644 index 00000000000..5047bdd0979 --- /dev/null +++ b/addons/website_instantclick/__openerp__.py @@ -0,0 +1,17 @@ +{ + 'name': 'Website Instantclick', + 'category': 'Website', + 'summary': 'Preloads and speeds up website on public browsing of the website using Instantclick.', + 'version': '1.0', + 'description': """ +Preloads data on anonymous mode of website +========================================== + + """, + 'author': 'OpenERP SA', + 'depends': ['website'], + 'installable': True, + 'data': [ + 'views/website_instantclick.xml', + ], +} diff --git a/addons/website_instantclick/static/lib/instantclick/instantclick.js b/addons/website_instantclick/static/lib/instantclick/instantclick.js new file mode 100644 index 00000000000..e5e4e3447d3 --- /dev/null +++ b/addons/website_instantclick/static/lib/instantclick/instantclick.js @@ -0,0 +1,430 @@ +/* InstantClick 2.1 | (C) 2014 Alexandre Dieulot | http://instantclick.io/license.html */ +var InstantClick = function(document, location) { + // Internal variables + var $currentLocationWithoutHash + var $urlToPreload + var $preloadTimer + + // Preloading-related variables + var $history = {} + var $xhr + var $url = false + var $title = false + var $hasBody = true + var $body = false + var $timing = {} + var $isPreloading = false + var $isWaitingForCompletion = false + + // Variables defined by public functions + var $useWhitelist + var $preloadOnMousedown + var $delayBeforePreload + var $eventsCallbacks = { + change: [] + } + + + ////////// HELPERS ////////// + + + function removeHash(url) { + var index = url.indexOf('#') + if (index < 0) { + return url + } + return url.substr(0, index) + } + + function getLinkTarget(target) { + while (target.nodeName != 'A') { + target = target.parentNode + } + return target + } + + function triggerPageEvent(eventType) { + for (var i = 0; i < $eventsCallbacks[eventType].length; i++) { + $eventsCallbacks[eventType][i]() + } + } + + function changePage(title, body, newUrl, scrollY_) { + var doc = document.implementation.createHTMLDocument('') + doc.documentElement.innerHTML = body + document.documentElement.replaceChild(doc.body, document.body) + /* We cannot just use `document.body = doc.body` as it causes Safari 5.1, 6.0, + and Mobile 7.0 to execute script tags directly. + */ + + var elem = document.createElement('i') + elem.innerHTML = title + document.title = elem.textContent + + if (newUrl) { + history.pushState(null, null, newUrl) + + var hashIndex = newUrl.indexOf('#') + var hashElem = hashIndex > -1 && document.getElementById(newUrl.substr(hashIndex + 1)) + var offset = 0 + if (hashElem) { + for (; hashElem.offsetParent; hashElem = hashElem.offsetParent) { + offset += hashElem.offsetTop + } + } + scrollTo(0, offset) + + $currentLocationWithoutHash = removeHash(newUrl) + } + else { + scrollTo(0, scrollY_) + } + + instantanize() + + triggerPageEvent('change') + } + + function setPreloadingAsHalted() { + $isPreloading = false + $isWaitingForCompletion = false + } + + + ////////// EVENT HANDLERS ////////// + + + function mousedown(e) { + preload(getLinkTarget(e.target).href) + } + + function mouseover(e) { + var a = getLinkTarget(e.target) + a.addEventListener('mouseout', mouseout) + if (!$delayBeforePreload) { + preload(a.href) + } + else { + $urlToPreload = a.href + $preloadTimer = setTimeout(preload, $delayBeforePreload) + } + } + + function click(e) { + if (e.which > 1 || e.metaKey || e.ctrlKey) { // Opening in new tab + return + } + e.preventDefault() + display(getLinkTarget(e.target).href) + } + + function mouseout() { + if ($preloadTimer) { + clearTimeout($preloadTimer) + $preloadTimer = false + return + } + + if (!$isPreloading || $isWaitingForCompletion) { + return + } + $xhr.abort() + setPreloadingAsHalted() + } + + function readystatechange() { + if ($xhr.readyState < 4) { + return + } + if ($xhr.status == 0) { + /* Request aborted */ + return + } + + $timing.ready = +new Date - $timing.start + + var text = $xhr.responseText + + var titleIndex = text.indexOf('