From 1839f2634b1d70dc61a409a683e644239cd2d7d0 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 2 Jul 2014 03:43:53 +0100 Subject: [PATCH] add jquery.fix.clone.js --- .../public/javascripts/jquery.fix.clone.js | 31 +++++++++++++++++++ Netdisco/share/views/layouts/main.tt | 1 + 2 files changed, 32 insertions(+) create mode 100644 Netdisco/share/public/javascripts/jquery.fix.clone.js diff --git a/Netdisco/share/public/javascripts/jquery.fix.clone.js b/Netdisco/share/public/javascripts/jquery.fix.clone.js new file mode 100644 index 00000000..83f523b3 --- /dev/null +++ b/Netdisco/share/public/javascripts/jquery.fix.clone.js @@ -0,0 +1,31 @@ +// Textarea and select clone() bug workaround | Spencer Tipping +// Licensed under the terms of the MIT source code license + +// Motivation. +// jQuery's clone() method works in most cases, but it fails to copy the value of textareas and select elements. This patch replaces jQuery's clone() method with a wrapper that fills in the +// values after the fact. + +// An interesting error case submitted by Piotr Przybyl: If two box itself rather than relying on jQuery's value-based val(). + +(function (original) { + jQuery.fn.clone = function () { + var result = original.apply(this, arguments), + my_textareas = this.find('textarea').add(this.filter('textarea')), + result_textareas = result.find('textarea').add(result.filter('textarea')), + my_selects = this.find('select').add(this.filter('select')), + result_selects = result.find('select').add(result.filter('select')); + + for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val()); + for (var i = 0, l = my_selects.length; i < l; ++i) { + for (var j = 0, m = my_selects[i].options.length; j < m; ++j) { + if (my_selects[i].options[j].selected === true) { + result_selects[i].options[j].selected = true; + } + } + } + return result; + }; +}) (jQuery.fn.clone); + +// Generated by SDoc diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index d7e75a81..e2ab8e8a 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -20,6 +20,7 @@ +