| 82 | |
| 83 | // init and build editor |
| 84 | function init() { |
| 85 | id = ''; nameSpace = ''; |
| 86 | if (options.id) { |
| 87 | id = 'id="'+options.id+'"'; |
| 88 | } else if ($$.attr("id")) { |
| 89 | id = 'id="markItUp'+($$.attr("id").substr(0, 1).toUpperCase())+($$.attr("id").substr(1))+'"'; |
| 90 | |
| 91 | } |
| 92 | if (options.nameSpace) { |
| 93 | nameSpace = 'class="'+options.nameSpace+'"'; |
| 94 | } |
| 95 | $$.wrap('<div '+nameSpace+'></div>'); |
| 96 | $$.wrap('<div '+id+' class="markItUp"></div>'); |
| 97 | $$.wrap('<div class="markItUpContainer"></div>'); |
| 98 | $$.addClass("markItUpEditor"); |
| 99 | |
| 100 | // add the header before the textarea |
| 101 | header = $('<div class="markItUpHeader"></div>').insertBefore($$); |
| 102 | $(dropMenus(options.markupSet)).appendTo(header); |
| 103 | |
| 104 | // add the footer after the textarea |
| 105 | footer = $('<div class="markItUpFooter"></div>').insertAfter($$); |
| 106 | |
| 107 | // add the resize handle after textarea |
| 108 | if (options.resizeHandle === true && $.browser.safari !== true) { |
| 109 | resizeHandle = $('<div class="markItUpResizeHandle"></div>') |
| 110 | .insertAfter($$) |
| 111 | .bind("mousedown", function(e) { |
| 112 | var h = $$.height(), y = e.clientY, mouseMove, mouseUp; |
| 113 | mouseMove = function(e) { |
| 114 | $$.css("height", Math.max(20, e.clientY+h-y)+"px"); |
| 115 | return false; |
| 116 | }; |
| 117 | mouseUp = function(e) { |
| 118 | $("html").unbind("mousemove", mouseMove).unbind("mouseup", mouseUp); |
| 119 | return false; |
| 120 | }; |
| 121 | $("html").bind("mousemove", mouseMove).bind("mouseup", mouseUp); |
| 122 | }); |
| 123 | footer.append(resizeHandle); |
| 124 | } |
| 125 | |
| 126 | // listen key events |
| 127 | $$.keydown(keyPressed).keyup(keyPressed); |
| 128 | |
| 129 | // bind an event to catch external calls |
| 130 | $$.bind("insertion", function(e, settings) { |
| 131 | if (settings.target !== false) { |
| 132 | get(); |
| 133 | } |
| 134 | if (textarea === $.markItUp.focused) { |
| 135 | markup(settings); |
| 136 | } |
| 137 | }); |
| 138 | |
| 139 | // remember the last focus |
| 140 | $$.focus(function() { |
| 141 | $.markItUp.focused = this; |