Created
November 12, 2014 19:18
-
-
Save wallynm/cc3ad696a7261b08dfd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// My region controller, it's located where the application it's booted | |
App.mainRegion.on("show", function( view ){ | |
window.onViewRendered( view ); | |
}); | |
// The function which it's been called - The rendered view was passed by the regionManager | |
window.onViewRendered = function (renderedView){ | |
languageFiles = ['system', 'appBar', 'etc...']; | |
// I've created a local var which it's responsible for defer the onShow method, | |
var onshow = renderedView.onShow | |
// So, even if the Marionette layout manager dispatch the child itemView on show event, it will be undefined | |
renderedView.onShow = undefined; | |
// At this function, i load some json files, and the Marionette control was executing child itemView on show before this function really finish | |
// Your example about using $.then would be used here, but with the workaround of turning onShow undefined solves the problem | |
translateContent(languageFiles, {}, function(){ | |
// Apply some default things on the view | |
// Here's the workarround... I finally call the onShow, passing the view reference | |
onShow.apply(renderedView); | |
}); | |
} | |
// Loads the json files, so it takes a bit to response the callback | |
window.translateContent = function(namespaces, data, callback) { | |
console.log('helper.js --------> translateContent'); | |
if(_.isEmpty(namespaces)) namespaces = 'dashboard'; | |
if(typeof data != "object") { data = {}; } | |
if($.i18n.exists(namespaces+':')) | |
{ | |
App.mainRegion.$el.i18n(data); | |
if(typeof callback == "function") { callback(); } | |
} | |
else | |
{ | |
$.i18n.loadNamespaces(namespaces, function() { | |
App.mainRegion.$el.i18n(data); | |
if(typeof callback == "function") { callback(); } | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment