Mercurial > hg > rc2
diff plugins/jqueryui/js/jquery.tagedit.min.js @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/jqueryui/js/jquery.tagedit.min.js Thu Jan 04 15:52:31 2018 -0500 @@ -0,0 +1,1 @@ +(function(a){a.fn.tagedit=function(m){m=a.extend(true,{autocompleteURL:null,checkToDeleteURL:null,deletedPostfix:"-d",addedPostfix:"-a",additionalListClass:"",allowEdit:true,allowDelete:true,allowAdd:true,direction:"ltr",animSpeed:500,autocompleteOptions:{select:function(o,p){a(this).val(p.item.value).trigger("transformToTag",[p.item.id]);return false}},breakKeyCodes:[13,44],checkNewEntriesCaseSensitive:false,texts:{removeLinkTitle:"Remove from list.",saveEditLinkTitle:"Save changes.",deleteLinkTitle:"Delete this tag from database.",deleteConfirmation:"Are you sure to delete this entry?",deletedElementTitle:"This Element will be deleted.",breakEditLinkTitle:"Cancel",forceDeleteConfirmation:"There are more records using this tag, are you sure do you want to remove it?"},tabindex:false},m||{});if(this.length==0){return}if(m.autocompleteURL){m.autocompleteOptions.source=m.autocompleteURL}var l=this.attr("dir");if(l&&l.length>0){m.direction=this.attr("dir")}var c=this;var b=null;var n=new RegExp("^(.*)\\[([0-9]*?("+m.deletedPostfix+"|"+m.addedPostfix+")?)?]$","i");var d=c.eq(0).attr("name").match(n);if(d&&d.length==4){d=d[1]}else{alert("elementname dows not match the expected format (regexp: "+n+")");return}var e;if(!m.tabindex&&(e=c.eq(0).attr("tabindex"))){m.tabindex=e}g();function g(){var o='<ul class="tagedit-list '+m.additionalListClass+'">';c.each(function(r){var t=a(this).attr("name").match(n);if(t&&t.length==4&&(m.deleteEmptyItems==false||a(this).val().length>0)){if(t[1].length>0){var q=typeof t[2]!="undefined"?t[2]:"",s="tagedit-"+d+"-"+(q||r);o+='<li class="tagedit-listelement tagedit-listelement-old" aria-labelledby="'+s+'">';o+='<span dir="'+m.direction+'" id="'+s+'">'+a(this).val()+"</span>";o+='<input type="hidden" name="'+d+"["+q+']" value="'+a(this).val()+'" />';if(m.allowDelete){o+='<a class="tagedit-close" title="'+m.texts.removeLinkTitle+'" aria-label="'+m.texts.removeLinkTitle+" "+a(this).val()+'">x</a>'}o+="</li>"}}});c.last().after(o);var p=c.last().next();c.remove();c=p;if(m.deletedPostfix.length>0){c.find('input[name$="'+m.deletedPostfix+']"]').each(function(){h(a(this).parent())})}o='<li class="tagedit-listelement tagedit-listelement-new">';if(m.allowAdd){o+='<input type="text" name="'+d+'[]" value="" id="tagedit-input" disabled="disabled" class="tagedit-input-disabled" dir="'+m.direction+'"/>'}o+="</li>";o+="</ul>";c.append(o).attr("tabindex",m.tabindex).find("#tagedit-input").attr("tabindex",m.tabindex).each(function(){a(this).autoGrowInput({comfortZone:15,minWidth:15,maxWidth:20000});a(this).bind("transformToTag",function(u,w){var s=(typeof w!="undefined"&&(w.length>0||w>0));var q=s==true||m.autocompleteOptions.noCheck?false:true;var t=i(a(this).val(),q);if(t[0]===true||(t[0]===false&&typeof t[1]=="string")){if(s==false&&typeof t[1]=="string"){s=true;w=t[1]}if(m.allowAdd==true||s){var v="tagedit-"+d+"-"+w;o='<li class="tagedit-listelement tagedit-listelement-old" aria-labelledby="'+v+'">';o+='<span dir="'+m.direction+'" id="'+v+'">'+a(this).val()+"</span>";var r=s?d+"["+w+m.addedPostfix+"]":d+"[]";o+='<input type="hidden" name="'+r+'" value="'+a(this).val()+'" />';o+='<a class="tagedit-close" title="'+m.texts.removeLinkTitle+'" aria-label="'+m.texts.removeLinkTitle+" "+a(this).val()+'">x</a>';o+="</li>";a(this).parent().before(o)}}a(this).val("");if(m.autocompleteOptions.source){if(a(this).is(":ui-autocomplete")){a(this).autocomplete("close")}}}).keydown(function(t){var s=t.keyCode>0?t.keyCode:t.which;switch(s){case 46:if(!b){break}case 8:if(b){b.fadeOut(m.animSpeed,function(){a(this).remove()});j();t.preventDefault();return false}else{if(a(this).val().length==0){var q=c.find("li.tagedit-listelement-old").last();q.fadeOut(m.animSpeed,function(){q.remove()});t.preventDefault();return false}}break;case 9:if(a(this).val().length>0&&a("ul.ui-autocomplete #ui-active-menuitem").length==0){a(this).trigger("transformToTag");t.preventDefault();return false}break;case 37:case 39:if(a(this).val().length==0){var u=s==37?-1:1,r=c.find("li.tagedit-listelement-old");x=r.length,next=0;r.each(function(v,w){if(a(w).hasClass("tagedit-listelement-focus")){x=v;return true}});j();next=Math.max(0,x+u);if(r.get(next)){b=r.eq(next).addClass("tagedit-listelement-focus");a(this).attr("aria-activedescendant",b.attr("aria-labelledby"));if(m.autocompleteOptions.source!=false){a(this).autocomplete("close").autocomplete("disable")}}t.preventDefault();return false}break;default:if(b!==null){t.preventDefault();t.bubble=false;return false}}return true}).keypress(function(r){var q=r.keyCode>0?r.keyCode:r.which;if(a.inArray(q,m.breakKeyCodes)>-1){if(a(this).val().length>0&&a("ul.ui-autocomplete #ui-active-menuitem").length==0){a(this).trigger("transformToTag")}r.preventDefault();return false}else{if(a(this).val().length>0){j()}}return true}).bind("paste",function(r){var q=a(this);if(r.type=="paste"){setTimeout(function(){q.trigger("transformToTag")},1)}}).blur(function(){if(a(this).val().length==0){a(this).attr("disabled","disabled").addClass("tagedit-input-disabled")}else{var q=a(this);a(this).data("blurtimer",window.setTimeout(function(){q.val("")},500))}j();if(m.tabindex){c.attr("tabindex",m.tabindex)}}).focus(function(){window.clearTimeout(a(this).data("blurtimer"));c.attr("tabindex","-1")});if(m.autocompleteOptions.source!=false){a(this).autocomplete(m.autocompleteOptions)}}).end().click(function(q){switch(q.target.tagName){case"A":a(q.target).parent().fadeOut(m.animSpeed,function(){a(q.target).parent().remove();c.find("#tagedit-input").focus()});break;case"INPUT":case"SPAN":case"LI":if(a(q.target).hasClass("tagedit-listelement-deleted")==false&&a(q.target).parent("li").hasClass("tagedit-listelement-deleted")==false){return f(q)}default:a(this).find("#tagedit-input").removeAttr("disabled").removeClass("tagedit-input-disabled").focus()}return false}).focus(function(q){a(this).click()})}function j(){if(b){if(m.autocompleteOptions.source!=false){c.find("#tagedit-input").autocomplete("enable")}b.removeClass("tagedit-listelement-focus");b=null;c.find("#tagedit-input").removeAttr("aria-activedescendant")}}function f(p){if(m.allowEdit==false){return}var o=p.target.tagName=="SPAN"?a(p.target).parent():a(p.target);var r=null;o.bind("finishEdit",function(u,v){window.clearTimeout(r);var t=a(this).find(":text");var s=i(t.val(),true);if(t.val().length>0&&(typeof v=="undefined"||v===false)&&(s[0]==true)){a(this).find(":hidden").val(t.val());a(this).find("span").html(t.val())}t.remove();a(this).find("a.tagedit-save, a.tagedit-break, a.tagedit-delete").remove();a(this).removeClass("tagedit-listelement-edit").unbind("finishEdit");return false});var q=o.find(":hidden");html='<input type="text" name="tmpinput" autocomplete="off" value="'+q.val()+'" class="tagedit-edit-input" dir="'+m.direction+'"/>';html+='<a class="tagedit-save" title="'+m.texts.saveEditLinkTitle+'">o</a>';html+='<a class="tagedit-break" title="'+m.texts.breakEditLinkTitle+'">x</a>';if(m.allowDelete==true&&o.find(":hidden").length>0&&typeof o.find(":hidden").attr("name").match(n)[3]!="undefined"){html+='<a class="tagedit-delete" title="'+m.texts.deleteLinkTitle+'">d</a>'}q.after(html);o.addClass("tagedit-listelement-edit").find("a.tagedit-save").click(function(){a(this).parent().trigger("finishEdit");return false}).end().find("a.tagedit-break").click(function(){a(this).parent().trigger("finishEdit",[true]);return false}).end().find("a.tagedit-delete").click(function(){window.clearTimeout(r);if(confirm(m.texts.deleteConfirmation)){var s=k(a(this).parent());if(!s&&confirm(m.texts.forceDeleteConfirmation)){h(a(this).parent())}if(s){h(a(this).parent())}a(this).parent().find(":text").trigger("finishEdit",[true])}else{a(this).parent().find(":text").trigger("finishEdit",[true])}return false}).end().find(":text").focus().autoGrowInput({comfortZone:10,minWidth:15,maxWidth:20000}).keypress(function(s){switch(s.keyCode){case 13:s.preventDefault();a(this).parent().trigger("finishEdit");return false;case 27:s.preventDefault();a(this).parent().trigger("finishEdit",[true]);return false}return true}).blur(function(){var s=a(this);r=window.setTimeout(function(){s.parent().trigger("finishEdit",[true])},500)})}function k(q){if(m.checkToDeleteURL===null){return false}var o=q.find("input:hidden").attr("name");var s=new RegExp("\\d");var r=o.match(s);var p=false;a.ajax({async:false,url:m.checkToDeleteURL,dataType:"json",type:"POST",data:{tagId:r},complete:function(u,v){var t=a.parseJSON(u.responseText);if(t.success===true){p=t.allowDelete}}});return p}function h(o){o.trigger("finishEdit",[true]).addClass("tagedit-listelement-deleted").attr("title",m.deletedElementTitle);o.find(":hidden").each(function(){var q=new RegExp("("+m.addedPostfix+"|"+m.deletedPostfix+")?]");var p=a(this).attr("name").replace(q,m.deletedPostfix+"]");a(this).attr("name",p)})}function i(v,t){t=typeof t=="undefined"?false:t;var q=null;var w=m.checkNewEntriesCaseSensitive==true?v:v.toLowerCase();var s=true;c.find("li.tagedit-listelement-old input:hidden").each(function(){var z=m.checkNewEntriesCaseSensitive==true?a(this).val():a(this).val().toLowerCase();if(z==w){s=false}});if(s==true&&t==true&&m.autocompleteOptions.source!=false){var y=[];if(a.isArray(m.autocompleteOptions.source)){y=m.autocompleteOptions.source}else{if(a.isFunction(m.autocompleteOptions.source)){m.autocompleteOptions.source({term:v},function(z){y=z})}else{if(typeof m.autocompleteOptions.source==="string"){var p=m.autocompleteOptions.source;if(p.match(/\?/)){p+="&"}else{p+="?"}p+="term="+v;a.ajax({async:false,url:p,dataType:"json",complete:function(z,A){y=a.parseJSON(z.responseText)}})}}}for(var r=0;r<y.length;r++){var o=y[r].label?y[r].label:y[r];var u=m.checkNewEntriesCaseSensitive==true?o:o.toLowerCase();if(u==w){s=false;q=typeof y[r]=="string"?r:y[r].id;break}}}return new Array(s,q)}}})(jQuery);(function(a){a.fn.autoGrowInput=function(b){b=a.extend({maxWidth:1000,minWidth:0,comfortZone:70},b);this.filter("input:text").each(function(){var f=b.minWidth||a(this).width(),g="",d=a(this),e=a("<tester/>").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:d.css("fontSize"),fontFamily:d.css("fontFamily"),fontWeight:d.css("fontWeight"),letterSpacing:d.css("letterSpacing"),whiteSpace:"nowrap"}),c=function(){if(g===(g=d.val())){return}var l=g.replace(/&/g,"&").replace(/\s/g," ").replace(/</g,"<").replace(/>/g,">");e.html(l);var j=e.width(),k=(j+b.comfortZone)>=f?j+b.comfortZone:f,i=d.width(),h=(k<i&&k>=f)||(k>f&&k<b.maxWidth);if(h){d.width(k)}};e.insertAfter(d);a(this).bind("keyup keydown blur update",c);c()});return this}})(jQuery); \ No newline at end of file