some JSHint'ing and reorganizing of the project-structure

This commit is contained in:
Manuel Friedli 2014-07-03 16:53:07 +02:00
parent 340669c5eb
commit afe923c136
25 changed files with 182 additions and 104 deletions

78
.jshintrc Normal file
View file

@ -0,0 +1,78 @@
{
// Settings
"passfail" : false, // Stop on first error.
"maxerr" : 100, // Maximum error before stopping.
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"node" : false,
"rhino" : false,
"couch" : false,
"wsh" : true, // Windows Scripting Host.
"jquery" : true,
"ender" : true,
"prototypejs" : false,
"mootools" : false,
"dojo" : false,
"predef" : [
// "define",
// "suite",
// "test",
// "teardown",
// "setup",
// "sinon",
// "mocha",
// "requirejs"
],
// Development.
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"devel" : true, // Allow developments statements e.g. `console.log();`.
// ECMAScript 5.
"es5" : true, // Allow ECMAScript 5 syntax.
"strict" : true, // Require `use strict` pragma in every file.
"globalstrict" : true, // Allow global "use strict" (also enables 'strict').
// The Good Parts.
"asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"eqnull" : false, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohipit variable use before definition.
"loopfunc" : false, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : true, // Tolerate script-targeted URLs.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"undef" : true, // Require all non-global variables be declared before they are used.
// Personal styling preferences.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"nomen" : true, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true, // Prohibit trailing whitespaces.
"white" : true, // Check against strict whitespace and indentation rules.
"indent" : 0 // Specify indentation spacing
}

View file

@ -21,19 +21,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-title" content="Bärneruhr" /> <meta name="apple-mobile-web-app-title" content="Bärneruhr" />
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1" /> <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1" />
<link rel="stylesheet" type="text/css" href="uhr.css" /> <link rel="stylesheet" type="text/css" href="css/uhr.css" />
<link rel="stylesheet" type="text/css" href="uhr-black.css" data-class="black" data-name="Schwarz" /> <link rel="stylesheet" type="text/css" href="css/uhr-black.css" data-class="black" data-name="Schwarz" />
<link rel="shortcut icon" type="image/png" href="favicon.png" /> <link rel="shortcut icon" type="image/png" href="resources/favicon.png" />
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png" /> <link rel="apple-touch-icon-precomposed" href="resources/apple-touch-icon-precomposed.png" />
<script type="text/javascript" src="jquery-2.1.0.min.js"></script> <script type="text/javascript" src="lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.10.4.custom.min.js"></script> <script type="text/javascript" src="lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="jquery-cookie-1.4.0.js"></script> <script type="text/javascript" src="lib/jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="uhr.js"></script> <script type="text/javascript" src="js/uhr.js"></script>
</head> </head>
<body style="padding:0;margin:0;"> <body style="padding:0;margin:0;">
<div id="uhr"></div> <div id="uhr"></div>
<p id="disclaimer">Created by <a href="http://www.fritteli.ch/">fritteli</a>, inspired by <a href="http://www.qlocktwo.com/">QLOCKTWO</a>. <a href="info/">Read more!</a> - <a href="showcase">View full showcase!</a></p> <p id="disclaimer">Created by <a href="http://www.fritteli.ch/">fritteli</a>, inspired by <a href="http://www.qlocktwo.com/">QLOCKTWO</a>. <a href="info/">Read more!</a> - <a href="showcase">View full showcase!</a></p>
<script type="text/javascript" src="uhr-de_CH.js"></script> <script type="text/javascript" src="js/uhr-de_CH.js"></script>
<script type="text/javascript"> <script type="text/javascript">
(function($) { (function($) {
var width = $(window).width(); var width = $(window).width();

View file

@ -18,15 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<title>Die Zeit im Wort - Informationen</title> <title>Die Zeit im Wort - Informationen</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width,user-scalable=yes,initial-scale=1" /> <meta name="viewport" content="width=device-width,user-scalable=yes,initial-scale=1" />
<link rel="stylesheet" type="text/css" href="../uhr.css" /> <link rel="stylesheet" type="text/css" href="../css/uhr.css" />
<link rel="stylesheet" type="text/css" href="../uhr-black.css" data-class="black" /> <link rel="stylesheet" type="text/css" href="../css/uhr-black.css" data-class="black" />
<link rel="stylesheet" type="text/css" href="info.css" /> <link rel="stylesheet" type="text/css" href="info.css" />
<link rel="shortcut icon" type="image/png" href="../favicon.png" /> <link rel="shortcut icon" type="image/png" href="../resources/favicon.png" />
<script type="text/javascript" src="../jquery-2.1.0.min.js"></script> <script type="text/javascript" src="../lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../jquery-ui-1.10.4.custom.min.js"></script> <script type="text/javascript" src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="../jquery-cookie-1.4.0.js"></script> <script type="text/javascript" src="../lib/jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="../uhr.js"></script> <script type="text/javascript" src="../js/uhr.js"></script>
<script type="text/javascript" src="../uhr-de_CH.js"></script> <script type="text/javascript" src="../js/uhr-de_CH.js"></script>
</head> </head>
<body> <body>
<h1 id="main-title">Die Zeit im Wort</h1> <h1 id="main-title">Die Zeit im Wort</h1>

View file

@ -67,4 +67,4 @@ var layout = {
"11,23": {5:[6,7,8]} "11,23": {5:[6,7,8]}
} }
}; };
window,_uhr.register('de', layout); window,uhr.register('de', layout);

View file

@ -93,4 +93,4 @@ var layout = {
} }
}; };
// Das Layout bei der Uhr unter dem Code "de_CH" registrieren. // Das Layout bei der Uhr unter dem Code "de_CH" registrieren.
window,_uhr.register('de_CH', layout); window,uhr.register('de_CH', layout);

View file

@ -68,4 +68,4 @@ var layout = {
"11,23": {9:[8,9,10,11]} "11,23": {9:[8,9,10,11]}
} }
}; };
window,_uhr.register('de_CH_genau', layout); window,uhr.register('de_CH_genau', layout);

View file

@ -76,4 +76,4 @@ var layout = {
return hour; return hour;
} }
}; };
window,_uhr.register('en', layout); window,uhr.register('en', layout);

View file

@ -78,4 +78,4 @@ var layout = {
return hour; return hour;
} }
}; };
window,_uhr.register('fr', layout); window,uhr.register('fr', layout);

View file

@ -75,4 +75,4 @@ var layout = {
return hour; return hour;
} }
}; };
window,_uhr.register('it', layout); window,uhr.register('it', layout);

View file

@ -15,17 +15,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
(function ($) { (function ($) {
'use strict'; 'use strict';
if (window._uhr !== undefined) { if (window.uhr !== undefined) {
return; return;
} }
window._uhr = { window.uhr = {
id: 0, id: 0,
languages: [], languages: [],
themes: [], themes: [],
register: function (code, language) { register: function (code, language) {
for (var i = 0; i < this.languages.length; i++) { for (var i = 0; i < this.languages.length; i++) {
if (code == this.languages[i].code) { if (code === this.languages[i].code) {
console.error('Error: Language code ' + code + ' cannot be registered for language "' + language.language + '" because it is already registered for language "' + this.languages[i].language + '"!'); console.error('Error: Language code ' + code + ' cannot be registered for language "' + language.language + '" because it is already registered for language "' + this.languages[i].language + '"!');
return false; return false;
} }
@ -44,19 +44,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (name === undefined) { if (name === undefined) {
name = styleClass; name = styleClass;
} }
window._uhr.themes.push({'styleClass': styleClass, 'name': name}); window.uhr.themes.push({'styleClass': styleClass, 'name': name});
} }
} }
// fall-back if no theme was included // fall-back if no theme was included
if (window._uhr.themes.length == 0) { if (window.uhr.themes.length === 0) {
window._uhr.themes.push({}); window.uhr.themes.push({});
} }
$.widget("fritteli.uhr", { $.widget("fritteli.uhr", {
options: { options: {
width: '100%', width: '100%',
status: 'on', status: 'on',
language: 'de_CH', language: 'de_CH',
theme: window._uhr.themes[0].styleClass, theme: window.uhr.themes[0].styleClass,
force: false, force: false,
controls: true controls: true
}, },
@ -101,7 +101,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} }
}, },
theme: function (theme) { theme: function (theme) {
if (theme != this.options.theme) { if (theme !== this.options.theme) {
this.element.removeClass(this.options.theme).addClass(theme); this.element.removeClass(this.options.theme).addClass(theme);
$('#uhr-onoffswitch' + this._id).removeClass(this.options.theme).addClass(theme); $('#uhr-onoffswitch' + this._id).removeClass(this.options.theme).addClass(theme);
this.options.theme = theme; this.options.theme = theme;
@ -110,10 +110,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}, },
time: function (time) { time: function (time) {
this._currentMinute = -1; this._currentMinute = -1;
if (time == null) { if (time === null) {
this.options.time = new Date(); this.options.time = new Date();
} else { } else {
if (this._timer != null) { if (this._timer !== null) {
window.clearInterval(this._timer); window.clearInterval(this._timer);
} }
this.options.time = time; this.options.time = time;
@ -131,7 +131,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
_update: function () { _update: function () {
if (this._isOn()) { if (this._isOn()) {
var time = this.options.time; var time = this.options.time;
if (time.getMinutes() == this._currentMinute) { if (time.getMinutes() === this._currentMinute) {
return; return;
} }
this._currentMinute = time.getMinutes(); this._currentMinute = time.getMinutes();
@ -154,8 +154,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this._highlight('hour' + hour); this._highlight('hour' + hour);
}, },
_language: function () { _language: function () {
for (var i = 0; i < window._uhr.languages.length; i++) { for (var i = 0; i < window.uhr.languages.length; i++) {
var language = window._uhr.languages[i]; var language = window.uhr.languages[i];
if (language.code == this.options.language) { if (language.code == this.options.language) {
return language; return language;
} }
@ -193,7 +193,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
return minutes % 5; return minutes % 5;
}, },
_create: function () { _create: function () {
this._id = window._uhr.id++; this._id = window.uhr.id++;
var userTime = this.options.time; var userTime = this.options.time;
if (this.options.time === undefined) { if (this.options.time === undefined) {
this.options.time = new Date(); this.options.time = new Date();
@ -232,20 +232,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
e.after(toggleSwitch); e.after(toggleSwitch);
// language chooser // language chooser
if (window._uhr.languages.length > 1) { if (window.uhr.languages.length > 1) {
var languageChooser = $('<select id="uhr-languagechooser' + this._id + '"></select>'); var languageChooser = $('<select id="uhr-languagechooser' + this._id + '"></select>');
for (var i = 0; i < window._uhr.languages.length; i++) { for (var i = 0; i < window.uhr.languages.length; i++) {
var language = window._uhr.languages[i]; var language = window.uhr.languages[i];
languageChooser.append('<option value="' + language.code + '">' + language.language + '</option>'); languageChooser.append('<option value="' + language.code + '">' + language.language + '</option>');
} }
e.after(languageChooser); e.after(languageChooser);
} }
// theme chooser // theme chooser
if (window._uhr.themes.length > 1) { if (window.uhr.themes.length > 1) {
var themeChooser = $('<select id="uhr-themechooser' + this._id + '"></select>'); var themeChooser = $('<select id="uhr-themechooser' + this._id + '"></select>');
for (var i = 0; i < window._uhr.themes.length; i++) { for (var i = 0; i < window.uhr.themes.length; i++) {
var theme = window._uhr.themes[i]; var theme = window.uhr.themes[i];
themeChooser.append('<option value="' + theme.styleClass + '">' + theme.name + '</option>'); themeChooser.append('<option value="' + theme.styleClass + '">' + theme.name + '</option>');
} }
e.after(themeChooser); e.after(themeChooser);
@ -261,11 +261,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
uhr.toggle(); uhr.toggle();
}); });
var status = $.cookie('uhr-status' + this._id); var status = $.cookie('uhr-status' + this._id);
if (status == undefined || this.options.force) { if (status === undefined || this.options.force) {
status = this.options.status; status = this.options.status;
} }
toggleSwitch.prop('checked', status == 'on'); toggleSwitch.prop('checked', status === 'on');
if (status == 'on') { if (status === 'on') {
this.start(); this.start();
} else { } else {
this.stop(); this.stop();
@ -277,21 +277,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
uhr.language(this.value); uhr.language(this.value);
}); });
var selectedLanguage = $.cookie('uhr-language' + this._id); var selectedLanguage = $.cookie('uhr-language' + this._id);
if (selectedLanguage == undefined || this.options.force) { if (selectedLanguage === undefined || this.options.force) {
selectedLanguage = this.options.language; selectedLanguage = this.options.language;
} }
var found = false; var found = false;
for (var i = 0; i < window._uhr.languages.length; i++) { for (var i = 0; i < window.uhr.languages.length; i++) {
var code = window._uhr.languages[i].code; var code = window.uhr.languages[i].code;
if (selectedLanguage == code) { if (selectedLanguage === code) {
found = true; found = true;
break; break;
} }
} }
if (!found) { if (!found) {
var fallback; var fallback;
if (window._uhr.languages.length > 0) { if (window.uhr.languages.length > 0) {
fallback = window._uhr.languages[0].code; fallback = window.uhr.languages[0].code;
} else { } else {
fallback = ''; fallback = '';
} }
@ -308,19 +308,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
uhr.theme(this.value); uhr.theme(this.value);
}); });
var selectedTheme = $.cookie('uhr-theme' + this._id); var selectedTheme = $.cookie('uhr-theme' + this._id);
if (selectedTheme == undefined || this.options.force) { if (selectedTheme === undefined || this.options.force) {
selectedTheme = this.options.theme; selectedTheme = this.options.theme;
} }
found = false; found = false;
for (var i = 0; i < window._uhr.themes.length; i++) { for (var i = 0; i < window.uhr.themes.length; i++) {
var styleClass = window._uhr.themes[i].styleClass; var styleClass = window.uhr.themes[i].styleClass;
if (selectedTheme == styleClass) { if (selectedTheme === styleClass) {
found = true; found = true;
break; break;
} }
} }
if (!found) { if (!found) {
var fallback = window._uhr.themes[0].styleClass; var fallback = window.uhr.themes[0].styleClass;
console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback); console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback);
selectedTheme = fallback; selectedTheme = fallback;
} }

View file

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.3 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -21,30 +21,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-title" content="Bärneruhr" /> <meta name="apple-mobile-web-app-title" content="Bärneruhr" />
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1" /> <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1" />
<link rel="stylesheet" type="text/css" href="../uhr.css" /> <link rel="stylesheet" type="text/css" href="../css/uhr.css" />
<link rel="stylesheet" type="text/css" href="../uhr-black.css" data-class="black" data-name="Schwarz" /> <link rel="stylesheet" type="text/css" href="../css/uhr-black.css" data-class="black" data-name="Schwarz" />
<link rel="stylesheet" type="text/css" href="../uhr-white.css" data-class="white" data-name="Weiss" /> <link rel="stylesheet" type="text/css" href="../css/uhr-white.css" data-class="white" data-name="Weiss" />
<link rel="stylesheet" type="text/css" href="../uhr-red.css" data-class="red" data-name="Rot" /> <link rel="stylesheet" type="text/css" href="../css/uhr-red.css" data-class="red" data-name="Rot" />
<link rel="stylesheet" type="text/css" href="../uhr-green.css" data-class="green" data-name="Grün" /> <link rel="stylesheet" type="text/css" href="../css/uhr-green.css" data-class="green" data-name="Grün" />
<link rel="stylesheet" type="text/css" href="../uhr-yellow.css" data-class="yellow" data-name="Gelb" /> <link rel="stylesheet" type="text/css" href="../css/uhr-yellow.css" data-class="yellow" data-name="Gelb" />
<link rel="stylesheet" type="text/css" href="../uhr-blue.css" data-class="blue" data-name="Blau" /> <link rel="stylesheet" type="text/css" href="../css/uhr-blue.css" data-class="blue" data-name="Blau" />
<link rel="stylesheet" type="text/css" href="../uhr-pink.css" data-class="pink" data-name="Pink" /> <link rel="stylesheet" type="text/css" href="../css/uhr-pink.css" data-class="pink" data-name="Pink" />
<link rel="shortcut icon" type="image/png" href="favicon.png" /> <link rel="shortcut icon" type="image/png" href="favicon.png" />
<link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png" /> <link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png" />
<script type="text/javascript" src="../jquery-2.1.0.min.js"></script> <script type="text/javascript" src="../lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../jquery-ui-1.10.4.custom.min.js"></script> <script type="text/javascript" src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="../jquery-cookie-1.4.0.js"></script> <script type="text/javascript" src="../lib/jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="../uhr.js"></script> <script type="text/javascript" src="../js/uhr.js"></script>
</head> </head>
<body style="padding:0;margin:0;"> <body style="padding:0;margin:0;">
<div id="uhr"></div> <div id="uhr"></div>
<p ><a href="..">Go back to the main page</a></p> <p ><a href="..">Go back to the main page</a></p>
<script type="text/javascript" src="../uhr-de_CH.js"></script> <script type="text/javascript" src="../js/uhr-de_CH.js"></script>
<script type="text/javascript" src="../uhr-de_CH_genau.js"></script> <script type="text/javascript" src="../js/uhr-de_CH_genau.js"></script>
<script type="text/javascript" src="../uhr-de.js"></script> <script type="text/javascript" src="../js/uhr-de.js"></script>
<script type="text/javascript" src="../uhr-en.js"></script> <script type="text/javascript" src="../js/uhr-en.js"></script>
<script type="text/javascript" src="../uhr-fr.js"></script> <script type="text/javascript" src="../js/uhr-fr.js"></script>
<script type="text/javascript" src="../uhr-it.js"></script> <script type="text/javascript" src="../js/uhr-it.js"></script>
<script type="text/javascript"> <script type="text/javascript">
(function($) { (function($) {
var width = $(window).width(); var width = $(window).width();