Commits

Shlomi Fish committed 9cc4727

Convert the JS to rel_path instead of base + current.

Comments (0)

Files changed (3)

Tests/js/jqtree-from-h-w-json-nav-menu-test.js

         equal (
             get_base_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/humour/',
+                    rel_path: 'humour/',
                 }
             ),
             './../',
         equal (
             get_base_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/humour.html',
+                    rel_path: 'humour.html',
                 }
             ),
             './',
         equal (
             get_base_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/sod/foobar/',
+                    rel_path: 'sod/foobar/',
                 }
             ),
             './../../',
         equal (
             get_base_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/sod/foobar/l.html',
+                    rel_path: 'sod/foobar/l.html',
                 }
             ),
             './../../',
         equal (
             get_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/humour/',
+                    rel_path: 'humour/',
                     to: 'me/intros/writers/'
                 }
             ),
         equal (
             get_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/humour/foo.html',
+                    rel_path: 'humour/foo.html',
                     to: 'me/intros/writers/'
                 }
             ),
         equal (
             get_relative_path(
                 {
-                    base: 'http://www.shlomifish.org/',
-                    current: 'http://www.shlomifish.org/me/intros/',
+                    rel_path: 'me/intros/',
                     to: 'humour/TheEnemy/te-heb.html'
                 }
             ),
             // TEST
             var expected = [
             {
+                id: 1,
                 label: '<a href="./../">Shlomi Fish</a>',
                 children: [
                 {
+                    id: 2,
                     label: '<a href="./../me/">About Myself</a>'
                 },
                 {
+                    id: 3,
                     label: '<a href="./../humour/" title="Stories and Aphorisms I wrote">Humour</a>'
                 }
                 ],
                 calc_jqtree_data_from_html_w_nav_menu_json(
                     {
                         input: input,
-                        base: 'http://www.shlomifish.org/',
-                        current: 'http://www.shlomifish.org/humour/'
+                        rel_path: 'humour/',
                     }
                 ),
                 expected,
             // TEST
             var expected = [
             {
+                id: 1,
                 label: '<a href="./../../">Shlomi Fish</a>',
                 children: [
                 {
+                    id: 2,
                     label: '<a href="./../../me/">About Myself</a>'
                 },
                 {
+                    id: 3,
                     label: '<a href="./../../humour/" title="Stories and Aphorisms I wrote">Humour</a>',
                     children: [
                         {
+                            id: 4,
                             label: '<a href="./../../humour/TOWTF/" title="Parody of The Fountainhead">The One With The Fountainhead</a>',
                         },
                         {
+                            id: 5,
                             label: '<a href="./../../humour/human-hacking/" title="The Human Hacking Field Guide">HHFG</a>',
                             children: [
                                 {
+                                    id: 6,
                                     label: '<a href="./../../humour/human-hacking/heb.html">Hebrew Translation</a>'
                                 }
                             ]
                 calc_jqtree_data_from_html_w_nav_menu_json(
                     {
                         input: input,
-                        base: 'http://www.shlomifish.org/',
-                        current: 'http://www.shlomifish.org/art/slogans/'
+                        rel_path: 'art/solgans/',
                     }
                 ),
                 expected,

common/js/to-jqtree-2.js

     var b = 'http://www.shlomifish.org/';
     $.getJSON(
         get_relative_path({
-            base: b,
-            current: b + page_path,
+            rel_path: page_path,
             to: '_data/nav.json',
         }),
         function(json_input) {
                 data: calc_jqtree_data_from_html_w_nav_menu_json(
                     {
                         input: json_input,
-                        base: b,
-                        current: b + page_path
+                        rel_path: page_path
                     }
                 )
             });

common/js/to-jqtree.js

 }
 
 function get_base_relative_path (args) {
-    var base = args.base;
-    var current = args.current;
+    var rel_path = args.rel_path;
 
-    var rel_path = current.substring(base.length);
+    //var rel_path = current.substring(base.length);
 
     var count = (rel_path.match(/\//g)||[]).length;
 
 }
 
 function calc_jqtree_data_from_html_w_nav_menu_json (args) {
-    var base = args.base;
-    var current = args.current;
+    var rel_path = args.rel_path;
 
     var _get_rel = function (href) {
         return get_relative_path(
             {
-                base: base,
-                current: current,
+                rel_path: rel_path,
                 to: href,
             }
         );