Merge lp:~openerp-dev/openobject-addons/trunk-instantclick2-dja into lp:openobject-addons

Proposed by Dharmraj Zala(OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-instantclick2-dja
Merge into: lp:openobject-addons
Diff against target: 509 lines (+469/-2)
4 files modified
website_anonymous/__openerp__.py (+18/-0)
website_anonymous/static/lib/instantclick/instantclick.js (+431/-0)
website_anonymous/views/website_anonymoustemplate.xml (+18/-0)
website_sale/views/templates.xml (+2/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-instantclick2-dja
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+218247@code.launchpad.net

Description of the change

Hello,

I've created a module website_anonymous to that loads instantclick.js in anonymous mode of website.

Thanks.

To post a comment you must log in.
9409. By Dharmraj Zala(OpenERP)

[MERGE] sync with trunk

9410. By Dharmraj Zala(OpenERP)

[MERGE] sync with trunk

9411. By Dharmraj Zala(OpenERP)

[MERGE] with trunk

9412. By Dharmraj Zala(OpenERP)

[MERGE] with trunk

9413. By Dharmraj Zala(OpenERP)

[MERGE] with trunk

Unmerged revisions

9413. By Dharmraj Zala(OpenERP)

[MERGE] with trunk

9412. By Dharmraj Zala(OpenERP)

[MERGE] with trunk

9411. By Dharmraj Zala(OpenERP)

[MERGE] with trunk

9410. By Dharmraj Zala(OpenERP)

[MERGE] sync with trunk

9409. By Dharmraj Zala(OpenERP)

[MERGE] sync with trunk

9408. By Dharmraj Zala(OpenERP)

[IMP] removed condition based on condition to check the impact

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'website_anonymous'
2=== added file 'website_anonymous/__init__.py'
3=== added file 'website_anonymous/__openerp__.py'
4--- website_anonymous/__openerp__.py 1970-01-01 00:00:00 +0000
5+++ website_anonymous/__openerp__.py 2014-05-12 04:47:20 +0000
6@@ -0,0 +1,18 @@
7+{
8+ 'name': 'Website Anonymous',
9+ 'category': 'Website',
10+ 'summary': 'Anonymous mode on website',
11+ 'version': '1.0',
12+ 'description': """
13+OpenERP Website CMS Anonymous Mode
14+==================================
15+
16+ """,
17+ 'author': 'OpenERP SA',
18+ 'depends': ['website'],
19+ 'installable': True,
20+ 'data': [
21+ 'views/website_anonymoustemplate.xml',
22+ ],
23+
24+}
25
26=== added directory 'website_anonymous/static'
27=== added directory 'website_anonymous/static/lib'
28=== added directory 'website_anonymous/static/lib/instantclick'
29=== added file 'website_anonymous/static/lib/instantclick/instantclick.js'
30--- website_anonymous/static/lib/instantclick/instantclick.js 1970-01-01 00:00:00 +0000
31+++ website_anonymous/static/lib/instantclick/instantclick.js 2014-05-12 04:47:20 +0000
32@@ -0,0 +1,431 @@
33+/* InstantClick 2.1 | (C) 2014 Alexandre Dieulot | http://instantclick.io/license.html */
34+var InstantClick = function(document, location) {
35+ // Internal variables
36+ var $currentLocationWithoutHash
37+ var $urlToPreload
38+ var $preloadTimer
39+
40+ // Preloading-related variables
41+ var $history = {}
42+ var $xhr
43+ var $url = false
44+ var $title = false
45+ var $hasBody = true
46+ var $body = false
47+ var $timing = {}
48+ var $isPreloading = false
49+ var $isWaitingForCompletion = false
50+
51+ // Variables defined by public functions
52+ var $useWhitelist
53+ var $preloadOnMousedown
54+ var $delayBeforePreload
55+ var $eventsCallbacks = {
56+ change: []
57+ }
58+
59+
60+ ////////// HELPERS //////////
61+
62+
63+ function removeHash(url) {
64+ var index = url.indexOf('#')
65+ if (index < 0) {
66+ return url
67+ }
68+ return url.substr(0, index)
69+ }
70+
71+ function getLinkTarget(target) {
72+ while (target.nodeName != 'A') {
73+ target = target.parentNode
74+ }
75+ return target
76+ }
77+
78+ function triggerPageEvent(eventType) {
79+ for (var i = 0; i < $eventsCallbacks[eventType].length; i++) {
80+ $eventsCallbacks[eventType][i]()
81+ }
82+ }
83+
84+ function changePage(title, body, newUrl, scrollY_) {
85+ var doc = document.implementation.createHTMLDocument('')
86+ doc.documentElement.innerHTML = body
87+ document.documentElement.replaceChild(doc.body, document.body)
88+ /* We cannot just use `document.body = doc.body` as it causes Safari 5.1, 6.0,
89+ and Mobile 7.0 to execute script tags directly.
90+ */
91+
92+ var elem = document.createElement('i')
93+ elem.innerHTML = title
94+ document.title = elem.textContent
95+
96+ if (newUrl) {
97+ history.pushState(null, null, newUrl)
98+
99+ var hashIndex = newUrl.indexOf('#')
100+ var hashElem = hashIndex > -1 && document.getElementById(newUrl.substr(hashIndex + 1))
101+ var offset = 0
102+ if (hashElem) {
103+ for (; hashElem.offsetParent; hashElem = hashElem.offsetParent) {
104+ offset += hashElem.offsetTop
105+ }
106+ }
107+ scrollTo(0, offset)
108+
109+ $currentLocationWithoutHash = removeHash(newUrl)
110+ }
111+ else {
112+ scrollTo(0, scrollY_)
113+ }
114+
115+ instantanize()
116+
117+ triggerPageEvent('change')
118+ }
119+
120+ function setPreloadingAsHalted() {
121+ $isPreloading = false
122+ $isWaitingForCompletion = false
123+ }
124+
125+
126+ ////////// EVENT HANDLERS //////////
127+
128+
129+ function mousedown(e) {
130+ preload(getLinkTarget(e.target).href)
131+ }
132+
133+ function mouseover(e) {
134+ var a = getLinkTarget(e.target)
135+ a.addEventListener('mouseout', mouseout)
136+ if (!$delayBeforePreload) {
137+ preload(a.href)
138+ }
139+ else {
140+ $urlToPreload = a.href
141+ $preloadTimer = setTimeout(preload, $delayBeforePreload)
142+ }
143+
144+ }
145+
146+ function click(e) {
147+ if (e.which > 1 || e.metaKey || e.ctrlKey) { // Opening in new tab
148+ return
149+ }
150+ e.preventDefault()
151+ display(getLinkTarget(e.target).href)
152+ }
153+
154+ function mouseout() {
155+ if ($preloadTimer) {
156+ clearTimeout($preloadTimer)
157+ $preloadTimer = false
158+ return
159+ }
160+
161+ if (!$isPreloading || $isWaitingForCompletion) {
162+ return
163+ }
164+ $xhr.abort()
165+ setPreloadingAsHalted()
166+ }
167+
168+ function readystatechange() {
169+ if ($xhr.readyState < 4) {
170+ return
171+ }
172+ if ($xhr.status == 0) {
173+ /* Request aborted */
174+ return
175+ }
176+
177+ $timing.ready = +new Date - $timing.start
178+
179+ var text = $xhr.responseText
180+
181+ var titleIndex = text.indexOf('<title')
182+ if (titleIndex > -1) {
183+ $title = text.substr(text.indexOf('>', titleIndex) + 1)
184+ $title = $title.substr(0, $title.indexOf('</title'))
185+ }
186+
187+ var bodyIndex = text.indexOf('<body')
188+ if (bodyIndex > -1) {
189+ $body = text.substr(bodyIndex)
190+ var closingIndex = $body.indexOf('</body')
191+ if (closingIndex > -1) {
192+ $body = $body.substr(0, closingIndex)
193+ }
194+
195+ var urlWithoutHash = removeHash($url)
196+ $history[urlWithoutHash] = {
197+ body: $body,
198+ title: $title,
199+ scrollY: urlWithoutHash in $history ? $history[urlWithoutHash].scrollY : 0
200+ }
201+ }
202+ else {
203+ $hasBody = false
204+ }
205+
206+ if ($isWaitingForCompletion) {
207+ $isWaitingForCompletion = false
208+ display($url)
209+ }
210+ }
211+
212+
213+ ////////// MAIN FUNCTIONS //////////
214+
215+
216+ function instantanize(isInitializing) {
217+ var as = document.getElementsByTagName('a'), a, domain = location.protocol + '//' + location.host
218+ for (var i = as.length - 1; i >= 0; i--) {
219+ a = as[i]
220+ if (a.target || // target="_blank" etc.
221+ a.hasAttribute('download') ||
222+ a.href.indexOf(domain + '/') != 0 || // another domain (or no href attribute)
223+ a.href.indexOf('#') > -1 && removeHash(a.href) == $currentLocationWithoutHash || // link to an anchor
224+ ($useWhitelist ? !a.hasAttribute('data-instant') : a.hasAttribute('data-no-instant'))) {
225+ continue
226+ }
227+ if ($preloadOnMousedown) {
228+ a.addEventListener('mousedown', mousedown)
229+ }
230+ else {
231+ a.addEventListener('mouseover', mouseover)
232+ }
233+ a.addEventListener('click', click)
234+ }
235+ if (!isInitializing) {
236+ var scripts = document.getElementsByTagName('script'), script, copy, parentNode, nextSibling
237+ for (i = 0, j = scripts.length; i < j; i++) {
238+ script = scripts[i]
239+ if (script.hasAttribute('data-no-instant')) {
240+ continue
241+ }
242+ copy = document.createElement('script')
243+ if (script.src) {
244+ copy.src = script.src
245+ }
246+ if (script.innerHTML) {
247+ copy.innerHTML = script.innerHTML
248+ }
249+ parentNode = script.parentNode
250+ nextSibling = script.nextSibling
251+ parentNode.removeChild(script)
252+ parentNode.insertBefore(copy, nextSibling)
253+ }
254+ }
255+ }
256+
257+ function preload(url) {
258+ if (!$preloadOnMousedown && 'display' in $timing && +new Date - ($timing.start + $timing.display) < 100) {
259+ /* After a page is displayed, if the user's cursor happens to be above a link
260+ a mouseover event will be in most browsers triggered automatically, and in
261+ other browsers it will be triggered when the user moves his mouse by 1px.
262+
263+ Here are the behavior I noticed, all on Windows:
264+ - Safari 5.1: auto-triggers after 0 ms
265+ - IE 11: auto-triggers after 30-80 ms (looks like it depends on page's size)
266+ - Firefox: auto-triggers after 10 ms
267+ - Opera 18: auto-triggers after 10 ms
268+
269+ - Chrome: triggers when cursor moved
270+ - Opera 12.16: triggers when cursor moved
271+
272+ To remedy to this, we do not start preloading if last display occurred less than
273+ 100 ms ago. If they happen to click on the link, they will be redirected.
274+ */
275+
276+ return
277+ }
278+ if ($preloadTimer) {
279+ $clearTimeout($preloadTimer)
280+ $preloadTimer = false
281+ }
282+
283+ if (!url) {
284+ url = $urlToPreload
285+ }
286+
287+ if ($isPreloading && (url == $url || $isWaitingForCompletion)) {
288+ return
289+ }
290+ $isPreloading = true
291+ $isWaitingForCompletion = false
292+
293+ $url = url
294+ $body = false
295+ $hasBody = true
296+ $timing = {
297+ start: +new Date
298+ }
299+ $xhr.open('GET', url)
300+ $xhr.send()
301+ }
302+
303+ function display(url) {
304+ if (!('display' in $timing)) {
305+ $timing.display = +new Date - $timing.start
306+ }
307+ if ($preloadTimer) {
308+ /* Happens when there’s a delay before preloading and that delay
309+ hasn't expired (preloading didn't kick in).
310+ */
311+
312+ if ($url && $url != url) {
313+ /* Happens when the user clicks on a link before preloading
314+ kicks in while another link is already preloading.
315+ */
316+
317+ location.href = url
318+ return
319+ }
320+ preload(url)
321+ $isWaitingForCompletion = true
322+ return
323+ }
324+ if (!$isPreloading || $isWaitingForCompletion) {
325+ /* If the page isn't preloaded, it likely means
326+ the user has focused on a link (with his Tab
327+ key) and then pressed Return, which triggered a click.
328+ Because very few people do this, it isn't worth handling this
329+ case and preloading on focus (also, focusing on a link
330+ doesn't mean it's likely that you'll "click" on it), so we just
331+ redirect them when they "click".
332+ It could also mean the user hovered over a link less than 100 ms
333+ after a page display, thus we didn't start the preload (see
334+ comments in `preload()` for the rationale behind this.)
335+
336+ If the page is waiting for completion, the user clicked twice
337+ while the page was preloading.
338+ Two possibilities:
339+ 1) He clicks on the same link again, either because it's slow
340+ to load (there's no browser loading indicator with
341+ InstantClick, so he might think his click hasn't registered
342+ if the page isn't loading fast enough) or because he has
343+ a habit of double clicking on the web;
344+ 2) He clicks on another link.
345+
346+ In the first case, we redirect him (send him to the page the old
347+ way) so that he can have the browser's loading indicator back.
348+ In the second case, we redirect him because we haven't preloaded
349+ that link, since we were already preloading the last one.
350+
351+ Determining if it's a double click might be overkill as there is
352+ (hopefully) not that many people that double click on the web.
353+ Fighting against the perception that the page is stuck is
354+ interesting though, a seemingly good way to do that would be to
355+ later incorporate a progress bar.
356+ */
357+
358+ location.href = url
359+ return
360+ }
361+ if (!$hasBody) {
362+ location.href = $url
363+ return
364+ }
365+ if (!$body) {
366+ $isWaitingForCompletion = true
367+ return
368+ }
369+ $history[$currentLocationWithoutHash].scrollY = pageYOffset
370+ setPreloadingAsHalted()
371+ changePage($title, $body, $url)
372+ }
373+
374+
375+ ////////// PUBLIC VARIABLE AND FUNCTIONS //////////
376+
377+
378+ var supported = 'pushState' in history
379+
380+ function init() {
381+ if ($currentLocationWithoutHash) {
382+ /* Already initialized */
383+ return
384+ }
385+ if (!supported) {
386+ triggerPageEvent('change')
387+ return
388+ }
389+ for (var i = arguments.length - 1; i >= 0; i--) {
390+ var arg = arguments[i]
391+ if (arg === true) {
392+ $useWhitelist = true
393+ }
394+ else if (arg == 'mousedown') {
395+ $preloadOnMousedown = true
396+ }
397+ else if (typeof arg == 'number') {
398+ $delayBeforePreload = arg
399+ }
400+ }
401+ $currentLocationWithoutHash = removeHash(location.href)
402+ $history[$currentLocationWithoutHash] = {
403+ body: document.body.outerHTML,
404+ title: document.title,
405+ scrollY: pageYOffset
406+ }
407+ $xhr = new XMLHttpRequest()
408+ $xhr.addEventListener('readystatechange', readystatechange)
409+
410+ instantanize(true)
411+
412+ triggerPageEvent('change')
413+
414+ addEventListener('popstate', function() {
415+ var loc = removeHash(location.href)
416+ if (loc == $currentLocationWithoutHash) {
417+ return
418+ }
419+ if (!(loc in $history)) {
420+ location.href = location.href // Reloads the page and makes use of cache for assets, unlike location.reload()
421+ return
422+ }
423+ $history[$currentLocationWithoutHash].scrollY = pageYOffset
424+ $currentLocationWithoutHash = loc
425+ changePage($history[loc].title, $history[loc].body, false, $history[loc].scrollY)
426+ })
427+ }
428+
429+ function on(eventType, callback) {
430+ $eventsCallbacks[eventType].push(callback)
431+ }
432+
433+ /* The debug function isn't included by default to reduce file size.
434+ To enable it, add a slash at the beginning of the comment englobing
435+ the debug function, and uncomment "debug: debug," in the return
436+ statement below the function. */
437+
438+ /*
439+ function debug() {
440+ return {
441+ currentLocationWithoutHash: $currentLocationWithoutHash,
442+ history: $history,
443+ xhr: $xhr,
444+ url: $url,
445+ title: $title,
446+ hasBody: $hasBody,
447+ body: $body,
448+ timing: $timing,
449+ isPreloading: $isPreloading,
450+ isWaitingForCompletion: $isWaitingForCompletion
451+ }
452+ }
453+ //*/
454+
455+
456+ return {
457+ // debug: debug,
458+ supported: supported,
459+ init: init,
460+ on: on
461+ }
462+
463+}(document, location);
464
465=== added directory 'website_anonymous/views'
466=== added file 'website_anonymous/views/website_anonymoustemplate.xml'
467--- website_anonymous/views/website_anonymoustemplate.xml 1970-01-01 00:00:00 +0000
468+++ website_anonymous/views/website_anonymoustemplate.xml 2014-05-12 04:47:20 +0000
469@@ -0,0 +1,18 @@
470+<?xml version="1.0" encoding="utf-8"?>
471+<!-- vim:fdn=3:
472+-->
473+<openerp>
474+ <data>
475+
476+<template id="show_sign_in_anonymous" inherit_option_id="website.show_sign_in" inherit_id="website.show_sign_in" name="Show Sign In" groups="base.group_public">
477+ <xpath expr="//div[@id='wrapwrap']" position="after">
478+ <script type="text/javascript" src="/website_anonymous/static/lib/instantclick/instantclick.js" data-no-instant=""></script>
479+ <script data-no-instant="">
480+ InstantClick.init();
481+ </script>
482+ </xpath>
483+</template>
484+
485+
486+ </data>
487+</openerp>
488
489=== modified file 'website_sale/views/templates.xml'
490--- website_sale/views/templates.xml 2014-05-07 15:32:23 +0000
491+++ website_sale/views/templates.xml 2014-05-12 04:47:20 +0000
492@@ -544,7 +544,7 @@
493 <td>
494 <div class="input-group">
495 <span class="input-group-addon">
496- <a t-attf-href="#" class="mb8 js_add_cart_json">
497+ <a t-attf-href="#" class="mb8 js_add_cart_json" data-no-instant="">
498 <i class="fa fa-minus"></i>
499 </a>
500 </span>
501@@ -553,7 +553,7 @@
502 t-att-data-product-id="line.product_id.id"
503 t-att-value="int(line.product_uom_qty)"/>
504 <span class="input-group-addon">
505- <a t-attf-href="#" class="mb8 float_left js_add_cart_json">
506+ <a t-attf-href="#" class="mb8 float_left js_add_cart_json" data-no-instant="">
507 <i class="fa fa-plus"></i>
508 </a>
509 </span>

Subscribers

People subscribed via source and target branches

to all changes: