Repository navigation
Expand file tree
/
Copy pathInlineDocsViewer.js
More file actions
1 lines (1 loc) · 3.6 KB
/
Copy pathInlineDocsViewer.js
File metadata and controls
1 lines (1 loc) · 3.6 KB
1
define(function(require,exports,module){var Dialogs=brackets.getModule("widgets/Dialogs"),ExtensionUtils=brackets.getModule("utils/ExtensionUtils"),InlineWidget=brackets.getModule("editor/InlineWidget").InlineWidget,KeyEvent=brackets.getModule("utils/KeyEvent"),Strings=brackets.getModule("strings"),Mustache=brackets.getModule("thirdparty/mustache/mustache"),Metrics=brackets.getModule("utils/Metrics"),inlineEditorTemplate=require("text!InlineDocsViewer.html"),SCROLL_LINE_HEIGHT=40;function InlineDocsViewer(PropName,PropDetails){InlineWidget.call(this);var templateVars={propName:PropName,summary:PropDetails.SUMMARY,fullscreenSummary:!(PropDetails.VALUES&&PropDetails.VALUES.length),propValues:PropDetails.VALUES||[],url:PropDetails.URL,Strings:Strings},html=Mustache.render(inlineEditorTemplate,templateVars);this.$wrapperDiv=$(html),this.$htmlContent.append(this.$wrapperDiv),Dialogs.addLinkTooltips(this.$wrapperDiv),this._sizeEditorToContent=this._sizeEditorToContent.bind(this),this._handleWheelScroll=this._handleWheelScroll.bind(this),this.$scroller=this.$wrapperDiv.find(".scroller"),this.$scroller.on("mousewheel",this._handleWheelScroll),this.$moreinfo=this.$wrapperDiv.find(".more-info"),this.$moreinfo.on("click",this._logAnalyticsData),this._onKeydown=this._onKeydown.bind(this)}ExtensionUtils.loadStyleSheet(module,"MDNDocs.less"),InlineDocsViewer.prototype=Object.create(InlineWidget.prototype),InlineDocsViewer.prototype.constructor=InlineDocsViewer,InlineDocsViewer.prototype.parentClass=InlineWidget.prototype,InlineDocsViewer.prototype.$wrapperDiv=null,InlineDocsViewer.prototype.$scroller=null,InlineDocsViewer.prototype._handleScrolling=function(event,scrollingUp,scroller){return event.stopPropagation(),scrollingUp&&0===scroller.scrollTop?(event.preventDefault(),!0):!scrollingUp&&scroller.scrollTop+scroller.clientHeight>=scroller.scrollHeight&&(event.preventDefault(),!0)},InlineDocsViewer.prototype._handleWheelScroll=function(event){var scrollingUp=event.originalEvent.wheelDeltaY>0,scroller=event.currentTarget;scroller.clientHeight>=scroller.scrollHeight||this._handleScrolling(event,scrollingUp,scroller)},InlineDocsViewer.prototype._onKeydown=function(event){var keyCode=event.keyCode,scroller=this.$scroller[0],scrollPos;if(event.altKey||event.ctrlKey||event.metaKey||event.shiftKey)return!1;switch(scrollPos=scroller.scrollTop,keyCode){case KeyEvent.DOM_VK_UP:scrollPos=Math.max(0,scrollPos-40);break;case KeyEvent.DOM_VK_PAGE_UP:scrollPos=Math.max(0,scrollPos-scroller.clientHeight);break;case KeyEvent.DOM_VK_DOWN:scrollPos=Math.min(scroller.scrollHeight-scroller.clientHeight,scrollPos+40);break;case KeyEvent.DOM_VK_PAGE_DOWN:scrollPos=Math.min(scroller.scrollHeight-scroller.clientHeight,scrollPos+scroller.clientHeight);break;default:return!1}return scroller.scrollTop=scrollPos,event.stopPropagation(),event.preventDefault(),!0},InlineDocsViewer.prototype.onAdded=function(){InlineDocsViewer.prototype.parentClass.onAdded.apply(this,arguments),this._sizeEditorToContent(),$(window).on("resize",this._sizeEditorToContent),this.$scroller[0].focus(),this.$wrapperDiv[0].addEventListener("keydown",this._onKeydown,!0)},InlineDocsViewer.prototype.onClosed=function(){InlineDocsViewer.prototype.parentClass.onClosed.apply(this,arguments),$(window).off("resize",this._sizeEditorToContent),this.$wrapperDiv[0].removeEventListener("keydown",this._onKeydown,!0)},InlineDocsViewer.prototype._sizeEditorToContent=function(){this.hostEditor.setInlineWidgetHeight(this,this.$wrapperDiv.height()+20,!0)},InlineDocsViewer.prototype._logAnalyticsData=function(){return Metrics.countEvent("MDNDocs","QuickDoc","ReadMore"),!1},module.exports=InlineDocsViewer});