Created
January 27, 2012 15:45
-
-
Save iwyg/1689365 to your computer and use it in GitHub Desktop.
Multilingual Field initialisation proposal
This file contains 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
(function ($, Symphony, window, undefined) { | |
function MultilingualField(field) { | |
this.field = field; | |
this.init(); | |
} | |
MultilingualField.prototype = { | |
init: function () { | |
var self = this, | |
activeTab = this.field.find('ul.tabs li.active'); | |
// Fallback to first tab if no tab is set as active by default | |
if (activeTab.length === 0) { | |
activeTab = this.field.find('ul.tabs li:eq(0)'); | |
} | |
// bind tab events | |
this.field.find('ul.tabs li').bind('click', function (e) { | |
e.preventDefault(); | |
self.setActiveTab(jQuery(this).attr('class').split(' ')[0]); | |
}); | |
// Show the active tab | |
this.setActiveTab(activeTab.attr('class').split(' ')[0]); | |
}, | |
setActiveTab: function (tab_name) { | |
var self = this; | |
// hide all tab panels | |
this.field.find('.tab-panel').hide(); | |
// find the desired tab and activate the tab and its panel | |
this.field.find('ul.tabs li').each(function () { | |
var tab = jQuery(this); | |
if (tab.hasClass(tab_name)) { | |
tab.addClass('active'); | |
var panel = tab.parent().parent().find('.tab-' + tab_name); | |
panel.show(); | |
} else { | |
tab.removeClass('active'); | |
} | |
}); | |
} | |
}; | |
// export Constructor | |
window.MultilingualField = MultilingualField; | |
}(this.jQuery, this.Symphony, this)); |
This file contains 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
(function ($, Symphony, window, undefined) { | |
function init() { | |
$('.field-multilingual_image_upload').each(function () { | |
var field = new MultilingualField($(this)); | |
}); | |
if ($('div.file:has(a):has(em)').length === 0) { | |
// Upload fields | |
$('<em>' + Symphony.Language.get('Remove File') + '</em>').appendTo('div.file:has(a)').click(function (event) { | |
var div = $(this).parent(), | |
name = div.find('input').attr('name'); | |
// Prevent clicktrough | |
event.preventDefault(); | |
// Add new empty file input | |
div.empty().append('<input name="' + name + '" type="file">'); | |
}); | |
} | |
} | |
// wait for DOM to be ready | |
$(function () { | |
var base = Symphony.WEBSITE + '/extensions/multilingual_image_upload/assets/'; | |
if (typeof this.MultilingualField !== 'function') { | |
$.getScript(base + 'multilingual-field.js', function () { | |
init(); | |
}); | |
} else { | |
init(); | |
} | |
}); | |
}(this.jQuery, this.Symphony, this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment