Skip to content

Commit

Permalink
Merge pull request #25 from DeuxHuitHuit/issue-22
Browse files Browse the repository at this point in the history
Release 1.2
  • Loading branch information
brendo committed Nov 7, 2013
2 parents acad20c + 9b1f05d commit 9508cc8
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 87 deletions.
21 changes: 21 additions & 0 deletions assets/publish_tabs.publish.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,25 @@

.tab-group-selected {
position: static;
}

ul.tabs li.invalid span {
background: #f4f4f4;
color: rgba(255, 255, 255, 0.7);
-webkit-box-shadow: none;
box-shadow: none;
display: inline-block;
vertical-align: top;
text-align: center;
width: 16px;
height: 16px;
line-height: 16px;
margin: 0 0 0 5px;
border-radius: 8px;
font-weight: bold;
}

ul.tabs li.invalid.selected span {
background: #dd4422;
color: #f4f4f4;
}
185 changes: 98 additions & 87 deletions assets/publish_tabs.publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,107 +10,118 @@ Symphony.Language.add({
/*-----------------------------------------------------------------------------
PublishTabs
-----------------------------------------------------------------------------*/

var PublishTabs = {
(function ($, undefined) {

tab_controls: null,
new_entry: null,
'use strict';

init: function() {
var self = this;

// thy shalt not pass if no Publush Tab fields used
var tab_fields = jQuery('.field-publish_tabs');
if (!tab_fields.length) return;

jQuery('body').addClass('publish-tabs');

// are we creating a new entry or editing an existing one?
var env = Symphony.Context.get('env');
this.new_entry = (env.page === 'new');

var has_invalid_tabs = false;
this.tab_controls = jQuery('<ul class="tabs"></ul>');

var publish_tabs = Symphony.Context.get('publish-tabs');
window.PublishTabs = {

tab_controls: null,
new_entry: false,

for(var i in publish_tabs) {

var main_fields = '';
var sidebar_fields = '';
init: function() {
var self = this;
var context = $('#context');

for(field in publish_tabs[i].main) main_fields += '#' + publish_tabs[i].main[field] + ', ';
for(field in publish_tabs[i].sidebar) sidebar_fields += '#' + publish_tabs[i].sidebar[field] + ', ';
// thy shalt not pass if no Publish Tab fields used
var tab_fields = $('.field-publish_tabs');
if (!tab_fields.length) return;

main_fields = main_fields.replace(/, $/,'');
sidebar_fields = sidebar_fields.replace(/, $/,'');
$('body').addClass('publish-tabs');

jQuery(main_fields).wrapAll('<div class="tab-group tab-group-' + publish_tabs[i]['tab_id'] + '"></div>');
jQuery(sidebar_fields).wrapAll('<div class="tab-group tab-group-' + publish_tabs[i]['tab_id'] + '"></div>');
// are we creating a new entry or editing an existing one?
var env = Symphony.Context.get('env');
this.new_entry = (env.page === 'new');

var tab_field = jQuery('#field-' + publish_tabs[i]['tab_id']).remove();
var tab_text = (tab_field.text() != '') ? tab_field.text() : Symphony.Language.get('Untitled Tab');
var tab_button = jQuery('<li class="tab-'+publish_tabs[i]['tab_id']+'" data-id="'+publish_tabs[i]['tab_id']+'">' + tab_text + '</li>');

this.tab_controls.append(tab_button);
var has_invalid_tabs = false;
this.tab_controls = $('<ul class="tabs"></ul>');

// add click event to tab
tab_button.bind('click', function() {
if (jQuery(this).hasClass('selected')) return;
tab_button.addClass('invalid').append('<span>!</span>');
});
var publish_tabs = Symphony.Context.get('publish-tabs');

// find invalid fields
if (jQuery('.tab-group-' + i + ' .invalid').length) {
has_invalid_tabs = true;
tab_button.addClass('invalid').append('<span>!</span>');
for(var i in publish_tabs) {

var main_fields = '';
var sidebar_fields = '';

for(var field in publish_tabs[i].main) main_fields += '#' + publish_tabs[i].main[field] + ', ';
for(var field in publish_tabs[i].sidebar) sidebar_fields += '#' + publish_tabs[i].sidebar[field] + ', ';

main_fields = main_fields.replace(/, $/,'');
sidebar_fields = sidebar_fields.replace(/, $/,'');

var $main_fields = $(main_fields);
var $sidebar_fields = $(sidebar_fields);

$main_fields.wrapAll('<div class="tab-group tab-group-' + publish_tabs[i]['tab_id'] + '"></div>');
$sidebar_fields.wrapAll('<div class="tab-group tab-group-' + publish_tabs[i]['tab_id'] + '"></div>');

var tab_field = $('#field-' + publish_tabs[i]['tab_id']).remove();
var tab_text = (tab_field.text() != '') ? tab_field.text() : Symphony.Language.get('Untitled Tab');
var tab_button = $('<li class="tab-'+publish_tabs[i]['tab_id']+'" data-id="'+publish_tabs[i]['tab_id']+'">' + tab_text + '</li>');

this.tab_controls.append(tab_button);

// add click event to tab
tab_button.on('click', function() {
var t = $(this);
var id = t.attr('data-id');
if (t.hasClass('selected')) return;
if (!!id) {
self.showTab(id);
}
});

// find invalid fields
if (!!$main_fields.add($sidebar_fields).find('.invalid').length) {
has_invalid_tabs = true;
tab_button.addClass('invalid').append('<span class="icon">!</span>');
}
}

}

if (has_invalid_tabs) {
this.tab_controls.find('li.invalid:first').click();
} else {
this.tab_controls.find('li:first').click();
}
// append tags controls
context.append(this.tab_controls);

// selected the right tab
if (has_invalid_tabs) {
this.tab_controls.find('li.invalid:first').click();
} else {
var initial_tab = self.getURLParameter('publish-tab');
var selector = !initial_tab ? 'li:first' : '.'+initial_tab;
this.tab_controls.find(selector).click();
}
},

jQuery('#context').append(this.tab_controls);
showTab: function(tab) {
var w = $('#contents').width();

// deselect current tab and select the new tab
this.tab_controls.find('li.selected').removeClass('selected');
this.tab_controls.find('li.tab-' + tab).addClass('selected');

// hide current tab group and select new group
$('.tab-group-selected').removeClass('tab-group-selected');
$('.tab-group-' + tab).addClass('tab-group-selected');

var invalid_field = $('.tab-group-' + tab + ' .invalid');
// focus first invalid element
if (invalid_field.length) {
invalid_field.eq(0).find('*[name*="fields["]').focus();
}
// focus first field in tab when creating a new entry
else if (this.new_entry) {
$('.tab-group-' + tab + ' .field:first *[name*="fields["]').focus();
}
},

var initial_tab = self.getURLParameter('publish-tab');
if( initial_tab !== undefined ){
jQuery('.'+initial_tab).trigger('click');
getURLParameter: function(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
},

showTab: function(tab) {
var w = jQuery('#contents').width();

// deselect current tab and select the new tab
this.tab_controls.find('li.selected').removeClass('selected');
this.tab_controls.find('li.tab-' + tab).addClass('selected');

// hide current tab group and select new group
jQuery('.tab-group-selected').removeClass('tab-group-selected');
jQuery('.tab-group-' + tab).addClass('tab-group-selected');

var invalid_field = jQuery('.tab-group-' + tab + ' .invalid');
// focus first invalid element
if (invalid_field.length) {
invalid_field.eq(0).find('*[name*="fields["]').focus();
}
// focus first field in tab when creating a new entry
else if (this.new_entry) {
jQuery('.tab-group-' + tab + ' .field:first *[name*="fields["]').focus();
}
},

getURLParameter: function(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}

}

jQuery(document).ready(function() {
PublishTabs.init();
jQuery('.drawer.vertical-left, .drawer.vertical-right').trigger('update.drawer');
});
$(document).ready(function() {
PublishTabs.init();
$('.drawer.vertical-left, .drawer.vertical-right').trigger('update.drawer');
});

})(jQuery);
8 changes: 8 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<author>
<name github="symphonists" symphony="community">Symphony Community</name>
</author>
<author>
<name github="DeuxHuitHuit" symphony="nitriques">Deux Huit Huit</name>
<website>http://deuxhuithuit.com</website>
</author>
<author>
<name github="nickdunn" symphony="nickdunn">Nick Dunn</name>
<website>http://nick-dunn.co.uk</website>
Expand All @@ -20,6 +24,10 @@
<item type="image" url="http://symphonyextensions.com/nickdunn/publish_tabs/media/publish_tabs.png">Publish Tabs: Add tab groups to entry create/edit forms</item>
</media>
<releases>
<release version="1.2.0" date="2013-11-06" min="2.3.x">
- Fixed issue #21
- Fixed issue #22
</release>
<release version="1.1.2" date="2012-05-17" min="2.3.x" />
<release version="1.1.1" date="2012-03-26" min="2.3.x" />
<release version="1.0.2" date="2011-12-11" min="2.2" max="2.2.x" />
Expand Down

0 comments on commit 9508cc8

Please sign in to comment.