[ Index ] |
PHP Cross Reference of GlotPress |
[Summary view] [Print] [Text view]
1 $gp.editor=function(o){return{current:null,orginal_translations:null,init:function(t){$gp.init(),$gp.editor.table=t,$gp.editor.install_hooks(),1===(t=$gp.editor.table.find("tr.preview")).length&&$gp.editor.show(t.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=o("#editor-"+e),i=o("#gmt-date-added-"+e),n=o("#local-date-added-"+e),t=(new Date).getTimezoneOffset(),i=new Date(i.text()),t=new Date(i-60*t*1e3);r.length&&($gp.editor.current&&$gp.editor.hide(),r.preview=o("#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=o('textarea[name="translation['+r.original_id+'][]"]',r).map(function(){return this.value}).get(),$gp.editor.current=r,n.text(t.toLocaleDateString()+" "+t.toLocaleTimeString()),r.show(),r.preview.hide(),o("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(),$gp.editor.current=null)},install_hooks:function(){o($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","button.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),o("#translations").tooltip({items:".glossary-word",content:function(){var i=o("<ul>");return o.each(o(this).data("translations"),function(t,e){var r=o("<li>");e.locale_entry&&r.append(o("<span>",{text:e.locale_entry}).addClass("locale-entry bubble")),r.append(o("<span>",{text:e.pos}).addClass("pos")),r.append(o("<span>",{text:e.translation}).addClass("translation")),r.append(o("<span>",{text:e.comment}).addClass("comment")),i.append(r)}),i},hide:!1,show:!1}),o.valHooks.textarea={get:function(t){return t.value.replace(/\r?\n/g,"\r\n")}}},keydown:function(t){var e,r,i,n;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=o(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<(n=o(".editor:visible").find(".copy")).length&&n.trigger("click");else if(107===t.keyCode&&t.ctrlKey||65===t.keyCode&&t.shiftKey&&t.ctrlKey)0<(n=o(".editor:visible").find(".approve")).length&&n.trigger("click");else if(109===t.keyCode&&t.ctrlKey||82===t.keyCode&&t.shiftKey&&t.ctrlKey)0<(i=o(".editor:visible").find(".reject")).length&&i.trigger("click");else{if(!(192===t.keyCode&&t.ctrlKey||192===t.keyCode&&t.shiftKey&&t.ctrlKey))return!0;0<(i=o(".editor:visible").find(".fuzzy")).length&&i.trigger("click")}return!1},replace_current:function(t){$gp.editor.current&&($gp.editor.current.after(t),(t=$gp.editor.current).attr("id",t.attr("id")+"-old"),t.preview.attr("id",t.preview.attr("id")+"-old"),$gp.editor.next(),t.preview.remove(),t.remove())},save:function(r){var t,e,i=[];$gp.editor.current&&(e=$gp.editor.current,r.prop("disabled",!0),$gp.notices.notice("Saving…"),i={original_id:e.original_id,_gp_route_nonce:r.data("nonce")},t="translation["+e.original_id+"][]",e=o('textarea[name="'+t+'"]',e).map(function(){return this.value}).get(),i[t]=e,o.ajax({type:"POST",url:$gp_editor_options.url,data:i,dataType:"json",success:function(t){for(var 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…"),e={priority:o("option:selected",r).val(),_gp_route_nonce:r.data("nonce")},o.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-"+o("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=!1;$gp.editor.current&&$gp.editor.current.translation_id&&(e=$gp.editor.current,o('[id*="translation_'+e.original_id+'_"]').each(function(){this.value!==this.defaultValue&&(i=!0)}),i?$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 “"+t+"”…"),t={translation_id:e.translation_id,status:t,_gp_route_nonce:r.data("nonce")},o.ajax({type:"POST",url:$gp_editor_options.set_status_url,data:t,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){$gp.editor.current&&($gp.notices.notice("Discarding…"),t={translation_id:$gp.editor.current.translation_id,key:t.data("key"),index:t.data("index"),_gp_route_nonce:t.data("nonce")},o.ajax({type:"POST",url:$gp_editor_options.discard_warning_url,data:t,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("_"),e=Math.min(parseInt(e[e.length-1],10),1),e=t.parents(".strings").find(".original_raw").eq(e).text();t.parents(".textareas").find("textarea").val(e).focus()},tab:function(t){var e=t.parents(".textareas").find("textarea"),r=e.prop("selectionStart"),i=e.val(),t=i.substring(0,r),i=i.substring(r,i.length);e.val(t+"\t"+i),e.focus(),e[0].selectionEnd=r+1},newline:function(t){var e=t.parents(".textareas").find("textarea"),r=e.prop("selectionStart"),i=e.val(),t=i.substring(0,r),i=i.substring(r,i.length);e.val(t+"\n"+i),e.focus(),e[0].selectionEnd=r+1},hooks:{show:function(){return $gp.editor.show(o(this)),!1},hide:function(){return $gp.editor.hide(),!1},ok:function(){return $gp.editor.save(o(this)),!1},cancel:function(){for(var t=0,t=0;t<$gp.editor.current.orginal_translations.length;t++)o('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(o(this)),!1},tab:function(){return $gp.editor.tab(o(this)),!1},newline:function(){return $gp.editor.newline(o(this)),!1},discard_warning:function(){return $gp.editor.discard_warning(o(this)),!1},set_status_current:function(){return $gp.editor.set_status(o(this),"current"),!1},set_status_rejected:function(){return $gp.editor.set_status(o(this),"rejected"),!1},set_status_fuzzy:function(){return $gp.editor.set_status(o(this),"fuzzy"),!1},set_priority:function(){return $gp.editor.set_priority(o(this)),!1}}}}(jQuery),jQuery(function(t){$gp.editor.init(t("#translations"))});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Dec 3 01:01:05 2024 | Cross-referenced by PHPXref 0.7.1 |