removed the window.uhr global variable! hooray!

This commit is contained in:
Manuel Friedli 2014-07-03 20:33:26 +02:00
parent 5a9ec0e0df
commit 85b5670dfc
8 changed files with 43 additions and 46 deletions

View file

@ -12,6 +12,7 @@ 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/>.
*/
'use strict';
var h = {
"_es_ist": {1:[1,2,4,5,6]},
"_nach": {4:[8,9,10,11]},
@ -67,4 +68,4 @@ var layout = {
"11,23": {5:[6,7,8]}
}
};
window.uhr.register('de', layout);
$.fritteli.uhr.register('de', layout);

View file

@ -12,6 +12,7 @@ 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/>.
*/
'use strict';
// hilfsvariablen
var h = {
"_es_isch": {1:[1,2,4,5,6,7]},
@ -93,4 +94,4 @@ var layout = {
}
};
// Das Layout bei der Uhr unter dem Code "de_CH" registrieren.
window.uhr.register('de_CH', layout);
$.fritteli.uhr.register('de_CH', layout);

View file

@ -12,6 +12,7 @@ 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/>.
*/
'use strict';
var h = {
"_es_isch": {1:[1,2,4,5,6,7]},
"_genau": {3:[7,8,9,10,11]},
@ -68,4 +69,4 @@ var layout = {
"11,23": {9:[8,9,10,11]}
}
};
window.uhr.register('de_CH_genau', layout);
$.fritteli.uhr.register('de_CH_genau', layout);

View file

@ -12,6 +12,7 @@ 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/>.
*/
'use strict';
var h = {
"_it_is": {1:[1,2,4,5]},
"_half": {4:[1,2,3,4]},
@ -76,4 +77,4 @@ var layout = {
return hour;
}
};
window.uhr.register('en', layout);
$.fritteli.uhr.register('en', layout);

View file

@ -13,6 +13,7 @@ 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/>.
*/
'use strict';
var h = {
"_il_est": {1:[1,2,4,5,6]},
"_et": {8:[1,2]},
@ -78,4 +79,4 @@ var layout = {
return hour;
}
};
window.uhr.register('fr', layout);
$.fritteli.uhr.register('fr', layout);

View file

@ -12,6 +12,7 @@ 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/>.
*/
'use strict';
var h = {
"_sono_le": {1:[1,2,3,4,6,7]},
"_e_l": {2:[1,3,4]},
@ -75,4 +76,4 @@ var layout = {
return hour;
}
};
window.uhr.register('it', layout);
$.fritteli.uhr.register('it', layout);

View file

@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"languages": [],
"themes": [],
registerLanguage: function registerLanguage(code, language) {
var alreadyExists = this.languages.reduce(function (exists, element) {
var alreadyExists = uhrGlobals.languages.reduce(function (exists, element) {
if (exists) {
return true;
}
@ -31,20 +31,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}, false);
if (!alreadyExists) {
language.code = code;
this.languages.push(language);
uhrGlobals.languages.push(language);
}
}
};
if (window.uhr !== undefined) {
return;
}
window.uhr = {
id: 0,
languages: [],
themes: [],
register: uhrGlobals.registerLanguage
};
// auto-detect themes
var styleSheets = $('link[rel=stylesheet]');
for (var i = 0; i < styleSheets.length; i++) {
@ -55,12 +46,12 @@ 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});
uhrGlobals.themes.push({'styleClass': styleClass, 'name': name});
}
}
// fall-back if no theme was included
if (window.uhr.themes.length === 0) {
window.uhr.themes.push({});
if (uhrGlobals.themes.length === 0) {
uhrGlobals.themes.push({});
}
// public interface methods (exported later)
@ -126,7 +117,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// private interface methods
var create = function create() {
this._id = window.uhr.id++;
this._id = uhrGlobals.id++;
var userTime = this.options.time;
if (this.options.time === undefined) {
this.options.time = new Date();
@ -167,20 +158,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
e.after(toggleSwitch);
// language chooser
if (window.uhr.languages.length > 1) {
if (uhrGlobals.languages.length > 1) {
var languageChooser = $('<select id="uhr-languagechooser' + uhr._id + '"></select>');
for (var i = 0; i < window.uhr.languages.length; i++) {
var language = window.uhr.languages[i];
for (var i = 0; i < uhrGlobals.languages.length; i++) {
var language = uhrGlobals.languages[i];
languageChooser.append('<option value="' + language.code + '">' + language.language + '</option>');
}
e.after(languageChooser);
}
// theme chooser
if (window.uhr.themes.length > 1) {
if (uhrGlobals.themes.length > 1) {
var themeChooser = $('<select id="uhr-themechooser' + uhr._id + '"></select>');
for (var i = 0; i < window.uhr.themes.length; i++) {
var theme = window.uhr.themes[i];
for (var i = 0; i < uhrGlobals.themes.length; i++) {
var theme = uhrGlobals.themes[i];
themeChooser.append('<option value="' + theme.styleClass + '">' + theme.name + '</option>');
}
e.after(themeChooser);
@ -215,8 +206,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
selectedLanguage = uhr.options.language;
}
var found = false;
for (var i = 0; i < window.uhr.languages.length; i++) {
var code = window.uhr.languages[i].code;
for (var i = 0; i < uhrGlobals.languages.length; i++) {
var code = uhrGlobals.languages[i].code;
if (selectedLanguage === code) {
found = true;
break;
@ -224,8 +215,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
if (!found) {
var fallback;
if (window.uhr.languages.length > 0) {
fallback = window.uhr.languages[0].code;
if (uhrGlobals.languages.length > 0) {
fallback = uhrGlobals.languages[0].code;
} else {
fallback = '';
}
@ -246,15 +237,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
selectedTheme = uhr.options.theme;
}
found = false;
for (var i = 0; i < window.uhr.themes.length; i++) {
var styleClass = window.uhr.themes[i].styleClass;
for (var i = 0; i < uhrGlobals.themes.length; i++) {
var styleClass = uhrGlobals.themes[i].styleClass;
if (selectedTheme === styleClass) {
found = true;
break;
}
}
if (!found) {
var fallback = window.uhr.themes[0].styleClass;
var fallback = uhrGlobals.themes[0].styleClass;
console.warn("Theme " + selectedTheme + " not found! Using fallback: " + fallback);
selectedTheme = fallback;
}
@ -332,7 +323,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
};
var language = function language(uhr) {
var matchingLanguages = window.uhr.languages.filter(function (element) {
var matchingLanguages = uhrGlobals.languages.filter(function (element) {
return (element.code === this.options.language)
}, uhr);
if (matchingLanguages.length > 0) {
@ -340,14 +331,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
// fallback: return empty object
return {};
/* for (var i = 0; i < window.uhr.languages.length; i++) {
var language = window.uhr.languages[i];
if (language.code == uhr.options.language) {
return language;
}
}
// fallback: return empty object
return {};*/
};
$.widget("fritteli.uhr", {
@ -355,7 +338,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
width: '100%',
status: 'on',
language: 'de_CH',
theme: window.uhr.themes[0].styleClass,
theme: uhrGlobals.themes[0].styleClass,
force: false,
controls: true
},
@ -372,6 +355,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"_timer": null,
"_currentMinute": -1
});
$.fritteli.uhr.register = uhrGlobals.registerLanguage;
/**
* Hilfsklasse zum Rendern der Uhr.
* @param layout Layout-Objekt, das gerendert werden soll.

View file

@ -5,8 +5,12 @@
<title>Test</title>
<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="../css/uhr-pink.css" data-class="pink"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-white.css" data-class="white"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-red.css" data-class="red"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-yellow.css" data-class="yellow"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-green.css" data-class="green"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-blue.css" data-class="blue"/>
<link rel="stylesheet" type="text/css" href="../css/uhr-pink.css" data-class="pink"/>
<script src="../lib/jquery-2.1.0.min.js"></script>
<script src="../lib/jquery-ui-1.10.4.custom.min.js"></script>
<script src="../lib/jquery-cookie-1.4.0.js"></script>
@ -14,6 +18,9 @@
<script src="../js/uhr-de_CH.js"></script>
<script src="../js/uhr-de_CH_genau.js"></script>
<script src="../js/uhr-de.js"></script>
<script src="../js/uhr-en.js"></script>
<script src="../js/uhr-fr.js"></script>
<script src="../js/uhr-it.js"></script>
</head>
<body>
<div id="u1"></div>
@ -21,7 +28,7 @@
<div id="u3"></div>
<script type="text/javascript">
$(document).ready(function () {
$('div').uhr({'width':'200px','controls':false});
$('div').uhr({'width':'200px','controls':true});
});
</script>
</body>