//-- copyright
// Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
// See doc/COPYRIGHT.rdoc for more details.
jQuery(document).ready(function(t){var e;init_members_cb=function(){formatItems=function(t,e,i){var n=t.name.toUpperCase().indexOf(i.term.toUpperCase()),s=i.term.length,o=[];return 0>n?"<span data-value='"+t.id+"'>"+OpenProject.Helpers.markupEscape(t.name)+"</span>":(o.push(OpenProject.Helpers.markupEscape(t.name.substring(0,n))),o.push("<span class='select2-match' data-value='"+t.id+"'>"),o.push(OpenProject.Helpers.markupEscape(t.name.substring(n,n+s))),o.push("</span>"),o.push(OpenProject.Helpers.markupEscape(t.name.substring(n+s,t.name.length))),o.join(""))},formatItemSelection=function(t){return OpenProject.Helpers.markupEscape(t.name)},t("#members_add_form select.select2-select").each(function(e,i){t(i).hasClass("remote")||void 0!==t(i).attr("data-ajaxURL")?t.isEmptyObject(i.siblings("div.select2-select.select2-container"))||setTimeout(function(){var e,n,s,o;e={},n=["title","placeholder"];for(var r=0;r<t(i).get(0).attributes.length;r++)s=t(i).get(0).attributes[r].name,0===s.indexOf("data-")||t.inArray(s,n),e[s]=t(i).attr(s);o=t(i).after("<input type='hidden'></input>").siblings(":input:first"),o.attr(e),t(o).select2({multiple:o.attr("multiple"),minimumInputLength:o.attr("data-minimumInputLength")||0,ajax:{url:t(o).attr("data-ajaxURL"),quietMillis:500,dataType:"json",data:function(t,e){return{q:t,page_limit:10,page:e,id:o.attr("data-projectId")}},results:function(e){return active_items=[],e.results.items.each(function(e){e.name=t("<pre>").text(e.name).html(),active_items.push(e)}),{results:active_items,more:e.results.more}}},formatResult:formatItems,formatSelection:formatItemSelection}),t(i).remove()},0):t(i).select2()})},e=t("#tab-members").first(),null!==e&&e.hasClass("selected")?init_members_cb():e.click(init_members_cb)});