适合具备 C 语言基础的 C++ 教程(六)

C++
wenzi 嵌入式软件
发布时间: 2021-02-22
阅读: 1464
");markdownTextarea =this.markdownTextarea =editor.children("textarea");} markdownTextarea.addClass(classNames.textarea.markdown).attr("placeholder",settings.placeholder);if (typeof markdownTextarea.attr("name") ==="undefined" ||markdownTextarea.attr("name") ==="") {markdownTextarea.attr("name",(settings.name !=="") ?settings.name :id + "-markdown-doc");} var appendElements =[(!settings.readOnly) ?"" :"",((settings.saveHTMLToTextarea) ?"" :"" ),"
","
","
" ].join("\n");editor.append(appendElements).addClass(classPrefix + "vertical");if (settings.theme !=="") {editor.addClass(classPrefix + "theme-" + settings.theme);} this.mask =editor.children("." + classPrefix + "mask");this.containerMask =editor.children("." + classPrefix + "container-mask");if (settings.markdown !=="") {markdownTextarea.val(settings.markdown);} if (settings.appendMarkdown !=="") {markdownTextarea.val(markdownTextarea.val() + settings.appendMarkdown);} this.htmlTextarea =editor.children("." + classNames.textarea.html);this.preview =editor.children("." + classPrefix + "preview");this.previewContainer =this.preview.children("." + classPrefix + "preview-container");if (settings.previewTheme !=="") {this.preview.addClass(classPrefix + "preview-theme-" + settings.previewTheme);} if (typeof define ==="function" &&define.amd) {if (typeof katex !=="undefined") {editormd.$katex =katex;} if (settings.searchReplace &&!settings.readOnly) {editormd.loadCSS(settings.path + "codemirror/addon/dialog/dialog");editormd.loadCSS(settings.path + "codemirror/addon/search/matchesonscrollbar");} } if ((typeof define ==="function" &&define.amd) ||!settings.autoLoadModules) {if (typeof CodeMirror !=="undefined") {editormd.$CodeMirror =CodeMirror;} if (typeof marked !=="undefined") {editormd.$marked =marked;} this.setCodeMirror().setToolbar().loadedDisplay();} else {this.loadQueues();} return this;},loadQueues :function() {var _this =this;var settings =this.settings;var loadPath =settings.path;var loadFlowChartOrSequenceDiagram =function() {if (editormd.isIE8) {_this.loadedDisplay();return ;} if (settings.flowChart ||settings.sequenceDiagram) {editormd.loadScript(loadPath + "raphael.min",function() {editormd.loadScript(loadPath + "underscore.min",function() {if (!settings.flowChart &&settings.sequenceDiagram) {editormd.loadScript(loadPath + "sequence-diagram.min",function() {_this.loadedDisplay();});} else if (settings.flowChart &&!settings.sequenceDiagram) {editormd.loadScript(loadPath + "flowchart.min",function() {editormd.loadScript(loadPath + "jquery.flowchart.min",function() {_this.loadedDisplay();});});} else if (settings.flowChart &&settings.sequenceDiagram) {editormd.loadScript(loadPath + "flowchart.min",function() {editormd.loadScript(loadPath + "jquery.flowchart.min",function() {editormd.loadScript(loadPath + "sequence-diagram.min",function() {_this.loadedDisplay();});});});} });});} else {_this.loadedDisplay();} };editormd.loadCSS(loadPath + "codemirror/codemirror.min");if (settings.searchReplace &&!settings.readOnly) {editormd.loadCSS(loadPath + "codemirror/addon/dialog/dialog");editormd.loadCSS(loadPath + "codemirror/addon/search/matchesonscrollbar");} if (settings.codeFold) {editormd.loadCSS(loadPath + "codemirror/addon/fold/foldgutter");} editormd.loadScript(loadPath + "codemirror/codemirror.min",function() {editormd.$CodeMirror =CodeMirror;editormd.loadScript(loadPath + "codemirror/modes.min",function() {editormd.loadScript(loadPath + "codemirror/addons.min",function() {_this.setCodeMirror();if (settings.mode !=="gfm" &&settings.mode !=="markdown") {_this.loadedDisplay();return false;} _this.setToolbar();editormd.loadScript(loadPath + "marked.min",function() {editormd.$marked =marked;if (settings.previewCodeHighlight) {editormd.loadScript(loadPath + "prettify.min",function() {loadFlowChartOrSequenceDiagram();});} else {loadFlowChartOrSequenceDiagram();} });});});});return this;},setTheme :function(theme) {var editor =this.editor;var oldTheme =this.settings.theme;var themePrefix =this.classPrefix + "theme-";editor.removeClass(themePrefix + oldTheme).addClass(themePrefix + theme);this.settings.theme =theme;return this;},setEditorTheme :function(theme) {var settings =this.settings;settings.editorTheme =theme;if (theme !=="default") {editormd.loadCSS(settings.path + "codemirror/theme/" + settings.editorTheme);} this.cm.setOption("theme",theme);return this;},setCodeMirrorTheme :function (theme) {this.setEditorTheme(theme);return this;},setPreviewTheme :function(theme) {var preview =this.preview;var oldTheme =this.settings.previewTheme;var themePrefix =this.classPrefix + "preview-theme-";preview.removeClass(themePrefix + oldTheme).addClass(themePrefix + theme);this.settings.previewTheme =theme;return this;},setCodeMirror :function() {var settings =this.settings;var editor =this.editor;if (settings.editorTheme !=="default") {editormd.loadCSS(settings.path + "codemirror/theme/" + settings.editorTheme);} var codeMirrorConfig ={mode :settings.mode,theme :settings.editorTheme,tabSize :settings.tabSize,dragDrop :false,autofocus :settings.autoFocus,autoCloseTags :settings.autoCloseTags,readOnly :(settings.readOnly) ?"nocursor" :false,indentUnit :settings.indentUnit,lineNumbers :settings.lineNumbers,lineWrapping :settings.lineWrapping,extraKeys :{"Ctrl-Q":function(cm) {cm.foldCode(cm.getCursor());} },foldGutter :settings.codeFold,gutters :["CodeMirror-linenumbers","CodeMirror-foldgutter"],matchBrackets :settings.matchBrackets,indentWithTabs :settings.indentWithTabs,styleActiveLine :settings.styleActiveLine,styleSelectedText :settings.styleSelectedText,autoCloseBrackets :settings.autoCloseBrackets,showTrailingSpace :settings.showTrailingSpace,highlightSelectionMatches :((!settings.matchWordHighlight) ?false :{showToken:(settings.matchWordHighlight ==="onselected") ?false :/\w/ } ) };this.codeEditor =this.cm =editormd.$CodeMirror.fromTextArea(this.markdownTextarea[0],codeMirrorConfig);this.codeMirror =this.cmElement =editor.children(".CodeMirror");if (settings.value !=="") {this.cm.setValue(settings.value);} this.codeMirror.css({fontSize :settings.fontSize,width :(!settings.watch) ?"100%" :"50%" });if (settings.autoHeight) {this.codeMirror.css("height","auto");this.cm.setOption("viewportMargin",Infinity);} if (!settings.lineNumbers) {this.codeMirror.find(".CodeMirror-gutters").css("border-right","none");} return this;},getCodeMirrorOption :function(key) {return this.cm.getOption(key);},setCodeMirrorOption :function(key,value) {this.cm.setOption(key,value);return this;},addKeyMap :function(map,bottom) {this.cm.addKeyMap(map,bottom);return this;},removeKeyMap :function(map) {this.cm.removeKeyMap(map);return this;},gotoLine :function (line) {var settings =this.settings;if (!settings.gotoLine) {return this;} var cm =this.cm;var editor =this.editor;var count =cm.lineCount();var preview =this.preview;if (typeof line ==="string") {if(line ==="last") {line =count;} if (line ==="first") {line =1;} } if (typeof line !=="number") {alert("Error: The line number must be an integer.");return this;} line =parseInt(line) - 1;if (line >count) {alert("Error: The line number range 1-" + count);return this;} cm.setCursor({line :line,ch :0} );var scrollInfo =cm.getScrollInfo();var clientHeight =scrollInfo.clientHeight;var coords =cm.charCoords({line :line,ch :0},"local");cm.scrollTo(null,(coords.top + coords.bottom - clientHeight) / 2);if (settings.watch) {var cmScroll =this.codeMirror.find(".CodeMirror-scroll")[0];var height =$(cmScroll).height();var scrollTop =cmScroll.scrollTop;var percent =(scrollTop / cmScroll.scrollHeight);if (scrollTop ===0) {preview.scrollTop(0);} else if (scrollTop + height >=cmScroll.scrollHeight - 16) {preview.scrollTop(preview[0].scrollHeight);} else {preview.scrollTop(preview[0].scrollHeight *percent);} } cm.focus();return this;},extend :function() {if (typeof arguments[1] !=="undefined") {if (typeof arguments[1] ==="function") {arguments[1] =$.proxy(arguments[1],this);} this[arguments[0]] =arguments[1];} if (typeof arguments[0] ==="object" &&typeof arguments[0].length ==="undefined") {$.extend(true,this,arguments[0]);} return this;},set :function (key,value) {if (typeof value !=="undefined" &&typeof value ==="function") {value =$.proxy(value,this);} this[key] =value;return this;},config :function(key,value) {var settings =this.settings;if (typeof key ==="object") {settings =$.extend(true,settings,key);} if (typeof key ==="string") {settings[key] =value;} this.settings =settings;this.recreate();return this;},on :function(eventType,callback) {var settings =this.settings;if (typeof settings["on" + eventType] !=="undefined") {settings["on" + eventType] =$.proxy(callback,this);} return this;},off :function(eventType) {var settings =this.settings;if (typeof settings["on" + eventType] !=="undefined") {settings["on" + eventType] =function(){};} return this;},showToolbar :function(callback) {var settings =this.settings;if(settings.readOnly) {return this;} if (settings.toolbar &&(this.toolbar.length < 1 ||this.toolbar.find("." + this.classPrefix + "menu").html() ==="") ) {this.setToolbar();} settings.toolbar =true;this.toolbar.show();this.resize();$.proxy(callback ||function(){},this)();return this;},hideToolbar :function(callback) {var settings =this.settings;settings.toolbar =false;this.toolbar.hide();this.resize();$.proxy(callback ||function(){},this)();return this;},setToolbarAutoFixed :function(fixed) {var state =this.state;var editor =this.editor;var toolbar =this.toolbar;var settings =this.settings;if (typeof fixed !=="undefined") {settings.toolbarAutoFixed =fixed;} var autoFixedHandle =function(){var $window =$(window);var top =$window.scrollTop();if (!settings.toolbarAutoFixed) {return false;} if (top - editor.offset().top >10 &&top < editor.height()) {toolbar.css({position :"fixed",width :editor.width() + "px",left :($window.width() - editor.width()) / 2 + "px" });} else {toolbar.css({position :"absolute",width :"100%",left :0 });} };if (!state.fullscreen &&!state.preview &&settings.toolbar &&settings.toolbarAutoFixed) {$(window).bind("scroll",autoFixedHandle);} return this;},setToolbar :function() {var settings =this.settings;if(settings.readOnly) {return this;} var editor =this.editor;var preview =this.preview;var classPrefix =this.classPrefix;var toolbar =this.toolbar =editor.children("." + classPrefix + "toolbar");if (settings.toolbar &&toolbar.length < 1) {var toolbarHTML ="
    ";editor.append(toolbarHTML);toolbar =this.toolbar =editor.children("." + classPrefix + "toolbar");} if (!settings.toolbar) {toolbar.hide();return this;} toolbar.show();var icons =(typeof settings.toolbarIcons ==="function") ?settings.toolbarIcons() :((typeof settings.toolbarIcons ==="string") ?editormd.toolbarModes[settings.toolbarIcons] :settings.toolbarIcons);var toolbarMenu =toolbar.find("." + this.classPrefix + "menu"),menu ="";var pullRight =false;for (var i =0,len =icons.length;i < len;i++) {var name =icons[i];if (name ==="||") {pullRight =true;} else if (name ==="|") {menu +="
  • |
  • ";} else {var isHeader =(/h(\d)/.test(name));var index =name;if (name ==="watch" &&!settings.watch) {index ="unwatch";} var title =settings.lang.toolbar[index];var iconTexts =settings.toolbarIconTexts[index];var iconClass =settings.toolbarIconsClass[index];title =(typeof title ==="undefined") ?"" :title;iconTexts =(typeof iconTexts ==="undefined") ?"" :iconTexts;iconClass =(typeof iconClass ==="undefined") ?"" :iconClass;var menuItem =pullRight ?"
  • " :"
  • ";if (typeof settings.toolbarCustomIcons[name] !=="undefined" &&typeof settings.toolbarCustomIcons[name] !=="function") {menuItem +=settings.toolbarCustomIcons[name];} else {menuItem +="";menuItem +=""+((isHeader) ?name.toUpperCase() :((iconClass ==="") ?iconTexts :"") ) + "";menuItem +="";} menuItem +="
  • ";menu =pullRight ?menuItem + menu :menu + menuItem;} } toolbarMenu.html(menu);toolbarMenu.find("[title=\"Lowercase\"]").attr("title",settings.lang.toolbar.lowercase);toolbarMenu.find("[title=\"ucwords\"]").attr("title",settings.lang.toolbar.ucwords);this.setToolbarHandler();this.setToolbarAutoFixed();return this;},dialogLockScreen :function() {$.proxy(editormd.dialogLockScreen,this)();return this;},dialogShowMask :function(dialog) {$.proxy(editormd.dialogShowMask,this)(dialog);return this;},getToolbarHandles :function(name) {var toolbarHandlers =this.toolbarHandlers =editormd.toolbarHandlers;return (name &&typeof toolbarIconHandlers[name] !=="undefined") ?toolbarHandlers[name] :toolbarHandlers;},setToolbarHandler :function() {var _this =this;var settings =this.settings;if (!settings.toolbar ||settings.readOnly) {return this;} var toolbar =this.toolbar;var cm =this.cm;var classPrefix =this.classPrefix;var toolbarIcons =this.toolbarIcons =toolbar.find("." + classPrefix + "menu > li > a");var toolbarIconHandlers =this.getToolbarHandles();toolbarIcons.bind(editormd.mouseOrTouch("click","touchend"),function(event) {var icon =$(this).children(".fa");var name =icon.attr("name");var cursor =cm.getCursor();var selection =cm.getSelection();if (name ==="") {return ;} _this.activeIcon =icon;if (typeof toolbarIconHandlers[name] !=="undefined") {$.proxy(toolbarIconHandlers[name],_this)(cm);} else {if (typeof settings.toolbarHandlers[name] !=="undefined") {$.proxy(settings.toolbarHandlers[name],_this)(cm,icon,cursor,selection);} } if (name !=="link" &&name !=="reference-link" &&name !=="image" &&name !=="code-block" &&name !=="preformatted-text" &&name !=="watch" &&name !=="preview" &&name !=="search" &&name !=="fullscreen" &&name !=="info") {cm.focus();} return false;});return this;},createDialog :function(options) {return $.proxy(editormd.createDialog,this)(options);},createInfoDialog :function() {var _this =this;


    原创作品,未经权利人授权禁止转载。详情见转载须知 举报文章

    点赞 (0)
    评论(0)

    登录后可评论,请登录注册

    相关文章推荐
    X
    你的打赏是对原创作者最大的认可
    请选择打赏IC币的数量,一经提交无法退回 !
    100IC币
    500IC币
    1000IC币
    自定义
    IC币
    确定
    X
    提交成功 !谢谢您的支持
    返回

    我要举报该内容理由

    ×
    请输入您举报的理由(50字以内)