Skip to content

Commit cd41e26

Browse files
committed
Ported sassdoc-theme-light source code to sassdoc-theme-default
1 parent e3e527c commit cd41e26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2435
-4
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
.sass-cache
4+
npm-debug.log
5+
assets/css/main.css.map

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
SASS = sass
2+
UGLIFY = node_modules/uglify-js/bin/uglifyjs
3+
4+
all: sass min
5+
6+
min: assets/js/main.min.js
7+
8+
assets/js/main.min.js: \
9+
assets/js/vendor/fuse.min.js \
10+
assets/js/sidebar.js \
11+
assets/js/search.js \
12+
assets/js/main.js \
13+
assets/js/vendor/prism.min.js
14+
cat $^ | $(UGLIFY) > $@
15+
16+
sass:
17+
$(SASS) --update scss:assets/css --style compressed
18+
19+
clean:
20+
$(RM) -r assets/js/main.min.js assets/css

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
# SassDoc Default Theme
22

3-
This leads to [sassdoc-theme-light](https://github.com/SassDoc/sassdoc-theme-light).
3+
This is [SassDoc](https://github.com/SassDoc/sassdoc)'s default theme which means this is the theme that will be used when running SassDoc without a custom theme.
4+
5+
This theme uses [Themeleon](https://github.com/themeleon/themeleon) as a theme engine, and [themeleon-swig](https://github.com/themeleon/themeleon-swig) as a template engine, directly plugged into Themeleon.
6+
7+
Because this is likely to be the most used theme of all, it is not as simple as a theme can get. For instance, there is quite a bit of logic in both `index.js` and the Swig templates. Fortunately, you don't have to deal with that at all.
8+
9+
## Customising the view
10+
11+
There are some possibilites to customise the theme's view. Essentially what's being displayed, what's not, and what are the project informations to be displayed in the header and footer.
12+
13+
To learn how to customise the theme's view, please read [the documentation on SassDoc's site](http://sassdoc.com/customising-the-view/). Fear not! It's all about creating a configuration file. No big deal.

assets/css/main.css

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/main.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* global document */
2+
3+
(function ($, global) {
4+
'use strict';
5+
6+
// Constructor
7+
var App = function (conf) {
8+
this.conf = $.extend({
9+
// Search module
10+
search: new global.Search(),
11+
12+
// Sidebar module
13+
sidebar: new global.Sidebar(),
14+
15+
// Initialisation
16+
init: true
17+
}, conf || {});
18+
19+
// Launch the module
20+
if (this.conf.init !== false) {
21+
this.initialize();
22+
}
23+
};
24+
25+
// Initialisation method
26+
App.prototype.initialize = function () {
27+
this.codePreview();
28+
};
29+
30+
// Toggle code preview collapsed/expanded modes
31+
App.prototype.codePreview = function () {
32+
var $item;
33+
var $code;
34+
var switchTo;
35+
36+
$('.item__code--togglable').on('click', function () {
37+
$item = $(this);
38+
$code = $item.find('code');
39+
switchTo = $item.attr('data-current-state') === 'expanded' ? 'collapsed' : 'expanded';
40+
41+
$item.attr('data-current-state', switchTo);
42+
$code.html($item.attr('data-' + switchTo));
43+
Prism.highlightElement($code[0]);
44+
});
45+
};
46+
47+
global.App = App;
48+
}(window.jQuery, window));
49+
50+
(function ($, global) {
51+
52+
$(document).ready(function () {
53+
var app = new global.App();
54+
});
55+
56+
}(window.jQuery, window));

assets/js/main.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/search.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
(function ($, global) {
2+
3+
var Search = function (conf) {
4+
this.conf = $.extend({
5+
// Search DOM
6+
search: {
7+
items: '.sassdoc__item',
8+
input: '#js-search-input',
9+
form: '#js-search',
10+
suggestionsWrapper: '#js-search-suggestions'
11+
},
12+
13+
// Fuse options
14+
fuse: {
15+
keys: ['name'],
16+
threshold: 0.3
17+
},
18+
19+
init: true
20+
}, conf || {});
21+
22+
if (this.conf.init === true) {
23+
this.initialize();
24+
}
25+
};
26+
27+
Search.prototype.initialize = function () {
28+
// Fuse engine instanciation
29+
this.index = new Fuse($.map($(this.conf.search.items), function (item) {
30+
var $item = $(item);
31+
32+
return {
33+
name: $item.data('name'),
34+
type: $item.data('type'),
35+
node: $item
36+
};
37+
}), this.conf.fuse);
38+
39+
this.initializeSearch();
40+
};
41+
42+
// Fill DOM with search suggestions
43+
Search.prototype.fillSuggestions = function (items) {
44+
var searchSuggestions = $(this.conf.search.suggestionsWrapper);
45+
searchSuggestions.html('');
46+
47+
var suggestions = $.map(items.slice(0, 10), function (item) {
48+
var $li = $('<li />', {
49+
'data-type': item.type,
50+
'data-name': item.name,
51+
'html': '<a href="#' + item.type + '-' + item.name + '"><code>' + item.type.slice(0, 3) + '</code> ' + item.name + '</a>'
52+
});
53+
54+
searchSuggestions.append($li);
55+
return $li;
56+
});
57+
58+
return suggestions;
59+
};
60+
61+
// Perform a search on a given term
62+
Search.prototype.search = function (term) {
63+
return this.fillSuggestions(this.index.search(term));
64+
};
65+
66+
// Search logic
67+
Search.prototype.initializeSearch = function () {
68+
var searchForm = $(this.conf.search.form);
69+
var searchInput = $(this.conf.search.input);
70+
var searchSuggestions = $(this.conf.search.suggestionsWrapper);
71+
72+
var currentSelection = -1;
73+
var suggestions = [];
74+
var selected;
75+
76+
var self = this;
77+
78+
// Clicking on a suggestion
79+
searchSuggestions.on('click', function (e) {
80+
var target = $(event.target);
81+
82+
if (target.nodeName === 'A') {
83+
searchInput.val(target.parent().data('name'));
84+
suggestions = self.fillSuggestions([]);
85+
}
86+
});
87+
88+
// Filling the form
89+
searchForm.on('keyup', function (e) {
90+
e.preventDefault();
91+
92+
// Enter
93+
if (e.keyCode === 13) {
94+
if (selected) {
95+
suggestions = self.fillSuggestions([]);
96+
searchInput.val(selected.data('name'));
97+
window.location = selected.children().first().attr('href');
98+
}
99+
100+
e.stopPropagation();
101+
}
102+
103+
// KeyDown
104+
if (e.keyCode === 40) {
105+
currentSelection = (currentSelection + 1) % suggestions.length;
106+
}
107+
108+
// KeyUp
109+
if (e.keyCode === 38) {
110+
currentSelection = currentSelection - 1;
111+
112+
if (currentSelection < 0) {
113+
currentSelection = suggestions.length - 1;
114+
}
115+
}
116+
117+
if (suggestions[currentSelection]) {
118+
if (selected) {
119+
selected.removeClass('selected');
120+
}
121+
122+
selected = suggestions[currentSelection];
123+
selected.addClass('selected');
124+
}
125+
126+
});
127+
128+
searchInput.on('keyup', function (e) {
129+
if (e.keyCode !== 40 && e.keyCode !== 38) {
130+
currentSelection = -1;
131+
suggestions = self.search($(this).val());
132+
}
133+
134+
else {
135+
e.preventDefault();
136+
}
137+
}).on('search', function () {
138+
suggestions = self.search($(this).val());
139+
});
140+
};
141+
142+
global.Search = Search;
143+
144+
}(window.jQuery, window));

assets/js/sidebar.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
(function ($, global) {
2+
3+
var Sidebar = function (conf) {
4+
this.conf = $.extend({
5+
6+
// Collapsed class
7+
collapsedClass: 'is-collapsed',
8+
9+
// Storage key
10+
storageKey: '_sassdoc_sidebar_index',
11+
12+
// Index attribute
13+
indexAttribute: 'data-slug',
14+
15+
// Toggle button
16+
toggleBtn: '.js-btn-toggle',
17+
18+
// Automatic initialization
19+
init: true
20+
}, conf || {});
21+
22+
if (this.conf.init === true) {
23+
this.initialize();
24+
}
25+
};
26+
27+
/**
28+
* Initialize module
29+
*/
30+
Sidebar.prototype.initialize = function () {
31+
this.conf.nodes = $('[' + this.conf.indexAttribute + ']');
32+
33+
this.load();
34+
this.updateDOM();
35+
this.bind();
36+
};
37+
38+
/**
39+
* Load data from storage or create fresh index
40+
*/
41+
Sidebar.prototype.load = function () {
42+
var index = 'localStorage' in global ?
43+
global.localStorage.getItem(this.conf.storageKey) :
44+
null;
45+
46+
this.index = index ? JSON.parse(index) : this.buildIndex();
47+
};
48+
49+
/**
50+
* Build a fresh index
51+
*/
52+
Sidebar.prototype.buildIndex = function () {
53+
var index = {};
54+
var $item;
55+
56+
this.conf.nodes.each($.proxy(function (index, item) {
57+
$item = $(item);
58+
59+
index[$item.attr(this.conf.indexAttribute)] = !$item.hasClass(this.conf.collapsedClass);
60+
}, this));
61+
62+
return index;
63+
};
64+
65+
/**
66+
* Update DOM based on index
67+
*/
68+
Sidebar.prototype.updateDOM = function () {
69+
var item;
70+
71+
for (item in this.index) {
72+
if (this.index[item] === false) {
73+
$('[' + this.conf.indexAttribute + '="' + item + '"]').addClass(this.conf.collapsedClass);
74+
}
75+
}
76+
};
77+
78+
/**
79+
* Save index in storage
80+
*/
81+
Sidebar.prototype.save = function () {
82+
if (!('localStorage' in global)) {
83+
return;
84+
}
85+
86+
global.localStorage.setItem(this.conf.storageKey, JSON.stringify(this.index));
87+
};
88+
89+
/**
90+
* Bind UI events
91+
*/
92+
Sidebar.prototype.bind = function () {
93+
var $item, slug, fn, text;
94+
var collapsed = false;
95+
96+
// Save index in localStorage
97+
global.onbeforeunload = $.proxy(function () {
98+
this.save();
99+
}, this);
100+
101+
// Toggle all
102+
$(this.conf.toggleBtn).on('click', $.proxy(function (event) {
103+
$node = $(event.target);
104+
105+
text = $node.attr('data-alt');
106+
$node.attr('data-alt', $node.text());
107+
$node.text(text);
108+
109+
fn = collapsed === true ? 'removeClass' : 'addClass';
110+
111+
this.conf.nodes.each($.proxy(function (index, item) {
112+
$item = $(item);
113+
slug = $item.attr(this.conf.indexAttribute);
114+
115+
this.index[slug] = collapsed;
116+
117+
$('[' + this.conf.indexAttribute + '="' + slug + '"]')[fn](this.conf.collapsedClass);
118+
}, this));
119+
120+
collapsed = !collapsed;
121+
this.save();
122+
}, this));
123+
124+
// Toggle item
125+
this.conf.nodes.on('click', $.proxy(function (event) {
126+
$item = $(event.target);
127+
slug = $item.attr(this.conf.indexAttribute);
128+
129+
// Update index
130+
this.index[slug] = !this.index[slug];
131+
132+
// Update DOM
133+
$item.toggleClass(this.conf.collapsedClass);
134+
}, this));
135+
};
136+
137+
global.Sidebar = Sidebar;
138+
139+
}(window.jQuery, window));

0 commit comments

Comments
 (0)