Skip to content

Commit

Permalink
ADD support for modx chrome extra
Browse files Browse the repository at this point in the history
  • Loading branch information
bartholomej committed Mar 1, 2015
1 parent 21e749e commit 2f18d6d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 15 deletions.
41 changes: 37 additions & 4 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Actions onClicked
chrome.browserAction.onClicked.addListener(function(tab) {
var tab_url = tab.url;
var tabIndex = tab.index;
Expand All @@ -11,7 +12,7 @@ chrome.browserAction.onClicked.addListener(function(tab) {


chrome.tabs.sendMessage(tab.id, {
command: "getResource"
command: "getManager"
},
function(docid) {

Expand All @@ -23,12 +24,44 @@ chrome.browserAction.onClicked.addListener(function(tab) {
chrome.browserAction.setTitle({title:"Preview MODX website"});
} else {
newUrl = base;
}
}

//chrome.browserAction.setIcon ({path: 'images/icon128.png'});
chrome.tabs.create({
url: newUrl,
index: tabIndex + 1
});
});
});
});

// Change icon onMessage
var badge_color = [0, 0, 0, 255];
var success_color = [95, 181, 77, 255];
var error_color = [229, 62, 48, 255];


chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {

if (request.published == '0') badge_color = error_color;
if (request.published == '1') badge_color = success_color;

var tooltip = [];
if (request.docid) tooltip.push('docid: ' + request.docid);
if (request.published) tooltip.push('published: ' + request.published);
if (request.editedby) tooltip.push('editedby: ' + request.editedby);
if (request.editedon) tooltip.push('editedon: ' + request.editedon);


chrome.browserAction.setBadgeText ({
text: request.published,
tabId: sender.tab.id
});
chrome.browserAction.setBadgeBackgroundColor({
color: badge_color,
tabId: sender.tab.id
});
chrome.browserAction.setTitle({
title: tooltip.join('\n'),
tabId: sender.tab.id
});
});
37 changes: 26 additions & 11 deletions src/content.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
/* Listen for messages and get modResource meta tag*/
var META_NAME = 'application-name';
var APP_NAME = 'modxchromemanager';

var meta = document.querySelector("meta[name='" + META_NAME + "'][content='" + APP_NAME + "']");
var docid,
published,
editedon,
editedby;

if (meta) {
docid = meta.getAttribute('data-id');
published = meta.getAttribute('data-published'),
editedon = meta.getAttribute('data-editedon'),
editedby = meta.getAttribute('data-editedby');

chrome.runtime.sendMessage({
"docid": docid,
"published": published,
"editedon": editedon,
"editedby": editedby,
});
}

/* Listen for messages and get docid meta tag*/
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
if (msg.command && (msg.command == "getResource")) {

function getMetaContentByName(name,content){
var content = (content==null)?'content':content;
var meta = document.querySelector("meta[name='" + name + "']");
if (meta) {
return meta.getAttribute(content);
}
if (msg.command && (msg.command == "getManager")) {
sendResponse(docid);
}
sendResponse(getMetaContentByName('application-name','data-id'));
}
});

0 comments on commit 2f18d6d

Please sign in to comment.