(function (/* Object */ ns) { 'use strict'; /** * @alias app.product.Tree * @param {Object} options * @constructor */ ns.Tree = function (options) { this.construct.apply(this, arguments); }; ns.Tree.prototype.construct = function (options) { this.options = $.extend({ treeContainerId: 'tree-container', currentNodeId: null }, options); this.screen = { width1: 767, width2: 800 }; this.initActions(); this.initTree(); }; ns.Tree.prototype.initTree = function () { var treeview = $('#' + this.options.treeContainerId); var options = { core: { themes: { icons: false, responsive: true }, expand_selected_onload: true }, plugins: [ 'state' ], state: { key: this.options.treeContainerId } }; treeview.on('changed.jstree', _.bind(this.onNodeChange, this)); treeview.on('close_node.jstree', _.bind(this.onNodeClose, this)); treeview.on('open_node.jstree', _.bind(this.onNodeOpen, this)); treeview.jstree(options); setTimeout(_.bind(function () { if (this.options.currentNodeId) { var instance = treeview.jstree(true); instance.select_node(this.options.currentNodeId); var selected = instance.get_selected(true); for (var i in selected) { if (!instance.is_leaf(selected[i].id) && !instance.is_open(selected[i].id)) { instance.open_node(selected[i]) } } } treeview.show(); }, this), 0); }; ns.Tree.prototype.onNodeChange = function (e, data) { switch (data.action) { case 'select_node': if (undefined != data.event) { this.onNodeSelect(data); } break; } }; ns.Tree.prototype.onNodeClose = function (e, data) { data.instance.save_state(); }; ns.Tree.prototype.onNodeOpen = function (e, data) { data.instance.save_state(); }; ns.Tree.prototype.onNodeSelect = function (data) { if (data.node.a_attr.href) { document.location.href = data.node.a_attr.href; } else { } }; ns.Tree.prototype.initActions = function () { $(window).on('resize', _.bind(this.onResize, this)); $(window).trigger('resize'); }; ns.Tree.prototype.onResize = function () { var windowWidth = $(window).width(); var left = $('.clmn-left'); var center = $('.clmn-center'); if (windowWidth >= this.screen.width1 && windowWidth <= this.screen.width2) { if (left.hasClass('span4')) { left.removeClass('span4').addClass('span5'); center.removeClass('span8').addClass('span7'); } } else { if (left.hasClass('span5')) { left.removeClass('span5').addClass('span4'); center.removeClass('span7').addClass('span8'); } } }; })(qs.defineNS('app.product'));