Commit d070594f authored by Sven Franck's avatar Sven Franck

made translate gadget autonomous, removed translate interactions

parent 686356ed
......@@ -11,11 +11,6 @@
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
// interaction listener
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
};
// trigger enhancement
$(this).trigger("render_enhance", {gadget: gadget.dom});
});
......
......@@ -17,11 +17,6 @@
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
// interaction listener
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
};
// trigger enhancement
$(this).trigger("render_enhance", {gadget: gadget.dom});
});
......
......@@ -347,11 +347,6 @@
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
// interaction listener
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
};
// trigger enhancement
$(this).trigger("render_enhance", {gadget: gadget.dom});
......
......@@ -17,9 +17,7 @@
<div class="headWrapRight ui-btn-right">
<div id="translator" data-gadget="../gadgets/translate.html"></div>
</div>
<div data-gadget="" class="main-interactor" data-gadget-connection="[
{&quot;source&quot;: &quot;translator.translate&quot;, &quot;destination&quot;: &quot;index_wrapper.translate&quot;}
]">
<div data-gadget="" class="main-interactor" data-gadget-connection="[]">
</div>
</div>
......@@ -58,11 +56,6 @@
}
}
// interactions
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
};
$(document).ready(function() {
// trigger enhancement
$(this).trigger("render_enhance", {gadget: gadget.dom});
......
......@@ -11,21 +11,12 @@
<p class="mini t" data-i18n="gen.disclaimer"></p>
<!-- interactions -->
<div data-gadget="" class="main-interactor"
data-gadget-connection="[
{&quot;source&quot;: &quot;index_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;index_configure.translate&quot;}
, {&quot;source&quot;: &quot;index_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;index_social.translate&quot;}
, {&quot;source&quot;: &quot;index_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;index_analysis.translate&quot;}
, {&quot;source&quot;: &quot;index_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;index_nav.translate&quot;}
]">
data-gadget-connection="[]">
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
gadget.dom.trigger("route_translate");
};
});
//]]>
</script>
......
......@@ -28,11 +28,6 @@
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
// interaction listener
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
};
// trigger enhancement
$(this).trigger("render_enhance", {gadget: gadget.dom});
});
......
......@@ -16,22 +16,13 @@
<p class="mini t" data-i18n="gen.disclaimer"></p>
<!-- interactions -->
<div data-gadget="" class="main-interactor"
data-gadget-connection="[
{&quot;source&quot;: &quot;results_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;results_list.translate&quot;}
, {&quot;source&quot;: &quot;results_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;results_ad.translate&quot;}
, {&quot;source&quot;: &quot;results_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;results_social.translate&quot;}
, {&quot;source&quot;: &quot;results_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;results_analysis.translate&quot;}
, {&quot;source&quot;: &quot;results_wrapper.route_translate&quot;, &quot;destination&quot;: &quot;results_nav.translate&quot;}
]">
data-gadget-connection="[]">
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
gadget.dom.trigger("route_translate");
};
});
//]]>
</script>
......
......@@ -22,10 +22,7 @@
//<![CDATA[
$(document).ready(function() {
var gadget = RenderJs.getSelfGadget();
// interaction listener
gadget.translate = function(){
$.fn.util.lang(gadget.dom);
};
// trigger enhancement
$(this).trigger("render_enhance", {gadget: gadget.dom});
});
......
......@@ -63,64 +63,97 @@
<div data-role="popup" id="" class="all_popups">
<ul data-role="listview" data-inset="true" data-divider-theme="f">
<li data-role="list-divider" class="t" data-i18n="gen.language"></li>
<li data-icon="false"><a class="t change_language" href="?lang=FR-fr" data-i18n-target=".ui-li-text" data-i18n="[title]gen.language_info;[html]gen.lang.fr"><span class="ui-icon ui-fake-icon ui-li-icon ui-icon-lang ui-li-thumb FR">&nbsp;</span><span class="ui-li-text"></span></a></li>
<li data-icon="false"><a class="t change_language" href="?lang=DE-de" data-i18n-target=".ui-li-text" data-i18n="[title]gen.language_info;[html]gen.lang.de"><span class="ui-icon ui-fake-icon ui-li-icon ui-icon-lang ui-li-thumb DE">&nbsp;</span><span class="ui-li-text"></span></a></li>
<li data-icon="false"><a class="t change_language" href="?lang=EN-en" data-i18n-target=".ui-li-text" data-i18n="[title]gen.language_info;[html]gen.lang.en"><span class="ui-icon ui-fake-icon ui-li-icon ui-icon-lang ui-li-thumb EN">&nbsp;</span><span class="ui-li-text"></span></a></li>
<li data-icon="false"><a class="t change_language" href="?lang=fr-FR" data-i18n-target=".ui-li-text" data-i18n="[title]gen.language_info;[html]gen.lang.fr"><span class="ui-icon ui-fake-icon ui-li-icon ui-icon-lang ui-li-thumb FR">&nbsp;</span><span class="ui-li-text"></span></a></li>
<li data-icon="false"><a class="t change_language" href="?lang=de-DE" data-i18n-target=".ui-li-text" data-i18n="[title]gen.language_info;[html]gen.lang.de"><span class="ui-icon ui-fake-icon ui-li-icon ui-icon-lang ui-li-thumb DE">&nbsp;</span><span class="ui-li-text"></span></a></li>
<li data-icon="false"><a class="t change_language" href="?lang=en-EN" data-i18n-target=".ui-li-text" data-i18n="[title]gen.language_info;[html]gen.lang.en"><span class="ui-icon ui-fake-icon ui-li-icon ui-icon-lang ui-li-thumb EN">&nbsp;</span><span class="ui-li-text"></span></a></li>
</ul>
</div>
<script type="text/javascript" language="javascript">
//<![CDATA[
var gadget = RenderJs.getSelfGadget(),
i,
list = RenderJs.GadgetIndex.getGadgetList(),
current_gadget,
recursive_gadgets = gadget.dom.find("[data-gadget]").not(".main-interactor"),
len = recursive_gadgets.length,
lang = $.fn.fauna.i18n_current_lang,
switchIcon = function () {
// this should be the callback after create, which sets the icon
// however setting elem here cannot access the JQM enhanced elements
// although the functions is called after JQM is done enhancing...
// var elem = gadget.dom.find(".setIcon .ui-icon");
// if (elem.length > 0) {
// elem.removeClass()
// .addClass('ui-icon ui-shadow ui-icon-lang '+set_icon);
// }
switchIcon = function (id, icon) {
var current_gadget, elem, gadget_to_translate;
// not possible without, because JQM will not be done enhancing
window.setTimeout(function(){
current_gadget = RenderJs.GadgetIndex.getGadgetById(id),
elem = current_gadget.dom.find(".setIcon .ui-icon");
elem = $(".setIcon .ui-icon")
if (elem.length > 0) {
elem.removeClass()
.addClass('ui-icon ui-shadow ui-icon-lang '+icon);
}
},50);
},
// set interactions
// set language
set_lang = function (language) {
var set_icon, elem;
switch (language) {
case "de-DE":
set_icon = "DE";
break;
case "fr-FR":
set_icon = "FR";
break;
default:
set_icon = "EN";
break;
};
$.fn.fauna.i18n_current_lang = language;
var set_icon, elem, override = false, remote;
switch (language) {
case "de-DE":
set_icon = "DE";
break;
case "fr-FR":
set_icon = "FR";
break;
default:
set_icon = "EN";
break;
};
// modfiy elements, trigger translation
gadget.dom.trigger("translate");
// trigger create
if (gadget.isEnhanced() === false) {
//$(document).trigger("render_enhance", {"gadget": gadget.dom, "callback":switchIcon(gadget.id, set_icon)});
$(document).trigger("render_enhance", {"gadget": gadget.dom });
// no other way to translate popups, because the popup will be moved to the end of the DOM
remote = gadget.dom.find("a").attr('href');
$(remote+'-popup').find(".t").i18n()
}
if (gadget.isEnhanced() === false) {
$(document).trigger("render_enhance", {"gadget": gadget.dom, "callback":switchIcon()});
gadget.setEnhanced(true);
if ( $.fn.fauna.i18n_current_lang !== language ) {
override = true;
}
// translate all gadgets in the gadget list (dom available)
for (i = 0; i < list.length; i += 1) {
gadget_to_translate = list[i];
if (gadget_to_translate.isEnhanced() === false || override ) {
gadget_to_translate.dom.find(".t").i18n();
gadget_to_translate.setEnhanced(true);
}
}
$.fn.fauna.i18n_current_lang = language;
switchIcon(gadget.id, set_icon);
},
// i18n handler
lang = function (lang) {
// init
if ($.fn.fauna.i18n_set === undefined) {
$.i18n.init({
lng: 'en-EN',
load: 'current',
detectLngQS: 'lang',
fallbackLng: false,
resGetPath: '../lang/__lng__/__ns__.json',
ns: 'gen'
// , debug: true,
// , useLocalStorage: true
// , localStorageExpirationTime: 86400000 // in ms, default 1 week
}, function () {
set_lang($.i18n.lng());
});
$.fn.fauna.i18n_set = true;
} else {
set_lang(lang);
}
};
// NONO!
setTimeout(function () {
elem = gadget.dom.find(".setIcon .ui-icon");
if (elem.length > 0) {
elem.removeClass()
.addClass('ui-icon ui-shadow ui-icon-lang '+set_icon);
}
},50);
};
// modify gadget
// customize gadget
if (gadget.self !== undefined) {
for (key in gadget.self) {
if (gadget.self.hasOwnProperty(key)) {
......@@ -142,42 +175,30 @@
// dynamic gadget-id
$(this).attr('id', new_id);
// update interactions
string = gadget.dom.find(".main-interactor").attr("data-gadget-connection");
new_string = string.replace(current_id,new_id);
gadget.dom.find(".main-interactor").attr("data-gadget-connection",new_string);
});
// initializing setter
$(document).on('i18n_ready', function (e, data) {
set_lang(data.lang);
RenderJs.bindReady(function () {
var current_lang = $.fn.fauna.i18n_current_lang;
// also pass undefined on first run
lang(current_lang);
});
$(document).ready(function() {
// regular page setter
if (lang !== undefined) {
set_lang($.fn.fauna.i18n_current_lang);
}
// switch language
// add switch language binding
$(this)
.filter(function() { return $(this).jqmData("i18n") !== true; })
.jqmData('i18n',true)
.on('click', '.change_language', function(e) {
var lang = $(this).attr('href').replace('?lang=','');
var new_language = $(this).attr('href').replace('?lang=','');
e.preventDefault();
$('.all_popups').popup( "close" );
// switch to new language
$.i18n.setLng(lang, function() {
// translate everything in gadget
$.fn.util.lang(gadget.dom);
// interaction! switch icon (triggers translate on all other gadgets
set_lang($.i18n.lng());
});
$.i18n.setLng(new_language, function() {
// switch to new language
lang(new_language);
});
});
});
});
//]]>
</script>
</body>
......
......@@ -108,36 +108,6 @@ define([], function () {
$(this).appendTo($('#configure tbody tr').eq(i).find('td').show().last());
});
}
},
// languages i18n handler
lang : function (elem) {
var translate = function (elem) {
elem.find('.t').i18n();
};
// init
if (fauna.i18n_set === undefined) {
i18n.init({
lng: 'en-EN',
load: 'current',
detectLngQS: 'lang',
fallbackLng: false,
resGetPath: '../lang/__lng__/__ns__.json',
ns: 'gen'
// , debug: true,
// , useLocalStorage: true
// , localStorageExpirationTime: 86400000 // in ms, default 1 week
}, function () {
translate(elem);
// set current language, trigger i18n_ready
fauna.i18n_current_lang = i18n.lng();
$(document).trigger('i18n_ready',{ lang: i18n.lng()});
});
fauna.i18n_set = true;
} else {
translate(elem);
}
}
};
......@@ -195,11 +165,6 @@ define([], function () {
// initialize renderjs
RenderJs.init();
RenderJs.bindReady(function () {
var elem = $(this);
util.lang(elem);
});
});
// reset gadgets on pages that are being removed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment