mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Removed dependency of ss.i18n.js on other libraries by replacing $$ with document.getElementsByTagName() and implementing a custom event attacher - see #2927
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@64010 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
617711c7e6
commit
54fa45c2fc
@ -15,7 +15,6 @@ if(typeof(ss) == 'undefined') ss = {};
|
||||
* Based on 'javascript i18n that almost doesn't suck' by markos
|
||||
* http://markos.gaivo.net/blog/?p=100
|
||||
*/
|
||||
ss.i18n = Class.create();
|
||||
ss.i18n = {
|
||||
|
||||
currentLocale: null,
|
||||
@ -149,11 +148,13 @@ ss.i18n = {
|
||||
var detectedLocale;
|
||||
|
||||
// get by meta
|
||||
$$('meta').each(function(el) {
|
||||
if(el.attributes['http-equiv'] && el.attributes['http-equiv'].nodeValue.toLowerCase() == 'content-language') {
|
||||
rawLocale = el.attributes['content'].nodeValue;
|
||||
var metas = document.getElementsByTagName('meta');
|
||||
for(var i=0; i<metas.length; i++) {
|
||||
if(metas[i].attributes['http-equiv'] && metas[i].attributes['http-equiv'].nodeValue.toLowerCase() == 'content-language') {
|
||||
rawLocale = metas[i].attributes['content'].nodeValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// fallback to default locale
|
||||
if(!rawLocale) rawLocale = this.defaultLocale;
|
||||
|
||||
@ -172,9 +173,28 @@ ss.i18n = {
|
||||
}
|
||||
|
||||
return detectedLocale;
|
||||
},
|
||||
|
||||
/**
|
||||
* Attach an event listener to the given object.
|
||||
* Modeled after behaviour.js, but externalized
|
||||
* to keep the i18n library standalone for now.
|
||||
*/
|
||||
addEvent: function(obj, evType, fn, useCapture){
|
||||
if (obj.addEventListener){
|
||||
obj.addEventListener(evType, fn, useCapture);
|
||||
return true;
|
||||
} else if (obj.attachEvent){
|
||||
var r = obj.attachEvent("on"+evType, fn);
|
||||
return r;
|
||||
} else {
|
||||
alert("Handler could not be attached");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Event.observe(window, "load", function() {
|
||||
|
||||
|
||||
ss.i18n.addEvent(window, "load", function() {
|
||||
ss.i18n.init();
|
||||
});
|
Loading…
Reference in New Issue
Block a user