[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 |
|
---|
| 30 | options.hidebuttondiv.on ('click.action', 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 |
|
---|
[250] | 40 | this.element.find ("ul > li").addClass (options.menuButtonClass);
|
---|
[249] | 41 |
|
---|
[250] | 42 | options.contentdiv.children ("div").addClass (options.contentDivClass);
|
---|
| 43 | this.element.on ('click.action', "ul > li", function (event) {
|
---|
| 44 | var menuElement = $(this);
|
---|
| 45 | var linkElement = menuElement.children ("a");
|
---|
| 46 | var linkName = linkElement.attr ("href");
|
---|
| 47 | self.openTab (linkName);
|
---|
| 48 | });
|
---|
[249] | 49 |
|
---|
[250] | 50 | self.tabs = {};
|
---|
| 51 | this.element.find (".menu_button").each (function () {
|
---|
| 52 | self.tabs [$(this).children ("a").attr ("href")] = $(this);
|
---|
| 53 | });
|
---|
| 54 | },
|
---|
| 55 |
|
---|
| 56 | applyPermissions: function () {
|
---|
| 57 | var self = this;
|
---|
| 58 | this.element.find (".menu_button").each (function () {
|
---|
| 59 | if ($(this).children ("a").data ("permission")) {
|
---|
| 60 | var perm = $(this).children ("a").data ("permission");
|
---|
| 61 | if (HasPermission (perm)) {
|
---|
| 62 | $(this).addClass (self.options.allowedMenuButtonClass);
|
---|
| 63 | }
|
---|
| 64 | } else {
|
---|
| 65 | $(this).addClass (self.options.allowedMenuButtonClass);
|
---|
| 66 | }
|
---|
| 67 | });
|
---|
[249] | 68 |
|
---|
[250] | 69 | this.element.find ("." + self.options.allowedMenuButtonClass).first ().click ();
|
---|
| 70 | },
|
---|
| 71 |
|
---|
| 72 | openTab: function (name) {
|
---|
| 73 | if (name.indexOf ("#") != 0)
|
---|
| 74 | name = "#" + name;
|
---|
[245] | 75 |
|
---|
[250] | 76 | if (!this.tabs.hasOwnProperty(name)) {
|
---|
| 77 | console.log ("no tab named " + name + " in " + this);
|
---|
| 78 | return;
|
---|
| 79 | }
|
---|
[245] | 80 |
|
---|
[250] | 81 | var menuElement = $(".menu_button > a[href=" + name + "]").parent ();
|
---|
| 82 |
|
---|
| 83 | $("*").removeClass (this.options.currentTabClass);
|
---|
| 84 | menuElement.addClass (this.options.currentTabClass);
|
---|
| 85 | $(name).addClass (this.options.currentTabClass);
|
---|
| 86 | var oldTab = this.currentTab;
|
---|
| 87 | this.currentTab = name;
|
---|
| 88 |
|
---|
| 89 | if (oldTab != name) {
|
---|
| 90 | this._trigger ("tabopened", null, { oldTab: oldTab, newTab: name } );
|
---|
[245] | 91 | }
|
---|
[250] | 92 | },
|
---|
| 93 |
|
---|
| 94 | currentOpenTab: function () {
|
---|
| 95 | return this.currentTab;
|
---|
| 96 | },
|
---|
| 97 |
|
---|
| 98 | isTabOpen: function (name) {
|
---|
| 99 | if (name.indexOf ("#") != 0)
|
---|
| 100 | name = "#" + name;
|
---|
[245] | 101 |
|
---|
[250] | 102 | return this.currentTab == name;
|
---|
| 103 | },
|
---|
[245] | 104 |
|
---|
[250] | 105 | /*
|
---|
| 106 | value: function (value) {
|
---|
| 107 | if ( value === undefined ) {
|
---|
| 108 | return this.options.value;
|
---|
| 109 | } else {
|
---|
| 110 | this.options.value = this._constrain( value );
|
---|
| 111 | var progress = this.options.value + "%";
|
---|
| 112 | this.element.text( progress );
|
---|
| 113 | }
|
---|
| 114 | },
|
---|
| 115 | */
|
---|
| 116 | });
|
---|