source: binary-improvements/webserver/js/tabs.js@ 417

Last change on this file since 417 was 293, checked in by alloc, 8 years ago

Web: Added option to not show the navbar on page load

File size: 3.1 KB
RevLine 
[250]1$.widget( "7dtd.tabbedContent", {
2 options: {
3 contentdiv: null,
[274]4 hidebuttondiv: null,
5 menubardiv: null,
6 hideOnStart: false,
7 hideClass: "hidenav",
[250]8 currentTabClass: "current_tab",
9 menuButtonClass: "menu_button",
10 allowedMenuButtonClass: "allowed",
11 contentDivClass: "contenttab",
12 },
13
14 _create: function () {
15 var options = this.options;
16 var self = this;
17
18 if (options.contentdiv == null) {
19 console.log ("contentdiv has to be set!");
20 }
21
[274]22 if (options.hidebuttondiv == null) {
23 console.log ("hidebuttondiv has to be set!");
24 }
25
26 if (options.menubardiv == null) {
27 console.log ("menubardiv has to be set!");
28 }
29
[293]30 var hidebarevent = function (event) {
[274]31 if (options.hidebuttondiv.hasClass (options.hideClass)) {
32 $("*").removeClass (options.hideClass);
33 } else {
34 options.hidebuttondiv.addClass (options.hideClass);
35 options.contentdiv.addClass (options.hideClass);
36 options.menubardiv.addClass (options.hideClass);
37 }
[293]38 };
39 options.hidebuttondiv.on ('click.action', hidebarevent);
[274]40
[250]41 this.element.find ("ul > li").addClass (options.menuButtonClass);
[249]42
[250]43 options.contentdiv.children ("div").addClass (options.contentDivClass);
44 this.element.on ('click.action', "ul > li", function (event) {
45 var menuElement = $(this);
46 var linkElement = menuElement.children ("a");
47 var linkName = linkElement.attr ("href");
48 self.openTab (linkName);
49 });
[249]50
[250]51 self.tabs = {};
52 this.element.find (".menu_button").each (function () {
53 self.tabs [$(this).children ("a").attr ("href")] = $(this);
54 });
[293]55
56 if (options.hideOnStart == true) {
57 hidebarevent ();
58 }
[250]59 },
60
61 applyPermissions: function () {
62 var self = this;
63 this.element.find (".menu_button").each (function () {
64 if ($(this).children ("a").data ("permission")) {
65 var perm = $(this).children ("a").data ("permission");
66 if (HasPermission (perm)) {
67 $(this).addClass (self.options.allowedMenuButtonClass);
68 }
69 } else {
70 $(this).addClass (self.options.allowedMenuButtonClass);
71 }
72 });
[249]73
[250]74 this.element.find ("." + self.options.allowedMenuButtonClass).first ().click ();
75 },
76
77 openTab: function (name) {
78 if (name.indexOf ("#") != 0)
79 name = "#" + name;
[245]80
[250]81 if (!this.tabs.hasOwnProperty(name)) {
82 console.log ("no tab named " + name + " in " + this);
83 return;
84 }
[245]85
[250]86 var menuElement = $(".menu_button > a[href=" + name + "]").parent ();
87
88 $("*").removeClass (this.options.currentTabClass);
89 menuElement.addClass (this.options.currentTabClass);
90 $(name).addClass (this.options.currentTabClass);
91 var oldTab = this.currentTab;
92 this.currentTab = name;
93
94 if (oldTab != name) {
95 this._trigger ("tabopened", null, { oldTab: oldTab, newTab: name } );
[245]96 }
[250]97 },
98
99 currentOpenTab: function () {
100 return this.currentTab;
101 },
102
103 isTabOpen: function (name) {
104 if (name.indexOf ("#") != 0)
105 name = "#" + name;
[245]106
[250]107 return this.currentTab == name;
108 },
[245]109
[250]110/*
111 value: function (value) {
112 if ( value === undefined ) {
113 return this.options.value;
114 } else {
115 this.options.value = this._constrain( value );
116 var progress = this.options.value + "%";
117 this.element.text( progress );
118 }
119 },
120*/
121});
Note: See TracBrowser for help on using the repository browser.