Advertisement
Guest User

Untitled

a guest
Nov 14th, 2012
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function loadRepos() {
  2.     $.ajax("https://api.github.com/legacy/repos/search/javascript").done(function(e) {
  3.         var t, n;
  4.         $.each(e.repositories, function(e, t) {
  5.             $("#allRepos").append("<li><a href='repo-detail.html?owner=" + t.username + "&name=" + t.name + "'>" + "<h4>" + t.name + "</h4>" + "<p>" + t.username + "</p></a></li>");
  6.         }), $("#allRepos").listview("refresh");
  7.     });
  8. }
  9.  
  10. function loadRepoDetail(e, t) {
  11.     $.ajax("https://api.github.com/repos/" + e + "/" + t).done(function(e) {
  12.         var t = e;
  13.         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>");
  14.     });
  15. }
  16.  
  17. function saveFave() {
  18.     db.transaction(saveFaveDb, txError, txSuccessFave);
  19. }
  20.  
  21. function checkFave() {
  22.     db.transaction(checkFaveDb, txError);
  23. }
  24.  
  25. function createDb(e) {
  26.     e.executeSql("DROP TABLE IF EXISTS repos"), e.executeSql("CREATE TABLE repos(user,name)");
  27. }
  28.  
  29. function saveFaveDb(e) {
  30.     var t = getUrlVars().owner, n = getUrlVars().name;
  31.     e.executeSql("INSERT INTO repos(user,name) VALUES (?, ?)", [ t, n ]);
  32. }
  33.  
  34. function checkFaveDb(e) {
  35.     var t = getUrlVars().owner, n = getUrlVars().name;
  36.     e.executeSql("SELECT * FROM repos WHERE user = ? AND name = ?", [ t, n ], txSuccessCheckFave);
  37. }
  38.  
  39. function loadFavesDb(e) {
  40.     e.executeSql("SELECT * FROM repos", [], txSuccessLoadFaves);
  41. }
  42.  
  43. function txError(e) {
  44.     console.log(e), console.log("Database error: " + e);
  45. }
  46.  
  47. function txSuccess() {
  48.     console.log("Success");
  49. }
  50.  
  51. function txSuccessFave() {
  52.     console.log("Save success"), disableSaveButton();
  53. }
  54.  
  55. function txSuccessCheckFave(e, t) {
  56.     console.log("Read success"), t.rows.length && disableSaveButton();
  57. }
  58.  
  59. function txSuccessLoadFaves(e, t) {
  60.     console.log("Read success");
  61.     if (t.rows.length) {
  62.         var n = t.rows.length, r;
  63.         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>");
  64.         $("#savedItems").listview("refresh");
  65.     } else navigator.notification.alert("You haven't saved any favorites yet.", alertDismissed);
  66. }
  67.  
  68. function alertDismissed() {
  69.     $.mobile.changePage("index.html");
  70. }
  71.  
  72. function disableSaveButton() {
  73.     var e = $("#saveBtn").closest(".ui-btn");
  74.     $("span.ui-btn-text", e).text("Saved").closest(".ui-btn-inner").addClass("ui-btn-up-b"), $("#saveBtn").unbind("click", saveFave);
  75. }
  76.  
  77. function getUrlVars() {
  78.     var e = [], t, n = window.location.href.slice(window.location.href.indexOf("?") + 1).split("&");
  79.     for (var r = 0; r < n.length; r++) t = n[r].split("="), e.push(t[0]), e[t[0]] = t[1];
  80.     return e;
  81. }
  82.  
  83. var db;
  84.  
  85. $("#reposHome").bind("pageinit", function(e) {
  86.     loadRepos(), db = window.openDatabase("repodb", "0.1", "GitHub Repo Db", 1e3), db.transaction(createDb, txError, txSuccess);
  87. }), $("#reposDetail").live("pageshow", function(e) {
  88.     var t = getUrlVars().owner, n = getUrlVars().name;
  89.     loadRepoDetail(t, n), checkFave(), $("#saveBtn").bind("click", saveFave);
  90. }), $("#favesHome").live("pageshow", function(e) {
  91.     db.transaction(loadFavesDb, txError, txSuccess);
  92. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement