├── DevDocsViewer.css
├── LICENSE
├── README.md
├── devdocs-sprite.svg
├── main.js
├── package.json
└── panel.html
/DevDocsViewer.css:
--------------------------------------------------------------------------------
1 | /* Toolbar icon */
2 | #devdocs-viewer-icon {
3 | background: url(devdocs-sprite.svg);
4 | background-repeat: no-repeat;
5 | background-position: 0 0;
6 | }
7 |
8 | #devdocs-viewer-icon.active {
9 | background-position: 0 -24px !important;
10 | }
11 |
12 | /* DevDocs panel */
13 | #devdocs-viewer-iframe {
14 | background: white;
15 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Glenn Ruehle. All rights reserved.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a
4 | copy of this software and associated documentation files (the "Software"),
5 | to deal in the Software without restriction, including without limitation
6 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 | and/or sell copies of the Software, and to permit persons to whom the
8 | Software is furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 | DEALINGS IN THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## DevDocs Viewer
2 |
3 | This is a [Brackets](http://brackets.io) extension for searching and viewing [devdocs.io](http://devdocs.io) content.
4 |
5 | ## Installation
6 |
7 | * Select **File > Extension Manager...** (or click the "brick" icon in the toolbar)
8 | * Click **Install from URL...**
9 | * Enter the url of this repo
10 | * For Brackets Sprint 27: https://github.com/gruehle/dev-docs-viewer/archive/sprint-27.zip
11 | * For Brackets Sprint 28 (or later): https://github.com/gruehle/dev-docs-viewer
12 | * Click **Install**
13 |
14 | ## How to use
15 |
16 | Click the "book" icon in the toolbar to open and close the viewer panel. The panel can be resized vertically.
17 |
18 | Select **Navigate > Lookup in DevDocs** to search the devdocs.io content using the current editor selection.
19 |
20 | ## Credits
21 |
22 | Thanks to [@DevDocs](http://twitter.com/DevDocs) for the [great content](http://devdocs.io).
23 |
24 | ## Version History
25 |
26 | 07/24/2013 v0.1.1 - New toolbar icon (thanks @larz!)
27 | 07/13/2013 v0.1.0 - Initial release.
28 |
--------------------------------------------------------------------------------
/devdocs-sprite.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013 Glenn Ruehle
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a
5 | * copy of this software and associated documentation files (the "Software"),
6 | * to deal in the Software without restriction, including without limitation
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | * and/or sell copies of the Software, and to permit persons to whom the
9 | * Software is furnished to do so, subject to the following conditions:
10 | *
11 | * The above copyright notice and this permission notice shall be included in
12 | * all copies or substantial portions of the Software.
13 | *
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | * DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | /*
24 | TODO:
25 | - package.json
26 | */
27 |
28 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
29 | /*global define, brackets, $, window */
30 |
31 | define(function (require, exports, module) {
32 | "use strict";
33 |
34 | // Brackets modules
35 | var CommandManager = brackets.getModule("command/CommandManager"),
36 | EditorManager = brackets.getModule("editor/EditorManager"),
37 | ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
38 | KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
39 | Menus = brackets.getModule("command/Menus"),
40 | NativeApp = brackets.getModule("utils/NativeApp"),
41 | PanelManager = brackets.getModule("view/PanelManager");
42 |
43 | // Local modules
44 | var panelHTML = require("text!panel.html");
45 |
46 | // Constants
47 | var NAVIGATE_LOOKUP_IN_DEVDOCS = "Lookup in DevDocs",
48 | CMD_LOOKUP_IN_DEVDOCS = "gruehle.lookupInDevDocs";
49 |
50 | // jQuery objects
51 | var $icon,
52 | $iframe;
53 |
54 | // Other vars
55 | var query,
56 | panel,
57 | visible = false,
58 | realVisibility = false;
59 |
60 | function _resizeIframe() {
61 | if (visible && $iframe) {
62 | var iframeWidth = panel.$panel.innerWidth();
63 | $iframe.attr("width", iframeWidth + "px");
64 | }
65 | }
66 |
67 | function _loadDocumentation() {
68 | var url = "http://devdocs.io/";
69 |
70 | if (query) {
71 | url += "#q=" + query;
72 | }
73 |
74 | $iframe.attr("src", url);
75 | $iframe.load(function () {
76 | $iframe.contents().get(0).addEventListener("click", function (e) {
77 | if (e.target && e.target.href) {
78 | if (e.target.href.indexOf("http://devdocs.io") !== 0) {
79 | // Open external links in the default browser
80 | NativeApp.openURLInDefaultBrowser(e.target.href);
81 | e.preventDefault();
82 | e.stopImmediatePropagation();
83 | }
84 | }
85 | }, true);
86 | $iframe.contents().get(0).addEventListener("keydown", function (e) {
87 | if (e.keyCode === 27) { // ESC key
88 | EditorManager.focusEditor();
89 | e.preventDefault();
90 | e.stopImmediatePropagation();
91 | }
92 | }, true);
93 | });
94 | }
95 |
96 | function _setPanelVisibility(isVisible) {
97 | if (isVisible === realVisibility) {
98 | return;
99 | }
100 |
101 | realVisibility = isVisible;
102 | if (isVisible) {
103 | if (!panel) {
104 | var $panel = $(panelHTML);
105 | $iframe = $panel.find("#devdocs-viewer-iframe");
106 |
107 | panel = PanelManager.createBottomPanel("devdocs-viewer-panel", $panel);
108 | $panel.on("panelResizeUpdate", function (e, newSize) {
109 | $iframe.attr("height", newSize);
110 | });
111 | $iframe.attr("height", $panel.height());
112 |
113 | _loadDocumentation();
114 |
115 | window.setTimeout(_resizeIframe);
116 | }
117 | $icon.toggleClass("active");
118 | panel.show();
119 | } else {
120 | $icon.toggleClass("active");
121 | panel.hide();
122 | }
123 | }
124 |
125 | function _toggleVisibility() {
126 | visible = !visible;
127 | _setPanelVisibility(visible);
128 | }
129 |
130 | // Insert CSS for this extension
131 | ExtensionUtils.loadStyleSheet(module, "DevDocsViewer.css");
132 |
133 | // Add toolbar icon
134 | $icon = $("")
135 | .attr({
136 | id: "devdocs-viewer-icon",
137 | href: "#",
138 | title: "DevDocs"
139 | })
140 | .click(_toggleVisibility)
141 | .appendTo($("#main-toolbar .buttons"));
142 |
143 | // Listen for resize events
144 | $(PanelManager).on("editorAreaResize", _resizeIframe);
145 | $("#sidebar").on("panelCollapsed panelExpanded panelResizeUpdate", _resizeIframe);
146 |
147 | // Add "Lookup in DevDocs" command
148 | function _handleLookupInDevDocs() {
149 | var editor = EditorManager.getActiveEditor();
150 |
151 | if (!editor) {
152 | return;
153 | }
154 | if (!editor.hasSelection()) {
155 | editor.selectWordAt(editor.getSelection().start);
156 | }
157 | query = editor.getSelectedText();
158 |
159 | function _resetDocumentation() {
160 | // Hack to force the iframe to reload with the new query.
161 | $iframe.attr("src", "");
162 | window.setTimeout(_loadDocumentation, 0);
163 | }
164 |
165 | if (!visible) {
166 | visible = true;
167 | _setPanelVisibility(visible);
168 | window.setTimeout(_resetDocumentation);
169 | } else {
170 | _resetDocumentation();
171 | }
172 | }
173 |
174 |
175 | // Register the command and shortcut
176 | CommandManager.register(
177 | NAVIGATE_LOOKUP_IN_DEVDOCS,
178 | CMD_LOOKUP_IN_DEVDOCS,
179 | _handleLookupInDevDocs
180 | );
181 | KeyBindingManager.addBinding(CMD_LOOKUP_IN_DEVDOCS, "Shift-Ctrl-L");
182 |
183 | // Create a menu item bound to the command
184 | var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
185 | menu.addMenuItem(CMD_LOOKUP_IN_DEVDOCS);
186 | });
187 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gruehle.dev-docs-viewer",
3 | "title": "DevDocs Viewer",
4 | "description": "Viewer for devdocs.io content",
5 | "homepage": "https://github.com/gruehle/dev-docs-viewer",
6 | "version": "0.1.1",
7 | "author": "Glenn Ruehle (http://github.com/gruehle)",
8 | "license": "MIT",
9 | "engines": {
10 | "brackets": ">=0.27.0"
11 | }
12 | }
--------------------------------------------------------------------------------
/panel.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------