Created
August 16, 2012 02:00
-
-
Save litzinger/3365612 to your computer and use it in GitHub Desktop.
Add disabled functionality to PT Pill
This file contains hidden or 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
ul.pt-pill { display: inline-block; margin: 5px 0; padding: 0; list-style-type: none; height: 18px; cursor: default; white-space: nowrap; | |
-webkit-user-select: none; -moz-user-select: none; } | |
ul.pt-pill li { float: left; margin: 0 -1px 0 0; padding: 0 7px; border: 1px solid #a8b1b3; line-height: 18px; background: #fff url(../images/option_bg.gif) repeat-x; cursor: pointer; } | |
ul.pt-pill li:first-child { -webkit-border-top-left-radius: 3px; -webkit-border-bottom-left-radius: 3px; -moz-border-radius: 3px 0 0 3px; } | |
ul.pt-pill li:last-child { -webkit-border-top-right-radius: 3px; -webkit-border-bottom-right-radius: 3px; -moz-border-radius: 0 3px 3px 0; } | |
ul.pt-pill li.selected { background: #fff; position: relative; z-index: 1; text-shadow: 0 1px #fff; cursor: default; | |
background: url(../images/selected_bg.gif) repeat-x; | |
background: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(0,0,0,0.15)), to(rgba(0,0,0,0.1))); | |
background: -moz-linear-gradient(top, rgba(0,0,0,0.15), rgba(0,0,0,0.1)); | |
-webkit-box-shadow: inset 0 1px rgba(0,0,0,0.1); | |
-moz-box-shadow: inset 0 1px rgba(0,0,0,0.1); } | |
ul.pt-pill-disabled { opacity: 0.5; } | |
ul.pt-pill-disabled li { cursor: default; } | |
.matrix ul.pt-pill { margin: 0; } |
This file contains hidden or 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
// https://skitch.com/litzinger/ec7e7/edit-entry-expressionengine | |
ptPill = function($select){ | |
$select.hide(); | |
var $disabled = $select.attr('disabled') == 'disabled' ? ' pt-pill-disabled' : ''; | |
var obj = this, | |
$options = $('option', $select), | |
$ul = $('<ul class="pt-pill'+ $disabled +'" tabindex="0" />').insertAfter($select), | |
$selected; | |
$options.each(function(index){ | |
var $option = $(this), | |
$li = $('<li />').appendTo($ul).html($option.html()); | |
// prevent focus on click | |
$li.mousedown(function(event){ event.preventDefault(); }); | |
if ($disabled == '') { | |
$li.click(function(event, testing){ | |
if ($li == $selected) return; | |
if ($selected) { | |
$selected.removeClass('selected'); | |
$select.val($option.val()).change(); | |
} | |
$selected = $li.addClass('selected'); | |
}); | |
} | |
if ($option.attr('selected')) { | |
$li.click(); | |
$li.addClass('selected'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment