$(function() {
ListingEditor.register('description', {
fields: ['description'],
show: function(callback) {
var max = 900;
var context = this;
var editor = $$("div.editor");
var object = ListingEditor.workingListing();
$("
Edit Description
").appendTo(editor);
var input = $$("textarea.description", {rows: 10, cols: 20, name: 'description'}).appendTo(editor);
var countElement = $("Characters remaining: 900
").appendTo(editor);
editor.append(EditorFormatter.dialogButtons(function() {
var result = input.val();
if (result.length > max){
result = result.substring(0, max);
}
ListingEditor.updateSubmission('description', result);
ModalPopup.hide();
$('#description').effect('highlight', {}, 200);
if (callback) callback();
}, function () {
ModalPopup.hide();
}));
EditorFormatter.applyData(editor);
var lastCount = 0;
var recount = function(){
setTimeout(function(){
var remaining = max - input.val().length;
if (remaining <= 0){
if (remaining < lastCount){
countElement.find('.count').effect('highlight', {color: '#F44'}, 400);
}
input.addClass('error');
lastCount = remaining;
remaining = 0;
}
else{
input.removeClass('error');
}
countElement.find('.count').text(remaining);
}, 40);
};
recount();
input.keydown(recount);
ModalPopup.show(editor);
},
refresh: function() {
var el = $('#description div');
el.html(this.textilize(ListingEditor.workingListing().description))
},
textilize: function(s) {
var r = (s || "").replace(//g, '>');
// quick tags first
qtags = [['\\*', 'strong'],
['\\?\\?', 'cite'],
['\\+', 'ins'], //fixed
['~', 'sub'],
['\\^', 'sup'], // me
['@', 'code']];
for (var i=0;i'+'$1'+''+htag+'>');
}
// underscores count as part of a word, so do them separately
re = new RegExp('\\b_(.+?)_\\b','g');
r = r.replace(re,'$1');
//jeff: so do dashes
re = new RegExp('[\s\n]-(.+?)-[\s\n]','g');
r = r.replace(re,'$1');
// links
re = new RegExp('"\\b(.+?)\\(\\b(.+?)\\b\\)":([^\\s]+)','g');
r = r.replace(re,'$1');
re = new RegExp('"\\b(.+?)\\b":([^\\s]+)','g');
r = r.replace(re,'$1');
// images
re = new RegExp('!\\b(.+?)\\(\\b(.+?)\\b\\)!','g');
r = r.replace(re,'');
re = new RegExp('!\\b(.+?)\\b!','g');
r = r.replace(re,'');
// block level formatting
// Jeff's hack to show single line breaks as they should.
// insert breaks - but you get some....stupid ones
re = new RegExp('(.*)\n([^#\*\n].*)','g');
r = r.replace(re,'$1
$2');
// remove the stupid breaks.
re = new RegExp('\n
','g');
r = r.replace(re,'\n');
lines = r.split('\n');
nr = '';
for (var i=0;i')+'';
changed = 1;
}
// jeff adds h#.
if (line.search(/^\s*h[2|3|4|5|6]\.\s+/) != -1) {
re = new RegExp('h([2|3|4|5|6])\.(.+)','g');
line = line.replace(re,'$2');
changed = 1;
}
if (line.search(/^\s*\*\s+/) != -1) { line = line.replace(/^\s*\*\s+/,'\t') + ''; changed = 1; } // * for bullet list; make up an liu tag to be fixed later
if (line.search(/^\s*#\s+/) != -1) { line = line.replace(/^\s*#\s+/,'\t') + ''; changed = 1; } // # for numeric list; make up an lio tag to be fixed later
if (!changed && (line.replace(/\s/g,'').length > 0)) line = ''+line+'
';
lines[i] = line + '\n';
}
// Second pass to do lists
inlist = 0;
listtype = '';
for (var i=0;i AND
r = r.replace(/li[o|u]>/g,'li>');
return r;
}
});
});