Browse Source

update to es6 (#44)

pull/45/head
Cian Butler 4 years ago
committed by GitHub
parent
commit
127de6fb36
14 changed files with 1019 additions and 368 deletions
  1. +17
    -0
      .babelrc
  2. +3
    -0
      .eslintignore
  3. +65
    -0
      .eslintrc
  4. +49
    -60
      gulpfile.js
  5. +22
    -59
      package.json
  6. +17
    -19
      scripts/meta.js
  7. +1
    -3
      scripts/thumbnail.js
  8. +12
    -8
      source/js/contact.js
  9. +11
    -11
      source/js/form.js
  10. +72
    -70
      source/js/insight.js
  11. +34
    -29
      source/js/main.js
  12. +3
    -3
      source/js/menu.js
  13. +53
    -47
      source/js/share.js
  14. +660
    -59
      yarn.lock

+ 17
- 0
.babelrc View File

@@ -0,0 +1,17 @@
{
"presets": [
[
"es2015",
{
"modules": false
}
]
],
"plugins": [
"add-module-exports",
"transform-object-assign",
"es6-promise",
"transform-async-to-generator"
],
"compact": true
}

+ 3
- 0
.eslintignore View File

@@ -0,0 +1,3 @@
node_modules/
source/vendor
source/dist

+ 65
- 0
.eslintrc View File

@@ -0,0 +1,65 @@
{
"extends": "standard",
"env": {
"es6": true,
"jest": true,
"browser": true,
"jquery": true,
"node": true
},
"globals": {
"GENTLY": true,
"grecaptcha": true,
"__SHARE_BUTTON_BINDED__": true,
"hexo": true,
"classie": true
},
"rules": {
"no-multi-spaces": 0,
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"comma-dangle": [
"error",
"always-multiline"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-var": [
"error"
],
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
],
"key-spacing": [
"error",
{
"multiLine": {
"beforeColon": false,
"afterColon": true
},
"align": {
"beforeColon": false,
"afterColon": true,
"on": "colon",
"mode": "strict"
}
}
]
}
}

+ 49
- 60
gulpfile.js View File

@@ -7,73 +7,62 @@ const babel = require('gulp-babel');

gulp.task('default', ['minify']);
gulp.task('minify', ['vendor-styles', 'vendor-fonts', 'vendor-images', 'scripts']);
gulp.task('dev', ['minify'], function () {
gulp.watch(['./source'],['minify']);
gulp.task('dev', ['minify'], () => {
gulp.watch(['./source'], ['minify']);
});

gulp.task('vendor-styles', ['bower'], function () {
gulp.src([
'./source/vendor/components-font-awesome/css/font-awesome.min.css',
'./source/fonts/open-sans/css/styles.css',
'./source/fonts/source-code-pro/styles.css',
'./source/vendor/lightgallery/dist/css/lightgallery.min.css',
'./source/vendor/justifiedGallery/dist/css/justifiedGallery.min.css',
'./source/vendor/fullcalendar/dist/fullcalendar.css'
])
.pipe(concat('vendor-styles.min.css'))
.pipe(cleanCSS({compatibility: 'ie9', processImport: false, keepSpecialComments: 0}))
.pipe(gulp.dest('./source/dist/css/'));
gulp.task('vendor-styles', ['bower'], () => {
gulp
.src([
'./source/vendor/components-font-awesome/css/font-awesome.min.css',
'./source/fonts/open-sans/css/styles.css',
'./source/fonts/source-code-pro/styles.css',
'./source/vendor/lightgallery/dist/css/lightgallery.min.css',
'./source/vendor/justifiedGallery/dist/css/justifiedGallery.min.css',
'./source/vendor/fullcalendar/dist/fullcalendar.css',
])
.pipe(concat('vendor-styles.min.css'))
.pipe(cleanCSS({ compatibility: 'ie9', processImport: false, keepSpecialComments: 0 }))
.pipe(gulp.dest('./source/dist/css/'));
});

gulp.task('scripts', ['bower'], function () {
gulp.src([
'./source/vendor/classie/classie.js',
'./source/vendor/moment/min/moment.min.js',
'./source/vendor/lightgallery/dist/js/lightgallery.js',
'./source/vendor/lg-thumbnail/dist/lg-thumbnail.js',
'./source/vendor/lg-pager/dist/lg-pager.js',
'./source/vendor/lg-autoplay/dist/lg-autoplay.js',
'./source/vendor/lg-fullscreen/dist/lg-fullscreen.js',
'./source/vendor/lg-zoom/dist/lg-zoom.js',
'./source/vendor/lg-hash/dist/lg-hash.js',
'./source/vendor/lg-share/dist/lg-share.js',
'./source/vendor/lg-video/dist/lg-video.js',
'./source/vendor/justifiedGallery/dist/js/jquery.justifiedGallery.js',
'./source/vendor/fullcalendar/dist/fullcalendar.js',
'./source/vendor/fullcalendar/dist/gcal.js',
'./source/js/main.js',
'./source/js/insight.js',
'./source/js/share.js',
'./source/js/menu.js',
'./source/js/contact.js',
'./source/js/form.js'
])
.pipe(concat('main.js'))
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('./source/dist/js/'));
gulp.task('scripts', ['bower'], () => {
gulp
.src([
'./source/vendor/classie/classie.js',
'./source/vendor/moment/min/moment.min.js',
'./source/vendor/lightgallery/dist/js/lightgallery.js',
'./source/vendor/lg-thumbnail/dist/lg-thumbnail.js',
'./source/vendor/lg-pager/dist/lg-pager.js',
'./source/vendor/lg-autoplay/dist/lg-autoplay.js',
'./source/vendor/lg-fullscreen/dist/lg-fullscreen.js',
'./source/vendor/lg-zoom/dist/lg-zoom.js',
'./source/vendor/lg-hash/dist/lg-hash.js',
'./source/vendor/lg-share/dist/lg-share.js',
'./source/vendor/lg-video/dist/lg-video.js',
'./source/vendor/justifiedGallery/dist/js/jquery.justifiedGallery.js',
'./source/vendor/fullcalendar/dist/fullcalendar.js',
'./source/vendor/fullcalendar/dist/gcal.js',
'./source/js/main.js',
'./source/js/insight.js',
'./source/js/share.js',
'./source/js/menu.js',
'./source/js/contact.js',
'./source/js/form.js',
])
.pipe(concat('main.js'))
.pipe(babel())
.pipe(uglify())
.pipe(gulp.dest('./source/dist/js/'));
});

gulp.task('vendor-fonts', ['bower'], function () {
gulp.src([
'./source/vendor/components-font-awesome/fonts/*',
'./source/vendor/lightgallery/dist/fonts/*'
])
.pipe(gulp.dest('./source/dist/fonts'));
gulp.src([
'./source/fonts/open-sans/fonts/*',
'./source/fonts/source-code-pro/fonts/*'
])
.pipe(gulp.dest('./source/dist/css/fonts'));
gulp.task('vendor-fonts', ['bower'], () => {
gulp.src(['./source/vendor/components-font-awesome/fonts/*', './source/vendor/lightgallery/dist/fonts/*']).pipe(gulp.dest('./source/dist/fonts'));
gulp.src(['./source/fonts/open-sans/fonts/*', './source/fonts/source-code-pro/fonts/*']).pipe(gulp.dest('./source/dist/css/fonts'));
});

gulp.task('vendor-images', ['bower'], function () {
gulp.src([
'./source/vendor/lightgallery/dist/img/*'
])
.pipe(gulp.dest('./source/dist/img'));
gulp.task('vendor-images', ['bower'], () => {
gulp.src(['./source/vendor/lightgallery/dist/img/*']).pipe(gulp.dest('./source/dist/img'));
});

gulp.task('bower', function() {
return bower('./source/vendor');
});
gulp.task('bower', () => bower('./source/vendor'));

+ 22
- 59
package.json View File

@@ -4,11 +4,26 @@
"private": true,
"scripts": {
"postinstall": "gulp",
"test": "eslint source/js"
"test": "eslint source/js",
"lint": "eslint .",
"fix": "eslint . --fix",
"build": "babel src --source-maps --out-dir lib",
"build:watch": "babel src --watch --source-maps --out-dir lib"
},
"dependencies": {
"babel-preset-es2015": "^6.22.0",
"eslint": "^3.15.0",
"devDependencies": {
"babel-cli": "6.23.0",
"babel-core": "6.23.1",
"babel-eslint": "7.1.1",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-es6-promise": "1.1.1",
"babel-plugin-syntax-async-functions": "6.13.0",
"babel-plugin-transform-async-to-generator": "6.22.0",
"babel-plugin-transform-object-assign": "6.22.0",
"babel-preset-es2015": "6.22.0",
"eslint": "3.16.1",
"eslint-config-standard": "6.2.1",
"eslint-plugin-promise": "3.5.0",
"eslint-plugin-standard": "2.1.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-bower": "0.0.13",
@@ -16,59 +31,7 @@
"gulp-concat": "^2.6.0",
"gulp-uglify": "^2.0.0"
},
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"browser": true,
"es6": true,
"jquery": true
},
"globals": {
"grecaptcha": true,
"__SHARE_BUTTON_BINDED__": true,
"classie": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-var": [
"error"
],
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
]
}
},
"babel": {
"presets": [
[
"es2015",
{
"modules": false
}
]
],
"compact": true
"dependencies": {
"bower": "^1.8.0"
}
}
}

+ 17
- 19
scripts/meta.js View File

@@ -10,29 +10,27 @@ function trim (str) {

function split (str, sep) {
const result = [];
let matched = null;
while (matched = sep.exec(str)) {
result.push(matched[0]);
}
const matched = sep.exec(str);
result.push(matched[0]);
return result;
}

hexo.extend.helper.register('meta', function (post) {
const metas = post.meta || [];
const metaDOMArray = metas.map(function (meta) {
hexo.extend.helper.register('meta', ({ meta }) => {
const metas = meta || [];
const metaDOMArray = metas.map(meta => {
const entities = split(meta, /(?:[^\\;]+|\\.)+/g);
const entityArray = entities.map(function (entity) {
const keyValue = split(entity, /(?:[^\\=]+|\\.)+/g);
if (keyValue.length < 2) {
return null;
}
const key = trim(keyValue[0]);
const value = trim(keyValue[1]);
return key + '="' + value + '"';
}).filter(function (entity) {
return entity;
});
return '<meta ' + entityArray.join(' ') + ' />';
const entityArray = entities
.map(entity => {
const keyValue = split(entity, /(?:[^\\=]+|\\.)+/g);
if (keyValue.length < 2) {
return null;
}
const key = trim(keyValue[0]);
const value = trim(keyValue[1]);
return `${key}="${value}"`;
})
.filter(entity => entity);
return `<meta ${entityArray.join(' ')} />`;
});
return metaDOMArray.join('\n');
});

+ 1
- 3
scripts/thumbnail.js View File

@@ -4,6 +4,4 @@
* @example
* <%- thumbnail(post) %>
*/
hexo.extend.helper.register('thumbnail', function (post) {
return post.thumbnail || post.banner || '';
});
hexo.extend.helper.register('thumbnail', ({ thumbnail, banner }) => thumbnail || banner || '');

+ 12
- 8
source/js/contact.js View File

@@ -1,11 +1,15 @@
$(document).ready(function(){
$(document).ready(() => {
const site = window.location.origin;
let email, name, subject, text, recaptcha;
let email;
let name;
let subject;
let text;
let recaptcha;
let to = window.location.pathname;
to = to.substring(to.lastIndexOf('/')+1);
$('#contact').submit(function(e) {
to = to.substring(to.lastIndexOf('/') + 1);
$('#contact').submit(e => {
recaptcha = grecaptcha.getResponse();
if(recaptcha == '') {
if (recaptcha === '') {
e.preventDefault();
$('#message').empty().html('complete recaptcha');
} else {
@@ -15,11 +19,11 @@ $(document).ready(function(){
subject = $('#subject').val().trim();
text = $('#content').val().trim();
$('#message').text('Sending E-mail');
$.get(site + '/api/contact', { email:email, to:to, name:name, subject:subject, text:text, recaptcha:recaptcha}, function(data) {
if(!data.formSubmit) {
$.get(`${site}/api/contact`, { email, to, name, subject, text, recaptcha }, ({ formSubmit, errors }) => {
if (!formSubmit) {
$('#message').empty().html('Error in recaptcha');
} else {
const message = data.errors ? data.errors : 'Email Sent';
const message = errors || 'Email Sent';
$('#message').empty().html(message);
}
});


+ 11
- 11
source/js/form.js View File

@@ -1,20 +1,20 @@
[].slice.call( document.querySelectorAll( '.input' ) ).forEach( function( inputEl ) {
[].slice.call(document.querySelectorAll('.input')).forEach(inputEl => {
// in case the input is already filled..
if( inputEl.value.trim() !== '' ) {
classie.add( inputEl.parentNode, 'input--filled' );
if (inputEl.value.trim() !== '') {
classie.add(inputEl.parentNode, 'input--filled');
}

// events:
inputEl.addEventListener( 'focus', onInputFocus );
inputEl.addEventListener( 'blur', onInputBlur );
} );
inputEl.addEventListener('focus', onInputFocus);
inputEl.addEventListener('blur', onInputBlur);
});

function onInputFocus( ev ) {
classie.add( ev.target.parentNode, 'input--filled' );
function onInputFocus ({ target }) {
classie.add(target.parentNode, 'input--filled');
}

function onInputBlur( ev ) {
if( ev.target.value.trim() === '' ) {
classie.remove( ev.target.parentNode, 'input--filled' );
function onInputBlur ({ target }) {
if (target.value.trim() === '') {
classie.remove(target.parentNode, 'input--filled');
}
}

+ 72
- 70
source/js/insight.js View File

@@ -2,7 +2,7 @@
* Insight search plugin
* @author PPOffice { @link https://github.com/ppoffice }
*/
(function ($, CONFIG) {
(($, { TRANSLATION, ROOT_URL, CONTENT_URL }) => {
const $main = $('.ins-search');
const $input = $main.find('.ins-search-input');
const $wrapper = $main.find('.ins-section-wrapper');
@@ -11,14 +11,19 @@
$('body').append($main);

function section (title) {
return $('<section>').addClass('ins-section')
.append($('<header>').addClass('ins-section-header').text(title));
return $('<section>').addClass('ins-section').append($('<header>').addClass('ins-section-header').text(title));
}

function searchItem (icon, title, slug, preview, url) {
return $('<div>').addClass('ins-selectable').addClass('ins-search-item')
.append($('<header>').append($('<i>').addClass('fa').addClass('fa-' + icon)).append(title != null && title != '' ? title : CONFIG.TRANSLATION['UNTITLED'])
.append(slug ? $('<span>').addClass('ins-slug').text(slug) : null))
return $('<div>')
.addClass('ins-selectable')
.addClass('ins-search-item')
.append(
$('<header>')
.append($('<i>').addClass('fa').addClass(`fa-${icon}`))
.append(title !== null && title !== '' ? title : TRANSLATION['UNTITLED'])
.append(slug ? $('<span>').addClass('ins-slug').text(slug) : null)
)
.append(preview ? $('<p>').addClass('ins-search-preview').text(preview) : null)
.attr('data-url', url);
}
@@ -26,20 +31,17 @@
function sectionFactory (type, array) {
let $searchItems;
if (array.length === 0) return null;
const sectionTitle = CONFIG.TRANSLATION[type];
const sectionTitle = TRANSLATION[type];
switch (type) {
case 'POSTS':
case 'PAGES':
$searchItems = array.map(function (item) {
// Use config.root instead of permalink to fix url issue
return searchItem('file', item.title, null, item.text.slice(0, 150), CONFIG.ROOT_URL + item.path);
});
$searchItems = array.map((
{ title, text, path } // Use config.root instead of permalink to fix url issue
) => searchItem('file', title, null, text.slice(0, 150), ROOT_URL + path));
break;
case 'CATEGORIES':
case 'TAGS':
$searchItems = array.map(function (item) {
return searchItem(type === 'CATEGORIES' ? 'folder' : 'tag', item.name, item.slug, null, item.permalink);
});
$searchItems = array.map(({ name, slug, permalink }) => searchItem(type === 'CATEGORIES' ? 'folder' : 'tag', name, slug, null, permalink));
break;
default:
return null;
@@ -47,12 +49,12 @@
return section(sectionTitle).append($searchItems);
}

function extractToSet (json, key) {
function extractToSet ({ pages, posts }, key) {
const values = {};
const entries = json.pages.concat(json.posts);
entries.forEach(function (entry) {
const entries = pages.concat(posts);
entries.forEach(entry => {
if (entry[key]) {
entry[key].forEach(function (value) {
entry[key].forEach(value => {
values[value.name] = value;
});
}
@@ -65,11 +67,7 @@
}

function parseKeywords (keywords) {
return keywords.split(' ').filter(function (keyword) {
return !!keyword;
}).map(function (keyword) {
return keyword.toUpperCase();
});
return keywords.split(' ').filter(keyword => !!keyword).map(keyword => keyword.toUpperCase());
}

/**
@@ -79,15 +77,12 @@
*/
function filter (keywords, obj, fields) {
const keywordArray = parseKeywords(keywords);
const containKeywords = keywordArray.filter(function (keyword) {
const containFields = fields.filter(function (field) {
if (!obj.hasOwnProperty(field))
return false;
if (obj[field].toUpperCase().indexOf(keyword) > -1)
return true;
const containKeywords = keywordArray.filter(keyword => {
const containFields = fields.filter(field => {
if (!obj.hasOwnProperty(field)) return false;
if (obj[field].toUpperCase().indexOf(keyword) > -1) return true;
});
if (containFields.length > 0)
return true;
if (containFields.length > 0) return true;
return false;
});
return containKeywords.length === keywordArray.length;
@@ -95,18 +90,18 @@

function filterFactory (keywords) {
return {
POST: function (obj) {
POST (obj) {
return filter(keywords, obj, ['title', 'text']);
},
PAGE: function (obj) {
PAGE (obj) {
return filter(keywords, obj, ['title', 'text']);
},
CATEGORY: function (obj) {
CATEGORY (obj) {
return filter(keywords, obj, ['name', 'slug']);
},
TAG: function (obj) {
TAG (obj) {
return filter(keywords, obj, ['name', 'slug']);
}
},
};
}

@@ -118,9 +113,9 @@
*/
function weight (keywords, obj, fields, weights) {
let value = 0;
parseKeywords(keywords).forEach(function (keyword) {
parseKeywords(keywords).forEach(keyword => {
const pattern = new RegExp(keyword, 'img'); // Global, Multi-line, Case-insensitive
fields.forEach(function (field, index) {
fields.forEach((field, index) => {
if (obj.hasOwnProperty(field)) {
const matches = obj[field].match(pattern);
value += matches ? matches.length * weights[index] : 0;
@@ -132,18 +127,18 @@

function weightFactory (keywords) {
return {
POST: function (obj) {
POST (obj) {
return weight(keywords, obj, ['title', 'text'], [3, 1]);
},
PAGE: function (obj) {
PAGE (obj) {
return weight(keywords, obj, ['title', 'text'], [3, 1]);
},
CATEGORY: function (obj) {
CATEGORY (obj) {
return weight(keywords, obj, ['name', 'slug'], [1, 1]);
},
TAG: function (obj) {
TAG (obj) {
return weight(keywords, obj, ['name', 'slug'], [1, 1]);
}
},
};
}

@@ -155,10 +150,10 @@
const tags = extractToSet(json, 'tags');
const categories = extractToSet(json, 'categories');
return {
posts: posts.filter(FILTERS.POST).sort(function (a, b) { return WEIGHTS.POST(b) - WEIGHTS.POST(a); }).slice(0, 5),
pages: pages.filter(FILTERS.PAGE).sort(function (a, b) { return WEIGHTS.PAGE(b) - WEIGHTS.PAGE(a); }).slice(0, 5),
categories: categories.filter(FILTERS.CATEGORY).sort(function (a, b) { return WEIGHTS.CATEGORY(b) - WEIGHTS.CATEGORY(a); }).slice(0, 5),
tags: tags.filter(FILTERS.TAG).sort(function (a, b) { return WEIGHTS.TAG(b) - WEIGHTS.TAG(a); }).slice(0, 5)
posts : posts.filter(FILTERS.POST).sort((a, b) => WEIGHTS.POST(b) - WEIGHTS.POST(a)).slice(0, 5),
pages : pages.filter(FILTERS.PAGE).sort((a, b) => WEIGHTS.PAGE(b) - WEIGHTS.PAGE(a)).slice(0, 5),
categories: categories.filter(FILTERS.CATEGORY).sort((a, b) => WEIGHTS.CATEGORY(b) - WEIGHTS.CATEGORY(a)).slice(0, 5),
tags : tags.filter(FILTERS.TAG).sort((a, b) => WEIGHTS.TAG(b) - WEIGHTS.TAG(a)).slice(0, 5),
};
}

@@ -185,7 +180,7 @@
function selectItemByDiff (value) {
const $items = $.makeArray($container.find('.ins-selectable'));
let prevPosition = -1;
$items.forEach(function (item, index) {
$items.forEach((item, index) => {
if ($(item).hasClass('active')) {
prevPosition = index;
return;
@@ -203,7 +198,7 @@
}
}

$.getJSON(CONFIG.CONTENT_URL, function (json) {
$.getJSON(CONTENT_URL, json => {
if (location.hash.trim() === '#ins-search') {
$main.addClass('show');
}
@@ -214,25 +209,32 @@
$input.trigger('input');
});


$(document).on('click focus', '.search-form-input', function () {
$main.addClass('show');
$main.find('.ins-search-input').focus();
}).on('click', '.ins-search-item', function () {
gotoLink($(this));
}).on('click', '.ins-close', function () {
$main.removeClass('show');
}).on('keydown', function (e) {
if (!$main.hasClass('show')) return;
switch (e.keyCode) {
case 27: // ESC
$main.removeClass('show'); break;
case 38: // UP
selectItemByDiff(-1); break;
case 40: // DOWN
selectItemByDiff(1); break;
case 13: //ENTER
gotoLink($container.find('.ins-selectable.active').eq(0)); break;
}
});
$(document)
.on('click focus', '.search-form-input', () => {
$main.addClass('show');
$main.find('.ins-search-input').focus();
})
.on('click', '.ins-search-item', function () {
gotoLink($(this));
})
.on('click', '.ins-close', () => {
$main.removeClass('show');
})
.on('keydown', ({ keyCode }) => {
if (!$main.hasClass('show')) return;
switch (keyCode) {
case 27: // ESC
$main.removeClass('show');
break;
case 38: // UP
selectItemByDiff(-1);
break;
case 40: // DOWN
selectItemByDiff(1);
break;
case 13: // ENTER
gotoLink($container.find('.ins-selectable.active').eq(0));
break;
}
});
})(jQuery, window.INSIGHT_CONFIG);

+ 34
- 29
source/js/main.js View File

@@ -1,12 +1,12 @@
(function($){
const toTop = ($('#sidebar').height() - $(window).height()) + 60;
($ => {
const toTop = $('#sidebar').height() - $(window).height() + 60;
// Caption
$('.article-entry').each(function() {
$(this).find('img').each(function() {
$('.article-entry').each(function () {
$(this).find('img').each(function () {
if (this.alt) {
$(this).after('<span class="caption">' + this.alt + '</span>');
$(this).after(`<span class="caption">${this.alt}</span>`);
}
$(this).wrap('<a href="' + this.src + '" title="' + this.alt + '" class="gallery-item"></a>');
$(this).wrap(`<a href="${this.src}" title="${this.alt}" class="gallery-item"></a>`);
});
});
let options = {
@@ -16,37 +16,42 @@
$('.article-gallery').lightGallery(options);
options = {
rowHeight: 140,
margins: 4,
lastRow: 'justify'
margins : 4,
lastRow : 'justify',
};
$('.justified-gallery').justifiedGallery(options);

// Profile card
$(document).on('click', function () {
$('#profile').removeClass('card');
}).on('click', '#profile-anchor', function (e) {
e.stopPropagation();
$('#profile').toggleClass('card');
}).on('click', '.profile-inner', function (e) {
e.stopPropagation();
});
$(document)
.on('click', () => {
$('#profile').removeClass('card');
})
.on('click', '#profile-anchor', e => {
e.stopPropagation();
$('#profile').toggleClass('card');
})
.on('click', '.profile-inner', e => {
e.stopPropagation();
});

// To Top
if ($('#sidebar').length) {
$(document).on('scroll', function () {
if ($(document).width() >= 800) {
if(($(this).scrollTop() > toTop) && ($(this).scrollTop() > 0)) {
$('#toTop').fadeIn();
$('#toTop').css('left', $('#sidebar').offset().left);
$(document)
.on('scroll', function () {
if ($(document).width() >= 800) {
if ($(this).scrollTop() > toTop && $(this).scrollTop() > 0) {
$('#toTop').fadeIn();
$('#toTop').css('left', $('#sidebar').offset().left);
} else {
$('#toTop').fadeOut();
}
} else {
$('#toTop').fadeOut();
$('#toTop').fadeIn();
$('#toTop').css('right', 20);
}
} else {
$('#toTop').fadeIn();
$('#toTop').css('right', 20);
}
}).on('click', '#toTop', function () {
$('body, html').animate({ scrollTop: 0 }, 600);
});
})
.on('click', '#toTop', () => {
$('body, html').animate({ scrollTop: 0 }, 600);
});
}
})(jQuery);

+ 3
- 3
source/js/menu.js View File

@@ -1,8 +1,8 @@
$(document).ready(function () {
$('body').on('click', function() {
$(document).ready(() => {
$('body').on('click', () => {
$('.menu li').removeClass('active');
});
$('.menu .menu-list .dropdown-toggle').on('click', function(e) {
$('.menu .menu-list .dropdown-toggle').on('click', function (e) {
e.stopPropagation();
$('.menu li').removeClass('active');
const $parent = $(this).parent();


+ 53
- 47
source/js/share.js View File

@@ -1,60 +1,66 @@
(function ($) {
($ => {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
if (typeof __SHARE_BUTTON_BINDED__ === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
$('body')
.on('click', () => {
$('.article-share-box.on').removeClass('on');
})
.on('click', '.article-share-link', function (e) {
e.stopPropagation();

const $this = $(this);
const url = $this.attr('data-url');
const encodedUrl = encodeURIComponent(url);
const id = 'article-share-box-' + $this.attr('data-id');
const offset = $this.offset();
let box;
const $this = $(this);
const url = $this.attr('data-url');
const encodedUrl = encodeURIComponent(url);
const id = `article-share-box-${$this.attr('data-id')}`;
const offset = $this.offset();
let box;

if ($('#' + id).length) {
box = $('#' + id);
if ($(`#${id}`).length) {
box = $(`#${id}`);

if (box.hasClass('on')){
box.removeClass('on');
return;
if (box.hasClass('on')) {
box.removeClass('on');
return;
}
} else {
const html = [
`<div id="${id}" class="article-share-box">`,
`<input class="article-share-input" value="${url}">`,
'<div class="article-share-links">',
`<a href="https://twitter.com/intent/tweet?url=${encodedUrl}" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>`,
`<a href="https://www.facebook.com/sharer.php?u=${encodedUrl}" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>`,
`<a href="http://pinterest.com/pin/create/button/?url=${encodedUrl}" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>`,
`<a href="https://plus.google.com/share?url=${encodedUrl}" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>`,
'</div>',
'</div>',
].join('');
box = $(html);
$('body').append(box);
}
} else {
const html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}

$('.article-share-box.on').hide();
$('.article-share-box.on').hide();

box.css({
top: offset.top + 25,
left: offset.left
}).addClass('on');
box
.css({
top : offset.top + 25,
left: offset.left,
})
.addClass('on');
})
.on('click', '.article-share-box', e => {
e.stopPropagation();
})
.on('click', '.article-share-box-input', function () {
$(this).select();
})
.on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();

}).on('click', '.article-share-box', function (e) {
e.stopPropagation();
}).on('click', '.article-share-box-input', function () {
$(this).select();
}).on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();

window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
});
window.open(this.href, `article-share-box-window-${Date.now()}`, 'width=500,height=450');
});
})(jQuery);

+ 660
- 59
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save