Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit c899f43

Browse files
committed
feat: move assets to this repo
This patch moves the JS and CSS assets to this repository, instead of zf-mkdoc-theme. It also imports the zf-component-list.json file.
1 parent 672aac4 commit c899f43

34 files changed

+7120
-1
lines changed

_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
exclude: ["docs/", "mkdocs.yml", "Makefile"]
1+
exclude: ["docs/", "mkdocs.yml", "Makefile", "asset/"]

asset/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

asset/gulpfile.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
var gulp = require('gulp'),
2+
babel = require('gulp-babel'),
3+
sass = require('gulp-sass'),
4+
concat = require('gulp-concat'),
5+
uglify = require('gulp-uglify'),
6+
prism = [
7+
'core',
8+
'markup',
9+
'css',
10+
'clike',
11+
'markup-templating',
12+
'javascript',
13+
'apacheconf',
14+
'bash',
15+
'batch',
16+
'css-extras',
17+
'diff',
18+
'docker',
19+
'git',
20+
'handlebars',
21+
'http',
22+
'ini',
23+
'json',
24+
'less',
25+
'makefile',
26+
'markdown',
27+
'nginx',
28+
'php',
29+
'php-extras',
30+
'powershell',
31+
'puppet',
32+
'sass',
33+
'scss',
34+
'smarty',
35+
'sql',
36+
'twig',
37+
'vim',
38+
'yaml'
39+
];
40+
41+
// Images
42+
gulp.task('images', function () {
43+
return gulp.src('img/*')
44+
.pipe(gulp.dest('../img/'));
45+
});
46+
47+
// Icons
48+
gulp.task('icons', function () {
49+
return gulp.src('node_modules/font-awesome/fonts/**.*')
50+
.pipe(gulp.dest('../css/fonts'));
51+
});
52+
53+
// JavaScript
54+
gulp.task('scripts', function () {
55+
var prismComponents = [];
56+
for (var component in prism) {
57+
prismComponents[component] = 'node_modules/prismjs/components/prism-' + prism[component] + '.js';
58+
}
59+
60+
return gulp.src(
61+
prismComponents.concat(
62+
[
63+
'node_modules/prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js',
64+
'node_modules/prismjs/plugins/line-numbers/prism-line-numbers.js',
65+
'node_modules/jquery/dist/jquery.js',
66+
'node_modules/bootstrap-sass/assets/javascripts/bootstrap.js',
67+
'node_modules/anchor-js/anchor.js',
68+
'node_modules/choices.js/public/assets/scripts/choices.js',
69+
'js/component-list.js',
70+
'js/base.js'
71+
]
72+
)
73+
)
74+
.pipe(babel({presets: ['@babel/env'], sourceType: 'unambiguous'}))
75+
.pipe(concat({path : 'scripts.js'}))
76+
.pipe(uglify({mangle : false}).on('error', function (e) {
77+
console.log(e);
78+
}))
79+
.pipe(gulp.dest('../js/'));
80+
});
81+
82+
// CSS
83+
gulp.task('styles', function () {
84+
return gulp.src(
85+
[
86+
'node_modules/prismjs/themes/prism-okaidia.css',
87+
'node_modules/prismjs/plugins/line-numbers/prism-line-numbers.css',
88+
'sass/styles.scss'
89+
]
90+
)
91+
.pipe(sass({outputStyle : 'compressed'}))
92+
.pipe(concat({path : 'styles.css'}))
93+
.pipe(gulp.dest('../css/'));
94+
});
95+
96+
// Bundle
97+
gulp.task('default', gulp.series('images', 'icons', 'scripts', 'styles'));
98+
99+
// Watch
100+
gulp.task('watch', function () {
101+
gulp.watch(['js/**/*.js'], ['scripts']);
102+
gulp.watch(['sass/**/*.scss'], ['styles']);
103+
});

asset/img/favicon.ico

318 Bytes
Binary file not shown.

asset/img/zend-framework-logo.svg

+1
Loading

asset/img/zf-logo-mark.png

21.8 KB
Loading

asset/img/zf-logo-mark.svg

+1
Loading

asset/js/base.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(function () {
2+
"use strict";
3+
4+
// Tables
5+
var tables = document.querySelectorAll('.content table');
6+
if (tables.length) {
7+
[].forEach.call(tables, function(element) {
8+
element.classList.add('table', 'table-striped', 'table-hover');
9+
});
10+
}
11+
12+
// Anchors
13+
anchors.options.placement = 'left';
14+
anchors.add(
15+
'.content h1:not(.content__title), .content h2, .content > h3, .content h4, .content h5'
16+
);
17+
18+
// Pre elements
19+
var preElements = document.querySelectorAll('pre');
20+
[].forEach.call(preElements, function(element) {
21+
element.classList.add('line-numbers');
22+
});
23+
24+
// Search modal
25+
$('#mkdocs_search_modal').on('shown.bs.modal', function () {
26+
$('#mkdocs-search-query').focus();
27+
});
28+
29+
// Shift window
30+
var shiftWindow = function () {
31+
scrollBy(0, -50)
32+
};
33+
if (location.hash) {
34+
shiftWindow();
35+
}
36+
window.addEventListener('hashchange', shiftWindow);
37+
})();

asset/js/component-list.js

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
(function () {
2+
"use strict";
3+
4+
function getContainerElements() {
5+
return Array.prototype.concat.apply([], document.getElementsByClassName('component-selector'));
6+
}
7+
8+
function getSelectElements() {
9+
return Array.prototype.concat.apply([], document.getElementsByClassName('component-selector__control'));
10+
}
11+
12+
function prepareComponentList(components) {
13+
var componentList = {
14+
learn: {
15+
label: "Learn ZF",
16+
choices: []
17+
},
18+
middleware: {
19+
label: "Expressive and PSR-15 Middleware",
20+
choices: []
21+
},
22+
mvc: {
23+
label: "MVC Framework",
24+
choices: []
25+
},
26+
components: {
27+
label: "Components",
28+
choices: []
29+
},
30+
projects: {
31+
label: "Tooling and Composer Plugins",
32+
choices: []
33+
},
34+
};
35+
var uncategorized = [];
36+
37+
// eslint-disable-next-line no-use-before-define
38+
const matchActive = new RegExp('\/' + siteName + '(\/|$)');
39+
40+
components.forEach(function (component) {
41+
const selected = matchActive.test(component.url);
42+
const packageName = component.package.split('/');
43+
const label = component.name + '<br/><span class="choices__packagename">' + packageName[1] + '</span>';
44+
const choice = {
45+
value: component.url,
46+
label: label,
47+
selected: selected,
48+
customProperties: {
49+
description: component.description
50+
}
51+
};
52+
53+
componentList.hasOwnProperty(component.group)
54+
? componentList[component.group].choices.push(choice)
55+
: uncategorized.push(choice);
56+
});
57+
58+
// Initialize the Choices selector using the component selector as its element
59+
getSelectElements().forEach(function(element) {
60+
const choices = new Choices(element, {
61+
itemSelectText: '',
62+
renderChoiceLimit: -1,
63+
searchChoices: true,
64+
searchEnabled: true,
65+
searchFields: ['label', 'customProperties.description'],
66+
searchPlaceholderValue: 'Jump to package…',
67+
searchResultLimit: 10,
68+
shouldSort: false
69+
});
70+
71+
choices.setChoices(
72+
Array.prototype.concat.apply(Object.values(componentList), uncategorized),
73+
'value',
74+
'label',
75+
true
76+
);
77+
78+
// On selection of a choice, redirect to its URL
79+
element.addEventListener('choice', function (event) {
80+
window.location.href = event.detail.choice.value;
81+
}, false);
82+
83+
// Ensure the parent container expands to fit the list...
84+
element.addEventListener('showDropdown', function (event) {
85+
getContainerElements().forEach(function (container) {
86+
const choicesList = container.querySelector('.choices__list--dropdown');
87+
container.parentElement.style.minHeight = container.clientHeight + choicesList.clientHeight + "px";
88+
});
89+
}, false);
90+
91+
// ... and then shrinks back to size again.
92+
element.addEventListener('hideDropdown', function (event) {
93+
getContainerElements().forEach(function (container) {
94+
container.parentElement.style.minHeight = 'unset';
95+
});
96+
}, false);
97+
98+
// Load all starting and ending points for the sticky scene.
99+
// After all of them have loaded, toggle the sticky styles accordingly.
100+
element.addEventListener('showDropdown', function (event) {
101+
const groups = choices.choiceList.element.querySelectorAll('.choices__group');
102+
103+
groups.forEach(function (group, index) {
104+
var stickyStart = group.offsetTop;
105+
var stickyEnd = null;
106+
107+
if (groups.hasOwnProperty(index + 1)) {
108+
var nextGroup = groups[index + 1];
109+
stickyEnd = nextGroup.offsetTop;
110+
}
111+
112+
group.setAttribute('data-sticky-start', stickyStart);
113+
group.setAttribute('data-sticky-end', stickyEnd ? stickyEnd : '');
114+
});
115+
116+
groups.forEach(function (group) {
117+
toggleStickyGroupStyles(group, choices.choiceList.element.scrollTop);
118+
});
119+
}, false);
120+
121+
// Remove all sticky styles when the drop-down hides
122+
element.addEventListener('hideDropdown', function (event) {
123+
const groups = choices.choiceList.element.querySelectorAll('.choices__group');
124+
125+
groups.forEach(function (group) {
126+
unsetStickyGroupStyles(group);
127+
});
128+
}, false);
129+
130+
// Track the scroll position and apply sticky styles to the opt-group elements.
131+
// The "touchmove" event is used for touch devices, because on some browsers
132+
// the scroll event is triggered only once after the scroll animation has completed.
133+
['scroll', 'touchmove'].forEach(function (eventName) {
134+
choices.choiceList.element.addEventListener(eventName, function () {
135+
const groups = this.querySelectorAll('.choices__group');
136+
const scrollTop = this.scrollTop;
137+
138+
groups.forEach(function (group) {
139+
toggleStickyGroupStyles(group, scrollTop);
140+
});
141+
});
142+
});
143+
});
144+
}
145+
146+
function parseComponentList(event) {
147+
var request = event.target;
148+
if (request.readyState === request.DONE && request.status === 200) {
149+
prepareComponentList(JSON.parse(request.responseText));
150+
}
151+
}
152+
153+
function toggleStickyGroupStyles(group, scrollTop) {
154+
var stickyStart = parseInt(group.getAttribute('data-sticky-start'));
155+
var stickyEnd = group.getAttribute('data-sticky-end')
156+
? parseInt(group.getAttribute('data-sticky-end'))
157+
: null;
158+
159+
if (scrollTop >= stickyStart && (scrollTop <= stickyEnd || !stickyEnd)) {
160+
setStickyGroupStyles(group);
161+
return;
162+
}
163+
164+
unsetStickyGroupStyles(group);
165+
}
166+
167+
function setStickyGroupStyles(group) {
168+
group.classList.add('is-sticky');
169+
170+
if (group.nextElementSibling) {
171+
// Group element's position becomes fixed,
172+
// causing the height of the scrollable element to decrease.
173+
// The "removed" height is added as a margin top
174+
// on the next element in order to compensate for the losses.
175+
// This gives a smooth, non-jumping feeling to the end-user.
176+
group.nextElementSibling.style.marginTop = group.clientHeight + 'px';
177+
}
178+
}
179+
180+
function unsetStickyGroupStyles(group) {
181+
group.classList.remove('is-sticky');
182+
183+
if (group.nextElementSibling) {
184+
group.nextElementSibling.style.marginTop = null;
185+
}
186+
}
187+
188+
// When the window has finished loading the DOM, fetch the components and
189+
// populate the dropdown.
190+
window.addEventListener('load', function () {
191+
const request = new XMLHttpRequest();
192+
request.onreadystatechange = parseComponentList;
193+
request.open('GET', '//docs.zendframework.com/js/zf-component-list.json');
194+
request.send();
195+
});
196+
})();

0 commit comments

Comments
 (0)