From f2b1dd2f264dd7501db1fcce0167e58547bbcb92 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 5 Aug 2015 09:28:47 +0200 Subject: [PATCH] Added function to underscore convert strings. --- app/assets/javascripts/application.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index ca08f0c53..b68c7c063 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -155,7 +155,7 @@ function clone(item, full) { function clone2(item) { if (!item) { return item; } // null, undefined values check - var types = [ Number, String, Boolean ], + var types = [ Number, String, Boolean ], result; // normalizing primitives if someone did new String('aaa'), or new Number('444'); @@ -168,13 +168,13 @@ function clone2(item) { if (typeof result == "undefined") { if (Object.prototype.toString.call( item ) === "[object Array]") { result = []; - item.forEach(function(child, index, array) { + item.forEach(function(child, index, array) { result[index] = clone( child ); }); } else if (typeof item == "object") { // testing that this is DOM if (item.nodeType && typeof item.cloneNode == "function") { - var result = item.cloneNode( true ); + var result = item.cloneNode( true ); } else if (!item.prototype) { // check that this is a literal if (item instanceof Date) { result = new Date(item); @@ -203,6 +203,11 @@ function clone2(item) { return result; } +// taken from https://github.com/epeli/underscore.string/blob/master/underscored.js +function underscored (str) { + return str.trim().replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase(); +} + jQuery.event.special.remove = { remove: function(e) { if (e.handler) e.handler();