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

Last change on this file since 261 was 250, checked in by alloc, 9 years ago

Fixes 5_7_9

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