Skip to content
Snippets Groups Projects
Commit ade9ad43 authored by Eike Cochu's avatar Eike Cochu
Browse files

applied jshint and js prettify

parent fd5bc11d
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
* Vipra Application * Vipra Application
* Main application file * Main application file
******************************************************************************/ ******************************************************************************/
/* globals angular, console, NProgress */
(function() { (function() {
"use strict";
var app = angular.module('vipra.app', [ var app = angular.module('vipra.app', [
'ngResource', 'ngResource',
'ngSanitize', 'ngSanitize',
...@@ -23,7 +26,7 @@ ...@@ -23,7 +26,7 @@
$urlRouterProvider.otherwise('/'); $urlRouterProvider.otherwise('/');
// states // states
$stateProvider.state('index', { $stateProvider.state('index', {
url: '/', url: '/',
templateUrl: 'html/index.html', templateUrl: 'html/index.html',
...@@ -122,11 +125,11 @@ ...@@ -122,11 +125,11 @@
}]); }]);
app.config(['$httpProvider', function($httpProvider) { var loadingTimeout;
var loadingTimeout; app.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push(function ($q, $injector, $rootScope) { $httpProvider.interceptors.push(function($q, $injector, $rootScope) {
var requestIncrement = function(config) { var requestIncrement = function(config) {
$rootScope.loading.requests = ++$rootScope.loading.requests || 1; $rootScope.loading.requests = ++$rootScope.loading.requests || 1;
$rootScope.loading[config.method] = ++$rootScope.loading[config.method] || 1; $rootScope.loading[config.method] = ++$rootScope.loading[config.method] || 1;
...@@ -175,7 +178,7 @@ ...@@ -175,7 +178,7 @@
$rootScope.loading = {}; $rootScope.loading = {};
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { $rootScope.$on('$stateChangeStart', function(event, toState) {
console.log('changing state: ' + toState.name); console.log('changing state: ' + toState.name);
NProgress.start(); NProgress.start();
...@@ -187,4 +190,4 @@ ...@@ -187,4 +190,4 @@
}]); }]);
})(); })();
\ No newline at end of file
/* globals Vipra */
(function() { (function() {
"use strict";
window.Vipra = window.Vipra || {}; window.Vipra = window.Vipra || {};
Vipra.config = { Vipra.config = {
...@@ -10,4 +13,4 @@ ...@@ -10,4 +13,4 @@
pageSize: 100 pageSize: 100
}; };
})(); })();
\ No newline at end of file
This diff is collapsed.
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
* Vipra Application * Vipra Application
* Directives * Directives
******************************************************************************/ ******************************************************************************/
/* globals angular, $, console, Vipra */
(function() { (function() {
"use strict";
var app = angular.module('vipra.directives', [ var app = angular.module('vipra.directives', [
'ui.router' 'ui.router'
]); ]);
...@@ -17,7 +20,7 @@ ...@@ -17,7 +20,7 @@
replace: true, replace: true,
transclude: true, transclude: true,
template: '<a class="topic-link" ui-sref="topics.show({id:topic.id})"><span ng-bind="topic.name"></span><ng-transclude/></a>' template: '<a class="topic-link" ui-sref="topics.show({id:topic.id})"><span ng-bind="topic.name"></span><ng-transclude/></a>'
} };
}); });
app.directive('articleLink', function() { app.directive('articleLink', function() {
...@@ -29,7 +32,7 @@ ...@@ -29,7 +32,7 @@
replace: true, replace: true,
transclude: true, transclude: true,
template: '<a class="article-link" ui-sref="articles.show({id:article.id})"><span ng-bind="article.title"></span><ng-transclude/></a>' template: '<a class="article-link" ui-sref="articles.show({id:article.id})"><span ng-bind="article.title"></span><ng-transclude/></a>'
} };
}); });
app.directive('pagination', function() { app.directive('pagination', function() {
...@@ -54,7 +57,7 @@ ...@@ -54,7 +57,7 @@
}, },
link: function($scope, $element) { link: function($scope, $element) {
$scope.$watch('highcharts', function(newVal) { $scope.$watch('highcharts', function(newVal) {
if(!newVal) return; if (!newVal) return;
$element.highcharts($scope.highcharts); $element.highcharts($scope.highcharts);
}); });
...@@ -72,12 +75,12 @@ ...@@ -72,12 +75,12 @@
template: '<a class="hide-link" href="#" ng-bind="text" ng-click="change($event)"></a>', template: '<a class="hide-link" href="#" ng-bind="text" ng-click="change($event)"></a>',
link: function($scope) { link: function($scope) {
var target = $($scope.target); var target = $($scope.target);
if(!target.length) return; if (!target.length) return;
var store = $scope.store !== 'false'; var store = $scope.store !== 'false';
var name = 'hidelink-' + $scope.target; var name = 'hidelink-' + $scope.target;
if(store) { if (store) {
var visible = Store(name); var visible = Store(name);
if(visible !== null && typeof visible !== 'undefined') if (visible !== null && typeof visible !== 'undefined')
target.toggle(visible); target.toggle(visible);
} }
...@@ -90,7 +93,7 @@ ...@@ -90,7 +93,7 @@
var visible = !target.is(':visible'); var visible = !target.is(':visible');
setText(visible); setText(visible);
target.slideToggle(); target.slideToggle();
if(store) if (store)
Store(name, visible); Store(name, visible);
}; };
...@@ -106,7 +109,7 @@ ...@@ -106,7 +109,7 @@
$($attrs.target).slideToggle(); $($attrs.target).slideToggle();
}); });
} }
} };
}); });
app.directive('ngModelStore', ['Store', function(Store) { app.directive('ngModelStore', ['Store', function(Store) {
...@@ -114,15 +117,15 @@ ...@@ -114,15 +117,15 @@
restrict: 'A', restrict: 'A',
require: 'ngModel', require: 'ngModel',
link: function($scope, $elem, $attrs, $ctrl) { link: function($scope, $elem, $attrs, $ctrl) {
if(!$attrs.ngModelStore) { if (!$attrs.ngModelStore) {
console.log("no store key given"); console.log("no store key given");
return; return;
} }
var value = Store($attrs.ngModelStore); var value = Store($attrs.ngModelStore);
if(value != null) { if (value !== null) {
$ctrl.$setViewValue(value); $ctrl.$setViewValue(value);
$ctrl.$render(); $ctrl.$render();
} else if($attrs.ngModelDefault) { } else if ($attrs.ngModelDefault) {
$ctrl.$setViewValue($scope.$eval($attrs.ngModelDefault)); $ctrl.$setViewValue($scope.$eval($attrs.ngModelDefault));
$ctrl.$render(); $ctrl.$render();
} }
...@@ -145,7 +148,7 @@ ...@@ -145,7 +148,7 @@
link: function($scope) { link: function($scope) {
$scope.dropdownId = Vipra.randomId(); $scope.dropdownId = Vipra.randomId();
$scope.align = 'dropdown-menu-left'; $scope.align = 'dropdown-menu-left';
if($scope.align === 'right') if ($scope.align === 'right')
$scope.align = 'dropdown-menu-right'; $scope.align = 'dropdown-menu-right';
} }
}; };
...@@ -161,7 +164,7 @@ ...@@ -161,7 +164,7 @@
replace: true, replace: true,
templateUrl: 'html/directives/alert.html', templateUrl: 'html/directives/alert.html',
link: function($scope) { link: function($scope) {
if(!$scope.type) { if (!$scope.type) {
console.log('no alert type given'); console.log('no alert type given');
return; return;
} }
...@@ -169,7 +172,7 @@ ...@@ -169,7 +172,7 @@
$scope.dismissible = $scope.dismissible !== 'false'; $scope.dismissible = $scope.dismissible !== 'false';
var classes = 'alert alert-' + $scope.type; var classes = 'alert alert-' + $scope.type;
if($scope.dismissible) if ($scope.dismissible)
classes += ' alert-dismissible'; classes += ' alert-dismissible';
$scope.classes = classes; $scope.classes = classes;
} }
...@@ -182,10 +185,7 @@ ...@@ -182,10 +185,7 @@
ngModel: '=' ngModel: '='
}, },
restrict: 'E', restrict: 'E',
templateUrl: 'html/directives/checkbox.html', templateUrl: 'html/directives/checkbox.html'
link: function($scope) {
}
}; };
}); });
...@@ -201,12 +201,12 @@ ...@@ -201,12 +201,12 @@
transclude: true, transclude: true,
template: '<span ng-click="click()"><ng-transclude/><span ng-show="sortType == sortBy" class="caret" ng-class="{\'caret-up\':sortReverse}"></span></span>', template: '<span ng-click="click()"><ng-transclude/><span ng-show="sortType == sortBy" class="caret" ng-class="{\'caret-up\':sortReverse}"></span></span>',
link: function($scope, $elem, $attrs) { link: function($scope, $elem, $attrs) {
if(!$attrs.sortBy) { if (!$attrs.sortBy) {
console.log('no sort by key given'); console.log('no sort by key given');
return; return;
} }
var value = Store($scope.storeKey); var value = Store($scope.storeKey);
if(value) { if (value) {
value = value.split(','); value = value.split(',');
$scope.sortType = value[0]; $scope.sortType = value[0];
$scope.sortReverse = value[1] === 'true'; $scope.sortReverse = value[1] === 'true';
...@@ -227,17 +227,16 @@ ...@@ -227,17 +227,16 @@
ngModel: '=', ngModel: '=',
values: '=' values: '='
}, },
require: 'ngModel',
template: '<span ng-bind-html="label" ng-click="next()"></span>', template: '<span ng-bind-html="label" ng-click="next()"></span>',
link: function($scope, $elem, $attrs, $ctrl) { link: function($scope) {
var hasObjects = false; var hasObjects = false;
if($scope.values && $scope.values.length) if ($scope.values && $scope.values.length)
hasObjects = angular.isObject($scope.values[0]); hasObjects = angular.isObject($scope.values[0]);
var index = function() { var index = function() {
if(hasObjects) { if (hasObjects) {
for(var i = 0; i < $scope.values.length; i++) { for (var i = 0; i < $scope.values.length; i++) {
if($scope.values[i].value == $scope.ngModel) if ($scope.values[i].value == $scope.ngModel)
return i; return i;
} }
return 0; return 0;
...@@ -247,8 +246,8 @@ ...@@ -247,8 +246,8 @@
}; };
var select = function(i) { var select = function(i) {
if(i < 0 || i >= $scope.values.length) return; if (i < 0 || i >= $scope.values.length) return;
if(hasObjects) { if (hasObjects) {
$scope.ngModel = $scope.values[i].value; $scope.ngModel = $scope.values[i].value;
$scope.label = $scope.values[i].label; $scope.label = $scope.values[i].label;
} else { } else {
...@@ -257,7 +256,7 @@ ...@@ -257,7 +256,7 @@
}; };
$scope.next = function() { $scope.next = function() {
select((index() + 1) % $scope.values.length) select((index() + 1) % $scope.values.length);
}; };
$scope.$watch('ngModel', function() { $scope.$watch('ngModel', function() {
...@@ -267,4 +266,4 @@ ...@@ -267,4 +266,4 @@
}; };
}); });
})(); })();
\ No newline at end of file
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
* Vipra Application * Vipra Application
* Factories * Factories
******************************************************************************/ ******************************************************************************/
/* globals angular, Vipra */
(function() { (function() {
"use strict";
var app = angular.module('vipra.factories', []); var app = angular.module('vipra.factories', []);
app.factory('ArticleFactory', ['$resource', function($resource) { app.factory('ArticleFactory', ['$resource', function($resource) {
...@@ -36,11 +39,11 @@ ...@@ -36,11 +39,11 @@
return function(key, value) { return function(key, value) {
key += '-' + $state.current.name; key += '-' + $state.current.name;
var lsSupport = false; var lsSupport = false;
// Check for native support // Check for native support
if (localStorage) if (localStorage)
lsSupport = true; lsSupport = true;
// If value is detected, set new or modify store // If value is detected, set new or modify store
if (typeof value !== "undefined" && value !== null) { if (typeof value !== "undefined" && value !== null) {
// Convert object values to JSON // Convert object values to JSON
...@@ -52,23 +55,24 @@ ...@@ -52,23 +55,24 @@
else else
createCookie(key, value, 30); createCookie(key, value, 30);
} }
// No value supplied, return value // No value supplied, return value
if (typeof value === "undefined") { if (typeof value === "undefined") {
var data;
if (lsSupport) if (lsSupport)
data = localStorage.getItem(key); data = localStorage.getItem(key);
else else
data = readCookie(key); data = readCookie(key);
try { try {
data = JSON.parse(data); data = JSON.parse(data);
} catch(e) { } catch (e) {
data = data; data = data;
} }
return data; return data;
} }
// Null specified, remove store // Null specified, remove store
if (value === null) { if (value === null) {
if (lsSupport) if (lsSupport)
...@@ -76,7 +80,7 @@ ...@@ -76,7 +80,7 @@
else else
createCookie(key, '', -1); createCookie(key, '', -1);
} }
// Creates new cookie or removes cookie with negative expiration // Creates new cookie or removes cookie with negative expiration
function createCookie(key, value, exp) { function createCookie(key, value, exp) {
var date = new Date(); var date = new Date();
...@@ -84,7 +88,7 @@ ...@@ -84,7 +88,7 @@
var expires = "; expires=" + date.toGMTString(); var expires = "; expires=" + date.toGMTString();
document.cookie = key + "=" + value + expires + "; path=/"; document.cookie = key + "=" + value + expires + "; path=/";
} }
// Returns contents of cookie // Returns contents of cookie
function readCookie(key) { function readCookie(key) {
var nameEQ = key + "="; var nameEQ = key + "=";
...@@ -101,11 +105,11 @@ ...@@ -101,11 +105,11 @@
app.service('WebSocketService', ['$websocket', '$state', function($websocket, $state) { app.service('WebSocketService', ['$websocket', '$state', function($websocket, $state) {
var socket = $websocket(Vipra.config.websocketUrl), var socket = $websocket(Vipra.config.websocketUrl),
callback = null; callback = null;
socket.onMessage(function(message) { socket.onMessage(function(message) {
var data = JSON.parse(message.data); var data = JSON.parse(message.data);
if(callback) if (callback)
callback(data); callback(data);
}); });
...@@ -117,7 +121,7 @@ ...@@ -117,7 +121,7 @@
callback = fn; callback = fn;
}; };
this.send(1, {state: $state.current.name}); this.send(1, { state: $state.current.name });
}]); }]);
})(); })();
\ No newline at end of file
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
* Vipra Application * Vipra Application
* Filters * Filters
******************************************************************************/ ******************************************************************************/
/* globals angular, Vipra */
(function() { (function() {
"use strict";
var app = angular.module('vipra.filters', []); var app = angular.module('vipra.filters', []);
app.filter('toPercent', function() { app.filter('toPercent', function() {
...@@ -18,4 +21,4 @@ ...@@ -18,4 +21,4 @@
return Vipra.formatDateTime; return Vipra.formatDateTime;
}); });
})(); })();
\ No newline at end of file
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
* Vipra Application * Vipra Application
* Helpers & Polyfills * Helpers & Polyfills
******************************************************************************/ ******************************************************************************/
/* globals Vipra */
(function() { (function() {
"use strict";
window.Vipra = window.Vipra || {}; window.Vipra = window.Vipra || {};
/** /**
...@@ -20,7 +23,7 @@ ...@@ -20,7 +23,7 @@
}; };
Vipra.toPercent = function(input) { Vipra.toPercent = function(input) {
if(typeof input !== 'number') if (typeof input !== 'number')
input = parseInt(input, 10); input = parseInt(input, 10);
return Math.round(input * 100); return Math.round(input * 100);
}; };
...@@ -35,39 +38,39 @@ ...@@ -35,39 +38,39 @@
Vipra.getErrors = function(errors) { Vipra.getErrors = function(errors) {
var html = []; var html = [];
if(errors && errors.length) { if (errors && errors.length) {
for(var i = 0; i < errors.length; i++) for (var i = 0; i < errors.length; i++)
html.push('<strong>' + errors[i].title + '</strong>: ' + errors[i].detail); html.push('<strong>' + errors[i].title + '</strong>: ' + errors[i].detail);
} }
return html.join('<br>'); return html.join('<br>');
} };
/** /**
* Polyfills * Polyfills
*/ */
if(typeof String.prototype.ellipsize === 'undefined') if (typeof String.prototype.ellipsize === 'undefined')
String.prototype.ellipsize = function(max) { String.prototype.ellipsize = function(max) {
max = max || 20; max = max || 20;
if(this.length > max) { if (this.length > max) {
return this.substring(0, max) + '...'; return this.substring(0, max) + '...';
} }
return this; return this;
}; };
if(typeof String.prototype.multiline === 'undefined') if (typeof String.prototype.multiline === 'undefined')
String.prototype.multiline = function(max) { String.prototype.multiline = function(max) {
return this.split(new RegExp("((?:\\w+ ){" + max + "})", "g")).filter(Boolean).join("\n"); return this.split(new RegExp("((?:\\w+ ){" + max + "})", "g")).filter(Boolean).join("\n");
}; };
if(typeof String.prototype.startsWith === 'undefined') if (typeof String.prototype.startsWith === 'undefined')
String.prototype.startsWith = function(start) { String.prototype.startsWith = function(start) {
return this.lastIndexOf(start, 0) === 0; return this.lastIndexOf(start, 0) === 0;
}; };
if(typeof window.console === 'undefined') if (typeof window.console === 'undefined')
window.console = { window.console = {
log: function () {} log: function() {}
}; };
})(); })();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment