Skip to content

Commit

Permalink
Merge branch 'jwt-auth' of github.com:aptoma/no.aptoma.plugin-api
Browse files Browse the repository at this point in the history
  • Loading branch information
stefangrunert committed Apr 28, 2016
2 parents 2b70d4f + f954c08 commit 8021bf5
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 53 deletions.
91 changes: 42 additions & 49 deletions js/AH5Communicator.js
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -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;

Expand All @@ -39,10 +34,8 @@ PluginAPI.Editor = (function () {

};


AH5Communicator.prototype.selectedPluginElement = null;


/**
* Get name of current active editor
*
Expand Down Expand Up @@ -336,6 +329,7 @@ PluginAPI.Editor = (function () {
}, callback);
};


/**
* Initialize pre registered menus
*
Expand All @@ -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 = $('<div/>');
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()) {
Expand Down Expand Up @@ -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);
});
}
);
}
Expand Down
3 changes: 1 addition & 2 deletions js/ArticleCommunicator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global PluginAPI: true */

/* jshint maxstatements:44 */

/* jshint maxstatements:50 */
PluginAPI.Article = (function() {
"use strict";

Expand Down
15 changes: 15 additions & 0 deletions js/PluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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();
})();
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 8021bf5

Please sign in to comment.