Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated minified JS file.

  • Loading branch information...
commit 68e2d8c551debf048b224570be60e4d3b5f44cad 1 parent 529ef62
@lailsonbm authored
Showing with 1 addition and 1 deletion.
  1. +1 −1  vendor/assets/javascripts/jquery.nested-fields.min.js
View
2  vendor/assets/javascripts/jquery.nested-fields.min.js
@@ -4,4 +4,4 @@
* Requires jquery-ujs adapter.
* https://github.com/lailsonbm/awesome_nested_fields
*/
-(function(h){var i={beforeInsert:function(q,r){r()},afterInsert:function(q){},beforeRemove:function(q,r){r()},afterRemove:function(q){},itemTemplateSelector:".item.template",emptyTemplateSelector:".empty.template",containerSelector:".items, .container",itemSelector:".item",emptySelector:".empty",addSelector:".add",removeSelector:".remove",newItemIndex:"new_nested_item",unescapeTemplate:true};var d={init:function(q){return this.each(function(){var r=h(this);if(r.data("nested-fields.options")){g("Nested fields already defined for this element. If you want to redefine options, destroy it and init again.");return r}q=h.extend({},i,q);q.itemTemplate=h(q.itemTemplateSelector,r);q.emptyTemplate=h(q.emptyTemplateSelector,r);q.container=h(q.containerSelector,r);q.add=h(q.addSelector,r);r.data("nested-fields.options",q);l(q);b(q,r)})},insert:function(r,q){q=h.extend({},j(this),q);return f(r,q)},remove:function(r,q){q=h.extend({},j(this),q);return e(r,q)},removeAll:function(q){q=h.extend({},j(this),q);h(d.items.apply(this)).each(function(r,s){d.remove(s,q)})},items:function(){return c(j(this))},destroy:function(){h(this).removeData("nested-fields.options");h("*",this).unbind(".nested-fields")}};h.fn.nestedFields=function(q){if(d[q]){return d[q].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof q==="object"||!q){return d.init.apply(this,arguments)}else{h.error("Method "+q+" does not exist on jQuery.nestedFields")}}};function j(r){var q=h(r);while(q.length>0){var s=q.data("nested-fields.options");if(s){return s}else{q=q.parent()}}return null}function l(q){q.add.bind("click.nested-fields",function(r){r.preventDefault();f(null,q)})}function b(q,r){h(q.itemSelector,r).each(function(s,t){k(t,q)})}function m(r){var u=new RegExp(r.newItemIndex,"g");var q=new Date().getTime();var t=r.itemTemplate.html();if(r.unescapeTemplate){t=o(t)}var s=h(t.replace(u,q));s.attr("data-new-record",true);s.attr("data-record-id",q);k(s,r);return s}function f(q,r){var s=m(r);function t(){if(q){q(s)}a(r);r.container.append(s)}if(!r.skipBefore){r.beforeInsert(s,t);if(r.beforeInsert.length<=1){t()}}else{t()}if(!r.skipAfter){r.afterInsert(s)}return s}function a(q){p(q).remove()}function e(t,s){function q(){if(r.attr("data-new-record")){r.remove()}else{r.find("INPUT[name$='[_destroy]']").val("true");r.hide()}n(s)}var r=h(t);if(!s.skipBefore){s.beforeRemove(r,q);if(s.beforeRemove.length<=1){q()}}else{q()}if(!s.skipAfter){s.afterRemove(r)}return r}function n(q){if(c(q).length===0){var r=q.emptyTemplate.html();if(q.unescapeTemplate){r=o(r)}q.container.append(r)}}function k(t,r){var q=h(t).find(r.removeSelector);var u=q.attr("data-confirm");var s=u?"confirm:complete":"click";q.bind(s+".nested-fields",function(v,w){v.preventDefault();if(w===undefined||w===true){e(t,r)}})}function c(q){return q.container.find(q.itemSelector+":visible")}function p(q){return q.container.find(q.emptySelector)}function o(q){var r=document.createElement("div");r.innerHTML=q;return r.childNodes.length===0?"":jQuery.trim(r.childNodes[0].nodeValue)}function g(q){if(console&&console.log){console.log(q)}}})(jQuery);
+(function($){"use strict";var defaultSettings={beforeInsert:function(item,callback){callback()},afterInsert:function(item){},beforeRemove:function(item,callback){callback()},afterRemove:function(item){},itemTemplateSelector:".item.template",emptyTemplateSelector:".empty.template",containerSelector:".items, .container",itemSelector:".item",emptySelector:".empty",addSelector:".add",removeSelector:".remove",newItemIndex:"new_nested_item",unescapeTemplate:true};var methods={init:function(options){return this.each(function(){var $this=$(this);if($this.data("nested-fields.options")){log("Nested fields already defined for this element. If you want to redefine options, destroy it and init again.");return $this}options=$.extend({},defaultSettings,options);options.itemTemplate=$(options.itemTemplateSelector,$this);options.emptyTemplate=$(options.emptyTemplateSelector,$this);options.container=$(options.containerSelector,$this);options.add=$(options.addSelector,$this);$this.data("nested-fields.options",options);bindInsertToAdd(options);bindRemoveToItems(options,$this)})},insert:function(callback,options){options=$.extend({},getOptions(this),options);return insertItemWithCallbacks(callback,options)},remove:function(element,options){options=$.extend({},getOptions(this),options);return removeItemWithCallbacks(element,options)},removeAll:function(options){options=$.extend({},getOptions(this),options);$(methods.items.apply(this)).each(function(i,el){methods.remove(el,options)})},items:function(){return findItems(getOptions(this))},destroy:function(){$(this).removeData("nested-fields.options");$("*",this).unbind(".nested-fields")}};$.fn.nestedFields=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof method==="object"||!method){return methods.init.apply(this,arguments)}else{$.error("Method "+method+" does not exist on jQuery.nestedFields")}};function getOptions(element){var $element=$(element);while($element.length>0){var data=$element.data("nested-fields.options");if(data){return data}else{$element=$element.parent()}}return null}function bindInsertToAdd(options){options.add.bind("click.nested-fields",function(e){e.preventDefault();insertItemWithCallbacks(null,options)})}function bindRemoveToItems(options,$this){$(options.itemSelector,$this).each(function(i,item){bindRemoveToItem(item,options)})}function prepareTemplate(options){var regexp=new RegExp(options.newItemIndex,"g");var newId=(new Date).getTime();var contents=options.itemTemplate.html();if(options["unescapeTemplate"]){contents=unescape_html_tags(contents)}var newItem=$(contents.replace(regexp,newId));newItem.attr("data-new-record",true);newItem.attr("data-record-id",newId);bindRemoveToItem(newItem,options);return newItem}function insertItemWithCallbacks(onInsertCallback,options){var newItem=prepareTemplate(options);function insert(){if(onInsertCallback){onInsertCallback(newItem)}removeEmpty(options);options.container.append(newItem)}if(!options.skipBefore){options.beforeInsert(newItem,insert);if(options.beforeInsert.length<=1){insert()}}else{insert()}if(!options.skipAfter){options.afterInsert(newItem)}return newItem}function removeEmpty(options){findEmpty(options).remove()}function removeItemWithCallbacks(element,options){function remove(){if($element.attr("data-new-record")){$element.remove()}else{$element.find("INPUT[name$='[_destroy]']").val("true");$element.hide()}insertEmpty(options)}var $element=$(element);if(!options.skipBefore){options.beforeRemove($element,remove);if(options.beforeRemove.length<=1){remove()}}else{remove()}if(!options.skipAfter){options.afterRemove($element)}return $element}function insertEmpty(options){if(findItems(options).length===0){var contents=options.emptyTemplate.html();if(contents){if(options["unescapeTemplate"]){contents=unescape_html_tags(contents)}options.container.append(contents)}}}function bindRemoveToItem(item,options){var removeHandler=$(item).find(options.removeSelector);var needsConfirmation=removeHandler.attr("data-confirm");var event=needsConfirmation?"confirm:complete":"click";removeHandler.bind(event+".nested-fields",function(e,confirmed){e.preventDefault();if(confirmed===undefined||confirmed===true){removeItemWithCallbacks(item,options)}return false})}function findItems(options){return options.container.find(options.itemSelector+":visible")}function findEmpty(options){return options.container.find(options.emptySelector)}function unescape_html_tags(html){var e=document.createElement("div");e.innerHTML=html;return e.childNodes.length===0?"":jQuery.trim(e.childNodes[0].nodeValue)}function log(msg){if(console&&console.log){console.log(msg)}}})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.