Skip to content

Commit

Permalink
Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nitriques committed Nov 6, 2012
1 parent 2f3b441 commit 3f2a2bb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 62 deletions.
95 changes: 47 additions & 48 deletions assets/language_switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,50 @@
* @version 0.1
*/
(function($) {
$(document).ready(function() {

for (i in Symphony.Languages) {
var lang = Symphony.Languages[i];
$('nav#nav ul.structure').append(
// Nav menu item
$('<li />')
.addClass('backend_language_switcher')
.addClass(lang)
.addClass(lang == Symphony.Author.language ? 'selected' : '')
.addClass(i == 0 ? 'first' : '' )
.addClass(i == (Symphony.Languages.length-1) ? 'last' : '' )
.attr({
'title':'Change to '+lang,
'lang':lang
})
// Flag image
.append(
$('<img />')
.attr({
'src':Symphony.Context.get('root')+'/extensions/backend_language_switcher/assets/flags/'+lang+'.png',
'alt':lang.toUpperCase()
})
)
// Click handler - Construct request to change user language
.click(function(){
var li = $(this);
var lang = li.attr('lang');
var url = Symphony.Context.get('root') + '/symphony/system/authors/edit/' + Symphony.Author.id + '/';
var data = {
'action[save]' : true,
'fields[default_section]' : Symphony.Author.default_section,
'fields[email]' : Symphony.Author.email,
'fields[first_name]' : Symphony.Author.first_name,
'fields[last_name]' : Symphony.Author.last_name,
'fields[username]' : Symphony.Author.username,
'fields[language]' : lang
}
$.post(url, data, function(data, textStatus){
// Callback function, reload page
window.location.reload();
});
})
);
}

});
})(jQuery.noConflict());
$(function() {
for (var i in Symphony.Languages) {
var lang = Symphony.Languages[i];
$('nav#nav ul.structure').append(
// Nav menu item
$('<li />')
.addClass('backend_language_switcher')
.addClass(lang)
.addClass(lang == Symphony.Author.language ? 'selected' : '')
.addClass(i == 0 ? 'first' : '' )
.addClass(i == (Symphony.Languages.length-1) ? 'last' : '' )
.attr({
'title':'Change to '+lang,
'lang':lang
})
// Flag image
.append(
$('<img />')
.attr({
'src':Symphony.Context.get('root')+'/extensions/backend_language_switcher/assets/flags/'+lang+'.png',
'alt':lang.toUpperCase()
})
)
// Click handler - Construct request to change user language
.click(function(){
var li = $(this);
var lang = li.attr('lang');
var url = Symphony.Context.get('root') + '/symphony/system/authors/edit/' + Symphony.Author.id + '/';
var data = {
'action[save]' : true,
'fields[default_section]' : Symphony.Author.default_section,
'fields[email]' : Symphony.Author.email,
'fields[first_name]' : Symphony.Author.first_name,
'fields[last_name]' : Symphony.Author.last_name,
'fields[username]' : Symphony.Author.username,
'fields[language]' : lang
}
$.post(url, data, function(data, textStatus){
// Callback function, reload page
window.location.reload();
});
})
);
}

});
})(jQuery);
28 changes: 14 additions & 14 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
* Backend language switcher
*
* @author John J. Camilleri
* @version 1.2
* @version 1.2.1
*/
Class extension_backend_language_switcher extends Extension{

public static $xml;

public function getSubscribedDelegates(){
return array(
Expand All @@ -18,21 +16,21 @@ public function getSubscribedDelegates(){
),
);
}

private $LOAD_NUMBER = 955935299;

public function initializeAdmin($context) {
$LOAD_NUMBER = 955935299;
$assets_path = URL . '/extensions/backend_language_switcher/assets';
$page = Administration::instance()->Page;
// var_dump($context);die;
$author = Administration::instance()->Author;

//frontend localization
$codes = Symphony::Configuration()->get('langs', 'frontend_localisation');
//language redirect cases
if ($codes == '' || $codes == null) $codes = Symphony::Configuration()->get('language_codes', 'language_redirect');
if ($codes == '' || $codes == null) $codes = Symphony::Configuration()->get('languages', 'language_redirect');
$languages = array_map('trim',explode(',', $codes ));

$assets_path = URL . '/extensions/backend_language_switcher/assets';

// CSS & JS for all admin
$page->addStylesheetToHead($assets_path . '/language_switcher.css', 'all', $LOAD_NUMBER++);
$script = new XMLElement('script');
Expand Down Expand Up @@ -60,22 +58,24 @@ public function initializeAdmin($context) {
$author->get('language')
));
$script->setSelfClosingTag(false);
$page->addElementToHead($script, $LOAD_NUMBER++);
$page->addScriptToHead($assets_path . '/language_switcher.js', $LOAD_NUMBER++);
$page->addElementToHead($script, $this->LOAD_NUMBER++);
$page->addScriptToHead($assets_path . '/language_switcher.js', $this->LOAD_NUMBER++);
}

public function enable(){
public function enable() {
return $this->install();
}

public function disable(){
public function disable() {
return true;
}

public function install(){
public function install() {
return true;
}

public function uninstall(){
public function uninstall() {
return true;
}

}
?>

0 comments on commit 3f2a2bb

Please sign in to comment.