From 068006874dc84f604cb12029cb63c14a305a02c2 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sun, 20 Nov 2016 03:31:26 -0500 Subject: [PATCH] Closes #168 --- CTFd/static/admin/js/utils.js | 55 ++++++++++++++++++++++++++ CTFd/templates/admin/chals.html | 6 +-- CTFd/templates/admin/correct_keys.html | 2 +- CTFd/templates/admin/editor.html | 4 +- CTFd/templates/admin/graphs.html | 2 +- CTFd/templates/admin/pages.html | 4 +- CTFd/templates/admin/team.html | 12 +++--- CTFd/templates/admin/wrong_keys.html | 2 +- 8 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 CTFd/static/admin/js/utils.js diff --git a/CTFd/static/admin/js/utils.js b/CTFd/static/admin/js/utils.js new file mode 100644 index 0000000..5908ad4 --- /dev/null +++ b/CTFd/static/admin/js/utils.js @@ -0,0 +1,55 @@ +//http://stackoverflow.com/a/1186309 +$.fn.serializeObject = function() +{ + var o = {}; + var a = this.serializeArray(); + $.each(a, function() { + if (o[this.name] !== undefined) { + if (!o[this.name].push) { + o[this.name] = [o[this.name]]; + } + o[this.name].push(this.value || ''); + } else { + o[this.name] = this.value || ''; + } + }); + return o; +}; + + +//http://stackoverflow.com/a/2648463 - wizardry! +String.prototype.format = String.prototype.f = function() { + var s = this, + i = arguments.length; + + while (i--) { + s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); + } + return s; +}; + +//http://stackoverflow.com/a/7616484 +String.prototype.hashCode = function() { + var hash = 0, i, chr, len; + if (this.length == 0) return hash; + for (i = 0, len = this.length; i < len; i++) { + chr = this.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; + hash |= 0; // Convert to 32bit integer + } + return hash; +}; + +function colorhash (x) { + color = "" + for (var i = 20; i <= 60; i+=20){ + x += i + x *= i + color += x.toString(16) + }; + return "#" + color.substring(0, 6) +} + +function htmlentities(string) { + return $('
').text(string).html(); +} diff --git a/CTFd/templates/admin/chals.html b/CTFd/templates/admin/chals.html index 2adb5d7..d6f12db 100644 --- a/CTFd/templates/admin/chals.html +++ b/CTFd/templates/admin/chals.html @@ -298,7 +298,7 @@ {% endblock %} {% block scripts %} - - - + + + {% endblock %} diff --git a/CTFd/templates/admin/correct_keys.html b/CTFd/templates/admin/correct_keys.html index 3c23563..f340496 100644 --- a/CTFd/templates/admin/correct_keys.html +++ b/CTFd/templates/admin/correct_keys.html @@ -77,7 +77,7 @@ {% endblock %} {% block scripts %} - + + + + - - - + + + + +