MCPcopy Create free account
hub / github.com/unconed/TermKit / quickCodeHandler

Function quickCodeHandler

HTML/external/syntaxhighlighter_3.0.83/src/shCore.js:1123–1166  ·  view source on GitHub ↗

* Quick code mouse double click handler.

(e)

Source from the content-addressed store, hash-verified

1121 * Quick code mouse double click handler.
1122 */
1123function quickCodeHandler(e)
1124{
1125 var target = e.target,
1126 highlighterDiv = findParentElement(target, '.syntaxhighlighter'),
1127 container = findParentElement(target, '.container'),
1128 textarea = document.createElement('textarea'),
1129 highlighter
1130 ;
1131
1132 if (!container || !highlighterDiv || findElement(container, 'textarea'))
1133 return;
1134
1135 highlighter = getHighlighterById(highlighterDiv.id);
1136
1137 // add source class name
1138 addClass(highlighterDiv, 'source');
1139
1140 // Have to go over each line and grab it's text, can't just do it on the
1141 // container because Firefox loses all \n where as Webkit doesn't.
1142 var lines = container.childNodes,
1143 code = []
1144 ;
1145
1146 for (var i = 0; i < lines.length; i++)
1147 code.push(lines[i].innerText || lines[i].textContent);
1148
1149 // using \r instead of \r or \r\n makes this work equally well on IE, FF and Webkit
1150 code = code.join('\r');
1151
1152 // inject <textarea/> tag
1153 textarea.appendChild(document.createTextNode(code));
1154 container.appendChild(textarea);
1155
1156 // preselect all text
1157 textarea.focus();
1158 textarea.select();
1159
1160 // set up handler for lost focus
1161 attachEvent(textarea, 'blur', function(e)
1162 {
1163 textarea.parentNode.removeChild(textarea);
1164 removeClass(highlighterDiv, 'source');
1165 });
1166};
1167
1168/**
1169 * Match object.

Callers

nothing calls this directly

Calls 6

findParentElementFunction · 0.85
findElementFunction · 0.85
getHighlighterByIdFunction · 0.85
addClassFunction · 0.85
attachEventFunction · 0.85
removeClassFunction · 0.85

Tested by

no test coverage detected