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-title" content="Bärneruhr" />
<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="uhr-black.css" data-class="black" data-name="Schwarz" />
<link rel="shortcut icon" type="image/png" href="favicon.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="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="uhr.js"></script>
<link rel="stylesheet" type="text/css" href="css/uhr.css" />
<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="resources/favicon.png" />
<link rel="apple-touch-icon-precomposed" href="resources/apple-touch-icon-precomposed.png" />
<script type="text/javascript" src="lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="lib/jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="js/uhr.js"></script>
</head>
<body style="padding:0;margin:0;">
<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>
<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">
(function($) {
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>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<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="../uhr-black.css" data-class="black" />
<link rel="stylesheet" type="text/css" href="../css/uhr.css" />
<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="shortcut icon" type="image/png" href="../favicon.png" />
<script type="text/javascript" src="../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="../jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="../uhr.js"></script>
<script type="text/javascript" src="../uhr-de_CH.js"></script>
<link rel="shortcut icon" type="image/png" href="../resources/favicon.png" />
<script type="text/javascript" src="../lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="../lib/jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="../js/uhr.js"></script>
<script type="text/javascript" src="../js/uhr-de_CH.js"></script>
</head>
<body>
<h1 id="main-title">Die Zeit im Wort</h1>

View File

@ -67,4 +67,4 @@ var layout = {
"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.
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]}
}
};
window,_uhr.register('de_CH_genau', layout);
window,uhr.register('de_CH_genau', layout);

View File

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

View File

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

View File

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

View File

@ -12,20 +12,20 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
(function($) {
(function ($) {
'use strict';
if (window._uhr !== undefined) {
if (window.uhr !== undefined) {
return;
}
window._uhr = {
window.uhr = {
id: 0,
languages: [],
themes: [],
register: function(code, language) {
register: function (code, language) {
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 + '"!');
return false;
}
@ -44,23 +44,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
if (name === undefined) {
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
if (window._uhr.themes.length == 0) {
window._uhr.themes.push({});
if (window.uhr.themes.length === 0) {
window.uhr.themes.push({});
}
$.widget("fritteli.uhr", {
options: {
width: '100%',
status: 'on',
language: 'de_CH',
theme: window._uhr.themes[0].styleClass,
theme: window.uhr.themes[0].styleClass,
force: false,
controls: true
},
start: function() {
start: function () {
if (!this._isOn()) {
var uhr = this;
this._timer = window.setInterval(function() {
@ -72,22 +72,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
} else {
}
},
stop: function() {
if(this._isOn()) {
stop: function () {
if (this._isOn()) {
window.clearInterval(this._timer);
this._timer = null;
this._update();
this._setCookie('uhr-status', 'off');
}
},
toggle: function() {
if(this._isOn()) {
toggle: function () {
if (this._isOn()) {
this.stop();
} else {
this.start();
}
},
language: function(languageKey) {
language: function (languageKey) {
if (languageKey !== this.options.language) {
this.options.language = languageKey;
var renderer = new UhrRenderer(this._language(), this.element.find('.letterarea'));
@ -100,20 +100,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this._update();
}
},
theme: function(theme) {
if (theme != this.options.theme) {
theme: function (theme) {
if (theme !== this.options.theme) {
this.element.removeClass(this.options.theme).addClass(theme);
$('#uhr-onoffswitch' + this._id).removeClass(this.options.theme).addClass(theme);
this.options.theme = theme;
this._setCookie('uhr-theme', theme);
}
},
time: function(time) {
time: function (time) {
this._currentMinute = -1;
if (time == null) {
if (time === null) {
this.options.time = new Date();
} else {
if (this._timer != null) {
if (this._timer !== null) {
window.clearInterval(this._timer);
}
this.options.time = time;
@ -125,13 +125,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
_timer: null,
_currentMinute: -1,
// private methods
_isOn: function() {
_isOn: function () {
return this._timer !== null;
},
_update: function() {
_update: function () {
if (this._isOn()) {
var time = this.options.time;
if (time.getMinutes() == this._currentMinute) {
if (time.getMinutes() === this._currentMinute) {
return;
}
this._currentMinute = time.getMinutes();
@ -141,7 +141,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this._currentMinute = -1;
}
},
_show: function(time) {
_show: function (time) {
var dotMinute = this._getDotMinute(time);
var hour = this._getHour(time);
var coarseMinute = this._getCoarseMinute(time);
@ -153,9 +153,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this._highlight('minute' + coarseMinute);
this._highlight('hour' + hour);
},
_language: function() {
for (var i = 0; i < window._uhr.languages.length; i++) {
var language = window._uhr.languages[i];
_language: function () {
for (var i = 0; i < window.uhr.languages.length; i++) {
var language = window.uhr.languages[i];
if (language.code == this.options.language) {
return language;
}
@ -163,13 +163,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// fallback: return empty object
return {};
},
_highlight: function(itemClass) {
_highlight: function (itemClass) {
this.element.find('.item.' + itemClass).addClass('active');
},
_clear: function() {
_clear: function () {
this.element.find('.item').removeClass('active');
},
_getHour: function(date) {
_getHour: function (date) {
if (typeof this._language().getHour === 'function') {
return this._language().getHour(date);
}
@ -179,21 +179,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
return hour;
},
_getCoarseMinute: function(date) {
_getCoarseMinute: function (date) {
if (typeof this._language().getCoarseMinute === 'function') {
return this._language().getCoarseMinute(date);
}
return date.getMinutes();
},
_getDotMinute: function(date) {
_getDotMinute: function (date) {
if (typeof this._language().getDotMinute === 'function') {
return this._language().getDotMinute(date);
}
var minutes = date.getMinutes();
return minutes % 5;
},
_create: function() {
this._id = window._uhr.id++;
_create: function () {
this._id = window.uhr.id++;
var userTime = this.options.time;
if (this.options.time === undefined) {
this.options.time = new Date();
@ -204,7 +204,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this.time(userTime);
}
},
_setupHTML: function() {
_setupHTML: function () {
var e = this.element;
// Base clock area
e.addClass('uhr');
@ -232,40 +232,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
e.after(toggleSwitch);
// language chooser
if (window._uhr.languages.length > 1) {
if (window.uhr.languages.length > 1) {
var languageChooser = $('<select id="uhr-languagechooser' + this._id + '"></select>');
for (var i = 0; i < window._uhr.languages.length; i++) {
var language = window._uhr.languages[i];
for (var i = 0; i < window.uhr.languages.length; i++) {
var language = window.uhr.languages[i];
languageChooser.append('<option value="' + language.code + '">' + language.language + '</option>');
}
e.after(languageChooser);
}
// theme chooser
if (window._uhr.themes.length > 1) {
if (window.uhr.themes.length > 1) {
var themeChooser = $('<select id="uhr-themechooser' + this._id + '"></select>');
for (var i = 0; i < window._uhr.themes.length; i++) {
var theme = window._uhr.themes[i];
for (var i = 0; i < window.uhr.themes.length; i++) {
var theme = window.uhr.themes[i];
themeChooser.append('<option value="' + theme.styleClass + '">' + theme.name + '</option>');
}
e.after(themeChooser);
}
}
},
_wireFunctionality: function() {
_wireFunctionality: function () {
var uhr = this;
// on/off switch
var toggleSwitch = $('#uhr-onoffswitch-checkbox' + this._id);
toggleSwitch.on('click', function() {
toggleSwitch.on('click', function () {
uhr.toggle();
});
var status = $.cookie('uhr-status' + this._id);
if (status == undefined || this.options.force) {
if (status === undefined || this.options.force) {
status = this.options.status;
}
toggleSwitch.prop('checked', status == 'on');
if (status == 'on') {
toggleSwitch.prop('checked', status === 'on');
if (status === 'on') {
this.start();
} else {
this.stop();
@ -273,25 +273,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// language chooser
var languageChooser = $('#uhr-languagechooser' + this._id);
languageChooser.on('change', function() {
languageChooser.on('change', function () {
uhr.language(this.value);
});
var selectedLanguage = $.cookie('uhr-language' + this._id);
if (selectedLanguage == undefined || this.options.force) {
if (selectedLanguage === undefined || this.options.force) {
selectedLanguage = this.options.language;
}
var found = false;
for (var i = 0; i < window._uhr.languages.length; i++) {
var code = window._uhr.languages[i].code;
if (selectedLanguage == code) {
for (var i = 0; i < window.uhr.languages.length; i++) {
var code = window.uhr.languages[i].code;
if (selectedLanguage === code) {
found = true;
break;
}
}
if (!found) {
var fallback;
if (window._uhr.languages.length > 0) {
fallback = window._uhr.languages[0].code;
if (window.uhr.languages.length > 0) {
fallback = window.uhr.languages[0].code;
} else {
fallback = '';
}
@ -304,23 +304,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// theme chooser
var themeChooser = $('#uhr-themechooser' + this._id);
themeChooser.on('change', function() {
themeChooser.on('change', function () {
uhr.theme(this.value);
});
var selectedTheme = $.cookie('uhr-theme' + this._id);
if (selectedTheme == undefined || this.options.force) {
if (selectedTheme === undefined || this.options.force) {
selectedTheme = this.options.theme;
}
found = false;
for (var i = 0; i < window._uhr.themes.length; i++) {
var styleClass = window._uhr.themes[i].styleClass;
if (selectedTheme == styleClass) {
for (var i = 0; i < window.uhr.themes.length; i++) {
var styleClass = window.uhr.themes[i].styleClass;
if (selectedTheme === styleClass) {
found = true;
break;
}
}
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);
selectedTheme = fallback;
}
@ -328,7 +328,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this.options.theme = "";
this.theme(selectedTheme);
},
_setCookie: function(cookieName, cookieValue) {
_setCookie: function (cookieName, cookieValue) {
var options = {};
if (this.options.cookiePath !== undefined) {
options = {expires: 365, path: this.options.cookiePath};
@ -347,7 +347,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
this.layout = layout;
this.renderarea = renderarea;
}
UhrRenderer.prototype.render = function(uhr, beforeshow) {
UhrRenderer.prototype.render = function (uhr, beforeshow) {
var renderer = this;
if (this.layout._parsed === undefined) {
switch (this.layout.version) {
@ -361,7 +361,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
}
var letters = this.layout._parsed;
this.renderarea.fadeOut('fast', function() {
this.renderarea.fadeOut('fast', function () {
renderer.renderarea.empty();
for (var y = 0; y < letters.length; y++) {
for (var x = 0; x < letters[y].length; x++) {
@ -380,7 +380,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
};
function _UhrRendererV2Delegate(layout) {
this.layout = layout;
this._parseArrayOrObject = function(letters, styleClass, input) {
this._parseArrayOrObject = function (letters, styleClass, input) {
if (Array.isArray(input)) {
for (var i = 0; i < input.length; i++) {
this._parseObject(letters, styleClass, input[i]);

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-title" content="Bärneruhr" />
<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="../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="../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="../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="../uhr-pink.css" data-class="pink" data-name="Pink" />
<link rel="stylesheet" type="text/css" href="../css/uhr.css" />
<link rel="stylesheet" type="text/css" href="../css/uhr-black.css" data-class="black" data-name="Schwarz" />
<link rel="stylesheet" type="text/css" href="../css/uhr-white.css" data-class="white" data-name="Weiss" />
<link rel="stylesheet" type="text/css" href="../css/uhr-red.css" data-class="red" data-name="Rot" />
<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="../css/uhr-yellow.css" data-class="yellow" data-name="Gelb" />
<link rel="stylesheet" type="text/css" href="../css/uhr-blue.css" data-class="blue" data-name="Blau" />
<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="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="../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="../uhr.js"></script>
<script type="text/javascript" src="../lib/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="../lib/jquery-cookie-1.4.0.js"></script>
<script type="text/javascript" src="../js/uhr.js"></script>
</head>
<body style="padding:0;margin:0;">
<div id="uhr"></div>
<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="../uhr-de_CH_genau.js"></script>
<script type="text/javascript" src="../uhr-de.js"></script>
<script type="text/javascript" src="../uhr-en.js"></script>
<script type="text/javascript" src="../uhr-fr.js"></script>
<script type="text/javascript" src="../uhr-it.js"></script>
<script type="text/javascript" src="../js/uhr-de_CH.js"></script>
<script type="text/javascript" src="../js/uhr-de_CH_genau.js"></script>
<script type="text/javascript" src="../js/uhr-de.js"></script>
<script type="text/javascript" src="../js/uhr-en.js"></script>
<script type="text/javascript" src="../js/uhr-fr.js"></script>
<script type="text/javascript" src="../js/uhr-it.js"></script>
<script type="text/javascript">
(function($) {
var width = $(window).width();