text: if(!RedactorPlugins)var RedactorPlugins={};!function(a){var b=!1;a(window).keydown(function(a){18==a.which&&(b=!0)}).keyup(function(a){18==a.which&&(b=!1)}),RedactorPlugins.speek=function(){var c,d=window.speechSynthesis.getVoices();return window.speechSynthesis.onvoiceschanged=function(a){d=window.speechSynthesis.getVoices()},{getTemplate:function(){var b=a(document.createElement("section"));b.attr("id","redactor-modal-speek"),b.append("<p>Listen as you wish.</p>"),b.append('<label for="voice">Voice</label>'),b.append(document.createElement("select")),a.each(d,function(c,d){b.find("select").attr("id","voice").attr("name","voice").append(a('<option value="'+d.name+'">'+d.name+"</option>"))});var c=a('<div class="options"></div>');return c.append('<label for="volume">Volume</label><input data-varname="speechVolume" type="range" min="0" max="1" step="0.1" name="volume" id="volume" value="1">'),c.append('<label for="rate">Rate</label><input data-varname="speechRate" type="range" min="0" max="1" step="0.1" name="Rate" id="rate" value="1">'),c.append('<label for="pitch">Pitch</label><input data-varname="speechPitch" type="range" min="0" max="1" step="0.1" name="pitch" id="pitch" value="1">'),b.append(c),a(b)[0].outerHTML},init:function(){if(!(!1 in window)){var b=this,c=this.button.add("speek","Listen");this.button.setAwesome("speek","icon icon-headphones"),this.button.addCallback(c,this.speek.clicked),a.extend(this.opts.shortcuts,{esc:{func:"speek.shutup",params:[]}}),this.$element.on("modalClosedCallback",function(){b.speek.shutup()})}},clicked:function(){if(b)return void this.speek.show();this.speek.speek()},speek:function(){var b=window.speechSynthesis.speaking;this.speek.shutup();var e=this.button.get("speek"),f=this.opts.speechVoice||"Vicki";if(!b){var g=this.code.get(),h=[];a(g).each(function(b,c){h.push(a(c).text())}),g=h.join(" "),c=new SpeechSynthesisUtterance,c.text=g,c.lang=this.opts.speechLang||"en-US",c.voice=d.filter(function(a){return a.name==f})[0],c.rate=void 0!==this.opts.speechRate?this.opts.speechRate:1,c.pitch=void 0!==this.opts.speechPitch?this.opts.speechPitch:1,c.volume=void 0!==this.opts.speechVolume?this.opts.speechVolume:1,c.onend=c.onerror=function(){e.removeClass("speaking")},c.onstart=c.onresume=function(){e.addClass("speaking")},window.speechSynthesis.speak(c),e.addClass("speaking")}},show:function(){var b=this.button.get("speek"),c=this;this.modal.addTemplate("choose-voice",this.speek.getTemplate()),this.modal.load("choose-voice",this.lang.get("choose-voice")||"Choose Voice",300),this.modal.createCancelButton();var b=this.modal.createActionButton("Listen");b.on("click",this.speek.close),a("#redactor-modal-speek select").on("change",function(){var b=a(this).val();c.speek.vocalChange(b)}),a("#redactor-modal-speek select").val(c.opts.speechVoice),a("#redactor-modal-speek #volume, #redactor-modal-speek #rate, #redactor-modal-speek #pitch").each(function(){a(this).on("change",function(){b=c.button.get("speek"),c.opts[a(this).data("varname")]=a(this).val(),c.speek.shutup(),c.speek.speek(),b.addClass("speaking")}).val(c.opts[a(this).data("varname")])}),this.selection.save(),this.modal.show()},close:function(){this.modal.close(),this.speek.shutup(),this.speek.speek(),this.selection.restore()},vocalChange:function(a){var b=this.button.get("speek"),c=d.filter(function(b){return b.name==a})[0];c&&(this.opts.speechVoice=c.name,this.speek.shutup(),this.speek.speek(),b.addClass("speaking"))},shutup:function(){var a=!!window.speechSynthesis.speaking;window.speechSynthesis.cancel();var b=this.button.get("speek");if(c)try{c.cancel()}catch(a){}return window.speechSynthesis.cancel(),c=null,b.removeClass("speaking"),a}}}}(jQuery);