1var first_captcha_generated = false; 2var captcha_audio = null; 3function SystemsightCaptcha(element, options) { 4 var defaults = { 5 version: '1.0.0', 6 placeholder: '/Modules/Captcha/assets/images/captcha-preview.jpg' 7 } 8 var that = this; 9 that.options = $.extend(true, {}, defaults, options); 10 11 that.generated = false; 12 that.element = element; 13 that.$input = $(element); 14 that.$img = that.$input.parent().find('img.captcha-image'); 15 that.$audioBtn = that.$input.parent().find('[data-action="play"]'); 16 that.$refreshBtn = that.$input.parent().find('[data-action="refresh"]'); 17 18 that.init(); 19} 20 21SystemsightCaptcha.prototype.initialize = function () { 22 var that = this; 23 $('input.captcha-input').each(function (){ 24 if($(this).data('captchaInstance')) return; 25 26 $(this).data('captchaInstance', new SystemsightCaptcha(this)); 27 }) 28} 29SystemsightCaptcha.prototype.init = function () { 30 var that = this; 31 32 console.log('SystemsightCaptcha inited (' + that.options.version + ')'); 33 34 if(that.$audioBtn.length) 35 { 36 that.$audioBtn.data('autoplay', false); 37 that.$audioBtn.on('click', function (e) { 38 that.$audioBtn.data('autoplay', true); 39 if(that.captcha_image_source_exist()){ 40 that.captcha_play_captcha_audio(); 41 } 42 }); 43 that.$img.on('load', function (e) { 44 if (that.$audioBtn.data('autoplay')) { 45 that.captcha_play_captcha_audio(); 46 } 47 }); 48 } 49 50 that.$input.on('focus', function (e) { 51 if(that.generated) return; 52 that.captcha_image_source_exist(); 53 }); 54 that.$img.on('mouseover', function (e) { 55 if(that.generated) return; 56 that.captcha_image_source_exist(); 57 }); 58 59 var $collapseWrap = that.$img.closest('.collapse'); 60 if($collapseWrap.length){ 61 $collapseWrap.on('shown.bs.collapse', function () { 62 if(that.generated) return; 63 that.captcha_image_source_exist(); 64 }) 65 } 66 67 if(that.$refreshBtn){ 68 that.$refreshBtn.on('click', function (e) { 69 that.doRefresh(); 70 }); 71 } 72 that.$input.data('refresh', function () { 73 that.doRefresh(); 74 }); 75 76 if(!first_captcha_generated && that.$input.is(":visible")){ 77 first_captcha_generated = true 78 that.captcha_image_source_exist(); 79 } 80} 81SystemsightCaptcha.prototype.captcha_image_source_exist = function () { 82 var that = this; 83 if(captcha_audio){ 84 captcha_audio.pause(); 85 captcha_audio = null; 86 } 87 88 if(that.$img.attr('src') === that.options.placeholder){ 89 //TODO: gal to nereikia, jei naudosim namespace? 90 $("img.captcha-image").attr('src', that.options.placeholder) 91 that.$img.attr('src', that.$img.data('src') + '?r=' + Math.random()); 92 that.generated = true; 93 return false; 94 } 95 return true; 96} 97SystemsightCaptcha.prototype.captcha_play_captcha_audio = function () { 98 var that = this; 99 if(captcha_audio){ 100 captcha_audio.pause(); 101 captcha_audio = null; 102 } 103 104 var audioUrl = that.$audioBtn.data('url') + '?r=' + Math.random(); 105 captcha_audio = new Audio(audioUrl); 106 captcha_audio.play(); 107 108 $(captcha_audio).on('ended', function (e) { 109 that.$audioBtn.find('i.fa').addClass('fa-play-circle-o').removeClass('fa-circle-o-notch fa-spin'); 110 }) 111 112 that.$audioBtn.find('i.fa').removeClass('fa-play-circle-o').addClass('fa-circle-o-notch fa-spin'); 113 that.$audioBtn.data('autoplay', false); 114} 115SystemsightCaptcha.prototype.doRefresh = function () { 116 var that = this; 117 that.$img.attr('src', that.$img.data('src') + '?r=' + Math.random()) 118 if(captcha_audio){ 119 captcha_audio.pause(); 120 captcha_audio = null; 121 if(that.$audioBtn){ 122 that.$audioBtn.find('i.fa').addClass('fa-play-circle-o').removeClass('fa-circle-o-notch fa-spin'); 123 } 124 } 125} 126 127if (typeof module === "object" && typeof module.exports === "object"){ 128 //node modules support 129 SystemsightCaptcha.prototype.initialize(); 130 module.exports = SystemsightCaptcha 131}else{ 132 $(function(){ 133 SystemsightCaptcha.prototype.initialize(); 134 });
vendor: 1 bytes, line 135
135}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.