Make scrolling work

This commit is contained in:
2015-01-04 11:03:17 +01:00
parent 5048e9f07a
commit 514bb748e6
6 changed files with 29 additions and 89 deletions
@@ -1,74 +0,0 @@
$translations = {
en: {
models: <%= I18n.t('activemodel.models', locale: :en).to_json %>,
attributes: <%= I18n.t('activemodel.attributes', locale: :en).to_json %>,
helpers: <%= I18n.t('helpers', locale: :en).to_json %>,
pagination: <%= I18n.t('views.pagination', locale: :en).to_json %>,
},
nl: {
models: <%= I18n.t('activemodel.models', locale: :nl).to_json %>,
attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %>,
helpers: <%= I18n.t('helpers', locale: :nl).to_json %>,
pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %>,
}
}
$transformation_mappings = {
downcase: 'toLowerCase',
upcase: 'toUpperCase'
}
function t(path, vars){
vars || (vars = {});
var result, m, translatable, isafety,replacable;
var parts = path.split('.');
var accessor = '$translations.'+$locale+'["' + parts.join('"]["')+ '"]';
try{
result = eval(accessor);
} catch(err){
result = parts[parts.length - 1].capitalize();
}
if(result == '') return '';
if(!result) return parts[parts.length - 1].capitalize();
$.each(vars, function(v, value){ result = result.replace('%{'+v+'}', value)});
isafety = 0;
while(result.indexOf('${') > -1){
m = result.match(/\${([\w\.]+(\|\w+)?)}/);
if(m[2]){
translatable = m[1].replace(m[2], '');
operation = $transformation_mappings[m[2].substr(1) || m[2].substr(1)];
}else{
translatable = m[1];
operation = null;
}
replacable = t(translatable);
if(operation) replacable = replacable[operation]();
result = result.replace(m[0], replacable);
if(isafety > 10) break;
isafety += 1;
}
return result;
}
function setLocale(locale){
Qstorage.setItem('locale', locale);
$locale = locale;
setTranslations();
}
function setTranslations(selector){
var list = $('#top-navigation-list');
list.find('.locale').show();
list.find('.locale-'+$locale).hide();
moment.lang($locale);
if(selector){
$(selector).find('[data-t]').each(function(){$(this).html(t($(this).data('t'), $(this).data('tAttributes')))})
$(selector).find('*[data-time]').each(function(){
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D MMM HH:mm'))
})
}else{
$('[data-t]').each(function(){$(this).html(t($(this).data('t'),$(this).data('tAttributes')))})
$('*[data-time]').each(function(){
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D MMM HH:mm'))
})
}
$('.datepicker').datepicker("option", $.datepicker.regional[$locale])
}
@@ -1,5 +1,5 @@
#= require_self
#= require jquery.touchSwipe
# require jquery.touchSwipe
#= require handlebars
#= require ember
#= require ember-data
@@ -1,19 +1,31 @@
App.ApplicationView = Ember.View.extend
didInsertElement: ->
# Side menu collapsing
targets = @$('.side-menu')
targets.addClass('closed').click -> targets.toggleClass('active').addClass('clicked').toggleClass('closed')
side_menu = @$('.side-menu')
side_menu.addClass('closed').click -> side_menu.toggleClass('active').addClass('clicked').toggleClass('closed')
controller = @get('controller')
@$('.main-section').swipe
swipe: (event, direction, distance, duration, fingerCount) ->
if fingerCount is 2
if direction is "right"
targets.addClass('active clicked').removeClass('closed')
if direction is "left"
targets.removeClass('active').addClass('closed')
if fingerCount is 3 and direction is "up"
controller.transitionToRoute "settings"
fingers: 'all'
#@$('.main-section').swipe
#swipe: (event, direction, distance, duration, fingerCount) ->
#if fingerCount is 2
#if direction is "right"
#side_menu.addClass('active clicked').removeClass('closed')
#if direction is "left"
#side_menu.removeClass('active').addClass('closed')
#if fingerCount is 3 and direction is "up"
#controller.transitionToRoute "settings"
#fingers: 'all'
document.addEventListener "backbutton", =>
# close side menu if open
if side_menu.hasClass('active')
side_menu.click()
else
# close the app when on the index route
if @controller.currentPath is 'index'
navigator.app.exitApp()
else
# go to index route otherwise
@controller.transitionToRoute 'index'
document.addEventListener "menubutton", -> side_menu.click()
#ios7 detection
if window.device and window.device.platform and window.device.platform.toLowerCase() is "ios" and parseFloat(window.device.version) >= 7.0
@@ -1,5 +1,5 @@
#= require jquery
#= require ../app/application
#= require ../app/manifest
#= require faye
#= require moment
#= require translations