From 790efeb8b96f9aa2ba328dae1252a39c2fe3a44e Mon Sep 17 00:00:00 2001 From: Federico Zivolo Date: Tue, 23 Sep 2014 11:21:38 +0200 Subject: [PATCH] replaced dynamic inputs detection --- scripts/material.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/material.js b/scripts/material.js index c9323cff..85aeeeaa 100644 --- a/scripts/material.js +++ b/scripts/material.js @@ -4,7 +4,7 @@ $(function (){ ripples.init(".btn:not(.btn-link), .navbar a, .nav-tabs a, .withripple"); - $(document).bind("DOMSubtreeModified", function(){ + var initInputs = function() { // Add fake-checkbox to material checkboxes $(".checkbox > label > input").not(".bs-material").addClass("bs-material").after(""); @@ -12,7 +12,7 @@ $(function (){ $(".radio > label > input").not(".bs-material").addClass("bs-material").after(""); // Add elements for material inputs - $("input.form-control, textarea.form-control, select.form-control").each( function() { + $("input.form-control, textarea.form-control, select.form-control").not(".bs-material").each( function() { if ($(this).is(".bs-material")) { return; } $(this).wrap("
"); $(this).after(""); @@ -32,8 +32,17 @@ $(function (){ } }); - }).trigger("DOMSubtreeModified"); + }; + initInputs(); + // Support for "arrive.js" to dynamically detect creation of elements + // include it before this script to take advantage of this feature + // https://github.com/uzairfarooq/arrive/ + if (document.arrive) { + document.arrive("input, textarea, select", function() { + initInputs(); + }); + } $(document).on("keyup change", ".form-control", function() { var self = $(this); @@ -67,4 +76,3 @@ $(function (){ $(this).prev().val(value); }); }); -