summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authorYehonal <yehonal.azeroth@gmail.com>2018-12-16 15:54:48 +0100
committerYehonal <yehonal.azeroth@gmail.com>2018-12-16 16:35:55 +0100
commit4a8156e08a5e3ffe540f56ecb894b951dd9b7c84 (patch)
treee14862984ffba17f4a8fe53d90b937917014827a /assets
parentd910d7263f43ddce21dbab7345dd679dc5b092b6 (diff)
downloadwiki-4a8156e08a5e3ffe540f56ecb894b951dd9b7c84.tar.gz
wiki-4a8156e08a5e3ffe540f56ecb894b951dd9b7c84.tar.bz2
wiki-4a8156e08a5e3ffe540f56ecb894b951dd9b7c84.zip
Git-Wiki 2.0
Diffstat (limited to 'assets')
-rw-r--r--assets/css/git-wiki-style.scss4
-rw-r--r--assets/css/style.scss4
-rw-r--r--assets/js/red-links.js28
-rw-r--r--assets/js/toc.js106
-rw-r--r--assets/js/wiki-features.js127
5 files changed, 138 insertions, 131 deletions
diff --git a/assets/css/git-wiki-style.scss b/assets/css/git-wiki-style.scss
new file mode 100644
index 0000000..34e537a
--- /dev/null
+++ b/assets/css/git-wiki-style.scss
@@ -0,0 +1,4 @@
+---
+---
+
+@import "git-wiki-style.scss";
diff --git a/assets/css/style.scss b/assets/css/style.scss
deleted file mode 100644
index 72a6aed..0000000
--- a/assets/css/style.scss
+++ /dev/null
@@ -1,4 +0,0 @@
----
----
-
-@import "style.scss";
diff --git a/assets/js/red-links.js b/assets/js/red-links.js
new file mode 100644
index 0000000..446db02
--- /dev/null
+++ b/assets/js/red-links.js
@@ -0,0 +1,28 @@
+
+(function ($) {
+ //
+ // RED LINK FEATURE (Hacky)
+ // TODO: filter external links
+ $.fn.redLinks = function () {
+ $('a').each(function () {
+ // avoid red link for external urls
+ if (this.hostname != window.location.hostname)
+ return;
+
+ var that = this;
+ $.ajax({
+ type: 'HEAD',
+ url: this.href,
+ success: function () {
+
+ },
+ error: function (xhr, ajaxOptions, thrownError) {
+ if (xhr.status == 404) {
+ $(that).css('color', 'red');
+ }
+ }
+ });
+ });
+ };
+
+})(jQuery);
diff --git a/assets/js/toc.js b/assets/js/toc.js
new file mode 100644
index 0000000..d8fcf33
--- /dev/null
+++ b/assets/js/toc.js
@@ -0,0 +1,106 @@
+
+// https://github.com/ghiculescu/jekyll-table-of-contents
+(function ($) {
+ $.fn.toc = function (options) {
+ var defaults = {
+ noBackToTopLinks: false,
+ title: '<i>Jump to...</i>',
+ minimumHeaders: 3,
+ headers: 'h1, h2, h3, h4, h5, h6',
+ listType: 'ol', // values: [ol|ul]
+ showEffect: 'show', // values: [show|slideDown|fadeIn|none]
+ showSpeed: 'slow', // set to 0 to deactivate effect
+ classes: {
+ list: '',
+ item: ''
+ }
+ },
+ settings = $.extend(defaults, options);
+
+ function fixedEncodeURIComponent(str) {
+ return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
+ return '%' + c.charCodeAt(0).toString(16);
+ });
+ }
+
+ function createLink(header) {
+ var innerText = (header.textContent === undefined) ? header.innerText : header.textContent;
+ return "<a href='#" + fixedEncodeURIComponent(header.id) + "'>" + innerText + "</a>";
+ }
+
+ var headers = $(settings.headers).filter(function () {
+ // get all headers with an ID
+ var previousSiblingName = $(this).prev().attr("name");
+ if (!this.id && previousSiblingName) {
+ this.id = $(this).attr("id", previousSiblingName.replace(/\./g, "-"));
+ }
+
+ // Yehonal
+ if (!this.id) {
+ this.id = $(this).text().replace(/\W/g, '_');
+ }
+
+ return this.id;
+ }), output = $(this);
+ if (!headers.length || headers.length < settings.minimumHeaders || !output.length) {
+ $(this).hide();
+ return;
+ }
+
+ if (0 === settings.showSpeed) {
+ settings.showEffect = 'none';
+ }
+
+ var render = {
+ show: function () { output.hide().html(html).show(settings.showSpeed); },
+ slideDown: function () { output.hide().html(html).slideDown(settings.showSpeed); },
+ fadeIn: function () { output.hide().html(html).fadeIn(settings.showSpeed); },
+ none: function () { output.html(html); }
+ };
+
+ var get_level = function (ele) { return parseInt(ele.nodeName.replace("H", ""), 10); };
+ var highest_level = headers.map(function (_, ele) { return get_level(ele); }).get().sort()[0];
+ var return_to_top = '<i class="icon-arrow-up back-to-top"> </i>';
+
+ var level = get_level(headers[0]),
+ this_level,
+ html = settings.title + " <" + settings.listType + " class=\"" + settings.classes.list + "\">";
+ headers.on('click', function () {
+ if (!settings.noBackToTopLinks) {
+ window.location.hash = this.id;
+ }
+ })
+ .addClass('clickable-header')
+ .each(function (_, header) {
+ this_level = get_level(header);
+ if (!settings.noBackToTopLinks && this_level === highest_level) {
+ $(header).addClass('top-level-header').after(return_to_top);
+ }
+ if (this_level === level) // same level as before; same indenting
+ html += "<li class=\"" + settings.classes.item + "\">" + createLink(header);
+ else if (this_level <= level) { // higher level than before; end parent ol
+ for (var i = this_level; i < level; i++) {
+ html += "</li></" + settings.listType + ">"
+ }
+ html += "<li class=\"" + settings.classes.item + "\">" + createLink(header);
+ }
+ else if (this_level > level) { // lower level than before; expand the previous to contain a ol
+ for (i = this_level; i > level; i--) {
+ html += "<" + settings.listType + " class=\"" + settings.classes.list + "\">" +
+ "<li class=\"" + settings.classes.item + "\">"
+ }
+ html += createLink(header);
+ }
+ level = this_level; // update for the next one
+ });
+ html += "</" + settings.listType + ">";
+ if (!settings.noBackToTopLinks) {
+ $(document).on('click', '.back-to-top', function () {
+ $(window).scrollTop(0);
+ window.location.hash = '';
+ });
+ }
+
+ render[settings.showEffect]();
+ };
+})(jQuery);
diff --git a/assets/js/wiki-features.js b/assets/js/wiki-features.js
deleted file mode 100644
index 41e5216..0000000
--- a/assets/js/wiki-features.js
+++ /dev/null
@@ -1,127 +0,0 @@
-
-// https://github.com/ghiculescu/jekyll-table-of-contents
-(function($){
- $.fn.toc = function(options) {
- var defaults = {
- noBackToTopLinks: false,
- title: '<i>Jump to...</i>',
- minimumHeaders: 3,
- headers: 'h1, h2, h3, h4, h5, h6',
- listType: 'ol', // values: [ol|ul]
- showEffect: 'show', // values: [show|slideDown|fadeIn|none]
- showSpeed: 'slow', // set to 0 to deactivate effect
- classes: { list: '',
- item: ''
- }
- },
- settings = $.extend(defaults, options);
-
- function fixedEncodeURIComponent (str) {
- return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
- return '%' + c.charCodeAt(0).toString(16);
- });
- }
-
- function createLink (header) {
- var innerText = (header.textContent === undefined) ? header.innerText : header.textContent;
- return "<a href='#" + fixedEncodeURIComponent(header.id) + "'>" + innerText + "</a>";
- }
-
- var headers = $(settings.headers).filter(function() {
- // get all headers with an ID
- var previousSiblingName = $(this).prev().attr( "name" );
- if (!this.id && previousSiblingName) {
- this.id = $(this).attr( "id", previousSiblingName.replace(/\./g, "-") );
- }
-
- // Yehonal
- if (!this.id) {
- this.id = $(this).text().replace(/\W/g,'_');
- }
-
- return this.id;
- }), output = $(this);
- if (!headers.length || headers.length < settings.minimumHeaders || !output.length) {
- $(this).hide();
- return;
- }
-
- if (0 === settings.showSpeed) {
- settings.showEffect = 'none';
- }
-
- var render = {
- show: function() { output.hide().html(html).show(settings.showSpeed); },
- slideDown: function() { output.hide().html(html).slideDown(settings.showSpeed); },
- fadeIn: function() { output.hide().html(html).fadeIn(settings.showSpeed); },
- none: function() { output.html(html); }
- };
-
- var get_level = function(ele) { return parseInt(ele.nodeName.replace("H", ""), 10); };
- var highest_level = headers.map(function(_, ele) { return get_level(ele); }).get().sort()[0];
- var return_to_top = '<i class="icon-arrow-up back-to-top"> </i>';
-
- var level = get_level(headers[0]),
- this_level,
- html = settings.title + " <" +settings.listType + " class=\"" + settings.classes.list +"\">";
- headers.on('click', function() {
- if (!settings.noBackToTopLinks) {
- window.location.hash = this.id;
- }
- })
- .addClass('clickable-header')
- .each(function(_, header) {
- this_level = get_level(header);
- if (!settings.noBackToTopLinks && this_level === highest_level) {
- $(header).addClass('top-level-header').after(return_to_top);
- }
- if (this_level === level) // same level as before; same indenting
- html += "<li class=\"" + settings.classes.item + "\">" + createLink(header);
- else if (this_level <= level){ // higher level than before; end parent ol
- for(var i = this_level; i < level; i++) {
- html += "</li></"+settings.listType+">"
- }
- html += "<li class=\"" + settings.classes.item + "\">" + createLink(header);
- }
- else if (this_level > level) { // lower level than before; expand the previous to contain a ol
- for(i = this_level; i > level; i--) {
- html += "<" + settings.listType + " class=\"" + settings.classes.list +"\">" +
- "<li class=\"" + settings.classes.item + "\">"
- }
- html += createLink(header);
- }
- level = this_level; // update for the next one
- });
- html += "</"+settings.listType+">";
- if (!settings.noBackToTopLinks) {
- $(document).on('click', '.back-to-top', function() {
- $(window).scrollTop(0);
- window.location.hash = '';
- });
- }
-
- render[settings.showEffect]();
- };
-
- //
- // RED LINK FEATURE (Hacky)
- // TODO: filter external links
- $.fn.redLinks = function () {
- $('a').each(function () {
- var that = this;
- $.ajax({
- type: 'HEAD',
- url: this.href,
- success: function () {
-
- },
- error: function (xhr, ajaxOptions, thrownError) {
- if (xhr.status == 404) {
- $(that).css('color', 'red');
- }
- }
- });
- });
- };
-
-})(jQuery);