Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move badge and path functions out of megafile #778

Merged
merged 4 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions binderhub/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'bootstrap';
import 'event-source-polyfill';

import BinderImage from './src/image';
import { markdownBadge, rstBadge } from './src/badge';
import { getPathType, updatePathText } from './src/path';

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/css/bootstrap-theme.min.css';
Expand Down Expand Up @@ -50,24 +52,6 @@ function v2url(providerPrefix, repository, ref, path, pathType) {
return url;
}

function getPathType() {
// return path type. 'file' or 'url'
return $("#url-or-file-selected").text().trim().toLowerCase();
}

function updatePathText() {
var pathType = getPathType();
var text;
if (pathType === "file") {
text = "Path to a notebook file (optional)";
} else {
text = "URL to open (optional)";
}
$("#filepath").attr('placeholder', text);
$("label[for=filepath]").text(text);
}


function updateRepoText() {
var text;
var provider = $("#provider_prefix").val();
Expand Down Expand Up @@ -137,20 +121,6 @@ function updateUrls(formValues) {
}
}


var BADGE_URL = window.location.origin + BASE_URL + 'badge_logo.svg';


function markdownBadge(url) {
// return markdown badge snippet
return '[![Binder](' + BADGE_URL + ')](' + url + ')'
}

function rstBadge(url) {
// return rst badge snippet
return '.. image:: ' + BADGE_URL + ' :target: ' + url
}

function build(providerSpec, log, path, pathType) {
update_favicon(BASE_URL + "favicon_building.ico");
// split provider prefix off of providerSpec
Expand Down
12 changes: 12 additions & 0 deletions binderhub/static/js/src/badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var BASE_URL = $("#base-url").data().url;
var BADGE_URL = window.location.origin + BASE_URL + "badge_logo.svg";

export function markdownBadge(url) {
// return markdown badge snippet
return "[![Binder](" + BADGE_URL + ")](" + url + ")";
}

export function rstBadge(url) {
// return rst badge snippet
return ".. image:: " + BADGE_URL + "\n :target: " + url;
}
20 changes: 20 additions & 0 deletions binderhub/static/js/src/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function getPathType() {
// return path type. 'file' or 'url'
const element = document.getElementById("url-or-file-selected");
return element.innerText.trim().toLowerCase();
}

export function updatePathText() {
var pathType = getPathType();
var text;
if (pathType === "file") {
text = "Path to a notebook file (optional)";
} else {
text = "URL to open (optional)";
}
const filePathElement = document.getElementById("filepath");
filePathElement.setAttribute("placeholder", text);

const filePathElementLabel = document.querySelector("label[for=filepath]");
filePathElementLabel.innerText = text;
}