Merge pull request #4469 from PaulAdamDavis/permalink-improvs

Improvements to the permalinks UI
This commit is contained in:
Hannah Wolfe 2014-11-19 20:46:32 +00:00
commit 0c38a839b0
2 changed files with 83 additions and 40 deletions

View File

@ -338,12 +338,14 @@
// Custom permalink
//
// Custom Permalinks
// --------------------------------------------------
.permalink-input-wrapper {
position: relative;
outline: 0; // Kills the blue outline we get by adding tabindex="0"
padding-top: 6px;
padding-bottom: 6px;
padding: 2px 0 2px 6px;
&:focus,
&.focus {
@ -359,42 +361,46 @@
.permalink-fake-input {
display: flex;
flex-wrap: wrap;
margin-right: 26px;
align-items: center;
margin-right: 40px;
}
.permalink-domain {
padding-right: 3px;
margin: 5px -1px 3px 0;
color: #7E878B;
}
// A collection of labels showing the URL structure
.permalink-structure {
.permalink-parameter {
position: relative;
padding: 3px 6px 4px;
margin: 4px 0 4px 9px;
max-height: 18px;
.permalink-parameter {
position: relative;
top: -2px;
margin-left: 6px;
// Change default label styles
background: #E3EDF2;
box-shadow: inset 0px 0px 0px 1px #CDD5D9;
color: #7E878B;
// The slash before each parameter
&:before {
content: "/";
position: absolute;
top: 4px;
left: -8px;
font-size: 1.4rem;
color: #7E878B;
}
// The slash before each parameter (using :after)
// Using `:before` does funky stuff here in Safari
&:after {
content: "/";
position: absolute;
top: 2px;
left: -7px;
font-size: 1.4rem;
color: #7E878B;
}
}
// The actual input, which resets some styles inherited from the global input style
.permalink-input {
flex: 1 0;
margin: -6px 0 -6px -2px;
margin: 0;
padding: 0 4px;
margin-right: -4px;
background: transparent;
min-width: 60px;
min-height: 30px;
border: 0;
}
@ -426,5 +432,6 @@
// Shift the popover (than opens over the top of everything) to the left a bit
.popover-item {
margin-left: -5px;
min-width: 320px;
}
}//.permalink-input-wrapper

View File

@ -128,13 +128,16 @@
<div class="permalink-fake-input">
<span class="permalink-domain">http://myblog.ghost.io</span>
<span class="permalink-structure">
<span class="permalink-parameter label label-default">journal</span>
<span class="permalink-parameter label label-default">year</span>
<span class="permalink-parameter label label-default">month</span>
<span class="permalink-parameter label label-default">day</span>
<span class="permalink-parameter label label-default">title</span>
</span>
<span class="permalink-parameter label label-default">journal</span>
<span class="permalink-parameter label label-default">year</span>
<span class="permalink-parameter label label-default">hello</span>
<span class="permalink-parameter label label-default">agaian</span>
<span class="permalink-parameter label label-default">this</span>
<span class="permalink-parameter label label-default">is</span>
<span class="permalink-parameter label label-default">nice</span>
<span class="permalink-parameter label label-default">yo</span>
<span class="permalink-parameter label label-default">yo</span>
<span class="permalink-parameter label label-default">yo</span>
<input id="blog-permalinks" class="permalink-input" type="text" name="general[permalinks]">
</div>
@ -191,24 +194,57 @@
<script>
$(function(){
$("#blog-permalinks").on("focus", function(){
$(".permalink-input-wrapper").addClass("focus");
$("#blog-permalinks").focus();
});
$("#blog-permalinks").on("blur", function(){
$(".permalink-input-wrapper").removeClass("focus");
$('.permalink-input-wrapper').on('click', function(){
$(this).addClass('focus');
$('#blog-permalinks').focus();
});
$(".hover-me").hover(function(){
$(this).next(".popover-item").addClass("open fade-in").removeClass("closed fade-out");
$('#blog-permalinks').on('blur', function(){
$('.permalink-input-wrapper').removeClass('focus');
});
$('.hover-me').hover(function(){
$(this).next('.popover-item').addClass('open fade-in').removeClass('closed fade-out');
}, function(){
$(this).next(".popover-item").removeClass("fade-in").addClass("fade-out");
$(this).next(".popover-item").on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function (event) {
$(this).next('.popover-item').removeClass('fade-in').addClass('fade-out');
$(this).next('.popover-item').on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function (event) {
if (event.originalEvent.animationName === 'fade-out') {
$(this).removeClass("open fade-out").addClass("closed");
$(this).removeClass('open fade-out').addClass('closed');
}
});
});
function convertToSlug(Text){
return Text.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-').trim();
}
$('#blog-permalinks').on('keyup', function(e){
// 188 = comma
// Append the new parameter when pressing comma
if (e.keyCode === 188) {
var input_val = convertToSlug($(this).val());
var the_param = '<span class="permalink-parameter label label-default">' + input_val + '</span>';
// If a parameter exists, append after it.
// Else append after the domain
if ($('.permalink-parameter').length) {
$('.permalink-parameter:last').after(the_param);
} else {
$('.permalink-domain').after(the_param);
}
$(this).val('');
}
// 8 = backspace
// When backspace is pressed AND the input is empty, delete the last parameter
if (e.keyCode === 8 && $(this).val() == '') {
$('.permalink-parameter:last').remove();
}
});
});
</script>