Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
1 lines (1 loc) · 2.48 KB
/
Copy pathmain.js
File metadata and controls
1 lines (1 loc) · 2.48 KB
1
define(function(require,exports,module){var _=brackets.getModule("thirdparty/lodash"),EditorManager=brackets.getModule("editor/EditorManager"),FileSystem=brackets.getModule("filesystem/FileSystem"),FileUtils=brackets.getModule("file/FileUtils"),CSSUtils=brackets.getModule("language/CSSUtils"),HTMLUtils=brackets.getModule("language/HTMLUtils"),ExtensionUtils=brackets.getModule("utils/ExtensionUtils"),Metrics=brackets.getModule("utils/Metrics"),InlineDocsViewer=require("InlineDocsViewer"),promiseCache={};function getDocs(fileName){if(!promiseCache[fileName]){var result=new $.Deferred,path=ExtensionUtils.getModulePath(module,fileName),file=FileSystem.getFileForPath(path);FileUtils.readAsText(file).done(function(text){var jsonData;try{jsonData=JSON.parse(text)}catch(ex){console.error("Malformed documentation database: ",ex),result.reject()}result.resolve(jsonData)}).fail(function(err){console.error("Unable to load documentation database: ",err),result.reject()}),promiseCache[fileName]=result.promise()}return promiseCache[fileName]}function inlineProvider(hostEditor,pos){var jsonFile,propInfo,propQueue=[],langId=hostEditor.getLanguageForSelection().getId(),supportedLangs,isQuickDocAvailable;if(!(langId?{css:!0,scss:!0,less:!0,html:!0}[langId]:-1))return null;Metrics.countEvent("MDNDocs","QuickDoc","css");var sel=hostEditor.getSelection();if(sel.start.line!==sel.end.line)return null;if("html"===langId?(jsonFile="html.json",(propInfo=HTMLUtils.getTagInfo(hostEditor,sel.start)).position.tokenType===HTMLUtils.ATTR_NAME&&propInfo.attr&&propInfo.attr.name&&propQueue.push(propInfo.attr.name.toLowerCase()),propInfo.tagName&&(propInfo=propInfo.tagName.toLowerCase(),propQueue.push("<"+propInfo+">"))):(jsonFile="css.json",(propInfo=CSSUtils.getInfoAtPos(hostEditor,sel.start)).name&&(propQueue.push(propInfo.name),propQueue.push(propInfo.name.replace(/^-(?:webkit|moz|ms|o)-/,"")))),propQueue.length){var result=new $.Deferred;return getDocs(jsonFile).done(function(docs){var displayName,propDetails,propName=_.find(propQueue,function(propName){return docs.hasOwnProperty(propName)});if(propName&&(propDetails=docs[propName],displayName=propName.substr(propName.lastIndexOf("/")+1)),propDetails){var inlineWidget=new InlineDocsViewer(displayName,propDetails);inlineWidget.load(hostEditor),result.resolve(inlineWidget)}else result.reject()}).fail(function(){result.reject()}),result.promise()}return null}EditorManager.registerInlineDocsProvider(inlineProvider),exports._getDocs=getDocs,exports._inlineProvider=inlineProvider});