From 009cc5278e2fba1e744f50674ccc898ab79d6477 Mon Sep 17 00:00:00 2001
From: Christophe Matthieu <chm@odoo.com>
Date: Wed, 6 Aug 2014 16:47:11 +0200
Subject: [PATCH] [FIX] website_quote: scroll spy is crazy if the user change
 quote template. Must remove id created by the javascript of scroll spy.

---
 .../website_quote/static/src/js/website_quotation.js | 12 +++++++-----
 addons/website_quote/views/website_quotation.xml     |  4 ++--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/addons/website_quote/static/src/js/website_quotation.js b/addons/website_quote/static/src/js/website_quotation.js
index 646cbe25375c..1e9203b5df66 100644
--- a/addons/website_quote/static/src/js/website_quotation.js
+++ b/addons/website_quote/static/src/js/website_quotation.js
@@ -65,24 +65,26 @@ $(document).ready(function () {
     });
 
     // automatically generate a menu from h1 and h2 tag in content
-    var ul = $('[data-id="quote_sidebar"]');
+    var $container = $('body[data-target=".navspy"]');
+    var ul = $('[data-id="quote_sidebar"]', $container);
     var sub_li = null;
     var sub_ul = null;
-    $("section h1, section h2").each(function() {
+    $("[id^=quote_header_], [id^=quote_]", $container).attr("id", "");
+    $("h1, h2", $container).each(function() {
         switch (this.tagName.toLowerCase()) {
             case "h1":
-                id = _.uniqueId('quote_header_')
+                id = _.uniqueId('quote_header_');
                 $(this.parentNode).attr('id',id);
                 sub_li = $("<li>").html('<a href="#'+id+'">'+$(this).text()+'</a>').appendTo(ul);
                 sub_ul = null;
                 break;
             case "h2":
-                id = _.uniqueId('quote_')
+                id = _.uniqueId('quote_');
                 if (sub_li) {
                     if (!sub_ul) {
                         sub_ul = $("<ul class='nav'>").appendTo(sub_li);
                     }
-                    $(this.parentNode).attr('id',id)
+                    $(this.parentNode).attr('id',id);
                     $("<li>").html('<a href="#'+id+'">'+$(this).text()+'</a>').appendTo(sub_ul);
                 }
                 break;
diff --git a/addons/website_quote/views/website_quotation.xml b/addons/website_quote/views/website_quotation.xml
index 0415e2401ad1..19e1c675387f 100644
--- a/addons/website_quote/views/website_quotation.xml
+++ b/addons/website_quote/views/website_quotation.xml
@@ -167,7 +167,7 @@
             <link rel='stylesheet' href='/website_quote/static/src/css/website_quotation.css'/>
             <t t-raw="head or ''"/>
         </t>
-        <body data-spy="scroll" data-target=".navspy">
+        <body data-spy="scroll" data-target=".navspy" data-offset="50">
             <div class="container">
               <div class="row mt16">
                   <div class="col-md-3">
@@ -462,7 +462,7 @@
             <link rel='stylesheet' href='/website_quote/static/src/css/website_quotation.css'/>
             <t t-raw="head or ''"/>
         </t>
-        <body data-spy="scroll" data-target=".navspy">
+        <body data-spy="scroll" data-target=".navspy" data-offset="50">
             <div class="container">
                 <div class="row mt16">
                     <div class="col-md-3">
-- 
GitLab