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

Subscribers

People subscribed via source and target branches

to all changes: