1'use strict'; 2 3var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 4 5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 6 7// TODO: make this library agnostic 8// TODO: document the events 9 10(function ($) { 11 12 var PLUGIN_NAME = 'slideMenu'; 13 var DEFAULT_OPTIONS = { 14 position: 'left', 15 showBackLink: true, 16 keycodeOpen: null, 17 keycodeClose: 27, //esc 18 submenuLinkBefore: '', 19 submenuLinkAfter: '', 20 backLinkBefore: '', 21 backLinkAfter: '', 22 23 }; 24 25 var SlideMenu = function () { 26 function SlideMenu(options) { 27 _classCallCheck(this, SlideMenu); 28 29 this.options = options; 30 31 this._menu = options.elem; 32 33 // Add wrapper 34 this._menu.find('ul:first').wrap('<div class="slider">'); 35 36 this._anchors = this._menu.find('a'); 37 this._slider = this._menu.find('.slider:first'); 38 39 this._level = 0; 40 this._isOpen = false; 41 this._isAnimating = false; 42 this._hasMenu = this._anchors.length > 0; 43 this._lastAction = null; 44 45 this._setupEventHandlers(); 46 this._setupMenu(); 47 48 if (this._hasMenu) this._setupSubmenus(); 49 } 50 51 /** 52 * Toggle the menu 53 * @param {boolean|null} open 54 * @param {boolean} animate 55 */ 56 57 58 _createClass(SlideMenu, [{ 59 key: 'toggle', 60 value: function toggle() { 61 var open = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; 62 var animate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; 63 64 var offset = void 0; 65 66 if (open === null) { 67 if (this._isOpen) { 68 this.close(); 69 } else { 70 this.open(); 71 } 72 return; 73 } else if (open) { 74 offset = 0; 75 this._isOpen = true; 76 } else { 77 offset = this.options.position === 'left' ? '-100%' : '100%'; 78 this._isOpen = false; 79 } 80 81 this._triggerEvent(); 82 83 if (animate) this._triggerAnimation(this._menu, offset);else { 84 this._pauseAnimations(this._triggerAnimation.bind(this, this._menu, offset)); 85 this._isAnimating = false; 86 } 87 } 88 89 /** 90 * Open the menu 91 * @param {boolean} animate Use CSS transitions 92 */ 93 94 }, { 95 key: 'open', 96 value: function open() { 97 var animate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; 98 99 this._lastAction = 'open'; 100 this.toggle(true, animate); 101 } 102 103 /** 104 * Close the menu 105 * @param {boolean} animate Use CSS transitions 106 */ 107 108 }, { 109 key: 'close', 110 value: function close() { 111 var animate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; 112 113 this._lastAction = 'close'; 114 this.toggle(false, animate); 115 } 116 117 /** 118 * Navigate one menu hierarchy back if possible 119 */ 120 121 }, { 122 key: 'back', 123 value: function back() { 124 this._lastAction = 'back'; 125 this._navigate(null, -1); 126 } 127 128 /** 129 * Navigate to a specific link on any level (useful to open the correct hierarchy directly) 130 * @param {string|object}
130 target A string selector a plain DOM object or a jQuery instance 131 */ 132 133 }, { 134 key: 'backToMain', 135 value: function backToMain() { 136 this._lastAction = 'back'; 137 this._level = 0; 138 this._triggerAnimation(this._slider, -0); 139 } 140 141 /** 142 * Navigate to a specific link on any level (useful to open the correct hierarchy directly) 143 * @param {string|object} target A string selector a plain DOM object or a jQuery instance 144 */ 145 146 }, { 147 key: 'navigateTo', 148 value: function navigateTo(target) { 149 var _this = this; 150 151 target = this._menu.find($(target)).first(); 152 153 if (!target.length) return false; 154 155 var parents = target.parents('ul'); 156 var level = parents.length - 1; 157 158 if (level === 0) return false; 159 160 this._pauseAnimations(function () { 161 _this._level = level; 162 parents.show().first().addClass('active'); 163 _this._triggerAnimation(_this._slider, -_this._level * 100); 164 }); 165 } 166 167 /** 168 * Set up all event handlers 169 * @private 170 */ 171 172 }, { 173 key: '_setupEventHandlers', 174 value: function _setupEventHandlers() { 175 var _this2 = this; 176 177 if (this._hasMenu) { 178 this._anchors.click(function (event) { 179 var anchor = $(event.target).is('a') ? $(event.target) : $(event.target).parents('a:first'); 180 _this2._navigate(anchor); 181 }); 182 } 183 184 $(this._menu.add(this._slider)).on('transitionend msTransitionEnd', function () { 185 _this2._isAnimating = false; 186 _this2._triggerEvent(true); 187 }); 188 189 $(document).keydown(function (e) { 190 switch (e.which) { 191 case _this2.options.keycodeClose: 192 _this2.close(); 193 break; 194 195 case _this2.options.keycodeOpen: 196 _this2.open(); 197 break; 198 199 default: 200 return; 201 } 202 e.preventDefault(); 203 }); 204 205 this._menu.on('sm.back-after', function () { 206 var lastActiveUl = 'ul ' + '.active '.repeat(_this2._level + 1); 207 _this2._menu.find(lastActiveUl).removeClass('active').hide(); 208 }); 209 } 210 211 /** 212 * Trigger a custom event to support callbacks 213 * @param {boolean} afterAnimation Mark this event as `before` or `after` callback 214 * @private 215 */ 216 217 }, { 218 key: '_triggerEvent', 219 value: function _triggerEvent() { 220 var afterAnimation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; 221 222 var eventName = 'sm.' + this._lastAction; 223 if (afterAnimation) eventName += '-after'; 224 this._menu.trigger(eventName); 225 } 226 227 /** 228 * Navigate the _menu - that is slide it one step left or right 229 * @param {jQuery} anchor The clicked anchor or button element 230 * @param {int} dir Navigation direction: 1 = forward, 0 = backwards 231 * @private 232 */ 233 234 }, { 235 key: '_navigate', 236 value: function _navigate(anchor) { 237 var dir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; 238 239 // Abort if an animation is still running 240 if (this._isAnimating) { 241 return; 242 } 243 244 var offset = (this._level + dir) * -100; 245 246 if (dir > 0) { 247 if (!anchor.next('ul').length) return; 248 249 anchor.next('ul').addClass('active').show(); 250 } else if (this._level === 0) { 251 return; 252 } 253 254 this._lastAction = dir > 0 ? 'forward' : 'back';
255 this._level = this._level + dir; 256 257 this._triggerAnimation(this._slider, offset); 258 } 259 260 /** 261 * Start the animation (the CSS transition) 262 * @param elem 263 * @param offset 264 * @private 265 */ 266 267 }, { 268 key: '_triggerAnimation', 269 value: function _triggerAnimation(elem, offset) { 270 this._triggerEvent(); 271 272 if (!(String(offset).indexOf('%') !== -1)) offset += '%'; 273 274 elem.css('transform', 'translateX(' + offset + ')'); 275 this._isAnimating = true; 276 } 277 278 /** 279 * Initialize the menu 280 * @private 281 */ 282 283 }, { 284 key: '_setupMenu', 285 value: function _setupMenu() { 286 var _this3 = this; 287 288 this._pauseAnimations(function () { 289 switch (_this3.options.position) { 290 case 'left': 291 _this3._menu.css({ 292 left: 0, 293 right: 'auto', 294 transform: 'translateX(-100%)' 295 }); 296 break; 297 default: 298 _this3._menu.css({ 299 left: 'auto', 300 right: 0 301 }); 302 break; 303 } 304 _this3._menu.show(); 305 }); 306 } 307 308 /** 309 * Pause the CSS transitions, to apply CSS changes directly without an animation 310 * @param work 311 * @private 312 */ 313 314 }, { 315 key: '_pauseAnimations', 316 value: function _pauseAnimations(work) { 317 this._menu.addClass('no-transition'); 318 work(); 319 this._menu[0].offsetHeight; // trigger a reflow, flushing the CSS changes 320 this._menu.removeClass('no-transition'); 321 } 322 323 /** 324 * Enhance the markup of menu items which contain a submenu 325 * @private 326 */ 327 328 }, { 329 key: '_setupSubmenus', 330 value: function _setupSubmenus() { 331 var _this4 = this; 332 333 this._anchors.each(function (i, anchor) { 334 anchor = $(anchor); 335 if (anchor.next('ul').length) { 336 // prevent default behaviour (use link just to navigate) 337 anchor.click(function (ev) { 338 ev.preventDefault(); 339 }); 340 341 // add `before` and `after` text 342 var anchorTitle = anchor.text(); 343 anchor.html(_this4.options.submenuLinkBefore + anchorTitle + _this4.options.submenuLinkAfter); 344 var parent_url=anchor.data('pageurl'); 345 // add a back button 346 if (_this4.options.showBackLink) { 347 if(anchor.parent().hasClass('top-lavel-link')){ 348 //anchorTitle = ' Main Menu'; 349 } 350 if($.trim(anchorTitle) != "Media Center" ){ 351 var activeLink = $('<a href="'+parent_url+'" class="hide-link" data-action="back" >See '+anchorTitle+'</a>'); 352 activeLink.html(_this4.options.backLinkBefore + activeLink.text() + _this4.options.backLinkAfter); 353 } 354 //else{ 355 // var activeLink = $('<a class="slide-menu-control special-link" data-action="back" >See '+anchorTitle+' Services</a>'); 356 // } 357 anchor.next('ul').prepend($('<li>').append(activeLink)); 358 var backLink = $('<a href class="slide-menu-control" data-action="backToMain">Back to Main Menu</a>'); 359 backLink.html(_this4.options.backLinkBefore + backLink.text() + _this4.options.backLinkAfter);
360 anchor.next('ul').prepend($('<li>').append(backLink)); 361 } 362 } 363 }); 364 } 365 }]); 366 367 return SlideMenu; 368 }(); 369 370 // Link control buttons with the API 371 372 373 $('body').on('click', '.slide-menu-control', function (e) { 374 var menu = void 0; 375 var target = $(this).data('target'); 376 377 if (!target || target === 'this') { 378 menu = $(this).parents('.slide-menu:first'); 379 } else { 380 menu = $('#' + target); 381 } 382 383 if (!menu.length) return; 384 385 var instance = menu.data(PLUGIN_NAME); 386 var action = $(this).data('action'); 387 388 if (instance && typeof instance[action] === 'function') { 389 instance[action](); 390 } 391 392 if(action === 'toggle'){ 393 $(".fix-bottom-resources").addClass('d-none'); 394 $(".side-pannel").addClass('d-none'); 395 }else if(action === 'close'){ 396 $(".fix-bottom-resources").removeClass('d-none'); 397 $(".side-pannel").removeClass('d-none'); 398 } 399 400 return false; 401 }); 402 403 // Register the jQuery plugin 404 $.fn[PLUGIN_NAME] = function (options) { 405 if (!$(this).length) { 406 console.warn('Slide Menu: Unable to find menu DOM element. Maybe a typo?'); 407 return; 408 } 409 410 options = $.extend({}, DEFAULT_OPTIONS, options); 411 options.elem = $(this); 412 413 var instance = new SlideMenu(options); 414 $(this).data(PLUGIN_NAME, instance); 415 416 return instance; 417 }; 418})(jQuery); 419//# sourceMappingURL=slide-menu.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.