Permalink
Browse files

JSHint - code always in style.

  • Loading branch information...
iissnan committed Nov 18, 2015
1 parent 332b36e commit d367c2f70e78fea71f07e36b98e3c37a84535ad5
View
@@ -1,20 +1,27 @@
{
+ "asi": false,
+ "bitwise": true,
+ "browser": true,
+ "camelcase": true,
"curly": true,
- "eqnull": true,
- "eqeqeq": true,
- "undef": true,
+ "forin": true,
+ "immed": true,
+ "latedef": "nofunc",
+ "maxlen": 120,
"newcap": true,
+ "noarg": true,
+ "noempty": true,
+ "nonew": true,
+ "predef": [
+ "$",
+ "jQuery",
+ "NexT",
+ "CONFIG"
+ ],
+ "quotmark": true,
+ "trailing": true,
"undef": true,
"unused": true,
- "laxcomma": false,
- "asi": false,
- "expr": true,
- "loopfunc": false,
- "strict": false,
- "globals": {
- "$": true,
- "window": true,
- "document": true
- }
+ "expr": true
}
View
@@ -0,0 +1,16 @@
+gulp = require('gulp')
+jshint = require('gulp-jshint')
+stylish = require('jshint-stylish')
+
+gulp.task 'lint', ->
+ return gulp.src([
+ './source/js/src/utils.js',
+ './source/js/src/motion.js',
+ './source/js/src/hook-duoshuo.js'
+ './source/js/src/bootstrap.js',
+ './source/js/src/schemes/pisces.js'
+ ]).pipe jshint()
+ .pipe jshint.reporter(stylish)
+
+
+gulp.task 'default', ['lint']
@@ -86,6 +86,10 @@
scheme: '{{ theme.scheme }}',
sidebar: '{{ theme.sidebar }}',
fancybox: {{ theme.fancybox }},
- motion: {{ theme.use_motion }}
+ motion: {{ theme.use_motion }},
+ duoshuo: {
+ userId: {{ theme.duoshuo_info.user_id }},
+ author: '{{ theme.duoshuo_info.admin_nickname | default(__('author'))}}'
+ }
};
</script>
@@ -133,7 +133,7 @@
$('.post-toc a').on('click', function (e) {
e.preventDefault();
- var targetSelector = escapeSelector(this.getAttribute('href'));
+ var targetSelector = NexT.utils.escapeSelector(this.getAttribute('href'));
var offset = $(targetSelector).offset().top;
hasVelocity ?
html.velocity('stop').velocity('scroll', {
@@ -146,11 +146,12 @@
});
// Expand sidebar on post detail page by default, when post has a toc.
- motionMiddleWares.sidebar = function () {
+ NexT.motion.middleWares.sidebar = function () {
var $tocContent = $('.post-toc-content');
+
if (CONFIG.sidebar === 'post') {
if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
- displaySidebar();
+ NexT.utils.displaySidebar();
}
}
};
@@ -21,10 +21,6 @@
{% if theme.duoshuo_info.ua_enable %}
{% if theme.duoshuo_info.admin_enable %}
- <script type="text/javascript">
- var duoshuo_user_ID = {{theme.duoshuo_info.user_id}};
- var duoshuo_admin_nickname = "{{theme.duoshuo_info.admin_nickname | default(__('author'))}}";
- </script>
<script src="{{ url_for(theme.vendors) }}/ua-parser-js/dist/ua-parser.min.js"></script>
<script src="{{ url_for(theme.js) }}/src/hook-duoshuo.js"></script>
{% endif %}
View
@@ -0,0 +1,32 @@
+{
+ "name": "hexo-theme-next",
+ "version": "0.5.0",
+ "description": "Elegant theme for Hexo",
+ "main": "index.js",
+ "directories": {
+ "test": "test"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/iissnan/hexo-theme-next.git"
+ },
+ "keywords": [
+ "NexT",
+ "Hexo"
+ ],
+ "author": "iissnan <iissnan@gmail.com>",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/iissnan/hexo-theme-next/issues"
+ },
+ "homepage": "https://github.com/iissnan/hexo-theme-next#readme",
+ "devDependencies": {
+ "coffee-script": "^1.10.0",
+ "gulp": "^3.9.0",
+ "gulp-jshint": "^1.12.0",
+ "jshint-stylish": "^2.1.0"
+ }
+}
@@ -172,7 +172,7 @@
}
}
- #ds-reset .duoshuo-ua-seperator {
+ #ds-reset .duoshuo-ua-separator {
display: inline-block;
margin-left: 5px;
}
View
@@ -4,11 +4,11 @@ $(document).ready(function () {
$(document).trigger('bootstrap:before');
- isMobile() && FastClick.attach(document.body);
+ NexT.utils.isMobile() && window.FastClick.attach(document.body);
- $("#posts").find('img').lazyload({
- placeholder: "/images/loading.gif",
- effect: "fadeIn"
+ $('#posts').find('img').lazyload({
+ placeholder: '/images/loading.gif',
+ effect: 'fadeIn'
});
$('.back-to-top').on('click', function () {
@@ -34,16 +34,16 @@ $(document).ready(function () {
// Define Motion Sequence.
- motionIntegrator
- .add(motionMiddleWares.logo)
- .add(motionMiddleWares.menu)
- .add(motionMiddleWares.postList)
- .add(motionMiddleWares.sidebar);
+ NexT.motion.integrator
+ .add(NexT.motion.middleWares.logo)
+ .add(NexT.motion.middleWares.menu)
+ .add(NexT.motion.middleWares.postList)
+ .add(NexT.motion.middleWares.sidebar);
$(document).trigger('motion:before');
// Bootstrap Motion.
- CONFIG.motion && motionIntegrator.bootstrap();
+ CONFIG.motion && NexT.motion.integrator.bootstrap();
$(document).trigger('bootstrap:after');
});
@@ -1,35 +1,38 @@
+/* global DUOSHUO: true */
+/* jshint camelcase: false */
+
typeof DUOSHUO !== 'undefined' ?
- hookDUOSHUO_tp() :
- ($('#duoshuo-script')[0].onload = hookDUOSHUO_tp);
+ hookTemplate() :
+ ($('#duoshuo-script')[0].onload = hookTemplate);
-function hookDUOSHUO_tp() {
- var _D_post = DUOSHUO.templates.post;
+function hookTemplate() {
+ var post = DUOSHUO.templates.post;
DUOSHUO.templates.post = function (e, t) {
- var rs = _D_post(e, t);
+ var rs = post(e, t);
var agent = e.post.agent;
var userId = e.post.author.user_id;
var admin = '';
- if (userId && (userId == duoshuo_user_ID)) {
- admin = '<span class="duoshuo-ua-admin">' + duoshuo_admin_nickname + '</span>';
+ if (userId && (userId === CONFIG.duoshuo.userId)) {
+ admin = '<span class="duoshuo-ua-admin">' + CONFIG.duoshuo.author + '</span>';
}
if (agent && /^Mozilla/.test(agent)) {
rs = rs.replace(/<\/div><p>/, admin + getAgentInfo(agent) + '</div><p>');
}
return rs;
- }
+ };
}
function getAgentInfo(string) {
$.ua.set(string);
var UNKNOWN = 'Unknown';
var sua = $.ua;
- var seperator = isMobile() ? '<br><br>' : '<span class="duoshuo-ua-seperator"></span>';
+ var separator = isMobile() ? '<br><br>' : '<span class="duoshuo-ua-separator"></span>';
var osName = sua.os.name || UNKNOWN;
var osVersion = sua.os.version || UNKNOWN;
var browserName = sua.browser.name || UNKNOWN;
@@ -56,18 +59,18 @@ function getAgentInfo(string) {
var osIcon = iconMapping.os[osName.toLowerCase()];
var browserIcon = iconMapping.browser[browserName.toLowerCase()];
- return seperator +
+ return separator +
'<span class="duoshuo-ua-platform duoshuo-ua-platform-' + osName.toLowerCase() + '">' +
'<i class="fa fa-' + osIcon + '"></i>' +
osName + ' ' + osVersion +
- '</span>' + seperator +
+ '</span>' + separator +
'<span class="duoshuo-ua-browser duoshuo-ua-browser-' + browserName.toLowerCase() + '">' +
'<i class="fa fa-' + browserIcon + '"></i>' +
browserName + ' ' + browserVersion +
'</span>';
function isMobile() {
- var userAgent = navigator.userAgent;
+ var userAgent = window.navigator.userAgent;
var isiPad = userAgent.match(/iPad/i) !== null;
var mobileUA = [
View
@@ -1,20 +1,5 @@
$(document).ready(function () {
- var motionIntegrator = {
- queue: [],
- cursor: -1,
- add: function (fn) {
- this.queue.push(fn);
- return this;
- },
- next: function () {
- this.cursor++;
- var fn = this.queue[this.cursor];
- $.isFunction(fn) && fn(motionIntegrator);
- },
- bootstrap: function () {
- this.next();
- }
- };
+ NexT.motion = {};
var sidebarToggleLines = {
lines: [],
@@ -104,7 +89,7 @@ $(document).ready(function () {
$(document)
.on('sidebar.isShowing', function () {
- isDesktop() && $('body').velocity('stop').velocity(
+ NexT.utils.isDesktop() && $('body').velocity('stop').velocity(
{paddingRight: SIDEBAR_WIDTH},
SIDEBAR_DISPLAY_DURATION
);
@@ -160,7 +145,7 @@ $(document).ready(function () {
this.sidebarEl.trigger('sidebar.isShowing');
},
hideSidebar: function () {
- isDesktop() && $('body').velocity('stop').velocity({paddingRight: 0});
+ NexT.utils.isDesktop() && $('body').velocity('stop').velocity({paddingRight: 0});
this.sidebarEl.find('.motion-element').velocity('stop').css('display', 'none');
this.sidebarEl.velocity('stop').velocity({width: 0}, {display: 'none'});
@@ -180,7 +165,24 @@ $(document).ready(function () {
};
sidebarToggleMotion.init();
- var motionMiddleWares = {
+ NexT.motion.integrator = {
+ queue: [],
+ cursor: -1,
+ add: function (fn) {
+ this.queue.push(fn);
+ return this;
+ },
+ next: function () {
+ this.cursor++;
+ var fn = this.queue[this.cursor];
+ $.isFunction(fn) && fn(NexT.motion.integrator);
+ },
+ bootstrap: function () {
+ this.next();
+ }
+ };
+
+ NexT.motion.middleWares = {
logo: function (integrator) {
var sequence = [];
var $brand = $('.brand');
@@ -195,10 +197,10 @@ $(document).ready(function () {
o: {duration: 200}
});
- isMist() && hasElement([$logoLineTop, $logoLineBottom]) &&
+ NexT.utils.isMist() && hasElement([$logoLineTop, $logoLineBottom]) &&
sequence.push(
- getMistLineSettings($logoLineTop, "100%"),
- getMistLineSettings($logoLineBottom, "-100%")
+ getMistLineSettings($logoLineTop, '100%'),
+ getMistLineSettings($logoLineBottom, '-100%')
);
hasElement($title) && sequence.push({
@@ -278,12 +280,10 @@ $(document).ready(function () {
sidebar: function (integrator) {
if (CONFIG.sidebar === 'always') {
- displaySidebar();
+ NexT.utils.displaySidebar();
}
integrator.next();
}
};
- window.motionMiddleWares = motionMiddleWares;
- window.motionIntegrator = motionIntegrator;
});
@@ -8,7 +8,7 @@ $(document).ready(function () {
.css({ 'margin-top': sidebarTop })
.show();
- isDesktop() && $('.page-post-detail .sidebar-inner').affix({
+ NexT.utils.isDesktop() && $('.page-post-detail .sidebar-inner').affix({
offset: {
top: sidebarTop,
bottom: footerOffset
@@ -64,7 +64,7 @@
.map(function () {
var $el = $(this)
var href = $el.data('target') || $el.attr('href')
- var $href = /^#./.test(href) && $(escapeSelector(href)) // Need to escape selector.
+ var $href = /^#./.test(href) && $(NexT.utils.escapeSelector(href)) // Need to escape selector.
return ($href
&& $href.length
Oops, something went wrong.

0 comments on commit d367c2f

Please sign in to comment.