|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <link> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <title>Hello World DrPublish Plugin</title> |
| 7 | + <link type="text/css" rel="stylesheet" href="styles.css"/> |
| 8 | + <script type="application/javascript" src="node_modules/jquery/dist/jquery.min.js"></script> |
| 9 | + <script type="application/javascript" |
| 10 | + src="node_modules/@aptoma/drpublish-plugin-api/dist/jquery.postmessage.js"></script> |
| 11 | + <script type="application/javascript" src="node_modules/@aptoma/drpublish-plugin-api/dist/bundle.js"></script> |
| 12 | + <script type="application/javascript" src="https://localhost/plugin-api/dist/bundle.js"></script> |
| 13 | + <script type="application/javascript" src="helloworld.js"></script> |
| 14 | +</head> |
| 15 | +<body> |
| 16 | + |
| 17 | + |
| 18 | +<h1>Demo plugin</h1> |
| 19 | +<h3>Fetch article id dynamically, each time a new article is loaded in the editor</h3> |
| 20 | +<input id="fetchArticleId-result" /> |
| 21 | +<code> |
| 22 | + function initPlugin() { |
| 23 | + PluginAPI.setPluginName('helloworld'); |
| 24 | + // fetch article id after the article has been loaded |
| 25 | + fetchArticleIdDynamically(); |
| 26 | + } |
| 27 | + function fetchArticleIdDynamically() { |
| 28 | + PluginAPI.Article.getId(function(id) { |
| 29 | + console.log('stef:fetchedartid', id); |
| 30 | + $('#fetchArticleId-result').val(id); |
| 31 | + }); |
| 32 | + } |
| 33 | + |
| 34 | +</code> |
| 35 | +<hr/> |
| 36 | + |
| 37 | +<h3>Inject HTML text string at cursor position</h3> |
| 38 | +<button onclick="insertHelloWorld()">say hello</button> |
| 39 | +<code>PluginAPI.Editor.insertString('<h3>Hello World</h3>');</code> |
| 40 | +<hr/> |
| 41 | + |
| 42 | +<h3>Read article content</h3> |
| 43 | +<button onclick="readContent()">do it</button> |
| 44 | +<textarea id="readContent-result"></textarea> |
| 45 | +<code>PluginAPI.Editor.getHTMLBySelector('*', function (data) { |
| 46 | + $('#result-preview-txt').val(data); |
| 47 | +});</code> |
| 48 | +<hr/> |
| 49 | + |
| 50 | +<h3>Get article id</h3> |
| 51 | +<button onclick="getId()">do it</button> |
| 52 | +<input id="getId-result" /> |
| 53 | +<code> |
| 54 | +PluginAPI.Article.getId(function (id) { |
| 55 | + $('#getId-result').val(id); |
| 56 | +});</code> |
| 57 | +<hr/> |
| 58 | + |
| 59 | + |
| 60 | +<h3>Get tags</h3> |
| 61 | +<button onclick="getTags()">do it</button> |
| 62 | +<textarea id="getTags-result" ></textarea> |
| 63 | +<code> |
| 64 | +PluginAPI.Article.getTags(function (tags) { |
| 65 | + $('#getTags-result').val(tags.length > 0 ? JSON.stringify(tags) : 'article has no tags'); |
| 66 | +});</code> |
| 67 | +<hr/> |
| 68 | + |
| 69 | +<h3>Get custom metadata (aka. "article property")</h3> |
| 70 | +<input placeholder="property name*" id="getCustomMeta-input" /><button onclick="getCustomMeta()">do it</button> |
| 71 | +<textarea id="getCustomMeta-result" ></textarea> |
| 72 | +<div class="hint">* If no value is provided, all available custom metadata are fetched</div> |
| 73 | +<code> |
| 74 | +PluginAPI.Article.getTags(function (tags) { |
| 75 | + $('#getTags-result').val(tags.length > 0 ? JSON.stringify(tags) : 'article has no tags'); |
| 76 | +});</code> |
| 77 | +<hr/> |
| 78 | + |
| 79 | +<h3>Set custom metadata (aka. "article property")</h3> |
| 80 | +<input placeholder="property name" id="setCustomMeta-name-input" /> |
| 81 | +<input placeholder="property value" id="setCustomMeta-value-input" /> |
| 82 | +<button onclick="setCustomMeta()">do it</button> |
| 83 | +<textarea id="setCustomMeta-result" ></textarea> |
| 84 | + |
| 85 | +<code> |
| 86 | +PluginAPI.Article.getTags(function (tags) { |
| 87 | + $('#getTags-result').val(tags.length > 0 ? JSON.stringify(tags) : 'article has no tags'); |
| 88 | +});</code> |
| 89 | +<hr/> |
| 90 | + |
| 91 | + |
| 92 | +</body> |
| 93 | +</html> |
0 commit comments