diff --git a/js/AH5Communicator.js b/js/AH5Communicator.js index c7e2c2b..fbb64dc 100644 --- a/js/AH5Communicator.js +++ b/js/AH5Communicator.js @@ -1,11 +1,9 @@ /* global PluginAPI: true */ +/* jshint maxstatements:30 */ PluginAPI.Editor = (function () { "use strict"; - - - /** * This will be used by editor apps to communicate with the editor * @@ -19,16 +17,13 @@ PluginAPI.Editor = (function () { */ var AH5Communicator = function() { - var selectedPluginElement = null; - - var pluginElementSelected = function(element) { - PluginAPI.selectedPluginElement = element - } + PluginAPI.selectedPluginElement = element; + }; var pluginElementDeselected = function() { PluginAPI.selectedPluginElement = null; - } + }; this.DEBUG = false; @@ -39,10 +34,8 @@ PluginAPI.Editor = (function () { }; - AH5Communicator.prototype.selectedPluginElement = null; - /** * Get name of current active editor * @@ -336,6 +329,7 @@ PluginAPI.Editor = (function () { }, callback); }; + /** * Initialize pre registered menus * @@ -350,45 +344,40 @@ PluginAPI.Editor = (function () { }, callback); }; - AH5Communicator.prototype.updateAssetMedia = function(data, callback) { - PluginAPI.request('update-asset-media', data, callback); + /** + * Opens the plugin editor for a given element. + * + * @param {String} id Plugin element ID + */ + AH5Communicator.prototype.openPluginElementEditor = function (id) { + PluginAPI.request('open-element-editor', { + id: id + }); }; - - AH5Communicator.prototype.insertEmbeddedMedia = function(markup, data, callback) { - var insert = function(dpArticleId, callback) { - data.internalId = dpArticleId; - var element = $('
'); - element.attr('id', 'asset-' + dpArticleId); - element.attr('data-internal-id', dpArticleId); - element.attr('data-external-id', data.externalId); - element.addClass(data.assetClass); - var customMarkup = $(markup); - element.append(customMarkup); - this.insertElement(element, { select: true} , callback) - }.bind(this); - - var cb = function(callback) { - PluginAPI.request('update-embedded-asset', data, callback); - }; - - if (PluginAPI.selectedPluginElement) { - var dpArticleId = PluginAPI.selectedPluginElement.dpArticleId; - if (!dpArticleId) { - throw "Selected plugin element: expected dpArticleId not found (tried reading from attribute 'data-internal-id')"; - } - insert(dpArticleId, cb); - } else { - PluginAPI.createEmbeddedObject( - data.embeddedTypeId, - function(dpArticleId) { - insert(dpArticleId, cb); - } - ); - } + + /** + * Returns the total number of words in the currently open article. + * + * @param {Function} callback Receives the total word count as its single parameter + */ + AH5Communicator.prototype.getTotalWordCount = function (callback) { + PluginAPI.request('total-word-count', null, callback); }; - AH5Communicator.prototype.insertEmbeddedMedia = function(markup, data, callback) { + /** + * Returns the total number of characters in the currently open article. + * + * @param {Function} callback Receives the total character count as its single parameter + */ + AH5Communicator.prototype.getTotalCharCount = function (callback) { + PluginAPI.request('total-char-count', null, callback); + }; + + AH5Communicator.prototype.updateAssetData = function(data, callback) { + PluginAPI.request('update-asset-media', data, callback); + }; + AH5Communicator.prototype.insertEmbeddedAsset = function(markup, data, callback) { var replaceElement = false; if (PluginAPI.selectedPluginElement) { if (data.assetSource !== PluginAPI.getAppName()) { @@ -422,18 +411,22 @@ PluginAPI.Editor = (function () { var updateEmbeddedAssetRequest = function(callback) { PluginAPI.request('update-embedded-asset', data, callback); }; - + if (PluginAPI.selectedPluginElement) { var dpArticleId = PluginAPI.selectedPluginElement.dpArticleId; if (!dpArticleId) { throw "Selected plugin element: expected dpArticleId not found (tried reading from attribute 'data-internal-id')"; } - insert(dpArticleId, function() {updateEmbeddedAssetRequest(callback)}); + insert(dpArticleId, function() { + updateEmbeddedAssetRequest(callback); + }); } else { PluginAPI.createEmbeddedObject( data.embeddedTypeId, function(dpArticleId) { - insert(dpArticleId, function() {updateEmbeddedAssetRequest(callback)}); + insert(dpArticleId, function() { + updateEmbeddedAssetRequest(callback); + }); } ); } diff --git a/js/ArticleCommunicator.js b/js/ArticleCommunicator.js index 89fc046..7813a4f 100644 --- a/js/ArticleCommunicator.js +++ b/js/ArticleCommunicator.js @@ -1,7 +1,6 @@ /* global PluginAPI: true */ -/* jshint maxstatements:44 */ - +/* jshint maxstatements:50 */ PluginAPI.Article = (function() { "use strict"; diff --git a/js/PluginAPI.js b/js/PluginAPI.js index cbefe7b..aa544f9 100644 --- a/js/PluginAPI.js +++ b/js/PluginAPI.js @@ -382,6 +382,15 @@ var PluginAPI = (function() { this.request('get-configuration', null, callback); }; + /** + * Get DrPublish configuratin + * + * @param {Function} callback function(Object) + */ + Api.prototype.getDrPublishConfiguration = function (callback) { + this.request('get-drpublish-configuration', null, callback); + }; + /** * Set configuration information about the app * @@ -625,5 +634,11 @@ var PluginAPI = (function() { this.request('get-custom-modal-inputs', null, callback); }; + Api.prototype.confirmAuthenticated = function() { + this.request("confirm-authenticated", { + pluginName: this.appName + }); + }; + return new Api(); })(); diff --git a/karma.conf.js b/karma.conf.js index ba0ace1..15644da 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -15,7 +15,7 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - 'js/vendor/jquery/dist/jquery.js', + 'node_modules/jquery/dist/jquery.js', 'js/vendors/*.js', 'js/Listeners.js', 'js/PluginAPI.js', diff --git a/package.json b/package.json index 9e21ebb..9f3f54d 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "karma-jasmine": "~0.2.0", "grunt-contrib-watch": "~0.6.1", "time-grunt": "~0.4.0", - "grunt-jsdoc": "~0.5.7" + "grunt-jsdoc": "~0.5.7", + "jquery": "~2.1.4" } }