{"version":3,"file":"YoutubeVideo.min.js","sources":["EncompassWebServices/includes/DashboardItemTypes/YoutubeVideo.js"],"sourcesContent":["\"use strict\";\r\n\r\n(async function () {\r\n let YouTubeVideoID = \"\";\r\n const videoType = {\r\n showEditButton: true,\r\n itemFields: [\"YouTubeVideoID\"],\r\n addItem(createNewItemCallback) {\r\n Show_Dashboard_YouTubeDialog({\r\n callback(control, id, title) {\r\n createNewItemCallback(title, {\r\n YouTubeVideoID: id\r\n });\r\n }\r\n });\r\n },\r\n editItem(title, itemFields, dashboardItem, editItemCallback) {\r\n Show_Dashboard_YouTubeDialog({\r\n callback(control, id, widgetTitle) {\r\n editItemCallback(widgetTitle, {\r\n YouTubeVideoID: id\r\n });\r\n },\r\n id: itemFields.YouTubeVideoID,\r\n widgetTitle: title\r\n });\r\n },\r\n async onLoaded(dashboardItem, itemFields) {\r\n const content = `
\r\n
`;\r\n dashboardItem.querySelector(\".content\").innerHTML = content;\r\n }\r\n };\r\n EWS.DashboardItemTypesManager.add(\"YoutubeVideo\", videoType);\r\n EWS.DashboardItemTypesManager.add(\"YouTube Video\", videoType);\r\n\r\n const pattern = /[\\\\?&]v=([^&#]*)/;\r\n\r\n const ParseYouTubeAddress = function (dialog, url) {\r\n let results = pattern.exec(url);\r\n let isNotNewFormat = true;\r\n\r\n if (results == null) {\r\n if (url.indexOf(\"https://youtu.be/\") > -1) {\r\n results = url.replace(\"https://youtu.be/\", \"\").trim();\r\n isNotNewFormat = false;\r\n }\r\n }\r\n\r\n if (results != null) {\r\n dialog.querySelector(\".tips\").classList.add(\"hidden\");\r\n dialog.querySelector(\"#ews-youtube-preview\").classList.remove(\"hidden\");\r\n if (isNotNewFormat) {\r\n results = decodeURIComponent(results[1].replace(/\\+/g, \" \"));\r\n }\r\n\r\n if (results !== YouTubeVideoID) {\r\n YouTubeVideoID = results;\r\n\r\n dialog.querySelector(\"#ews-youtube-preview\").src = `//www.youtube.com/embed/${YouTubeVideoID}?wmode=transparent`;\r\n if (!dialog.querySelector(\"#ews-youtube-title\").value) {\r\n dialog.querySelector(\"#ews-youtube-title\").value = \"YouTube Video\";\r\n }\r\n }\r\n } else {\r\n dialog.querySelector(\".tips\").classList.remove(\"hidden\");\r\n dialog.querySelector(\"#ews-youtube-preview\").classList.add(\"hidden\");\r\n dialog.querySelector(\"#ews-youtube-preview\").src = \"about:blank\";\r\n YouTubeVideoID = \"\";\r\n }\r\n };\r\n\r\n function Show_Dashboard_YouTubeDialog(insertArgs) {\r\n EWS.VerifySession(() => {\r\n // Task 1146755: Optimize Dashboard Widget-YouTube Video Implementation\r\n const content = `
Copy a YouTube video URL directly from your browser, and paste it into the 'URL' field\r\n
\r\n
\r\n
${EC_Fmt.Trn(\"YouTube URL\")}
\r\n
\r\n
\r\n
${EC_Fmt.Trn(\"Widget title\")}
\r\n
\r\n
\r\n
\r\n
${EC_Fmt.Trn(\"Preview\")}
\r\n
\r\n
\r\n \r\n Invalid YouTube URL\r\n Check the provided URL and sure it starts with https://youtube.com/watch?v=... or https://youtu.be/...\r\n \r\n
\r\n \r\n
\r\n
\r\n
`;\r\n\r\n const Dialog = ECP.Dialog.ShowDialog(EC_Fmt.Trn(\"Insert YouTube video\"), content, {\r\n width: 620,\r\n barPosition: \"top\",\r\n cancelButtonTitle: EC_Fmt.Trn(\"Cancel\"),\r\n confirmButtonTitle: EC_Fmt.Trn(\"Insert video\"),\r\n confirmButtonAction(dialog) {\r\n const title = dialog.querySelector(\"#ews-youtube-title\").value;\r\n if (!EC_Fmt.isNull(YouTubeVideoID)) {\r\n if (!EC_Fmt.isNull(insertArgs.callback)) {\r\n ECP.Dialog.CloseDialog(dialog);\r\n insertArgs.callback(dialog, YouTubeVideoID, title);\r\n }\r\n } else {\r\n dialog.style.display = \"block\";\r\n EWS.Alert(EC_Fmt.Trn(\"You must enter a YouTube video URL.\"));\r\n }\r\n }\r\n });\r\n\r\n YouTubeVideoID = \"\";\r\n const youtubeUrl = Dialog.querySelector(\"#ews-youtube-url\");\r\n if (insertArgs.id) {\r\n youtubeUrl.value = `https://youtu.be/${insertArgs.id}`;\r\n ParseYouTubeAddress(Dialog, youtubeUrl.value);\r\n }\r\n if (insertArgs.widgetTitle) {\r\n Dialog.querySelector(\"#ews-youtube-title\").value = insertArgs.widgetTitle;\r\n }\r\n youtubeUrl.addEventListener(\"change\", (e) => {\r\n ParseYouTubeAddress(Dialog, e.currentTarget.value);\r\n });\r\n });\r\n }\r\n}());\r\n"],"names":["async","let","YouTubeVideoID","videoType","showEditButton","itemFields","addItem","createNewItemCallback","Show_Dashboard_YouTubeDialog","callback","control","id","title","editItem","dashboardItem","editItemCallback","widgetTitle","onLoaded","content","EC_Fmt","MD5","querySelector","innerHTML","EWS","DashboardItemTypesManager","add","pattern","ParseYouTubeAddress","dialog","url","results","exec","isNotNewFormat","indexOf","replace","trim","classList","remove","decodeURIComponent","src","value","insertArgs","VerifySession","Trn","Dialog","ECP","ShowDialog","width","barPosition","cancelButtonTitle","confirmButtonTitle","confirmButtonAction","isNull","CloseDialog","style","display","Alert","youtubeUrl","addEventListener","e","currentTarget"],"mappings":"AAAA,cAECA,iBACGC,IAAIC,EAAiB,GACrB,MAAMC,EAAY,CACdC,eAAgB,KAChBC,WAAY,CAAC,kBACbC,QAAQC,GACJC,EAA6B,CACzBC,SAASC,EAASC,EAAIC,GAClBL,EAAsBK,EAAO,CACzBV,eAAgBS,CACpB,CAAC,CACL,CACJ,CAAC,CACL,EACAE,SAASD,EAAOP,EAAYS,EAAeC,GACvCP,EAA6B,CACzBC,SAASC,EAASC,EAAIK,GAClBD,EAAiBC,EAAa,CAC1Bd,eAAgBS,CACpB,CAAC,CACL,EACAA,GAAIN,EAAWH,eACfc,YAAaJ,CACjB,CAAC,CACL,EACAK,eAAeH,EAAeT,GAC1B,MAAMa;6BACWC,OAAOC,IAAIf,EAAWH,cAAc,gEAAgEG,EAAWH,kFAChIY,EAAcO,cAAc,UAAU,EAAEC,UAAYJ,CACxD,CACJ,EACAK,IAAIC,0BAA0BC,I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