mirror of
https://github.com/prymitive/karma
synced 2026-08-23 11:56:20 +00:00
Rewrite js classes using prototypes
This removes the requirement on ES6 support in the browser, which will allow to use unsee on older browsers
This commit is contained in:
+33
-37
@@ -1,5 +1,3 @@
|
||||
// jshint esversion: 6
|
||||
|
||||
/* globals LRUMap */ // lru.js
|
||||
/* globals moment */ // moment.js
|
||||
|
||||
@@ -11,43 +9,41 @@ var Alerts = (function() {
|
||||
var silences = {},
|
||||
labelCache = new LRUMap(1000);
|
||||
|
||||
class AlertGroup {
|
||||
constructor(groupData) {
|
||||
$.extend(this, groupData);
|
||||
}
|
||||
|
||||
Render() {
|
||||
return Templates.Render("alertGroup", {
|
||||
group: this,
|
||||
silences: silences,
|
||||
static_color_label: Colors.GetStaticLabels(),
|
||||
alert_limit: 5
|
||||
});
|
||||
}
|
||||
|
||||
// called after group was rendered for the first time
|
||||
Added() {
|
||||
UI.SetupAlertGroupUI($("#" + this.id));
|
||||
}
|
||||
|
||||
Update() {
|
||||
// hide popovers in this group
|
||||
$("#" + this.id + " [data-label-type='filter']").popover("hide");
|
||||
|
||||
// remove all elements prior to content update to purge all event listeners and hooks
|
||||
$.each($("#" + this.id).find(".panel-body, .panel-heading"), function(i, elem) {
|
||||
$(elem).remove();
|
||||
});
|
||||
|
||||
$("#" + this.id).html($(this.Render()).html());
|
||||
$("#" + this.id).data("hash", this.hash);
|
||||
|
||||
// pulse the badge to show that group content was changed, repeat it twice
|
||||
$("#" + this.id + " > .panel > .panel-heading > .badge:in-viewport").finish().fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
|
||||
}
|
||||
|
||||
function AlertGroup(groupData) {
|
||||
$.extend(this, groupData);
|
||||
}
|
||||
|
||||
AlertGroup.prototype.Render = function() {
|
||||
return Templates.Render("alertGroup", {
|
||||
group: this,
|
||||
silences: silences,
|
||||
static_color_label: Colors.GetStaticLabels(),
|
||||
alert_limit: 5
|
||||
});
|
||||
};
|
||||
|
||||
// called after group was rendered for the first time
|
||||
AlertGroup.prototype.Added = function() {
|
||||
UI.SetupAlertGroupUI($("#" + this.id));
|
||||
};
|
||||
|
||||
AlertGroup.prototype.Update = function() {
|
||||
// hide popovers in this group
|
||||
$("#" + this.id + " [data-label-type='filter']").popover("hide");
|
||||
|
||||
// remove all elements prior to content update to purge all event listeners and hooks
|
||||
$.each($("#" + this.id).find(".panel-body, .panel-heading"), function(i, elem) {
|
||||
$(elem).remove();
|
||||
});
|
||||
|
||||
$("#" + this.id).html($(this.Render()).html());
|
||||
$("#" + this.id).data("hash", this.hash);
|
||||
|
||||
// pulse the badge to show that group content was changed, repeat it twice
|
||||
$("#" + this.id + " > .panel > .panel-heading > .badge:in-viewport").finish().fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
|
||||
};
|
||||
|
||||
|
||||
var destroyGroup = function(groupID) {
|
||||
$("#" + groupID + " [data-label-type='filter']").popover("hide");
|
||||
$("#" + groupID + " [data-toggle='tooltip']").tooltip("hide");
|
||||
|
||||
+41
-47
@@ -1,5 +1,3 @@
|
||||
// jshint esversion: 6
|
||||
|
||||
/* globals Clipboard */ // clipboard.js
|
||||
/* globals Cookies */ // js.cookie.js
|
||||
|
||||
@@ -8,54 +6,50 @@
|
||||
/* exported ConfigOption */
|
||||
var ConfigOption = (function() {
|
||||
|
||||
class optionClass {
|
||||
|
||||
constructor(params) {
|
||||
this.Cookie = params.Cookie;
|
||||
this.QueryParam = params.QueryParam;
|
||||
this.Selector = params.Selector;
|
||||
this.Get = params.Getter || function() {
|
||||
return $(this.Selector).is(":checked");
|
||||
};
|
||||
this.Set = params.Setter || function(val) {
|
||||
$(this.Selector).bootstrapSwitch("state", $.parseJSON(val), true);
|
||||
};
|
||||
this.Action = params.Action || function() {};
|
||||
this.Init = params.Init || function() {
|
||||
var elem = this;
|
||||
$(this.Selector).on("switchChange.bootstrapSwitch", function(event, val) {
|
||||
elem.Save(val);
|
||||
elem.Action(val);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Load() {
|
||||
var currentVal = this.Get();
|
||||
|
||||
var val = Cookies.get(this.Cookie);
|
||||
if (val !== undefined) {
|
||||
this.Set(val);
|
||||
}
|
||||
|
||||
var q = QueryString.Parse();
|
||||
if (q[this.QueryParam] !== undefined) {
|
||||
this.Set(q[this.QueryParam]);
|
||||
}
|
||||
|
||||
if (currentVal != val) {
|
||||
this.Action(val);
|
||||
}
|
||||
}
|
||||
|
||||
Save(val) {
|
||||
Cookies.set(this.Cookie, val, {
|
||||
expires: 365,
|
||||
path: ""
|
||||
function optionClass(params) {
|
||||
this.Cookie = params.Cookie;
|
||||
this.QueryParam = params.QueryParam;
|
||||
this.Selector = params.Selector;
|
||||
this.Get = params.Getter || function() {
|
||||
return $(this.Selector).is(":checked");
|
||||
};
|
||||
this.Set = params.Setter || function(val) {
|
||||
$(this.Selector).bootstrapSwitch("state", $.parseJSON(val), true);
|
||||
};
|
||||
this.Action = params.Action || function() {};
|
||||
this.Init = params.Init || function() {
|
||||
var elem = this;
|
||||
$(this.Selector).on("switchChange.bootstrapSwitch", function(event, val) {
|
||||
elem.Save(val);
|
||||
elem.Action(val);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
optionClass.prototype.Load = function() {
|
||||
var currentVal = this.Get();
|
||||
|
||||
var val = Cookies.get(this.Cookie);
|
||||
if (val !== undefined) {
|
||||
this.Set(val);
|
||||
}
|
||||
|
||||
}
|
||||
var q = QueryString.Parse();
|
||||
if (q[this.QueryParam] !== undefined) {
|
||||
this.Set(q[this.QueryParam]);
|
||||
}
|
||||
|
||||
if (currentVal != val) {
|
||||
this.Action(val);
|
||||
}
|
||||
};
|
||||
|
||||
optionClass.prototype.Save = function(val) {
|
||||
Cookies.set(this.Cookie, val, {
|
||||
expires: 365,
|
||||
path: ""
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
New: optionClass
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user