From 98f86c4cddc1b82d424a8ecce92d502d435658dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=92scar=20Casajuana?= Date: Mon, 30 Jun 2014 17:32:12 +0200 Subject: [PATCH] Fixed count() method not properly counting. This was causing some buttons to appear when they should not --- jquery.sheepItPlugin.js | 140 ++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/jquery.sheepItPlugin.js b/jquery.sheepItPlugin.js index 51f0aeb..23c7ff0 100644 --- a/jquery.sheepItPlugin.js +++ b/jquery.sheepItPlugin.js @@ -11,15 +11,15 @@ * Gabriel Alonso: Bugfixes * * @license - * + * * SheepIt is free software: you can redistribute it and/or modify * it under the terms of the MIT license - * + * * SheepIt is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MIT license for more details. - * + * * You should have received a copy of the MIT license * along with SheepIt. If not, see . */ @@ -53,7 +53,7 @@ }; return clone; - + } /** @@ -87,7 +87,7 @@ if (typeof options.beforeRemoveCurrent === "function") { options.beforeRemoveCurrent(source); } - + if (options.removeCurrentConfirmation) { if ( confirm(options.removeCurrentConfirmationMsg) ) { removeCurrentForm($(this).data('removableClone')); @@ -95,7 +95,7 @@ } else { removeCurrentForm($(this).data('removableClone')); } - + // After remove current callBack function if (typeof options.afterRemoveCurrent === "function") { options.afterRemoveCurrent(source); @@ -137,14 +137,14 @@ } - + function getOrSetTemplate(element, attrname){ var template=element.attr(attrname+"template"); if(template) { return unescape(template); } var att=element.attr(attrname); - // Hide index occurrences inside the template (todo: better escaping method) + // Hide index occurrences inside the template (todo: better escaping method) element.attr(attrname+"template", escape(att)); return att; } @@ -160,7 +160,7 @@ ,nameTemplateAttr = getOrSetTemplate(that, "name") ,idAttr = that.attr("id") ,nameAttr = that.attr("name") - + /* Normalize field name attributes */ newNameAttr = nameTemplateAttr.replace(options.indexFormat, index); that.attr("name", newNameAttr); @@ -263,22 +263,22 @@ function normalizeForms() { if(hasForms()){ - + noFormsTemplate.hide(); - + if(options.continuousIndex) { - + var index=0 , form=getFirstForm(); - + do{ normalizeForm(form, index); index++; form = getNextForm(form); }while (form!=false) } - - + + }else{ noFormsTemplate.show(); } @@ -289,15 +289,15 @@ if (typeof index == 'undefined') { index=getIndex(); } - + var idTemplate=getOrSetTemplate(form, "id"); // Normalize form id if (form.attr("id")) { form.attr("id", idTemplate + index); } - - + + // Normalize indexes for fields name and id attributes normalizeFieldsForForm(form, index); @@ -311,7 +311,7 @@ // Replace all index occurrences inside the html form.html(form.html().replace(re, index)); } - + // Remove current form control var removeCurrent = form.find(options.removeCurrentSelector); (options.allowRemoveCurrent) ? removeCurrent.show() : removeCurrent.hide(); @@ -330,7 +330,7 @@ /** * Add a new form to the collection - * + * * @parameter normalize: avoid normalize all forms if not necessary */ function addForm(normalizeAllafterAdd, form) @@ -338,7 +338,7 @@ if (typeof normalizeAllafterAdd == 'undefined') { normalizeAllafterAdd = true; } - + if (typeof form == 'undefined') { form = false; } @@ -347,9 +347,9 @@ if (typeof options.beforeAdd === "function") { options.beforeAdd(source); } - + var newForm = false; - + // Pre-generated form if (form) { if ( typeof(form) == 'string' ) { @@ -360,9 +360,9 @@ } else { return false; } - + newForm.remove(); - + } // Cloned Form else { @@ -371,20 +371,20 @@ } if (canAddForm() && newForm) { - + newForm = normalizeForm(newForm); - + // Remove current control var removeCurrentBtn = newForm.find(options.removeCurrentSelector).first(); removeCurrentBtn.click(clickOnRemoveCurrent); removeCurrentBtn.data('removableClone', newForm); - - + + // Index newForm.data('formIndex', getIndex()); - + // Linked references (separators and forms) newForm.data('previousSeparator',false); newForm.data('nextSeparator',false); @@ -417,7 +417,7 @@ var x = 0; var nestedForms = []; - + for(x in options.nestedForms) { if (typeof(options.nestedForms[x].id) != 'undefined' && typeof(options.nestedForms[x].options) != 'undefined') { @@ -425,7 +425,7 @@ options.nestedForms[x].parentForm = source; var id = options.nestedForms[x].id.replace(options.indexFormat,newForm.data('formIndex')); var nestedForm = $('#' + id).sheepIt(options.nestedForms[x].options); - + nestedForms.push(nestedForm); } } @@ -433,12 +433,12 @@ } extendForm(newForm); - + forms.push(newForm); /** * If index has to be continuous, - * all items are reindexed/renumbered using + * all items are reindexed/renumbered using * normalizeAll() after add a new form clone */ if (normalizeAllafterAdd || options.continuousIndex) { @@ -451,7 +451,7 @@ } return true; - + } else { return false; } @@ -600,11 +600,11 @@ function next() { if (ip !== false) { - + if (forms.length > 1) { var i = 0; var init = parseFloat(ip+1); - + for (i=init; i=0 ; i--) { - + if (forms[i]) { ip = i; return true; @@ -706,7 +706,7 @@ var count = 0; var x = []; for (x in forms) { - if (forms[x] ) { + if (typeof forms[x] === 'object') { count++; } } @@ -759,7 +759,7 @@ { var x = 0; var position = 0; - + for (x=0; x<=index; x++) { if (forms[x]) { position++; @@ -767,7 +767,7 @@ } return position; } - + /** * Get the current index (Forms array length) */ @@ -842,7 +842,7 @@ return false; } } - + /** * Get a form by its position */ @@ -869,7 +869,7 @@ { if (hasForms()) { first(); - + var x = 0; var activeForms = []; for (x=0; x 0) { - + // Multiple values? var mv = false; if (typeof(value) == 'object') { @@ -1016,7 +1016,7 @@ if (mf) { if (mv) { - + var fieldsToFill = []; fieldsToFill['fields'] = []; fieldsToFill['values'] = []; @@ -1059,9 +1059,9 @@ } } } - + }); - + } @@ -1115,7 +1115,7 @@ } } - function setOptions(newOptions) + function setOptions(newOptions) { options = []; options = $.extend(defaults, newOptions); @@ -1174,7 +1174,7 @@ */ templateForm = $(options.formTemplateSelector); noFormsTemplate = $(options.noFormsTemplateSelector); - + // Get the template for clonning template = templateForm.cloneWithAttribut(true); templateForm.remove(); @@ -1291,7 +1291,7 @@ return false; } }, - + /* ----- Forms ----- */ // Get all Forms getForms: function() { @@ -1304,7 +1304,7 @@ getForm: function(val) { if (typeof(val) != 'undefined') { val++; - } + } return getForm(val); }, getLastForm: function() { @@ -1356,11 +1356,11 @@ /* ----- Advanced ----- */ inject: function(data) { - + // Loop over each data using a Proxy (function , context) $.each(data, $.proxy( fillData, source )); } - + }); } @@ -1369,7 +1369,7 @@ * Extends cloned forms with many useful methods, * used to control each form with javascript */ - function extendForm(form) + function extendForm(form) { // API $.extend( form, { @@ -1435,7 +1435,7 @@ * Gets the first element of the collection and decorates with jquery */ var source = $(this).first(); - + // Extend source with useful methods extendSource(source); @@ -1455,7 +1455,7 @@ ip = false, // Internal ip // Default options defaults = { - + // Controls selectors addSelector: '#' + $(this).attr("id") + '_add', addNSelector: '#' + $(this).attr("id") + '_add_n', @@ -1511,7 +1511,7 @@ afterRemoveCurrent: function(){}, beforeRemoveCurrent: function(){}, insertNewForms: 'after', - continuousIndex: true //Keep index continuous and starting from 0 + continuousIndex: true //Keep index continuous and starting from 0 };