summaryrefslogtreecommitdiff
path: root/lib/scripts/helpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/helpers.js')
-rw-r--r--lib/scripts/helpers.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js
index 129964d29..77e7ffc4a 100644
--- a/lib/scripts/helpers.js
+++ b/lib/scripts/helpers.js
@@ -144,3 +144,22 @@ function hasFlash(version){
if(ver >= version) return true;
return false;
}
+
+/**
+ * A PHP-style substr_replace
+ *
+ * Supports negative start and length and omitting length, but not
+ * str and replace arrays.
+ * See http://php.net/substr-replace for further documentation.
+ */
+function substr_replace(str, replace, start, length) {
+ var a2, b1;
+ a2 = (start < 0 ? str.length : 0) + start;
+ if (typeof length === 'undefined') {
+ length = str.length - a2;
+ } else if (length < 0 && start < 0 && length <= start) {
+ length = 0;
+ }
+ b1 = (length < 0 ? str.length : a2) + length;
+ return str.substring(0, a2) + replace + str.substring(b1);
+}