/*
* ChiliToolbar v1.4
*
* Copyright (c) 2008 Orkan (orkans@gmail.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Installation:
* Put these two lines in
section, after jquery.chili.js
*
* '+$.data(el, "chili.text").replace("&", "&")+'');
wnd.document.close();
}
},
CopyToClipboard: {
Label: "copy to clipboard",
Cmd: function(el){
if(window.clipboardData) {
window.clipboardData.setData("text", $.data(el, "chili.text"));
ChiliBook.Toolbar.Lang.Clipboard_Y && alert(ChiliBook.Toolbar.Lang.Clipboard_Y);
}
else if(ChiliBook.Toolbar.Clipboard.Swf) {
if(!ChiliBook.Toolbar.Clipboard.Div) ChiliBook.Toolbar.Clipboard.Div = $("
").appendTo(document.body);
ChiliBook.Toolbar.Clipboard.Div.html(' ');
ChiliBook.Toolbar.Lang.Clipboard_Y && alert(ChiliBook.Toolbar.Lang.Clipboard_Y);
}
else ChiliBook.Toolbar.Lang.Clipboard_N && alert(ChiliBook.Toolbar.Lang.Clipboard_N);
}
},
PrintSource: {
Label: "print",
Cmd: function(el){
var ifr = $("").css({position:"absolute", width:0, height:0, left:0, top:0}).appendTo(document.body).get(0);
var doc = ifr.contentWindow.document;
var p = el.parentNode;
ChiliBook.Toolbar.Utils.CopyStyles(doc);
doc.write('<'+p.tagName+' class="'+p.className+'"><'+el.tagName+' class="'+el.className+'">'+el.innerHTML+''+el.tagName+'>'+p.tagName+'>');
doc.close();
ifr.contentWindow.focus();
ifr.contentWindow.print();
alert(ChiliBook.Toolbar.Lang.Printing);
document.body.removeChild(ifr);
}
},
About: {
Label: "?",
Cmd: function(el){
var tpl = '';
var wnd = window.open("", "", "width=300, height=200, scrollbars=0");
var doc = wnd.document;
ChiliBook.Toolbar.Utils.CopyStyles(doc);
doc.write(tpl.replace('{V}', ChiliBook.Toolbar.Version).replace('{T}', ChiliBook.Toolbar.Utils.PopUpTarget));
doc.close();
wnd.focus();
}
}
},
Clipboard: {
Swf: "documentation/chili-toolbar/clipboard.swf",
Div: null
},
Utils: {
CopyStyles: function(doc) {
for(var i = 0; i < document.styleSheets.length; i++)
{
var style = document.styleSheets[i];
var owner = style.ownerNode ? style.ownerNode : style.owningElement;
var media = typeof style.media == "string" ? style.media : style.media.mediaText;
if(owner.tagName.toLowerCase() == 'link') doc.write(' ');
else doc.write('');
}
doc.write('');
},
IEOverflowFix: "1.5em",
FFOverflowFix: "1.5em",
PopUpTarget: "main"
},
Lang: {
Clipboard_Y: "The code is in your clipboard now",
Clipboard_N: "Sorry, the code cannot be copied to your clipboard",
Printing: "Printing..."
}
};
$.fn.chili = function(options) {
// Prepare toolbar
this.bind("chili.before_coloring", function()
{
var self = this,
$this = $(this),
$bar = $("
").addClass("bar"),
$tools = $("
").addClass("tools");
$.each(ChiliBook.Toolbar.Command, function(key, obj){ // TODO: need some improvements here
$(''+obj.Label+' ')
.click(function(){ obj.Cmd(self); })
.appendTo($tools);
});
$this.before($bar.append($tools));
$this.data("chili.text", $this.text());
});
this.bind("chili.after_coloring", function()
{
// Browser specific overflow bug fixes
if(this.scrollWidth > this.offsetWidth)
{
var fixCSS = null;
if($.browser.msie && ChiliBook.Toolbar.Utils.IEOverflowFix)
{
fixCSS = {"padding-bottom": ChiliBook.Toolbar.Utils.IEOverflowFix, "overflow-y": "hidden"};
}
else
{
// Note: this bug should be applied to elements with single line of code only
if($.browser.mozilla && ChiliBook.Toolbar.Utils.FFOverflowFix)
{
// I dont know why with ChiliBook.lineNumbers == true theres no elements at "chili.after_coloring" hook ?
// This happens when ChiliBook.recipeFolder is in use...
// var lines = (ChiliBook.lineNumbers || (options && options.lineNumbers)) ? $(this).find('li') : $(this).html().match(/ /ig) || [];
// if(lines.length == 1)
var li = $(this).find('li').length;
var nl = $(this).html().match(/(\x0A| )/ig);
if( (li == 1) || (nl && nl.length == 1) || (!li && !nl) )
{
fixCSS = {"line-height": ChiliBook.Toolbar.Utils.FFOverflowFix};
}
}
}
if(fixCSS)
{
$(this).css(fixCSS);
}
}
});
// Apply Chili
ChiliBook.Toolbar.Chili.apply(this, [options]);
};
})(jQuery);