Sorry to raise this again, but I made a few changes too (in addition to the ones listed above).
In Chrome, the tabs are bordered when opening and selecting (this might also happen in the tabs widget). They therefore have an orange box around them (might depend on the ui theme). To get around this, I added the following to the CSS...
- #tabdlg .ui-state-active a, #tabdlg .ui-state-active { outline: none; }
To see what I mean, the following link illustrates it. It also contains the solutions provided by other people - I used a combination of the ones that suited this particular issue.
Stack Overflow Explanation
I also tidied the HTML for the button line to look more like the dialog's close button (the top margin may be different on your setup - I also have a version that vertically aligned it, but for the purposes of this demo, it was perhaps overkill)...
- <span id="closer" class="ui-icon ui-icon-closethick" style="float: right; margin-right: .3em; margin-top: .35em;"></span>
In my version I put the styles for the close button into the css area, but hey.
Technically I guess you could rewrite the Jquery to implement the style changes itself, and perhaps put the close button in, negating the need for extra markup. Maybe wrap it all into a plugin. For now though, it all looks pretty neat.
To recap from visualwebeffects post to here...
The CSS...
- #tabdlg.ui-tabs, #tabdlg.ui-dialog-content, #tabdlg.ui-dialog { padding: 0; }
- #tabdlg .ui-state-active a, #tabdlg .ui-state-active { outline: none; }
- #closer { float: right; margin-right: .3em; margin-top: .35em; }
The Javascript (also converting the dialog opener button to a jquery ui button - last part of script)...
- $(document).ready(function(){
- $("#closer").click(function(){
- $("#tabdlg").tabs().dialog("close");
- });
-
- $("#tabdlg").tabs().dialog({
- autoOpen: false,
- width: 600,
- height: 400,
- draggable: false, // disable the dialogs default drag we will be using the tabs titlebar instead
- modal: true,
- buttons: {
- 'OK': function() {
- $(this).dialog('close');
- },
- 'Close': function() {
- $(this).dialog('close');
- }
- },
- open: function() {
- $('.ui-dialog-titlebar').hide(); // hide the default dialog titlebar
- },
- close: function() {
- $('.ui-dialog-titlebar').show(); // in case you have other ui-dialogs on the page, show the titlebar
- }
- }).parent().draggable({handle: ".ui-tabs-nav"}); // the ui-tabs element (#tabdlg) is the object parent, add these allows the tab to drag the dialog around with it
- // stop the tabs being draggable (optional)
- $('.ui-tabs-nav li').mousedown(function(e){
- e.stopPropagation();
- });
- $("#tabopener").button().click(function(){
- $("#tabdlg").tabs().dialog("open");
- });
- });
The HTML...
- <p><button id="tabopener">Open Tabbed Dialog</button></p>
- <div id="tabdlg">
- <ul>
- <li><a href="#ctabs-1">Tab One</a></li>
- <li><a href="#ctabs-2">Tab Two</a></li>
- <span id="closer" class="ui-icon ui-icon-closethick"></span>
- </ul>
- <div id="ctabs-1">
- <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
- </div>
- <div id="ctabs-2">
- <form>
- <fieldset class="ui-helper-reset">
- <label for="tab_title">Title</label>
- <input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
- <label for="tab_content">Content</label>
- <textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all"></textarea>
- </fieldset>
- </form>
- </div>
- </div>
Thanks for some great ideas guys - looks like it's solved this quite elegantly without too many hacks.