source: binary-improvements/webserver_legacy/js/tabs.js@ 464

Last change on this file since 464 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
Line 
1$.widget( "7dtd.tabbedContent", {
2 options: {
3 contentdiv: null,
4 hidebuttondiv: null,
5 menubardiv: null,
6 hideOnStart: false,
7 hideClass: "hidenav",
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
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
30 var hidebarevent = function (event) {
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 }
38 };
39 options.hidebuttondiv.on ('click.action', hidebarevent);
40
41 this.element.find ("ul > li").addClass (options.menuButtonClass);
42
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 });
50
51 self.tabs = {};
52 this.element.find (".menu_button").each (function () {
53 self.tabs [$(this).children ("a").attr ("href")] = $(this);
54 });
55
56 if (options.hideOnStart == true) {
57 hidebarevent ();
58 }
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 });
73
74 this.element.find ("." + self.options.allowedMenuButtonClass).first ().click ();
75 },
76
77 openTab: function (name) {
78 if (name.indexOf ("#") != 0)
79 name = "#" + name;
80
81 if (!this.tabs.hasOwnProperty(name)) {
82 console.log ("no tab named " + name + " in " + this);
83 return;
84 }
85
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 } );
96 }
97 },
98
99 currentOpenTab: function () {
100 return this.currentTab;
101 },
102
103 isTabOpen: function (name) {
104 if (name.indexOf ("#") != 0)
105 name = "#" + name;
106
107 return this.currentTab == name;
108 },
109
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.