//
/**
* @todo Remove gumpf
*/
$preview.find('.content-preview-content .wrapper').html($target.data('content'));
$preview.find('.post-controls .post-edit').attr('href', '/ghost/editor/' + $target.data('id'));
});
$('.options.up').on('click', function(){
$(this).next("ul").fadeToggle(200);
});
$('.editor-options').on('click', 'li', function(){
$('.button-save').data("state", $(this).data("title")).attr('data-state', $(this).data("title")).text($(this).text());
});
/** Tag Selector UI **/
var existingTags = [
'quim',
'quimtastic',
'quimmy',
'quimlord',
'joaquim pheonix',
'quimcy jones'
];
var suggestions = $("ul.suggestions").hide();
if($('.category-input').length) {
var categoryOffset = $('.category-input').offset().left;
$('.category-blocks').css({'left':categoryOffset + 'px'});
}
function findTerms(searchTerm, array) {
searchTerm = searchTerm.toUpperCase();
return $.map(array, function(item){
var match = item.toUpperCase().indexOf(searchTerm) !== -1;
return match ? item : null;
});
}
$('[data-input-behaviour="tag"]').keyup(function(e){
var searchTerm = $.trim($(this).val()).toLowerCase();
if (e.keyCode == 38) {
e.preventDefault();
if(suggestions.is(":visible")){
if(suggestions.children(".selected").length == 0){
suggestions.find("li:last-child").addClass('selected');
}
else{
suggestions.children(".selected").removeClass('selected').prev().addClass('selected');
}
}
return false;
}else if(e.keyCode == 40){
if(suggestions.is(":visible")){
if(suggestions.children(".selected").length == 0){
suggestions.find("li:first-child").addClass('selected');
}
else{
suggestions.children(".selected").removeClass('selected').next().addClass('selected');
}
}
return false;
}else if(e.keyCode == 27){
suggestions.hide();
}else if((e.keyCode == 13 || e.keyCode == 188) && searchTerm) { //enter or comma key
e.preventDefault();
if(suggestions.is(":visible") && suggestions.children(".selected").length != 0){
if($('.category:containsExact("'+suggestions.children(".selected").text()+'")').length == 0){
var category = $('<span class="category">'+suggestions.children(".selected").text()+'</span>');
if($(this).data('populate')){
var populator = $($(this).data('populate'));
populator.append(category);
}
}
suggestions.hide();
}else{
if($('.category:containsExact("'+searchTerm+'")').length == 0){
var category = $('<span class="category">'+searchTerm+'</span>');
if($(this).data('populate')){
var populator = $($(this).data('populate'));
populator.append(category);
}
}
}
$(this).val('').focus();
}else if(e.keyCode != 8) { //not deleting
}
if(searchTerm){
suggestions.show();
var results = findTerms(searchTerm, existingTags);
var pos = $(this).position();
var styles = {
left : pos.left
};
suggestions.css(styles);
suggestions.html("");
for(var i=0; i < results.length; i++){
suggestions.append("<li><a href='#'>"+results[i]+"</a></li>");
}
var suggest = $('ul.suggestions li a:contains("' + searchTerm+ '")');
suggest.each(function(){
var src_str = $(this).html();
var term = searchTerm;
term = term.replace(/(\s+)/,"(<[^>]+>)*$1(<[^>]+>)*");
var pattern = new RegExp("("+term+")", "i");
src_str = src_str.replace(pattern, "<mark>$1</mark>");
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/,"$1</mark>$2<mark>$4");
$(this).html(src_str);
});
}else{
suggestions.hide();
}
}).keydown(function(e){
Temporary Admin UI