String.prototype.replaceAll = function (search, replacement) { return this.replace(new RegExp(search, 'g'), replacement); }; String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); }; Array.prototype.remove = function (s) { if (typeof this.indexof === "undefined") { return; } var i = this.indexOf(s); if (i > -1) { this.splice(i, 1); } }; Array.prototype.equals = function (array) { // if the other array is a falsy value, return if (!array) return false; // compare lengths - can save a lot of time if (this.length != array.length) return false; for (var i = 0, l=this.length; i < l; i++) { // Check if we have nested arrays if (this[i] instanceof Array && array[i] instanceof Array) { // recurse into the nested arrays if (!this[i].equals(array[i])) return false; } else if (this[i] != array[i]) { // Warning - two different object instances will never be equal: {x:20} != {x:20} return false; } } return true; }; // Hide method from for-in loops Object.defineProperty(Array.prototype, 'equals', {enumerable: false}); Object.defineProperty(Array.prototype, 'remove', {enumerable: false}); jQuery.fn.exists = function () { return this.length !== 0; }; jQuery.fn.doesntExist = function () { return this.length === 0; }; jQuery.fn.isVisible = function () { return $(this).is(':visible'); }; jQuery.fn.notVisible = function () { return !$(this).is(':visible'); }; jQuery.fn.isMouseOver = function () { return $(this).is(':hover'); }; jQuery.fn.isChecked = function () { return $(this).is(':checked'); }; jQuery.fn.isCheckbox = function () { return $(this).prop('type') == 'checkbox'; }; jQuery.fn.hasAttr = function (name) { return $(this).attr(name) !== undefined; }; jQuery.fn.rebind = function (a, f) { $(this).off(a, f); $(this).on(a, f); }; jQuery.fn.isFocused = function () { return $(this).is(':focus'); }; jQuery.fn.changeHtml = function (newHtml) { $(this).each(function () { let $e = $(this); if (!$e.children('.wrapped').exists()) { $e.wrapInner('
'); let $dimmer = $e.children('.wrapped').children('.ui.dimmer'); if ($dimmer.exists()) { $dimmer.appendTo($e); } } $e.children('.wrapped') .html(newHtml) .unwrap(); }); }; jQuery.fn.extend({ qcss: function(css) { return $(this).queue(function(next) { $(this).css(css); next(); }); } }); jQuery.fn.getOffsetTopFromRootParent = function() { let elem = this[0]; let offset = 0; while (elem.offsetParent != null) { offset += elem.offsetTop; elem = $(elem.offsetParent)[0]; if (elem.offsetParent === null) { offset += elem.offsetTop; } } return offset; }; jQuery.fn.selectRange = function(start, end) { if (!end) { end = start; } return this.each(function() { if (this.setSelectionRange) { this.focus(); this.setSelectionRange(start, end); } else if (this.createTextRange) { var range = this.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } }); }; var uniqId = (function() { let i = 0; return function() { return i++; }; })();