[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/assets/js/ -> editor.min.js (source)

   1  $gp.editor=function(d){return{current:null,orginal_translations:null,init:function(t){var e;$gp.init(),$gp.editor.table=t,$gp.editor.install_hooks(),1===(e=$gp.editor.table.find("tr.preview")).length&&$gp.editor.show(e.eq(0))},original_id_from_row_id:function(t){return t.split("-")[0]},translation_id_from_row_id:function(t){return t.split("-")[1]},show:function(t){var e=t.closest("tr").attr("row"),r=d("#editor-"+e),i=d("#gmt-date-added-"+e),n=d("#local-date-added-"+e),o=(new Date).getTimezoneOffset(),a=new Date(i.text()),s=new Date(a-60*o*1e3);r.length&&($gp.editor.current&&$gp.editor.hide(),r.preview=d("#preview-"+e),r.row_id=e,r.original_id=$gp.editor.original_id_from_row_id(e),r.translation_id=$gp.editor.translation_id_from_row_id(e),r.orginal_translations=d('textarea[name="translation['+r.original_id+'][]"]',r).map(function(){return this.value}).get(),$gp.editor.current=r,n.text(s.toLocaleDateString()+" "+s.toLocaleTimeString()),r.show(),r.preview.hide(),d("tr:first",$gp.editor.table).hide(),d("textarea:first",r).focus())},prev:function(){var t;$gp.editor.current&&((t=$gp.editor.current.prevAll("tr.editor")).length?$gp.editor.show(t.eq(0)):$gp.editor.hide())},next:function(){var t;$gp.editor.current&&((t=$gp.editor.current.nextAll("tr.editor")).length?$gp.editor.show(t.eq(0)):$gp.editor.hide())},hide:function(t){(t=t||$gp.editor.current)&&(t.hide(),t.preview.show(),d("tr:first",$gp.editor.table).show(),$gp.editor.current=null)},install_hooks:function(){d($gp.editor.table).on("click","a.edit",$gp.editor.hooks.show).on("dblclick","tr.preview td",$gp.editor.hooks.show).on("change","select.priority",$gp.editor.hooks.set_priority).on("click","a.close",$gp.editor.hooks.cancel).on("click","a.discard-warning",$gp.editor.hooks.discard_warning).on("click","button.copy",$gp.editor.hooks.copy).on("click","button.inserttab",$gp.editor.hooks.tab).on("click","button.insertnl",$gp.editor.hooks.newline).on("click","button.approve",$gp.editor.hooks.set_status_current).on("click","button.reject",$gp.editor.hooks.set_status_rejected).on("click","button.fuzzy",$gp.editor.hooks.set_status_fuzzy).on("click","button.ok",$gp.editor.hooks.ok).on("keydown","tr.editor textarea",$gp.editor.hooks.keydown),d("#translations").tooltip({items:".glossary-word",content:function(){var i=d("<ul>");return d.each(d(this).data("translations"),function(t,e){var r=d("<li>");e.locale_entry&&r.append(d("<span>",{text:e.locale_entry}).addClass("locale-entry bubble")),r.append(d("<span>",{text:e.pos}).addClass("pos")),r.append(d("<span>",{text:e.translation}).addClass("translation")),r.append(d("<span>",{text:e.comment}).addClass("comment")),i.append(r)}),i},hide:!1,show:!1}),d.valHooks.textarea={get:function(t){return t.value.replace(/\r?\n/g,"\r\n")}}},keydown:function(t){var e,r,i,n,o;if(27===t.keyCode||90===t.keyCode&&t.shiftKey&&t.ctrlKey)$gp.editor.hide();else if(33===t.keyCode||38===t.keyCode&&t.ctrlKey)$gp.editor.prev();else if(34===t.keyCode||40===t.keyCode&&t.ctrlKey)$gp.editor.next();else if(13===t.keyCode&&t.shiftKey)e=d(t.target),0===t.altKey&&e.val().length&&((r=e.closest(".textareas").prev()).children()?e.val(r.find(".original").text()):e.val(r.text())),e.nextAll("textarea").length?e.nextAll("textarea").eq(0).focus():$gp.editor.save(e.parents("tr.editor").find("button.ok"));else if(13===t.keyCode&&t.ctrlKey||66===t.keyCode&&t.shiftKey&&t.ctrlKey)0<(o=d(".editor:visible").find(".copy")).length&&o.trigger("click");else if(107===t.keyCode&&t.ctrlKey||65===t.keyCode&&t.shiftKey&&t.ctrlKey)0<(i=d(".editor:visible").find(".approve")).length&&i.trigger("click");else if(109===t.keyCode&&t.ctrlKey||82===t.keyCode&&t.shiftKey&&t.ctrlKey)0<(n=d(".editor:visible").find(".reject")).length&&n.trigger("click");else{if(!(192===t.keyCode&&t.ctrlKey||192===t.keyCode&&t.shiftKey&&t.ctrlKey))return!0;0<(n=d(".editor:visible").find(".fuzzy")).length&&n.trigger("click")}return!1},replace_current:function(t){var e;$gp.editor.current&&($gp.editor.current.after(t),(e=$gp.editor.current).attr("id",e.attr("id")+"-old"),e.preview.attr("id",e.preview.attr("id")+"-old"),$gp.editor.next(),e.preview.remove(),e.remove())},save:function(r){var t,e,i,n=[];$gp.editor.current&&(t=$gp.editor.current,r.prop("disabled",!0),$gp.notices.notice("Saving&hellip;"),n={original_id:t.original_id,_gp_route_nonce:r.data("nonce")},e="translation["+t.original_id+"][]",i=d('textarea[name="'+e+'"]',t).map(function(){return this.value}).get(),n[e]=i,d.ajax({type:"POST",url:$gp_editor_options.url,data:n,dataType:"json",success:function(t){var e;for(e in r.prop("disabled",!1),$gp.notices.success("Saved!"),t)$gp.editor.replace_current(t[e]);$gp.editor.current.hasClass("no-warnings")&&$gp.editor.next()},error:function(t,e){r.prop("disabled",!1),e=t.responseText?"Error: "+t.responseText:"Error saving the translation!",$gp.notices.error(e)}}))},set_priority:function(r){var t,e;$gp.editor.current&&(t=$gp.editor.current,r.prop("disabled",!0),$gp.notices.notice("Setting priority&hellip;"),e={priority:d("option:selected",r).val(),_gp_route_nonce:r.data("nonce")},d.ajax({type:"POST",url:$gp_editor_options.set_priority_url.replace("%original-id%",t.original_id),data:e,success:function(){var t;r.prop("disabled",!1),$gp.notices.success("Priority set!"),t="priority-"+d("option:selected",r).text(),$gp.editor.current.addClass(t),$gp.editor.current.preview.addClass(t)},error:function(t,e){r.prop("disabled",!1),e=t.responseText?"Error: "+t.responseText:"Error setting the priority!",$gp.notices.error(e)}}))},set_status:function(r,t){var e,i,n=!1;$gp.editor.current&&$gp.editor.current.translation_id&&(e=$gp.editor.current,d('[id*="translation_'+e.original_id+'_"]').each(function(){this.value!==this.defaultValue&&(n=!0)}),n?$gp.notices.error("Translation has changed! Please add the new translation before changing its status."):(r.prop("disabled",!0),$gp.notices.notice("Setting status to &#8220;"+t+"&#8221;&hellip;"),i={translation_id:e.translation_id,status:t,_gp_route_nonce:r.data("nonce")},d.ajax({type:"POST",url:$gp_editor_options.set_status_url,data:i,success:function(t){r.prop("disabled",!1),$gp.notices.success("Status set!"),$gp.editor.replace_current(t),$gp.editor.next()},error:function(t,e){r.prop("disabled",!1),e=t.responseText?"Error: "+t.responseText:"Error setting the status!",$gp.notices.error(e)}})))},discard_warning:function(t){var e;$gp.editor.current&&($gp.notices.notice("Discarding&hellip;"),e={translation_id:$gp.editor.current.translation_id,key:t.data("key"),index:t.data("index"),_gp_route_nonce:t.data("nonce")},d.ajax({type:"POST",url:$gp_editor_options.discard_warning_url,data:e,success:function(t){$gp.notices.success("Saved!"),$gp.editor.replace_current(t)},error:function(t,e){e=t.responseText?"Error: "+t.responseText:"Error saving the translation!",$gp.notices.error(e)}}))},copy:function(t){var e=t.parents(".textareas").find("textarea").attr("id").split("_"),r=parseInt(e[e.length-1],10),i=t.parents(".textareas").prev().find(".original_raw").eq(r);i.hasClass("original_raw")||(i=t.parents(".strings").find(".original_raw").eq(r)),i=i.text(),t.parents(".textareas").find("textarea").val(i).focus()},tab:function(t){var e=t.parents(".textareas").find("textarea"),r=e.prop("selectionStart"),i=e.val(),n=i.substring(0,r),o=i.substring(r,i.length);e.val(n+"\t"+o),e.focus(),e[0].selectionEnd=r+1},newline:function(t){var e=t.parents(".textareas").find("textarea"),r=e.prop("selectionStart"),i=e.val(),n=i.substring(0,r),o=i.substring(r,i.length);e.val(n+"\n"+o),e.focus(),e[0].selectionEnd=r+1},hooks:{show:function(){return $gp.editor.show(d(this)),!1},hide:function(){return $gp.editor.hide(),!1},ok:function(){return $gp.editor.save(d(this)),!1},cancel:function(){var t=0;for(t=0;t<$gp.editor.current.orginal_translations.length;t++)d('textarea[id="translation_'+$gp.editor.current.original_id+"_"+t+'"]').val($gp.editor.current.orginal_translations[t]);return $gp.editor.hide(),!1},keydown:function(t){return $gp.editor.keydown(t)},copy:function(){return $gp.editor.copy(d(this)),!1},tab:function(){return $gp.editor.tab(d(this)),!1},newline:function(){return $gp.editor.newline(d(this)),!1},discard_warning:function(){return $gp.editor.discard_warning(d(this)),!1},set_status_current:function(){return $gp.editor.set_status(d(this),"current"),!1},set_status_rejected:function(){return $gp.editor.set_status(d(this),"rejected"),!1},set_status_fuzzy:function(){return $gp.editor.set_status(d(this),"fuzzy"),!1},set_priority:function(){return $gp.editor.set_priority(d(this)),!1}}}}(jQuery),jQuery(function(t){$gp.editor.init(t("#translations"))});


Generated: Wed Nov 25 01:01:57 2020 Cross-referenced by PHPXref 0.7.1