/*********************************************** * PAGE INIT ***********************************************/ // Event handler attachment function registerEventHandler (element, event, handler) { if (element.attachEvent) { element.attachEvent('on' + event, handler); } else if (element.addEventListener) { element.addEventListener(event, handler, false); } else { element[event] = handler; } } // Event handler detachment function unregisterEventHandler(element, event, handler) { if (typeof element.removeEventListener == "function") element.removeEventListener(event, handler, false); else element.detachEvent("on" + event, handler); } //element manipulation //window.onload=init; registerEventHandler(window, 'load', init); function init() { try { fixMoniker(); fixMsdnLinks(); mergeCodeSnippets(); loadLangFilter(); showSelectedLanguages(); } catch (e) { //alert(e + "/n" + e.stack); } } /*********************************************** * END PAGE INIT ***********************************************/ /********************************************** * EXPAND / COLLAPSE SECTION **********************************************/ function toggleSection(sectionLinkElm) { var sectionDiv = sectionLinkElm.parentNode.parentNode.parentNode; if (hasElementClass(sectionDiv, "collapsed")) { expandSection(sectionLinkElm); } else { collapseSection(sectionLinkElm); } } function expandSection(sectionLinkElm) { var sectionDiv = sectionLinkElm.parentNode.parentNode.parentNode; removeClassFromElement(sectionDiv, "collapsed"); sectionLinkElm.setAttribute("title", "Collapse"); } function collapseSection(sectionLinkElm) { var sectionDiv = sectionLinkElm.parentNode.parentNode.parentNode; addClassToElement(sectionDiv, "collapsed"); sectionLinkElm.setAttribute("title", "Expand"); } /********************************************** * END EXPAND / COLLAPSE SECTION **********************************************/ /*********************************************** * CODE SNIPPETS ***********************************************/ /** * Merges adjacent code snippets in different languages into * single code collection with tabs. */ function mergeCodeSnippets() { var allNodes = getElementAndTextNodes(document.body); var parentCodeSnippet = null; var i; for (i=0; i=0; i--) { if (classes[i].toLowerCase() == className) { classes.splice(i, 1); } } elm.className = classes.join(" "); } } /** * Adds specified CSS class to an element. */ function addClassToElement(elm, className) { if (elm == null) return; if (elm.className) { var classes = elm.className.split(" "); var classNameLow = className.toLowerCase(); var i; for (i=classes.length-1; i>=0; i--) { if (classes[i].toLowerCase() == classNameLow) { // class already exists return; } } classes[classes.length] = className; elm.className = classes.join(" "); } else { elm.className = className; } } /** * Superfast trim. Faster than pure regex solution. */ String.prototype.trim = function () { var str = this.replace(/^\s\s*/, ''), ws = /\s/, i = str.length; while (ws.test(str.charAt(--i))); return str.slice(0, i + 1); } /*********************************************** * END CODE SNIPPETS ***********************************************/ /*********************************************** * LANGUAGE FILTER ***********************************************/ // Specifies which language tab is shown as default for the first time. // Possible values: "codeVB", "codeCsharp", "codeCpp", "codeFsharp", "codeJScript" var DEFAULT_LANGUAGE_TO_SHOW = "codeCsharp"; var languageToShow = DEFAULT_LANGUAGE_TO_SHOW; function loadLangFilter() { languageToShow = loadSetting("languageToShow", DEFAULT_LANGUAGE_TO_SHOW); } function saveLangFilter() { saveSetting("languageToShow", languageToShow); } /** * Hides/shows the language sections according to language filter * @param langCode "VB", "Csharp", "Cpp", "Fsharp", "JScript" */ function CodeSnippet_SetLanguage(langCode) { languageToShow = "code" + langCode; showSelectedLanguages(); saveLangFilter(); } /** * A snippet is a DIV with class="codeSnippetContainer". */ function getAllCodeSnippets() { var divTags = document.getElementsByTagName("div"); var snippets = new Array(); var i, j; j = 0; for (i=0; i var code; code = shownCode.innerHTML; code = code.replace(/
/gi, "\n"); code = code.replace(/<\/td>/gi, "\n"); // syntax highlighter removes \n chars and puts each line in separate code = code.trim(); // remove leading spaces which are unwanted in FF // get plain text var tmpDiv = document.createElement('div'); tmpDiv.innerHTML = code; if (typeof(tmpDiv.textContent) != "undefined") { // standards compliant code = tmpDiv.textContent; } else if (typeof(tmpDiv.innerText) != "undefined") { // IE only code = tmpDiv.innerText; } try { // works in IE only window.clipboardData.setData("Text", code); } catch (ex) { popCodeWindow(code); } } } catch (e) { } } function popCodeWindow(code) { try { var codeWindow = window.open ("", "Copy the selected code", "location=0,status=0,toolbar=0,menubar =0,directories=0,resizable=1,scrollbars=1,height=400, width=400"); codeWindow.document.writeln(""); codeWindow.document.writeln(""); codeWindow.document.writeln("Copy the selected code"); codeWindow.document.writeln(""); codeWindow.document.writeln(""); codeWindow.document.writeln('
');
		codeWindow.document.writeln(escapeHTML(code));
		codeWindow.document.writeln("
"); codeWindow.document.writeln(""); // the selectNode function below, converted by http://www.howtocreate.co.uk/tutorials/jsexamples/syntax/prepareInline.html var ftn = "function selectNode (node) {\n\tvar selection, range, doc, win;\n\tif ((doc = node.ownerDocument) && \n\t\t(win = doc.defaultView) && \n\t\ttypeof win.getSelection != \'undefined\' && \n\t\ttypeof doc.createRange != \'undefined\' && \n\t\t(selection = window.getSelection()) && \n\t\ttypeof selection.removeAllRanges != \'undefined\') {\n\t\t\t\n\t\trange = doc.createRange();\n\t\trange.selectNode(node);\n selection.removeAllRanges();\n selection.addRange(range);\n\t} else if (document.body && \n\t\t\ttypeof document.body.createTextRange != \'undefined\' && \n\t\t\t(range = document.body.createTextRange())) {\n \n\t\t \trange.moveToElementText(node);\n \trange.select();\n }\n} "; codeWindow.document.writeln(ftn); codeWindow.document.writeln("selectNode(document.getElementById('code_text'));"); codeWindow.document.writeln(""); codeWindow.document.writeln(""); codeWindow.document.close(); } catch (ex) {} } function escapeHTML (str) { return str.replace(/&/g,"&"). replace(/>/g,">"). replace(/ in HxS format takes care of it, redirect.htm used in CHM format doesn't. So we must do it. */ var res = keyword; res = res.replace(/,/g, "\t"); res = res.replace(/;/g, "\n"); res = escape(res); return res; } /** * Converts MSDN2 keyword (cref) to MSDN2 web link */ function convertMsdnKeywordToMsdn2Link(keyword) { var res = keyword; // remove prefix res = res.replace(/^.+:(.*)/g, "$1"); // remove parameters res = res.replace(/(.*)\(.*/g, "$1"); res = res.toLowerCase(); res = "http://msdn.microsoft.com/en-us/library/" + res + ".aspx"; return res; } // Highest MSDN version installed. var msdnVersion; /** * Returns highest MSDN version installed. * @return The MSDN version found in format 8.0 or 9.0 or web. If none is found, * the "web" is returned. */ function getHighestMsdnVersion () { var MSDN_9_CSS = "ms-help://MS.VSCC.v90/dv_vscccommon/styles/presentation.css"; var MSDN_8_CSS = "ms-help://MS.VSCC.v80/dv_vscccommon/local/Classic.css"; if (cssFileExists(MSDN_9_CSS)) { return "9.0"; } if (cssFileExists(MSDN_8_CSS)) { return "8.0"; } return "web"; } /** * Tests whether specified CSS url exists. */ function cssFileExists(cssUrl) { var sheet = null var temporary = false res = false; // first detect whether this CSS is already used in this document (it should be) try { var i; for (i=0; i 0) { res = true } } else if (sheet.cssRules) { // FF if (sheet.cssRules.length > 0) { res = true } } } catch (ex) { } return res; } /*********************************************** * END MSDN LINKS FIX ***********************************************/