Skip to content

Commit

Permalink
Update JSCS. Fix code styling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pelkonen committed Mar 20, 2015
1 parent 33c60ef commit 5db742f
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 92 deletions.
1 change: 1 addition & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"preset": "airbnb",
"validateIndentation": 2,
"disallowMultipleVarDecl": null,
"requireMultipleVarDecl": true
}
71 changes: 35 additions & 36 deletions lib/app/js/controllers/appCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,46 @@

angular.module('sgApp')
.controller('AppCtrl', function($scope, ngProgress) {
// ngProgress do not respect styles assigned via CSS if we do not pass empty parameters
// See: https://github.com/VictorBjelkholm/ngProgress/issues/33
ngProgress.height('');
ngProgress.color('');

// Scroll top when page is changed
$scope.$on('$viewContentLoaded', function() {
window.scrollTo(0, 0);
});

// ngProgress do not respect styles assigned via CSS if we do not pass empty parameters
// See: https://github.com/VictorBjelkholm/ngProgress/issues/33
ngProgress.height('');
ngProgress.color('');

// Scroll top when page is changed
$scope.$on('$viewContentLoaded', function() {
window.scrollTo(0, 0);
});

$scope.$on('progress start', function() {
ngProgress.start();
});

$scope.$on('progress end', function() {
ngProgress.complete();
});
$scope.$on('progress start', function() {
ngProgress.start();
});

// Reload styles when server notifies about the changes
// Add cache buster to every stylesheet on the page forcing them to reload
$scope.$on('styles changed', function() {
var links = Array.prototype.slice.call(document.getElementsByTagName('link'));
links.forEach(function(link) {
if (typeof link === 'object' && link.getAttribute('type') === 'text/css' && link.getAttribute('data-noreload') === null) {
link.href = link.href.split('?')[0] + '?id=' + new Date().getTime();
}
});
});
$scope.$on('progress end', function() {
ngProgress.complete();
});

$scope.$on('socket connected', function() {
console.log('Socket connection established');
// Reload styles when server notifies about the changes
// Add cache buster to every stylesheet on the page forcing them to reload
$scope.$on('styles changed', function() {
var links = Array.prototype.slice.call(document.getElementsByTagName('link'));
links.forEach(function(link) {
if (typeof link === 'object' && link.getAttribute('type') === 'text/css' && link.getAttribute('data-noreload') === null) {
link.href = link.href.split('?')[0] + '?id=' + new Date().getTime();
}
});
});

$scope.$on('socket disconnected', function() {
console.error('Socket connection dropped');
ngProgress.reset();
});
$scope.$on('socket connected', function() {
console.log('Socket connection established');
});

$scope.$on('socket error', function(err) {
console.error('Socket error:', err);
});
$scope.$on('socket disconnected', function() {
console.error('Socket connection dropped');
ngProgress.reset();
});

$scope.$on('socket error', function(err) {
console.error('Socket error:', err);
});

});
4 changes: 2 additions & 2 deletions lib/app/js/controllers/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ angular.module('sgApp')
}

function updatePageData() {
var sections, result, element;
var sections, result, element, modifierStr;
if (!Styleguide.sections.data) {
return;
}
Expand All @@ -87,7 +87,7 @@ angular.module('sgApp')

// Set page title
if (Styleguide.config.data) {
var modifierStr = modifier ? '-' + modifier.toString() : '';
modifierStr = modifier ? '-' + modifier.toString() : '';
$rootScope.pageTitle = element.reference + modifierStr + ' ' + element.header + ' - ' + Styleguide.config.data.title;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/app/js/controllers/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ angular.module('sgApp')
return item.reference === section;
});
if (result.length > 0) {
var element = result[0];
$rootScope.pageTitle = element.reference + ' ' + element.header + ' - ' + Styleguide.config.data.title;
$rootScope.pageTitle = result[0].reference + ' ' + result[0].header + ' - ' + Styleguide.config.data.title;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/app/js/services/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
};

this.refreshValues = function() {
var oldIndex, oldValue, newObject, i;
if (serverData.length === 0) {
this.variables = [];
} else {
for (var i = 0; i < serverData.length; i++) {
var oldIndex;
for (i = 0; i < serverData.length; i++) {
if (this.variables[i] && !this.variableMatches(this.variables[i], serverData[i])) {
if (!this.getServerVar(this.variables[i])) {
// This variable does not exists anymore on the server. Remove it
Expand All @@ -84,9 +84,9 @@
// The variable already exists but in another position
// It is changed so we need to keep the old values
oldIndex = this.getLocalIndex(serverData[i]);
var oldValue = this.variables[oldIndex].value;
oldValue = this.variables[oldIndex].value;
this.variables.splice(oldIndex, 1);
var newObject = angular.copy(serverData[i]);
newObject = angular.copy(serverData[i]);
newObject.value = oldValue;
this.variables.splice(i, 0, newObject);
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/cli/styleguide-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = function(argv) {

try {

var styleguide = require(path.resolve(__dirname, '../../styleguide'));
var styleguide = require(path.resolve(__dirname, '../../styleguide')),
tasks = ['styleguide:generate', 'styleguide:applystyles'];

gulp.task('styleguide:generate', function() {
console.log('Generating style guide to output dir:', argv.output);
Expand Down Expand Up @@ -43,7 +44,6 @@ module.exports = function(argv) {
return gulp.watch(argv.styleSource, ['styleguide:applystyles']);
});

var tasks = ['styleguide:generate', 'styleguide:applystyles'];
if (argv.watch) {
tasks.push('watch:styles');
tasks.push('watch:kss');
Expand Down
5 changes: 2 additions & 3 deletions lib/modules/kss-sanitize-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module.exports = function(source) {
var pass = true;

source = source.split('\n').filter(function(line) {

var varName = line.match(/([\w\-]*):[\s]*$/);
var varName = line.match(/([\w\-]*):[\s]*$/),
isEmptyLine = /^[\s\/]*$/.test(line);

if (varName) {
// Named parangraph begins
Expand All @@ -20,7 +20,6 @@ module.exports = function(source) {
}

// When meets empty line, pass everything again
var isEmptyLine = /^[\s\/]*$/.test(line);
if (isEmptyLine) {
pass = true;
}
Expand Down
9 changes: 5 additions & 4 deletions lib/modules/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ module.exports = {
return '<li class="sg">' + text + '</li>\n';
};
renderer.link = function(href, title, text) {
var out, prot;
if (excludeLinks.indexOf(href) >= 0) {
return '';
}

if (this.options.sanitize) {
var prot = '';
prot = '';
try {
prot = decodeURIComponent(href)
.replace(/[^\w:]/g, '')
Expand All @@ -51,15 +52,15 @@ module.exports = {
}
//jshint +W107
}
var out = '<a class="sg" href="' + href + '"';
out = '<a class="sg" href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
}
out += '>' + text + '</a>';
return out;
};
renderer.code = function(code, lang, escaped) {
var htmlEscape = function(html, encode) {
var out, htmlEscape = function(html, encode) {
return html
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
.replace(/</g, '&lt;')
Expand All @@ -69,7 +70,7 @@ module.exports = {
};

if (this.options.highlight) {
var out = this.options.highlight(code, lang);
out = this.options.highlight(code, lang);
if (out !== null && out !== code) {
escaped = true;
code = out;
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/wrapper-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ function buildReferenceDictionary(sections) {
cursor = nested.sections;

sections.forEach(function(section) {
var ref = section.reference, par, length;
/* Check if the parent section was already mentioned
* in the tree */
var ref = section.reference;
/* Put cursor to the root for the root elements */
if (ref.indexOf('.') === -1 || ref.indexOf('.0', ref.length - 2) !== -1) {
cursor = nested.sections;
Expand All @@ -18,7 +18,7 @@ function buildReferenceDictionary(sections) {
ref = ref.substring(0, ref.lastIndexOf('.'));

/* Parent section */
var par = prevSections[prevSections.indexOf(ref)];
par = prevSections[prevSections.indexOf(ref)];
if (par) {
section.parentReference = par;
/* Create nested container if it does not exists yet */
Expand All @@ -29,7 +29,7 @@ function buildReferenceDictionary(sections) {
}
prevSections.push(section.reference);
/* Remember where we put current section */
var length = cursor.push(section);
length = cursor.push(section);
index[section.reference] = cursor[length - 1];
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"gulp-plumber": "~1.0.0",
"gulp-sourcemaps": "~1.5.1",
"istanbul": "~0.3.8",
"jscs": "~1.10.0",
"jscs": "~1.11.3",
"karma": "~0.12.31",
"karma-coverage": "~0.2.7",
"karma-mocha": "~0.1.10",
Expand Down
Loading

0 comments on commit 5db742f

Please sign in to comment.