Advertisement
Temporelucis

statRequest.js

Jun 27th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Statistics constructor
  2. var statisticsRequest = function (tier, rank) {
  3.   this["tier"] = tier;
  4.   this["rank"] = rank;
  5.   this["stats"] = "";
  6.   this["statsWindow"] = document.createElement("iframe");       //Creates an iframe
  7.   this["statsWindow"].hidden = true;
  8.   document.body.appendChild(this["statsWindow"]);
  9.   this["setHandleDownloadComplete_string"] = "this.default()";
  10. };
  11. statisticsRequest.prototype = Object.create(function () { });   //Statistics prototype
  12. statisticsRequest.prototype.constructor = statisticsRequest;    //Creates the constructor
  13. statisticsRequest.prototype.downloadStatistics = function () {  //Downloads the statistics
  14.   this["tier"] = this["tier"].toLowerCase();
  15.   this["rank"] = this["rank"].toLowerCase();
  16.   filename = this["tier"] + "-" + this["rank"] + ".txt";
  17.   var_name = "var" + Math.floor(Math.random()*10000) + Math.floor(Math.random()*10000);     //Creates a random name for a variable (It's a high number because it shouldn't be repeated)
  18.   eval(var_name + " = ''");                                                                 //Creates a variable named after the the previous one (THIS WILL COINTAIN THE USAGE STATISTICS)
  19.   //INCLUDE THE PATH OF THE LIBRARY ON THE LINK BELLOW
  20.   this["statsWindow"].src = "../js/lib/statRequest.php?filename="+filename+"&id="+var_name; //Sends the name of the file and the name to the variable to the server
  21.   this["statsWindow"].onload = (function (objThis, vname, objIframe) { return function () { objThis["stats"] = eval(vname); objThis.handleDownloadComplete(); } }) (this, var_name, this["statsWindow"]);         //Handles on document load (when the data is ready)
  22.   //this["iframe"] = statsWindow;
  23. };
  24. statisticsRequest.prototype.setAttributes = function (tier, rank) {                         //Sets the tier and the ranking of the statistics
  25.   this["tier"] = tier;
  26.   this["rank"] = rank;
  27. }
  28. //HANDLE PROGRESS
  29. statisticsRequest.prototype.handleDownloadComplete = function () {
  30.   eval(this["setHandleDownloadComplete_string"]);
  31. };
  32. statisticsRequest.prototype.setHandleDownloadComplete = function (functionName) {
  33.   this["setHandleDownloadComplete_string"] = functionName;
  34. };
  35. statisticsRequest.prototype.default = function () { };          //Empty function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement