(function($) { // insert, replace, getinput // draw observer // increment after wait? –> probably no use case! // get free teams?! $.jgames = function(options) { } $.jgames.write = function(options) { var function_name = '$.jgames.write' //console.log(options) var response_promise = $.ajax({ method: "POST", url: "plugin/php/jgames.write.php", dataType: "json", data: { options }, error: function(XMLHttpRequest, textStatus, errorThrown) { error(function_name, 'error', errorThrown) }, success: function(data) { console.log(data) //if(data.error) error(function_name, 'error', data.error) //else if(data.warning) error(function_name, 'warning', data.warning) } }) return response_promise } $.jgames.read = function(options) { var function_name = '$.jgames.read' //console.log(options) var response_promise = $.ajax({ method: "POST", url: "plugin/php/jgames.read.php", dataType: "json", data: { options }, error: function(XMLHttpRequest, textStatus, errorThrown) { error(function_name, 'error', errorThrown) }, success: function(data) { console.log(data) //if(data.error) error(function_name, 'error', data.error) //else if(data.warning) error(function_name, 'warning', data.warning) } }) return response_promise } $.jgames.init = function(options) { var function_name = '$.jgames.init' //console.log(options) var response_promise = $.ajax({ method: "POST", url: "plugin/php/jgames.init.php", dataType: "json", data: { options }, error: function(XMLHttpRequest, textStatus, errorThrown) { error(function_name, 'error', errorThrown) }, success: function(data) { console.log(data) //if(data.error) error(function_name, 'error', data.error) //else if(data.warning) error(function_name, 'warning', data.warning) } }) return response_promise } $.jgames.parameters = function(options) { var function_name = '$.jgames.parameters' //console.log(options) var response_promise = $.ajax({ method: "POST", url: "plugin/php/jgames.parameters.php", dataType: "json", data: options, error: function(XMLHttpRequest, textStatus, errorThrown) { error(function_name, 'error', errorThrown) }, success: function(data) { console.log(data) //if(data.error) error(function_name, 'error', data.error) //else if(data.warning) error(function_name, 'warning', data.warning) } }) return response_promise } $.jgames.wait = function(options) { var function_name = '$.jgames.wait' //console.log(options) if(typeof options['wait_interval'] === 'undefined') { options['wait_interval'] = 4000 } var def = $.Deferred() var loop = setInterval(function() { var response_promise = $.ajax({ method: "POST", url: "plugin/php/jgames.wait.php", dataType: "json", data: options, error: function(XMLHttpRequest, textStatus, errorThrown) { error(function_name, 'error', errorThrown) }, success: function(data) { //console.log(data) //if(data.error) error(function_name, 'error', data.error) //else if(data.warning) error(function_name, 'warning', data.warning) if(data.wait == false) { console.log("notice: waiting finished") if(typeof options['redirect'] !== 'undefined') $.jgames.redirect({ destination: options['redirect']}) clearInterval(loop) def.resolve() } else if(data.wait == true) { console.log(data.waitingfor) console.log("notice: waiting ...") } } }) }, options['wait_interval']) return def.promise() } $.jgames.redirect = function(options) { var function_name = '$.jgames.redirect' console.log('notice: redirecting'); window.location.replace(options['destination'] + '?ID=' + ID); } $.jgames.hideshow = function(options) { var function_name = '$.jgames.hideshow' if(typeof options['show'] != "object") options['show'] = [options['show']] if(typeof options['hide'] != "object") options['hide'] = [options['hide']] for (var i = 0; i < options['show'].length; i++) { if(options['fade'] == true) $('[name="' + options['show'][i] + '"]').fadeIn(options['fading_speed']) else $('[name="' + options['show'][i] + '"]').show() } for (var i = 0; i < options['hide'].length; i++) { if(options['fade'] == true) $('[name="' + options['hide'][i] + '"]').fadeOut(options['fading_speed']) else $('[name="' + options['hide'][i] + '"]').hide() } return self } $.jgames.timerstart = function(options) { start = new Date().getTime() return start } $.jgames.timerstop = function(options) { var elapsed = Math.round((new Date().getTime() - start)/10)/100 start = 0.0 console.log(elapsed) return elapsed } $.jgames.timerget = function(options) { var elapsed = Math.round((new Date().getTime() - start)/10)/100 console.log(elapsed) return elapsed } $.fn.replace = function(options) { //var regex = new RegExp(options['pattern'], 'g') $(this).html(function() { //return $(this).html().replace(regex, options['replace']) return $(this).html().replace(options['pattern'], options['replace']) }) } function getID() { var query = window.location.search.substring(1) var pair = query.split("=") //if(pair[1] != undefined) { // // window.group = pair[1].split("_")[0] // window.subject = pair[1].split("_")[1] //} return pair[1] } function error(source, type, message) { console.log(source) if(typeof message == 'object') { for (var i = 0; i < message.length; i++) { console.log(type + ": " + message[i]) } } else { console.log(type + ": " + message) } console.log('\n') } $(document).ready(function() { window.ID = getID() // block keys, right click and delete as back button blockedkeys = [17,18,112,91,92,116] $('html').bind('keydown', function(e) { //console.log(e.keyCode) //console.log(e.which) for (i = 0; i < blockedkeys.length; i++) { key = blockedkeys[i] if(e.which == key) event.preventDefault() } if(event.ctrlKey && event.keyCode == 82) { event.preventDefault(); } }) $("html").on('contextmenu',function() { return false }) // Prevent the backspace key from navigating back. $(document).unbind('keydown').bind('keydown', function (event) { var doPrevent = false if (event.keyCode === 8) { var d = event.srcElement || event.target if ((d.tagName.toUpperCase() === 'INPUT' && ( d.type.toUpperCase() === 'TEXT' || d.type.toUpperCase() === 'PASSWORD' || d.type.toUpperCase() === 'FILE' || d.type.toUpperCase() === 'SEARCH' || d.type.toUpperCase() === 'EMAIL' || d.type.toUpperCase() === 'NUMBER' || d.type.toUpperCase() === 'DATE' ) ) || d.tagName.toUpperCase() === 'TEXTAREA') { doPrevent = d.readOnly || d.disabled } else { doPrevent = true } } if (doPrevent) { event.preventDefault() } }) $(":button").hover( function() { $(this).addClass('button-active') }, function() { $(this).removeClass('button-active') }) $(":button").click(function() { var processing = $('
'); processing.html('
 
'); processing.appendTo('body') setTimeout(function() { processing.remove() }, 1000) }) }) }(jQuery))