Skip to content

Instantly share code, notes, and snippets.

@rc1
Created December 10, 2010 19:16
Show Gist options
  • Save rc1/736647 to your computer and use it in GitHub Desktop.
Save rc1/736647 to your computer and use it in GitHub Desktop.
uses the html-field extension
// for illustration only. need refactoring as it shows a non-exsistant defined group by sending an empty string to show
// add groups
ADMIN_SHOW_HIDE.addFieldGroup('Gallery Images', ['Images']);
function debugField (selector) {
objectForSymphonyLabel(selector).addClass('debug');
}
// actions
jQuery(document).ready( function ($) {
var select = 'input:[name=fields[use-main-gallery]]';
// show initially selected group
ADMIN_SHOW_HIDE.showFieldGroup( $(select).val() );
// add event
$(select).change( function () {
checkStatus();
})
function checkStatus () {
if($(select).attr('checked')) {
ADMIN_SHOW_HIDE.showFieldGroup( "" );
} else {
ADMIN_SHOW_HIDE.showFieldGroup( "Gallery Images" );
}
}
checkStatus();
});
<style type="text/css">
<!--
.field-html_panel {
display: none;
}
.debug {
border: 1px solid red;
}
-->
</style>
<script type="text/javascript">
<!--
// @issues selecting the symphony field can be a bit to generic
// @todo make this into an extension
ADMIN_SHOW_HIDE = new (function ($) {
// private
var self = this,
fieldGroups = new Array();
// public
// @param title string Name of the group
// @param selectors string Symphony Item Label
// @param selectors array Symphony Item Labels
this.addFieldGroup = function (title, selectors) {
if (typeof selectors == 'string') selectors = [selectors];
var group = {'title' : title, 'selectors' : selectors};
fieldGroups.push(group);
}
// @param title string Name of the group
this.showFieldGroup = function (title) {
for (var i = 0; i < fieldGroups.length; i++) {
if (fieldGroups[i].title == title) {
change(fieldGroups[i], 'show');
} else {
change(fieldGroups[i], 'hide');
}
}
}
// @param group array fieldGroups group
// @param mode string jQuery function i.e. 'show', 'hide'
function change(group, mode) {
for (var i = 0; i < group.selectors.length; i++) {
var object = objectForSymphonyLabel(group.selectors[i]) [mode] ();
}
}
function objectForSymphonyLabel(labelTitle) {
var $selection = $('.field:has(label:contains(\'' + labelTitle + '\'))');
if ($selection.length > 1) jQuery.error('objectForSymphonyLabel: label to generic, returning more that one jQuery object. may cause errors');
return $selection;
}
})(jQuery);
// custom
// add groups
ADMIN_SHOW_HIDE.addFieldGroup('Director Profile', ['Genres', 'Director Videos', 'Biography']);
ADMIN_SHOW_HIDE.addFieldGroup('Link', 'Link URL');
function debugField (selector) {
objectForSymphonyLabel(selector).addClass('debug');
}
// actions
jQuery(document).ready( function ($) {
var $select = $('select:[name=fields[entry-type]]');
// show initially selected group
ADMIN_SHOW_HIDE.showFieldGroup( $select.val() );
// add event
$select.change( function () {
ADMIN_SHOW_HIDE.showFieldGroup( $(this).val() );
})
});
-->
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment