Commit e24b879a0a2f10cd2e8ef21d4b3c914132154cd5

FIX: Navigation Menu highlight issue

  - Fix the highlighting issue in navigation menu when navigating to different
    pages.
  - Fix some small UI issues in the editor
  • Diff rendering mode:
  • inline
  • side by side

mouchak/static/js/mouchak.js

54 //console.log('rendering custom menu..');54 //console.log('rendering custom menu..');
55 this.$el.append(this.model.get('html'));55 this.$el.append(this.model.get('html'));
56 }56 }
57 this.$links = $('.nav li');
57 this.$links = $('.nav > li');
58 if(!this.$links) {58 if(!this.$links) {
59 throw new Error('Ill-formed menu! Please check you have <ul> element' +59 throw new Error('Ill-formed menu! Please check you have <ul> element' +
60 'inside your menu with class nav and <li> elements inside it');60 'inside your menu with class nav and <li> elements inside it');
81 }));*/81 }));*/
82 }, this);82 }, this);
83 },83 },
84 //FIXIT: sometimes clicking on nav link, this function does not handle the
85 //event directly. it is passed to showPage function of router, which calls
86 //this function. so this function is without an event object is some cases.
87 //Fix it always receive the click event.
84 navClicked: function(event) {88 navClicked: function(event) {
85 this.$links.removeClass('active');89 this.$links.removeClass('active');
86 if(!event) {
87 var fragment = location.hash.split('/')[1];
88 //var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]);
89 //console.log(fragment);
90 var pos = _.indexOf(this.model.get('menuOrder'), fragment);
91 //console.log(pos);
92 if(!fragment) {
93 pos = 0;
90 if(this.model.get('customMenu') === false) {
91 if(!event) {
92 var fragment = location.hash.split('/')[1];
93 //var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]);
94 var pos = _.indexOf(this.model.get('menuOrder'), fragment);
95 if(!fragment) {
96 pos = 0;
97 }
98 $(this.$links[pos]).addClass('active');
94 }99 }
95 $(this.$links[pos]).addClass('active');
100 else {
101 $(event.currentTarget).parent().addClass('active');
102 }
96 }103 }
97 else {
98 //console.log();
99 $(event.currentTarget).parent().addClass('active');
104 else if(this.model.get('customMenu') === true) {
105 // get the URL fragment
106 var fragment = location.hash.split('/')[1];
107 // find out where it is in the nav menu
108 var link = $('.nav').find('a[href="#/'+ fragment +'"]')[0];
109 // find its <li> parent all the way up in the main ul.nav
110 $(link).closest('ul.nav > li').addClass('active');
100 }111 }
101 }112 }
102});113});

mouchak/templates/editor.html

49 <script type="text/template" id="menu-config-template">49 <script type="text/template" id="menu-config-template">
50 <div class="page">50 <div class="page">
51 <div class="menu-config">51 <div class="menu-config">
52 <h4> Menu Config </h4>
52 <h4> Configure Navigation Menu </h4>
5353
54 <div class="row">54 <div class="row">
55 <div class="form-group col-lg-12" id="menu-order-wrap">
55 <div class="form-group col-lg-6">
56 <div class="input-group">56 <div class="input-group">
57 <span class="input-group-addon"> <strong> Menu Order</strong></span>
58 <input class="form-control" id="menu-order" type="text"
59 placeholder="list,page,slugs,for,menu,order" value="<%= menu_order %>">
57 <span class="input-group-addon">
58 <input id="custom-menu" type="checkbox">
59 </span>
60 <span class="input-group-addon"><strong>Custom Menu
61 </strong></span>
60 </div>62 </div>
61 <span class="help-block">63 <span class="help-block">
62 <small>csv list of page slugs to come up in the navigation menu
63 in that order
64 <small>
65 activate to write your own custom menu
64 </small>66 </small>
65 </span>67 </span>
66 </div>68 </div>
67 </div>69 </div>
6870
69 <div class="row">71 <div class="row">
70 <div class="form-group col-lg-6">
72 <div class="form-group col-lg-12" id="menu-order-wrap">
71 <div class="input-group">73 <div class="input-group">
72 <span class="input-group-addon">
73 <input id="custom-menu" type="checkbox">
74 </span>
75 <span class="input-group-addon"><strong>Custom Menu
76 </strong></span>
74 <span class="input-group-addon"> <strong> Menu Order</strong></span>
75 <input class="form-control" id="menu-order" type="text"
76 placeholder="list,page,slugs,for,menu,order" value="<%= menu_order %>">
77 </div>77 </div>
78 <span class="help-block">78 <span class="help-block">
79 <small>
80 activate to write your own custom menu
79 <small>csv list of page slugs to come up in the navigation menu
80 in that order
81 </small>81 </small>
82 </span>82 </span>
83 </div>83 </div>
110110
111 <script type="text/template" id="header-config-template">111 <script type="text/template" id="header-config-template">
112 <div class="page">112 <div class="page">
113 <h4> Configure your header here </h4>
113 <div><h4> Write HTML for your header here </h4></div>
114 <div id="header-input" class="ace-mouchak">114 <div id="header-input" class="ace-mouchak">
115 <%= M.escapeHtml(header) %>115 <%= M.escapeHtml(header) %>
116 </div>116 </div>
123123
124 <script type="text/template" id="footer-config-template">124 <script type="text/template" id="footer-config-template">
125 <div class="page">125 <div class="page">
126 <h4> Configure your footer here </h4>
126 <div><h4> Write HTML for your footer here </h4></div>
127 <div id="footer-input" class="ace-mouchak">127 <div id="footer-input" class="ace-mouchak">
128 <%= M.escapeHtml(footer) %>128 <%= M.escapeHtml(footer) %>
129 </div>129 </div>
140 <div id="pagelist"></div>140 <div id="pagelist"></div>
141 <button class="btn btn-primary" id="addPage">Add Page</button>141 <button class="btn btn-primary" id="addPage">Add Page</button>
142 <hr>142 <hr>
143 <p> <a href="#" id="menu-config"> Site Menu </a> </p>
144 <p> <a href="#" id="header-config"> Header Config </a> </p>
145 <p> <a href="#" id="footer-config"> Footer Config </a> </p>
143 <p> <a href="#" id="header-config"> Header </a> </p>
144 <p> <a href="#" id="footer-config"> Footer </a> </p>
145 <p> <a href="#" id="menu-config"> Navigation Menu </a> </p>
146 <p><a href="{{ url_for('index') }}"> Go to site </a></p>146 <p><a href="{{ url_for('index') }}"> Go to site </a></p>
147 </div>147 </div>
148 </script>148 </script>