-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Initial Quick Docs implementation #3449
Changes from 2 commits
058275f
fe83c92
737b5b9
e40867c
0f5caab
aaed25e
01e5c56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="css-prop-defn" tabIndex="0"> <!-- tabIndex needed: otherwise click focuses CodeMirror scroller --> | ||
<h1>{{propName}}</h1> | ||
<div class="css-prop-summary"> | ||
<h2>{{DOCS_SUMMARY}}</h2> | ||
<div>{{{summary}}}</div> | ||
</div> | ||
<div class="css-prop-values"> | ||
<h2>{{DOCS_VALUES}}</h2> | ||
<div> | ||
{{#propValues}} | ||
<dl> | ||
<dt>{{value}}</dt> | ||
<dd>{{{description}}}</dd> | ||
</dl> | ||
{{/propValues}} | ||
</div> | ||
</div> | ||
<p class="more-info"><a href="{{url}}">{{DOCS_MORE_LINK}}</a></p> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | ||
/*global define, brackets, $, window, Mustache */ | ||
|
||
/** | ||
* Inline widget to display WebPlatformDocs JSON data nicely formatted | ||
*/ | ||
define(function (require, exports, module) { | ||
'use strict'; | ||
|
||
// Load Brackets modules | ||
var InlineWidget = brackets.getModule("editor/InlineWidget").InlineWidget, | ||
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), | ||
Strings = brackets.getModule("strings"), | ||
NativeApp = brackets.getModule("utils/NativeApp"); | ||
|
||
// Load template | ||
var inlineEditorTemplate = require("text!InlineDocsViewer.html"); | ||
|
||
// Load CSS | ||
ExtensionUtils.loadStyleSheet(module, "WebPlatformDocs.less"); | ||
|
||
|
||
/** | ||
* @param {!string} cssPropName | ||
* @param {!{SUMMARY:string, URL:string, VALUES:Array.<{TITLE:string, DESCRIPTION:string}>}} cssPropDetails | ||
*/ | ||
function InlineDocsViewer(cssPropName, cssPropDetails) { | ||
this.cssPropName = cssPropName; | ||
this.cssPropDetails = cssPropDetails; | ||
InlineWidget.call(this); | ||
} | ||
|
||
InlineDocsViewer.prototype = Object.create(InlineWidget.prototype); | ||
InlineDocsViewer.prototype.constructor = InlineDocsViewer; | ||
InlineDocsViewer.prototype.parentClass = InlineWidget.prototype; | ||
|
||
InlineDocsViewer.prototype.cssPropName = null; | ||
InlineDocsViewer.prototype.cssPropDefn = null; | ||
InlineDocsViewer.prototype.$wrapperDiv = null; | ||
|
||
InlineDocsViewer.prototype.load = function (hostEditor) { | ||
InlineDocsViewer.prototype.parentClass.load.apply(this, arguments); | ||
|
||
var propValues = this.cssPropDetails.VALUES.map(function (valueInfo) { | ||
return { value: valueInfo.TITLE, description: valueInfo.DESCRIPTION }; | ||
}); | ||
|
||
var templateVars = $.extend({ | ||
propName: this.cssPropName, | ||
summary: this.cssPropDetails.SUMMARY, | ||
propValues: propValues, | ||
url: this.cssPropDetails.URL | ||
}, Strings); | ||
|
||
var html = Mustache.render(inlineEditorTemplate, templateVars); | ||
|
||
this.$wrapperDiv = $(html); | ||
this.$htmlContent.append(this.$wrapperDiv); | ||
|
||
this.$wrapperDiv.on("click", "a", function (event) { | ||
event.preventDefault(); | ||
var url = $(event.target).attr("href"); | ||
if (url) { | ||
// URLs in JSON data are relative | ||
if (url.substr(0, 4) !== "http") { | ||
url = "http://docs.webplatform.org" + (url.charAt(0) !== "/" ? "/" : "") + url.replace(" ", "_"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replacing spaces with underscores? Is that something we should cleanup in the JSON file? I also noticed a lot of unnecessary escaping of forward slashes. One more thought on URLs. Here's an example from the length link in padding-bottom:
The embedded HTML link specifies a title. Can we rewrite this to display the actual link instead? Otherwise, the user has no idea what the destination URL is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some searching in the JSON file and couldn't find any links containing spaces, so I'll just take that code out. I mentioned the unneeded forward-slash escaping to Adam; hopefully he can correct that. I'll also add code to preprocess the link tags and fixup the tooltips. |
||
} | ||
NativeApp.openURLInDefaultBrowser(url); | ||
} | ||
}); | ||
|
||
}; | ||
|
||
InlineDocsViewer.prototype.onAdded = function () { | ||
InlineDocsViewer.prototype.parentClass.onAdded.apply(this, arguments); | ||
window.setTimeout(this._sizeEditorToContent.bind(this)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for this to be async? I noticed the jump in size when initially displaying the docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's what InlineColorEditor and the sample InlineImageViewer do, so I'm assuming there's some reason for it. But I agree it shouldn't be necessary -- we're already in the CM DOM by the time this gets called. I'll investigate a little more... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the setTimeout() was a hack specific to InlineImageViewer that got erroneously copied into InlineColorEditor. Inline text editors set their size synch in onAdded() and work just fine. So I'll remove the timeout from both here and InlineColorEditor. |
||
}; | ||
|
||
InlineDocsViewer.prototype._sizeEditorToContent = function () { | ||
this.hostEditor.setInlineWidgetHeight(this, this.$htmlContent.height() + 20, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skipping review here until final UI. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually...what's the plan for updating the scrollers when the window resizes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By 'scrollers' I assume you mean the height of the inline widget? I hadn't thought of that :-) Will fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. Yes, thanks for assuming that. |
||
|
||
// TODO: scroll only right-hand pane | ||
// var summaryHt = this.$wrapperDiv.find(".css-prop-summary").height(); | ||
// this.hostEditor.setInlineWidgetHeight(this, summaryHt + 20, true); | ||
}; | ||
|
||
module.exports = InlineDocsViewer; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally we ask extensions to add menus within the extension and not in DefaultMenus right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but this isn't an extension Command, is a new Quick Docs Command handled by the Editor Manager and the extension just adds a new Quick Docs provider that uses this command, just like Quick Edit works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. Thanks for catching my mistake. :)