Created
November 17, 2015 16:02
-
-
Save reportbase/fff0a4eebb8a07353c3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var driveobject = (function () | |
{ | |
function init() | |
{ | |
this.key = "driveobject"; | |
var t = this; | |
t.data = new Array(); | |
var http = new XMLHttpRequest(); | |
http.open("GET", "https://www.googleapis.com/drive/v2/files?access_token=" + global.google_access_token); | |
http.responseType = "json"; | |
http.onreadystatechange = function() | |
{ | |
if (this.readyState != this.DONE) | |
return; | |
if (this.status != 200) | |
return; | |
t.data = this.response.items.slice(0); | |
}; | |
http.send(); | |
this.ANCHOR = localStorage.get_integer(this.key + ".ANCHOR", 0, this.data.length-1, 0); | |
this.CURRENT = localStorage.get_integer(this.key + ".CURRENT", 0, this.data.length-1, 0); | |
} | |
init.prototype = | |
{ | |
anchor : function() {return this.ANCHOR;}, | |
current : function() {return this.CURRENT;}, | |
start : function() {return 0;}, | |
length : function() {return this.data.length;}, | |
move : function (delta) {this.set_anchor(this.ANCHOR + delta);}, | |
get : function(index) | |
{ | |
index = typeof(index) == 'undefined' ? this.CURRENT : index; | |
index = Math.clamp(0, this.length()-1, index); | |
return this.data[index]; | |
}, | |
set_anchor : function(index) | |
{ | |
this.ANCHOR = Math.clamp(0, this.data.length-1, index); | |
this.CURRENT = Math.clamp(0, this.data.length-1, index); | |
localStorage.set_integer(this.key + ".ANCHOR", this.ANCHOR); | |
localStorage.set_integer(this.key + ".CURRENT", this.CURRENT); | |
}, | |
set_current : function(index) | |
{ | |
this.CURRENT = Math.clamp(0, this.data.length-1, index); | |
localStorage.set_integer(this.key + ".CURRENT", this.CURRENT); | |
}, | |
}; | |
return init; | |
})(); | |
var driveobj = new driveobject(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment