-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.min.js
1 lines (1 loc) · 5.91 KB
/
functions.min.js
1
function showInterface(){const e=document.getElementById("signatureText");e&&(e.style.display="block");const t=document.getElementById("saveSignature");t&&(t.style.display="block",t.onclick=saveSignature)}function showTaskPaneMessage(e,t){window.jQuery?$("#messageBox").text(e).show().delay(2500).queue(function(e){t&&$(this).hide(),e()}):console.log(e)}function resizeEditor(){const e=$("#saveSignature"),t=$("#signatureText"),o=t.closest(".trumbowyg-box");-1!==window.location.search.indexOf("?firstlaunch")&&($("body").css({padding:0}),e.css({margin:0,marginRight:6}));let n=e.position().top-o.position().top-12;o.css({height:n}),n=n-$(".trumbowyg-button-pane").height()-1,t.prev(".trumbowyg-editor").css({height:n}),t.css({height:n})}function cleanIDAndClassValues(e){return e.replaceAll(/(id|class)="x_(.*?)"/gi,'$1="$2"')}function saveSignature(){let e,t=Office.context.roamingSettings.get(signatureSetting);e=window.jQuery?cleanIDAndClassValues($("#signatureText").trumbowyg("html")):cleanIDAndClassValues(document.getElementById("signatureText").value),showTaskPaneMessage("✎ Saving…",!1),Office.context.roamingSettings.set(signatureSetting,Base64.encode(e)),Office.context.roamingSettings.saveAsync(function(e){e.status===Office.AsyncResultStatus.Succeeded?(showTaskPaneMessage("✓ Saved",!0),t||"function"==typeof Office.context.ui.messageParent&&Office.context.ui.messageParent((!0).toString())):(showTaskPaneMessage("✗ Save failed",!1),console.error("saveSignature",e.status,":",e.error.message))})}function addSignature(e){if("object"==typeof e){try{"function"==typeof e.completed&&(requestHeader=e)}catch(e){}e=!0}if(!Office.context.roamingSettings.get(signatureSetting))return console.log("addSignature: no saved signature found; opening save dialog"),void Office.context.ui.displayDialogAsync("https://simonrob.github.io/ocsa/taskpane.html?firstlaunch",{width:60,height:70,displayInIframe:!0},function(e){if(e.status===Office.AsyncResultStatus.Succeeded){const t=e.value;t.addEventHandler(Office.EventType.DialogMessageReceived,function(e){t.close(),"object"==typeof requestHeader&&(requestHeader.completed(),requestHeader=void 0)})}else console.log("displayDialogAsync",e.status,":",e.error.message)});Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html,function(e){e.status===Office.AsyncResultStatus.Succeeded?-1!==e.value.indexOf("</body>")?appendSignature(!1,e.value.replace("</body>",Base64.decode(Office.context.roamingSettings.get(signatureSetting))+"</body>")):appendSignature(!1,e.value+Base64.decode(Office.context.roamingSettings.get(signatureSetting))):console.log("addSignature",e.status,":",e.error.message)})}function appendSignature(e,t){Office.context.mailbox.item.body.setAsync(t,{coercionType:Office.CoercionType.Html},function(t){t.status===Office.AsyncResultStatus.Succeeded?e?addSignature(!1):"object"==typeof requestHeader&&(requestHeader.completed(),requestHeader=void 0):console.log("appendSignature",t.status,":",t.error.message)})}const signatureSetting="calendarSignature";let existingBody="",requestHeader=void 0;Office.onReady(function(e){e.host===Office.HostType.Outlook&&(window.jQuery?$(document).ready(function(){const e=["000000","262626","595959","8c8c8c","bfbfbf","d9d9d9","e9e9e9","f5f5f5","fafafa","ffffff","fbe9e6","fcede1","fcefd4","fcfbcf","e7f6d5","daf4f0","d9edfa","e0e8fa","ede1f8","f6e2ea","ffa39e","ffbb96","ffd591","fffb8f","b7eb8f","87e8de","91d5ff","adc6ff","d3adf7","ffadd2","ff4d4f","ff7a45","ffa940","ffec3d","73d13d","36cfc9","40a9ff","597ef7","9254de","f759ab","e13c39","e75f33","eb903a","f5db4d","72c040","59bfc0","4290f7","3658e2","6a39c9","d84493","cf1322","d4380d","d46b08","d4b106","389e0d","08979c","096dd9","1d39c4","531dab","c41d7f","820014","871400","873800","614700","135200","00474f","003a8c","061178","22075e","780650"],t=$("#signatureText");t.trumbowyg({btns:[["fontfamily","fontsize"],["bold","italic","underline","del"],["link"],["foreColor","backColor","unorderedList","orderedList","horizontalRule"],["viewHTML"]],semantic:!1,plugins:{colors:{foreColorList:e,allowCustomForeColor:!0,backColorList:e,allowCustomBackColor:!0}},autogrow:!1}),Office.context.roamingSettings.get(signatureSetting)&&t.trumbowyg("html",Base64.decode(Office.context.roamingSettings.get(signatureSetting)));let o=100;t.closest(".trumbowyg-box").css({minHeight:o}),o-=$(".trumbowyg-button-pane").height()-1,t.prev(".trumbowyg-editor").css({minHeight:o}),t.css({minHeight:o}),showInterface(),$(window).on("resize",resizeEditor),resizeEditor()}):showInterface())});var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t,o,n,a,i,r,s,c="",f=0;for(e=Base64._utf8_encode(e);f<e.length;)t=e.charCodeAt(f++),o=e.charCodeAt(f++),n=e.charCodeAt(f++),a=t>>2,i=(3&t)<<4|o>>4,r=(15&o)<<2|n>>6,s=63&n,isNaN(o)?r=s=64:isNaN(n)&&(s=64),c=c+this._keyStr.charAt(a)+this._keyStr.charAt(i)+this._keyStr.charAt(r)+this._keyStr.charAt(s);return c},decode:function(e){var t,o,n,a,i,r,s,c="",f=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");f<e.length;)a=this._keyStr.indexOf(e.charAt(f++)),i=this._keyStr.indexOf(e.charAt(f++)),r=this._keyStr.indexOf(e.charAt(f++)),s=this._keyStr.indexOf(e.charAt(f++)),t=a<<2|i>>4,o=(15&i)<<4|r>>2,n=(3&r)<<6|s,c+=String.fromCharCode(t),64!=r&&(c+=String.fromCharCode(o)),64!=s&&(c+=String.fromCharCode(n));return c=Base64._utf8_decode(c),c},_utf8_encode:function(e){var t="";e=e.replace(/\r\n/g,"\n");for(var o=0;o<e.length;o++){var n=e.charCodeAt(o);n<128?t+=String.fromCharCode(n):n>127&&n<2048?(t+=String.fromCharCode(n>>6|192),t+=String.fromCharCode(63&n|128)):(t+=String.fromCharCode(n>>12|224),t+=String.fromCharCode(n>>6&63|128),t+=String.fromCharCode(63&n|128))}return t},_utf8_decode:function(e){var t,o,n,a="",i=0;for(t=o=0;i<e.length;)t=e.charCodeAt(i),t<128?(a+=String.fromCharCode(t),i++):t>191&&t<224?(o=e.charCodeAt(i+1),a+=String.fromCharCode((31&t)<<6|63&o),i+=2):(o=e.charCodeAt(i+1),n=e.charCodeAt(i+2),a+=String.fromCharCode((15&t)<<12|(63&o)<<6|63&n),i+=3);return a}};