{"version":3,"file":"poodll_flashrecorder.min.js","sources":["../src/poodll_flashrecorder.js"],"sourcesContent":["/* jshint ignore:start */\ndefine(['jquery', 'core/log', 'filter_poodll/utils_amd', 'filter_poodll/uploader', 'filter_poodll/lzloader'], function ($, log, utils, uploader, lz) {\n\n    \"use strict\"; // jshint ;\n\n    log.debug('PoodLL Flash Recorder: initialising');\n\n    return {\n\n        instanceprops: [],\n\n        fetch_instance_props: function (widgetid) {\n            return this.instanceprops[widgetid];\n        },\n\n        init_instance_props: function (widgetid) {\n            var props = {};\n            props.savebutton = null;\n            props.audiodatacontrol = null;\n            props.config = null;\n            props.uploader = null;\n            this.instanceprops[widgetid] = props\n        },\n\n        // This recorder supports the current browser\n        supports_current_browser: function (config) {\n            var iOS = utils.is_ios();\n            var isAndroid = utils.is_android();\n            if (iOS || (!config.flashonandroid && isAndroid)) {\n                return false;\n            } else {\n                if (config.mediatype != 'audio') {\n                    return false;\n                }\n\n                log.debug('PoodLL Flash Recorder: supports this browser');\n                return true;\n            }\n        },\n\n        // Perform the embed of this recorder on the page\n        //into the element passed in. with config\n        embed: function (element, config) {\n\n            //if we are bypassing cloud tweak a few things\n            if (config.flashmp3_cloudbypass == 1) {\n                config.posturl = config.cloudbypassurl;\n                config.filename = false;\n                config.s3filename = false;\n                config.using_s3 = false;\n            }\n            this.init_instance_props(config.widgetid);\n            var ip = this.fetch_instance_props(config.widgetid);\n\n            //if this is internet explorer, we can't use js uploader\n            //because flash wont pass filedata correctly to DOM\n            //we need to upload direct from flash\n            ip.ie = utils.is_ie();\n            if (ip.ie) {\n                config.flashmp3audio_widgetjson = config.flashmp3audio_widgetjson.replace('sendmethod=post', 'sendmethod=ajax');\n            }\n\n            //set config\n            ip.config = config;\n\n            //swf recorder\n            var swfopts = $.parseJSON(config.flashmp3audio_widgetjson);\n            lz.embed.swf(swfopts);\n\n            //savebutton\n            var savebuttonstyle = '';\n            if (ip.ie) {\n                savebuttonstyle = ' style=\"display: none\" ';\n            }\n            var savebuttonid = config.widgetid + '_savebutton';\n            var savecontrol = '<button id=\"' + savebuttonid + '\" type=\"button\" class=\"poodll_save-recording\"' + savebuttonstyle + '>' + M.util.get_string('recui_save', 'filter_poodll') + '</button>';\n            $(element).append(savecontrol);\n\n\n            //audio control\n            var audiodatacontrolid = config.widgetid + '_adc';\n            var audiocontrol = '<input type=\"hidden\" name=\"audiodatacontrol\" id=\"' + audiodatacontrolid + '\" value=\"\" />';\n            $(element).prepend(audiocontrol);\n\n            //init the uploader\n            ip.uploader = uploader.clone();\n            ip.uploader.init(element, config);\n\n            //register events\n            lz.embed[config.widgetid].setCanvasAttribute('audiodatacontrol', audiodatacontrolid);\n            ip.savebutton = $('#' + savebuttonid);\n            ip.audiodatacontrol = $('#' + audiodatacontrolid);\n            this.registerevents(config.widgetid);\n        },\n\n        registerevents: function (widgetid) {\n            var ip = this.fetch_instance_props(widgetid);\n            ip.audioblob = false;\n\n            ip.savebutton.click(function () {\n                //here we convert a string of base64 data into a blob which represents \n                //an mp3 file.  \n                var audiodata = atob(ip.audiodatacontrol.val());\n\n                //we check if there is actually any data,because if not we want to complain\n                //if this is a resubmit, impossible though, we pass through to upload\n                var haveaudiodata = audiodata && audiodata.length > 0;\n                if (!haveaudiodata && !ip.audioblob) {\n                    ip.uploader.Output(M.util.get_string('recui_nothingtosaveerror', 'filter_poodll'));\n                    return false;\n                }\n\n                //create our audioblob if it is empty .. most likely\n                if (!ip.audioblob && haveaudiodata) {\n                    var audioblobdata = [];\n                    for (var i = 0; i < audiodata.length; i++) {\n                        audioblobdata.push(audiodata.charCodeAt(i));\n                    }\n                    ip.audioblob = new Blob([new Uint8Array(audioblobdata)], {type: 'audio/mpeg3'});\n                }\n\n                //and we upload that blob\n                ip.uploader.uploadBlob(ip.audioblob, 'audio/mpeg3');\n                //we would like to disable the recorder here\n                var apicall = 'poodllapi.mp3_disable()';\n                lz.embed[ip.config.widgetid].callMethod(apicall);\n\n                //we no longer need the data in the audiodata control and it will get submitted\n                //with the form which we don't want. So we clear it here. Justin 2017-03/03\n                ip.audiodatacontrol.val('');\n\n\n                //just in case\n                return false;\n            });//end of save button click\n\n        }\n    }//end of returned object\n});//total end"],"names":["define","$","log","utils","uploader","lz","debug","instanceprops","fetch_instance_props","widgetid","this","init_instance_props","props","supports_current_browser","config","iOS","is_ios","isAndroid","is_android","flashonandroid","mediatype","embed","element","flashmp3_cloudbypass","posturl","cloudbypassurl","filename","s3filename","using_s3","ip","ie","is_ie","flashmp3audio_widgetjson","replace","swfopts","parseJSON","swf","savebuttonstyle","savebuttonid","savecontrol","M","util","get_string","append","audiodatacontrolid","audiocontrol","prepend","clone","init","setCanvasAttribute","savebutton","audiodatacontrol","registerevents","audioblob","click","audiodata","atob","val","haveaudiodata","length","Output","audioblobdata","i","push","charCodeAt","Blob","Uint8Array","type","uploadBlob","callMethod"],"mappings":"AACAA,4CAAO,CAAC,SAAU,WAAY,0BAA2B,yBAA0B,2BAA2B,SAAUC,EAAGC,IAAKC,MAAOC,SAAUC,WAI7IH,IAAII,MAAM,uCAEH,CAEHC,cAAe,GAEfC,qBAAsB,SAAUC,iBACrBC,KAAKH,cAAcE,WAG9BE,oBAAqB,SAAUF,cACvBG,MAAQ,CACZA,WAAmB,KACnBA,iBAAyB,KACzBA,OAAe,KACfA,SAAiB,WACZL,cAAcE,UAAYG,OAInCC,yBAA0B,SAAUC,YAC5BC,IAAMZ,MAAMa,SACZC,UAAYd,MAAMe,qBAClBH,MAASD,OAAOK,gBAAkBF,aAGV,SAApBH,OAAOM,YAIXlB,IAAII,MAAM,iDACH,KAMfe,MAAO,SAAUC,QAASR,QAGa,GAA/BA,OAAOS,uBACPT,OAAOU,QAAUV,OAAOW,eACxBX,OAAOY,UAAW,EAClBZ,OAAOa,YAAa,EACpBb,OAAOc,UAAW,QAEjBjB,oBAAoBG,OAAOL,cAC5BoB,GAAKnB,KAAKF,qBAAqBM,OAAOL,UAK1CoB,GAAGC,GAAK3B,MAAM4B,QACVF,GAAGC,KACHhB,OAAO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