vendor/ui/js/src/gitorious.js in dolt-0.16.0 vs vendor/ui/js/src/gitorious.js in dolt-0.17.0
- old
+ new
@@ -1,149 +1,82 @@
-// $(".gts-select-onfocus").focus(function () {
-// this.select();
-// });
+/*global gts, reqwest, cull*/
-$(".gts-repo-url").click(function (e) {
- e.preventDefault();
- var btn = $(this);
- var parent = btn.parent();
- parent.find(".gts-repo-url").removeClass("active");
- btn.addClass("active");
- parent.find(".gts-current-repo-url").val(btn.attr("href")).focus();
-});
+this.gts.loadRefs = function (url) {
+ return reqwest({ url: url, type: "json" });
+};
-// $(".linenums li").mouseenter(function () {
-// $(this).addClass("focus");
-// });
+function refUrlTpl(url, ref) {
+ return gts.url.templatize(url, { ref: ref });
+}
-// $(".linenums li").mouseleave(function () {
-// $(this).removeClass("focus");
-// });
+// Environment variables
+gts.app.env("url", window.location.href);
+gts.app.env("redirect", function (url) { window.location = url; });
-// (function () {
-// var fileEl = document.getElementById("file");
-// var matches = window.location.href.match(/\#l(\d+)(?:-(\d+))?/);
-// if (!fileEl || !matches) { return; }
-// var lines = fileEl.getElementsByTagName("li");
-// var end = Math.max(matches[2] || matches[1], matches[1]);
+if ("onpopstate" in window) {
+ window.onpopstate = function (event) {
+ gts.app.env("url", window.location.href);
+ };
+}
-// for (var i = matches[1]; i <= end; ++i) {
-// $(lines[i - 1]).addClass("focus");
-// }
-// }());
+// Data
+gts.app.data("current-ref", gts.url.currentRef, { depends: ["url"] });
+gts.app.data("ref-url-template", refUrlTpl, { depends: ["url", "current-ref"] });
+gts.app.data("repository-refs", gts.loadRefs, { depends: ["repository-refs-url"] });
+gts.app.data("user-repo-view-state", gts.userRepoViewState, { depends: ["user-repository-path"] });
+gts.app.data("current-user", cull.prop("user"), { depends: ["user-repo-view-state"] });
+gts.app.data("blob-region", gts.blob.regionFromUrl, { depends: ["url"] });
-jQuery("[rel=tooltip]").tooltip();
+// Features
+// NB! While it is possible to lean on the function name when registering
+// features, e.g. gts.app.feature(gts.googleAnalytics, { ... }); we don't do
+// that, because uglify will strip out the function names, and the app will
+// crash.
+gts.app.feature("google-analytics", gts.googleAnalytics, {
+ depends: ["analytics-account", "analytics-domain-name"]
+});
-jQuery("[data-preview-target]").each(function () {
- var textarea = this;
- var target = document.getElementById(this.getAttribute("data-preview-target"));
- if (!target || !Showdown) { return; }
- var converter = new Showdown.converter();
- var previous, content;
+gts.app.feature("ref-selector", gts.refSelector, {
+ elements: ["gts-ref-selector-ph"],
+ depends: ["repository-refs", "current-ref", "ref-url-template"]
+});
- var cageSeed = new Date().getTime();
+gts.app.feature("tree-history", gts.treeHistory, {
+ elements: ["gts-tree-explorer"],
+ depends: ["tree-history-url"]
+});
- function zeroPad(num) {
- return num < 10 ? "0" + num : num;
- }
+gts.app.feature("commit-linker", gts.commitLinker, {
+ elements: ["gts-body"],
+ depends: ["commit-url-template", "redirect"]
+});
- function signature() {
- var now = new Date();
- return "<p>" +
- "<img width=\"24\" height=\"24\" class=\"gts-avatar\" alt=\"avatar\" src=\"http://cageme.herokuapp.com/24/24?" +
- cageSeed + "\">" +
- "<a href=\"/~zmalltalker\">Marius Mathiesen</a>" +
- zeroPad(now.getHours()) + ":" + zeroPad(now.getMinutes()) +
- ". <a href=\"#\">Edit comment</a></p>";
- }
+gts.app.feature("profile-menu", gts.profileMenu, {
+ elements: ["login_button"],
+ depends: ["current-user"]
+});
- function setPreview(preview) {
- target.style.display = preview ? "block" : "none";
- target.getElementsByTagName("div")[0].innerHTML = preview;
- }
+gts.app.feature("clone-url-selection", gts.cloneUrlSelection, {
+ elements: ["gts-repo-urls"]
+});
- function updatePreview() {
- content = textarea.value;
- if (content !== previous) {
- previous = content;
- setPreview(converter.makeHtml(content));
- }
- setTimeout(updatePreview, 20);
- }
+gts.app.feature("highlight-region", gts.blob.highlightRegion, {
+ elements: ["gts-lines"],
+ depends: ["blob-region"]
+});
- updatePreview();
+gts.app.feature("highlight-line-mouseover", gts.blob.highlightLineOnFocus, {
+ elements: ["gts-lines"]
});
-// Lest ye forget
-/*
-var _gaq = _gaq || [];
-_gaq.push(['_setAccount', 'UA-52238-3']);
-_gaq.push(['_setDomainName', '.gitorious.org']);
-_gaq.push(['_trackPageview']);
-(function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
-})();
-*/
+gts.app.feature("live-markdown-preview", gts.liveMarkdownPreview, {
+ elements: ["gts-live-markdown-preview"]
+});
-var gts = this.gts || {};
-
-// VERY TMP/TODO
-
-this.gts.loadRefs = function (repo, callback) {
- repo = repo ? "/" + repo : "";
-
- jQuery.ajax({
- url: repo + "/refs",
- success: function (refs) {
- callback(null, refs);
- }
- });
-};
-
-gts.run = function (env) {
- var placeHolder = document.getElementById("gts-ref-selector-ph");
-
- if (placeHolder) {
- gts.loadRefs(env.repository, function (err, refs) {
- var selector = gts.refSelector(refs, env.ref, env.refUrlTemplate);
- placeHolder.appendChild(selector);
- $(selector).find(".dropdown-toggle").dropdown();
- });
- }
-
- var treeBrowser = $("table[data-gts-tree-history]");
-
- if (treeBrowser.length > 0) {
- gts.treeHistory(treeBrowser[0], treeBrowser.attr("data-gts-tree-history"));
- }
-
- var gtsBody = $(".gts-body");
-
- if (gtsBody.length > 0) {
- gts.commitLinker(gtsBody[0], gts.commitUrlTemplate, function (url) {
- window.location = url;
- });
- }
-
- var userRepositoryPath = $("[data-gts-user-repository-path]").data("gts-user-repository-path");
-
- if (userRepositoryPath) {
- jQuery.ajax({
- url: userRepositoryPath,
- success: function (data) {
- gts.profileMenu(document.getElementById("login_button"), data.user);
- }
- });
- }
-};
-
-(function () {
- var ref = gts.url.currentRef(window.location.href);
-
- gts.run({
- repository: gts.repository || "",
- ref: ref,
- refUrlTemplate: gts.url.templatize(window.location.href, { ref: ref })
- });
-}());
+// Spin off app asynchronously so subsequent scripts have a chance
+// to register loggers etc before we roll
+setTimeout(function () {
+ // Scan the document for data-gts-* attributes that set
+ // "environment variables"
+ gts.app.scanEnvAttrs(document.body, "data-gts-env-");
+ gts.app.load(document.body);
+}, 10);