{"version":3,"file":"hermes.min.js","sources":["../src/hermes.js"],"sourcesContent":["/* jshint ignore:start */\ndefine(['jquery', 'core/log'], function ($, log) {\n\n    \"use strict\"; // jshint ;_;\n\n    log.debug('Hermes (the messenger) initialising');\n\n    //posts messages back to the parent frame.\n    //if it is allowed then we are good. Right?\n\n    return {\n\n        allowedURL: '',\n        id: '',\n        iframeembed: false,\n        enabled: false,\n        eventListeners: false,\n\n        //for making multiple instances\n        clone: function () {\n            return $.extend(true, {}, this);\n        },\n\n        //init\n        init: function (id, allowedURL, iframeembed) {\n            //the id tag is passed in initially passed in as $config->id from poodlltools::fetchAMDRecorderCode\n            //or from data-id in cloudpodll iframe. This allows the receiving code to know which recorder generated event\n            this.allowedURL = allowedURL;\n            this.id = id;\n            this.iframeembed = iframeembed;\n            this.enabled = true;\n            this.eventListeners = new Array();\n            this.registerEvents();\n        },\n\n        disable: function () {\n            this.enabled = false;\n        },\n\n        enable: function () {\n            this.enabled = true;\n        },\n\n        //this registers handlers for message events of a type from around the recorder\n        on: function(type,handler){\n            var listener = new Object();\n            listener.type = type;\n            listener.handler = handler;\n            this.eventListeners.push(listener);\n        },\n\n        //this handles the sending of message events recevied from parent around the recorder\n        sendEvent: function(event) {\n            for (var i = 0; i < this.eventListeners.length; i++) {\n                if (event.type == this.eventListeners[i].type) {\n                    this.eventListeners[i].handler(event);\n                }\n            }\n        },\n\n        //This posts a message to the parent page\n        postMessage: function (messageObject) {\n            if (!this.enabled) {\n                return;\n            }\n\n            if (!messageObject.hasOwnProperty('type')) {\n                log.debug('All message objects must have at least the \"type\" property');\n                return;\n            }\n            if (this.iframeembed) {\n                messageObject.id = this.id;\n                window.parent.postMessage(messageObject, this.allowedURL);\n            }\n        },\n\n        //We only listen to the message event from parent page\n        //if its valid, we pass it on to registered handlers within the recorder\n        registerEvents: function(){\n            //register our receive message handler\n            var that = this;\n            window.addEventListener('message', function (e) {\n                // Must be our parent\n                if ((that.allowedURL==null) || that.allowedURL.indexOf(e.origin) !== 0) {\n                    return;\n                }\n\n                //process data and if it is valid do the action\n                var data = e.data;\n                if (data && data.hasOwnProperty('id') &&\n                    data.id == that.id && data.hasOwnProperty('type')) {\n                    that.sendEvent(e.data);\n                }\n            });\n        }\n    };//end of returned object\n});//total end\n"],"names":["define","$","log","debug","allowedURL","id","iframeembed","enabled","eventListeners","clone","extend","this","init","Array","registerEvents","disable","enable","on","type","handler","listener","Object","push","sendEvent","event","i","length","postMessage","messageObject","hasOwnProperty","window","parent","that","addEventListener","e","indexOf","origin","data"],"mappings":"AACAA,8BAAO,CAAC,SAAU,aAAa,SAAUC,EAAGC,YAIxCA,IAAIC,MAAM,uCAKH,CAEHC,WAAY,GACZC,GAAI,GACJC,aAAa,EACbC,SAAS,EACTC,gBAAgB,EAGhBC,MAAO,kBACIR,EAAES,QAAO,EAAM,GAAIC,OAI9BC,KAAM,SAAUP,GAAID,WAAYE,kBAGvBF,WAAaA,gBACbC,GAAKA,QACLC,YAAcA,iBACdC,SAAU,OACVC,eAAiB,IAAIK,WACrBC,kBAGTC,QAAS,gBACAR,SAAU,GAGnBS,OAAQ,gBACCT,SAAU,GAInBU,GAAI,SAASC,KAAKC,aACVC,SAAW,IAAIC,OACnBD,SAASF,KAAOA,KAChBE,SAASD,QAAUA,aACdX,eAAec,KAAKF,WAI7BG,UAAW,SAASC,WACX,IAAIC,EAAI,EAAGA,EAAId,KAAKH,eAAekB,OAAQD,IACxCD,MAAMN,MAAQP,KAAKH,eAAeiB,GAAGP,WAChCV,eAAeiB,GAAGN,QAAQK,QAM3CG,YAAa,SAAUC,eACdjB,KAAKJ,UAILqB,cAAcC,eAAe,QAI9BlB,KAAKL,cACLsB,cAAcvB,GAAKM,KAAKN,GACxByB,OAAOC,OAAOJ,YAAYC,cAAejB,KAAKP,aAL9CF,IAAIC,MAAM,gEAWlBW,eAAgB,eAERkB,KAAOrB,KACXmB,OAAOG,iBAAiB,WAAW,SAAUC,MAEnB,MAAjBF,KAAK5B,YAA2D,IAAtC4B,KAAK5B,WAAW+B,QAAQD,EAAEE,aAKrDC,KAAOH,EAAEG,KACTA,MAAQA,KAAKR,eAAe,OAC5BQ,KAAKhC,IAAM2B,KAAK3B,IAAMgC,KAAKR,eAAe,SAC1CG,KAAKT,UAAUW,EAAEG"}