Commit c14e4eac authored by alexandre's avatar alexandre

Started to namespace utils functions

parent 16b6f4b7
......@@ -64,7 +64,7 @@ window.W = window.W || {};
} else if (interpolate) {
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
} else if (translate) {
source += "'+\n((__t=(W.translate('" + translate + "')))==null?'':__t)+\n'";
source += "'+\n((__t=(W.utils.translate('" + translate + "')))==null?'':__t)+\n'";
} else if (evaluate) {
source += "';\n" + evaluate + "\n__p+='";
}
......
......@@ -6,31 +6,7 @@ window.W = window.W || {};
(function(undefined) {
'use strict';
function setCookie(key, value) {
var expires = new Date();
expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
// This is for Django to allow POSTing forms
// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
var csrftoken = W.utils.getCookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
......@@ -52,7 +28,7 @@ window.W = window.W || {};
W.config = W.config || {};
var lang = getCookie("lang");
var lang = W.utils.getCookie("lang");
if (!lang) {
lang = window.navigator.userLanguage || window.navigator.language;
......
;
window.W = window.W || {};
(function (undefined) {
'use strict';
W.utils = {};
W.utils.translate = window.t = function (string) {
if (!(W.config.lang in W.lang)) {
console.log(W.config.lang + " n'est pas une langue defini. On passe au français");
W.config.lang = "fr"
};
var entries = W.lang[W.config.lang];
if (string in entries) {
return entries[string];
} else {
console.log(string + " n'est pas traduit");
return string;
}
}
W.utils.setCookie = function (key, value) {
var expires = new Date();
expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
W.utils.getCookie = function (name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
})();
......@@ -33,24 +33,6 @@ window.W = window.W || {};
}
});
W.translate = window.t = function (string) {
console.log("translating");
if (!(W.config.lang in W.lang)) {
console.log(W.config.lang + " n'est pas une langue defini. On passe en anglais");
W.config.lang = "fr"
};
var entries = W.lang[W.config.lang];
if (string in entries) {
return entries[string];
} else {
console.log(string + " n'est pas traduit");
return string;
}
}
Marionette.TemplateCache.prototype.compileTemplate = function compileTemplate(rawTemplate, options) {
return W.extendedTemplate(rawTemplate, options);
}
......@@ -96,42 +78,8 @@ window.W = window.W || {};
range: '3'
};
var languages = [
{
patt: /en/,
label: 'English'
},
{
patt: /fr/,
label: 'Français'
},
{
patt: /nl/,
label: 'Nederlands'
},
{
patt: /es/,
label: 'Español'
},
{
patt: /de/,
label: 'Deutsch'
}
];
var tags = W.tags = [">", "|", "//", "", "||"];
function getUserLanguage() {
var l = navigator.language;
for (var i = 0; i < languages.length; i++) {
if (l.search(languages[i].patt) > -1) {
return languages[i].label;
}
}
}
function formatTimestamp(timestring) {
var d = new Date(timestring);
return d.getDate()
......@@ -1773,18 +1721,13 @@ window.W = window.W || {};
},
switchLanguage: function (view, event) {
console.log("switching language");
W.config.lang = $(event.currentTarget).attr("data-lang");
console.log(this.getRegions());
_.each(this.getRegions(), function(element, index, list) {
console.log(element);
var currentView = element.currentView;
if (currentView) { currentView.render(); }
});
// Backbone.history.navigate(Backbone.history.fragment, true);
// Backbone.history.stop();
// Backbone.history.start();
},
showLogin: function(event) {
......
......@@ -129,6 +129,7 @@
<script src="{% static 'playground/js/i18n/fr.js' %}"></script>
<script src="{% static 'playground/js/i18n/en.js' %}"></script>
<script src="{% static 'playground/js/utils.js' %}"></script>
<script src="{% static 'playground/js/extendedTemplate.js' %}"></script>
<script src="{% static 'playground/js/models.js' %}"></script>
<script src="{% static 'playground/js/collections.js' %}"></script>
......
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