-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
locize-editor.min.js
1 lines (1 loc) · 9.03 KB
/
locize-editor.min.js
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).locizeEditor=e()}(this,function(){"use strict";function t(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t){var n,i,o={top:0,left:0,right:0,bottom:0},r=t&&t.ownerDocument;if(!(n=r&&r.documentElement))return o;"undefined"!==e(t.getBoundingClientRect)&&(o=t.getBoundingClientRect()),i=function(t){return null!=(e=t)&&e===e.window?t:9===t.nodeType&&t.defaultView;var e}(r);var s=o.top+i.pageYOffset-n.clientTop,a=o.left+i.pageXOffset-n.clientLeft;return{top:s,left:a,right:a+(o.right-o.left),bottom:s+(o.bottom-o.top)}}function i(t,e){var n=t,i=void 0!==e.options.nsSeparator?e.options.nsSeparator:":";if(t.indexOf(i)>-1){var o=t.split(i);o.shift(),n=o.join(i)}return n}function o(t,e,n){var i=n.options.defaultNS,o=n.options.nsSeparator||":";if(t.indexOf(o)>-1)i=t.split(o)[0];else{var r;!function t(e){var n=e.getAttribute&&e.getAttribute("i18next-options");if(n||(n=e.getAttribute&&e.getAttribute("data-i18next-options")),n||(n=e.getAttribute&&e.getAttribute("i18n-options")),n||(n=e.getAttribute&&e.getAttribute("data-i18n-options")),n){var i={};try{i=JSON.parse(n)}catch(t){}i.ns&&(r=i.ns)}r||(r=e.getAttribute&&e.getAttribute("i18next-ns")),r||(r=e.getAttribute&&e.getAttribute("data-i18next-ns")),r||(r=e.getAttribute&&e.getAttribute("i18n-ns")),r||(r=e.getAttribute&&e.getAttribute("data-i18n-ns")),!r&&e.parentElement&&t(e.parentElement)}(e),r&&(i=r)}return i}function r(t){if("undefined"==typeof window)return!1;for(var e=window.location.search.substring(1).split("&"),n=0;n<e.length;n++){var i=e[n].split("=");if(i[0]==t)return i[1]}return!1}var s='font-family: "Helvetica", "Arial", sans-serif; font-size: 14px; color: #fff; border: none; font-weight: 300; height: 30px; line-height: 30px; padding: 0; text-align: center; min-width: 90px; text-decoration: none; text-transform: uppercase; text-overflow: ellipsis; white-space: nowrap; outline: none; cursor: pointer;';var a={url:"https://old.locize.app",openDashboard:!1,enabled:!1,enableByQS:"locize",toggleKeyCode:24,toggleKeyModifier:"ctrlKey",lngOverrideQS:"useLng",lngOverride:null,hasNamespacePrefixed:!1,autoOpen:!0,onEditorSaved:function(t,e){},mode:r("locizeMode")||"iframe",iframeContainerStyle:"z-index: 2147480000; position: fixed; top: 0; right: 0; bottom: 0; width: 600px; box-shadow: -3px 0 5px 0 rgba(0,0,0,0.5);",iframeStyle:"height: 100%; width: 600px; border: none;",bodyStyle:"margin-right: 605px;",locizeEditorWindow:{appendTarget:!1,containerClasses:!1},locizeEditorToggle:{appendTarget:!1,containerClasses:!1,title:!1}};return{type:"3rdParty",init:function(e){var n,i=this;e&&!e.init&&(e={languages:[(n=e).lng],nsSeparator:n.nsSeparator||":",options:{editor:n,backend:n,defaultNS:n.defaultNS}}),this.enabled=!1,this.i18next=e,this.options=function(e){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?Object(arguments[n]):{},o=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(i).filter(function(t){return Object.getOwnPropertyDescriptor(i,t).enumerable}))),o.forEach(function(n){t(e,n,i[n])})}return e}({},a,e.options.editor),this.handler=this.handler.bind(this),this.handleSavedMissing=this.handleSavedMissing.bind(this),(this.options.enabled||this.options.enableByQS&&"true"===r(this.options.enableByQS))&&setTimeout(function(){i.options.autoOpen&&i.open()},500),document.addEventListener("keypress",function(t){t[i.options.toggleKeyModifier]&&t.which===i.options.toggleKeyCode&&(i.enabled?i.off():i.on())}),window.addEventListener("message",function(t){t.data[i.options.toggleKeyModifier]&&t.data.which===i.options.toggleKeyCode&&(i.enabled?i.off():i.on()),"savedSegments"===t.data.type&&i.options.onEditorSaved(t.data.lng,t.data.ns)})},handler:function(t){var e=this,s=function(t){if(t.srcElement&&1===t.srcElement.nodeType)return t.srcElement.getAttribute&&""===t.srcElement.getAttribute("ignorelocizeeditor")?null:t.srcElement;var e;if(t.originalEvent&&t.originalEvent.explicitOriginalTarget)e=t.originalEvent.explicitOriginalTarget;else{var i=t.srcElement;if(i.getAttribute&&""===i.getAttribute("ignorelocizeeditor"))return null;for(var o,r=t.pageX,s=t.pageY,a=(n(i),0),l=0;l<i.childNodes.length;l++){var d=i.childNodes[l],c=n(d);1===d.nodeType&&c.bottom<s&&(a=l+1),!o&&c.top+(d.clientHeight||0)>s&&(o=l)}a+1>i.childNodes.length&&(a=i.childNodes.length-1),o||(o=i.childNodes.length);for(var p=a;p<o;p++){var u=i.childNodes[p];if(n(u).left>r)break;u&&8!==u.nodeType&&(e=u)}}return e}(t);if(s){t.preventDefault(),t.stopPropagation();var a=s.textContent||s.text&&s.text.innerText||s.placeholder;if("string"==typeof a){var l=a.replace(/\n +/g,"").trim(),d=function(){var t={message:"searchForKey",projectId:e.i18next.options.backend.projectId,version:e.i18next.options.backend.version||"latest",lng:r(e.options.lngOverrideQS)||e.options.lngOverride||e.i18next.languages[0],ns:o(l,s,e.i18next),token:e.options.hasNamespacePrefixed?i(l,e.i18next):l};if(t.lng&&"cimode"!==t.lng.toLowerCase()||(t.lng=e.i18next.options.backend.referenceLng),e.options.handler)return e.options.handler(t);e.locizeInstance.postMessage(t,e.options.url),e.locizeInstance.focus()};this.options.autoOpen&&("iframe"!==this.options.mode&&!this.locizeInstance||this.locizeInstance.closed)?(this.open(),setTimeout(function(){d()},3e3)):d()}}},handleSavedMissing:function(t,e){if(this.locizeInstance&&!this.locizeInstance.closed){var n={message:"savedMissings",projectId:this.i18next.options.backend.projectId,version:this.i18next.options.backend.version||"latest",lng:t,ns:e};this.locizeInstance.postMessage(n,this.options.url)}},open:function(){var t=this.options.url;this.options.openDashboard||(t="".concat(t,"/pid/").concat(this.options.projectId||this.i18next.options.backend.projectId,"/v/").concat(this.i18next.options.backend.version||"latest")),"iframe"===this.options.mode?this.locizeInstance=function(t,e){e.locizeEditorWindow.appendTarget&&(e.iframeContainerStyle="position: absolute; top: 0; right: 0; bottom: 0; left: 0;",e.iframeStyle+=" width: 100%;");var n=document.createElement("div");n.setAttribute("style",e.iframeContainerStyle),n.setAttribute("ignorelocizeeditor",""),n.setAttribute("translated",""),e.locizeEditorWindow.containerClasses&&(e.locizeEditorWindow.containerClasses.length>1?e.locizeEditorWindow.containerClasses.split(" "):e.locizeEditorWindow.containerClasses).forEach(function(t){n.classList.add(t)});var i=document.createElement("iframe");if(i.setAttribute("style",e.iframeStyle),i.setAttribute("ignorelocizeeditor",""),i.setAttribute("translated",""),i.setAttribute("src",t),n.appendChild(i),e.locizeEditorWindow.appendTarget)e.locizeEditorWindow.appendTarget.appendChild(n);else{document.body.appendChild(n);var o=document.body.getAttribute("style");document.body.setAttribute("style","".concat(o,"; ").concat(e.bodyStyle))}return i.contentWindow}(t,this.options):this.locizeInstance=window.open(t),this.toggleUI=function(t,e,n){var i=document.createElement("div"),o='font-family: "Helvetica", "Arial", sans-serif; bottom: 20px; right: 20px; padding: 10px; background-color: #fff; border: solid 1px #1976d2; box-shadow: 0px 1px 2px 0px rgba(0,0,0,0.5);';n.locizeEditorToggle.appendTarget?o+="position: absolute;":o+=" z-index: 2147483647; position: fixed;",i.setAttribute("style",o),i.setAttribute("ignorelocizeeditor",""),i.setAttribute("translated",""),n.locizeEditorToggle.containerClasses&&(n.locizeEditorToggle.containerClasses.length>1?n.locizeEditorToggle.containerClasses.split(" "):n.locizeEditorToggle.containerClasses).forEach(function(t){i.classList.add(t)});var r=document.createElement("h4");r.id="locize-title",r.innerHTML=n.locizeEditorToggle.title||"locize editor",r.setAttribute("style",'font-family: "Helvetica", "Arial", sans-serif; font-size: 14px; margin: 0 0 5px 0; color: #1976d2; font-weight: 300;'),r.setAttribute("ignorelocizeeditor",""),i.appendChild(r);var a=document.createElement("button");a.innerHTML="On",a.setAttribute("style","".concat(s," display: none; background-color: #54A229;")),a.onclick=e,a.setAttribute("ignorelocizeeditor",""),i.appendChild(a);var l=document.createElement("button");return l.innerHTML="Off",l.setAttribute("style","".concat(s," display: none; background-color: #D50000;")),l.onclick=t,l.setAttribute("ignorelocizeeditor",""),i.appendChild(l),n.locizeEditorToggle.appendTarget?n.locizeEditorToggle.appendTarget.appendChild(i):document.body.appendChild(i),function(t){a.style.display=t?"block":"none",l.style.display=t?"none":"block"}}(this.on.bind(this),this.off.bind(this),this.options),this.on()},on:function(){document.body.addEventListener("click",this.handler,!0),this.toggleUI||this.open(),this.toggleUI(!0),this.enabled=!0},off:function(){document.body.removeEventListener("click",this.handler,!0),this.toggleUI||this.open(),this.toggleUI(!1),this.enabled=!1}}});