MCPcopy Create free account
hub / github.com/ronreiter/interactive-tutorials / markup

Function markup

static/scripts/markitup/jquery.markitup.js:254–341  ·  view source on GitHub ↗
(button)

Source from the content-addressed store, hash-verified

252
253 // define markup to insert
254 function markup(button) {
255 var len, j, n, i;
256 hash = clicked = button;
257 get();
258
259 $.extend(hash, { line:"",
260 root:options.root,
261 textarea:textarea,
262 selection:(selection||''),
263 caretPosition:caretPosition,
264 ctrlKey:ctrlKey,
265 shiftKey:shiftKey,
266 altKey:altKey
267 }
268 );
269 // callbacks before insertion
270 prepare(options.beforeInsert);
271 prepare(clicked.beforeInsert);
272 if (ctrlKey === true && shiftKey === true) {
273 prepare(clicked.beforeMultiInsert);
274 }
275 $.extend(hash, { line:1 });
276
277 if (ctrlKey === true && shiftKey === true) {
278 lines = selection.split(/\r?\n/);
279 for (j = 0, n = lines.length, i = 0; i < n; i++) {
280 if ($.trim(lines[i]) !== '') {
281 $.extend(hash, { line:++j, selection:lines[i] } );
282 lines[i] = build(lines[i]).block;
283 } else {
284 lines[i] = "";
285 }
286 }
287 string = { block:lines.join('\n')};
288 start = caretPosition;
289 len = string.block.length + (($.browser.opera) ? n : 0);
290 } else if (ctrlKey === true) {
291 string = build(selection);
292 start = caretPosition + string.openWith.length;
293 len = string.block.length - string.openWith.length - string.closeWith.length;
294 len -= fixIeBug(string.block);
295 } else if (shiftKey === true) {
296 string = build(selection);
297 start = caretPosition;
298 len = string.block.length;
299 len -= fixIeBug(string.block);
300 } else {
301 string = build(selection);
302 start = caretPosition + string.block.length ;
303 len = 0;
304 start -= fixIeBug(string.block);
305 }
306 if ((selection === '' && string.replaceWith === '')) {
307 caretOffset += fixOperaBug(string.block);
308
309 start = caretPosition + string.openWith.length;
310 len = string.block.length - string.openWith.length - string.closeWith.length;
311

Callers 3

initFunction · 0.85
dropMenusFunction · 0.85
keyPressedFunction · 0.85

Calls 10

prepareFunction · 0.85
buildFunction · 0.85
fixIeBugFunction · 0.85
fixOperaBugFunction · 0.85
refreshPreviewFunction · 0.85
getFunction · 0.70
insertFunction · 0.70
setFunction · 0.70
splitMethod · 0.45
trimMethod · 0.45

Tested by

no test coverage detected