{"version":3,"sources":["https:\/\/servizi.odsacb.it\/theme\/remui\/amd\/src\/dictionary.js"],"names":["define","$","Notification","init","mouseup","search","window","getSelection","toString","document","selection","createRange","text","trim","obj","range","rects","rect","doc","sel","x","y","type","collapse","boundingLeft","boundingTop","rangeCount","getRangeAt","cloneRange","getClientRects","length","left","top","span","createElement","appendChild","createTextNode","insertNode","spanParent","parentNode","removeChild","normalize","getSelectionCoords","token","settings","async","crossDomain","url","method","success","response","remove","meaning","i","results","senses","definition","data","append","failure","exception","ajax","getWord","scroll","click"],"mappings":"AAAA,aAGAA,OAAO,CAAC,SAAU,qBAAsB,SAAUC,EAAGC,GAoKnD,MAAO,CACLC,KA\/BF,WAEEF,EAAE,QAAQG,QAAQ,WAChB,IAAIC,EAnIFC,OAAOC,aACFD,OAAOC,eAAeC,WACpBC,SAASC,UACXD,SAASC,UAAUC,cAAcC,KAGnC,GA+HL,GAAqB,IAAjBP,EAAOQ,OAAX,CAIA,IAAIC,EAjFR,WACE,IAEIC,EACAC,EACAC,EAJAC,EAAMZ,OAAOG,SACbU,EAAMD,EAAIR,UAIVU,EAAI,EACJC,EAAI,EAER,GAAIF,EAAK,CACP,GAA6B,IAAzBA,EAAIX,WAAWK,QAAyC,aAAzBM,EAAIX,WAAWK,OAChD,OAAO,EAGO,WAAZM,EAAIG,MAAqC,IAAhBH,EAAIX,YAC\/BO,EAAQI,EAAIR,eACNY,UAAS,GACfH,EAAIL,EAAMS,aACVH,EAAIN,EAAMU,kBAEP,GAAInB,OAAOC,aAAc,CAG9B,GAA6B,KAF7BY,EAAMb,OAAOC,gBAELC,WAAWK,QAAyC,aAAzBM,EAAIX,WAAWK,OAChD,OAAO,EAGT,GAAIM,EAAIO,YAAgC,IAAlBP,EAAIX,cACxBO,EAAQI,EAAIQ,WAAW,GAAGC,cAEhBC,iBACRd,EAAMQ,UAAS,IACfP,EAAQD,EAAMc,kBAEJC,OAAS,IACjBb,EAAOD,EAAM,IAGfI,EAAIH,EAAKc,KACTV,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EAAE,qBAAqBkD,WAEzBlD,EAAE,QAAQ+D,MAAM,WACd\/D,EAAE,qBAAqBkD","sourcesContent":["'use strick';\ndefine(['jquery', 'core\/notification'], function($, Notification) {\n \/**\n * Function getSelected data will give the selected text\n * @return {String} Selection string\n *\/\n function getSelectedText() {\n if (window.getSelection) {\n return window.getSelection().toString();\n } else if (document.selection) {\n return document.selection.createRange().text;\n }\n return '';\n }\n\n \/**\n * Ajax to fetch the word meaning\n * @param {Number} x screen x cordinate\n * @param {Number} y screen y cordinate\n * @param {String} token token name\n * @param {String} search Search query\n *\/\n function getWord(x, y, token, search) {\n var searchword = token + '=' + search;\n var url = \"https:\/\/api.pearson.com\/v2\/dictionaries\/entries?\" + searchword;\n var settings = {\n \"async\": true,\n \"crossDomain\": true,\n \"url\": url,\n \"method\": \"GET\",\n \"success\": function(response) {\n\n if (response !== '' && response !== null) {\n $(\"#definition_layer\").remove();\n\n var meaning = 'No definition found.';\n var i = 0;\n for (i = 0; i < response.results.length; i++) {\n if (response.results[i].senses[0].definition !== null) {\n meaning = response.results[i].senses[0].definition;\n break;\n }\n }\n var data = \"
\";\n data += '
<\/div>';\n data += '

' + search + '<\/h3>';\n data += '

' + meaning + '<\/p><\/div><\/div>';\n data += '<\/div>';\n $(\"body\").append(data);\n\n }\n },\n \"failure\": Notification.exception\n };\n $.ajax(settings);\n }\n\n \/**\n * Get location of selected text\n * @return {Object} Mouse click cordinates\n *\/\n function getSelectionCoords() {\n var doc = window.document;\n var sel = doc.selection,\n range, rects, rect;\n var x = 0,\n y = 0;\n if (sel) {\n if (sel.toString().trim() == \"\" || sel.toString().trim() == \"undefined\") {\n return false;\n }\n if (sel.type != \"Control\" && sel.toString != \"\") {\n range = sel.createRange();\n range.collapse(true);\n x = range.boundingLeft;\n y = range.boundingTop;\n }\n } else if (window.getSelection) {\n sel = window.getSelection();\n if (sel.toString().trim() == \"\" || sel.toString().trim() == \"undefined\") {\n return false;\n }\n if (sel.rangeCount && sel.toString() != \"\") {\n range = sel.getRangeAt(0).cloneRange();\n if (range.getClientRects) {\n range.collapse(true);\n rects = range.getClientRects();\n if (rects.length > 0) {\n rect = rects[0];\n }\n x = rect.left;\n y = rect.top;\n }\n \/\/ Fall back to inserting a temporary element.\n if (x == 0 && y == 0) {\n var span = doc.createElement(\"span\");\n if (span.getClientRects) {\n \/\/ Ensure span has dimensions and position by adding a zero-width space character.\n span.appendChild(doc.createTextNode(\"\\u200b\"));\n range.insertNode(span);\n rect = span.getClientRects()[0];\n x = rect.left;\n y = rect.top;\n var spanParent = span.parentNode;\n spanParent.removeChild(span);\n\n \/\/ Glue any broken text nodes back together.\n spanParent.normalize();\n }\n }\n }\n }\n return {\n x: x,\n y: y\n };\n }\n\n \/**\n * Initialise events\n *\/\n function initialise() {\n \/\/ Event trigger for text selection.\n $('body').mouseup(function() {\n var search = getSelectedText();\n if (search.trim() == \"\") {\n return;\n }\n var obj = getSelectionCoords();\n if (obj.x != 'undefined' && obj.y != 'undefined') {\n \/\/ Old code var x = obj.x-152; end.\n var x = obj.x;\n x += 'px';\n \/\/ Old code var y = obj.y+12; end.\n var y = obj.y + 17;\n y += 'px';\n getWord(x, y, 'headword', search);\n }\n });\n\n \/\/ Close the Tooltip Event.\n $(window).scroll(function() {\n $(\"#definition_layer\").remove();\n });\n\n $('body').click(function() {\n $(\"#definition_layer\").remove();\n });\n }\n\n return {\n init: initialise\n };\n});"],"file":"dictionary.min.js"}