Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadRepos() {
- $.ajax("https://api.github.com/legacy/repos/search/javascript").done(function(e) {
- var t, n;
- $.each(e.repositories, function(e, t) {
- $("#allRepos").append("<li><a href='repo-detail.html?owner=" + t.username + "&name=" + t.name + "'>" + "<h4>" + t.name + "</h4>" + "<p>" + t.username + "</p></a></li>");
- }), $("#allRepos").listview("refresh");
- });
- }
- function loadRepoDetail(e, t) {
- $.ajax("https://api.github.com/repos/" + e + "/" + t).done(function(e) {
- var t = e;
- console.log(e), $("#repoName").html("<a href='" + t.homepage + "'>" + t.name + "</a>"), $("#description").text(t.description), $("#forks").html("<strong>Forks:</strong> " + t.forks + "<br><strong>Watchers:</strong> " + t.watchers), $("#avatar").attr("src", t.owner.avatar_url), $("#ownerName").html("<strong>Owner:</strong> <a href='" + t.owner.url + "'>" + t.owner.login + "</a>");
- });
- }
- function saveFave() {
- db.transaction(saveFaveDb, txError, txSuccessFave);
- }
- function checkFave() {
- db.transaction(checkFaveDb, txError);
- }
- function createDb(e) {
- e.executeSql("DROP TABLE IF EXISTS repos"), e.executeSql("CREATE TABLE repos(user,name)");
- }
- function saveFaveDb(e) {
- var t = getUrlVars().owner, n = getUrlVars().name;
- e.executeSql("INSERT INTO repos(user,name) VALUES (?, ?)", [ t, n ]);
- }
- function checkFaveDb(e) {
- var t = getUrlVars().owner, n = getUrlVars().name;
- e.executeSql("SELECT * FROM repos WHERE user = ? AND name = ?", [ t, n ], txSuccessCheckFave);
- }
- function loadFavesDb(e) {
- e.executeSql("SELECT * FROM repos", [], txSuccessLoadFaves);
- }
- function txError(e) {
- console.log(e), console.log("Database error: " + e);
- }
- function txSuccess() {
- console.log("Success");
- }
- function txSuccessFave() {
- console.log("Save success"), disableSaveButton();
- }
- function txSuccessCheckFave(e, t) {
- console.log("Read success"), t.rows.length && disableSaveButton();
- }
- function txSuccessLoadFaves(e, t) {
- console.log("Read success");
- if (t.rows.length) {
- var n = t.rows.length, r;
- for (var i = 0; i < n; i += 1) r = t.rows.item(i), console.log(r), $("#savedItems").append("<li><a href='repo-detail.html?owner=" + r.user + "&name=" + r.name + "'>" + "<h4>" + r.name + "</h4>" + "<p>" + r.user + "</p></a></li>");
- $("#savedItems").listview("refresh");
- } else navigator.notification.alert("You haven't saved any favorites yet.", alertDismissed);
- }
- function alertDismissed() {
- $.mobile.changePage("index.html");
- }
- function disableSaveButton() {
- var e = $("#saveBtn").closest(".ui-btn");
- $("span.ui-btn-text", e).text("Saved").closest(".ui-btn-inner").addClass("ui-btn-up-b"), $("#saveBtn").unbind("click", saveFave);
- }
- function getUrlVars() {
- var e = [], t, n = window.location.href.slice(window.location.href.indexOf("?") + 1).split("&");
- for (var r = 0; r < n.length; r++) t = n[r].split("="), e.push(t[0]), e[t[0]] = t[1];
- return e;
- }
- var db;
- $("#reposHome").bind("pageinit", function(e) {
- loadRepos(), db = window.openDatabase("repodb", "0.1", "GitHub Repo Db", 1e3), db.transaction(createDb, txError, txSuccess);
- }), $("#reposDetail").live("pageshow", function(e) {
- var t = getUrlVars().owner, n = getUrlVars().name;
- loadRepoDetail(t, n), checkFave(), $("#saveBtn").bind("click", saveFave);
- }), $("#favesHome").live("pageshow", function(e) {
- db.transaction(loadFavesDb, txError, txSuccess);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement