Skip to content

Commit

Permalink
Merge a57825d into afa9ddd
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Dowling committed Apr 20, 2015
2 parents afa9ddd + a57825d commit 2528709
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -91,6 +91,8 @@ To enable cross domain communictaion between your site and other pages on the 'n

config.action_controller.default_url_options = {:host => 'localhost', :port => 3000}

The port can also be supplied as a parameter in the bookmarklet.js file - this will override the value from the rails application. This is useful if you have middleware changing the port that the browser sees (e.g. nginx to implement ssl)

XDM bookmarklet code acts as a consumer for data or a service that is
supplied by the provider, a page on your app.

Expand Down
32 changes: 18 additions & 14 deletions app/assets/javascripts/easymarklet/consumer.js.erb
@@ -1,7 +1,6 @@
(function(){

var Easymarklet = window.Easymarklet || {}

Easymarklet.Consumer = function(bookmarklet){
if(bookmarklet == null){ alert('You must pass some bookmarklet to Easymarklet.Consumer.'); return;}
if(bookmarklet.consumer == null){ alert('Your bookmarklet definition is missing a consumer.'); return; }
Expand All @@ -21,19 +20,23 @@
if(bookmarklet.protocol){
protocol = bookmarklet.protocol;
}
var host = '<%= Rails.application.config.action_controller.default_url_options[:host] %>';
var port = '<%= Rails.application.config.action_controller.default_url_options[:port] %>';
var host = '<%= Rails.application.config.domain %>';
var port = '<%= Rails.application.config.port %>';
// Allow port to be overriden by the bookmarklet definition - useful for ssl
if(bookmarklet.port) {
port = bookmarklet.port;
}
port = port === '' ? '' : ':' + port;
var full_host = protocol + '://' + host + port;

// Once easyXDM is available this will create an iframe and set up the RPC channel
function scriptOnLoad(){

if (isLoaded || typeof easyXDM === "undefined" || typeof JSON === "undefined") {
return;
}
isLoaded = true;

if(bookmarklet.visible){
easymarkletDiv = document.createElement('div');
easymarkletDiv.id = "easymarklet_div";
Expand All @@ -44,14 +47,14 @@

//var dest = full_host + "/bookmarklet_frame?dest=";
//dest += encodeURIComponent("/bookmarklet/court_cases/check?court_case[url]=" + caseUrl);

var dest = full_host + bookmarklet.producer.path
dest += "?url=" + encodeURIComponent(document.location.href);
if(bookmarklet.producer.buffer){
dest = full_host + bookmarklet.producer.buffer + "?producer=" + encodeURIComponent(bookmarklet.producer.path);
dest += "&url=" + encodeURIComponent(document.location.href)
}

// here we put the main code, in this case we expose an ajax endpoint
_this.producer = new easyXDM.Rpc({
remote: dest,
Expand All @@ -69,7 +72,7 @@
}
}, _this.createRpcConfig() /*{
remote: {
post: {}
},
local : {
Expand Down Expand Up @@ -113,7 +116,7 @@
s1.onload = scriptOnLoad;
head.appendChild(s1);
}

this.loadJsonLib = function(){
// load JSON if needed
if (typeof JSON === "undefined" || !JSON) {
Expand All @@ -131,7 +134,7 @@
}

this.loadCss = function(){
//Load the css
//Load the css
bookmarklet.consumer.css = [].concat(bookmarklet.consumer.css)
for(var i = 0; i<bookmarklet.consumer.css.length; i++){
var src = bookmarklet.consumer.css[i]
Expand All @@ -140,7 +143,7 @@
css.type = 'text/css';
css.media = 'screen';
css.rel = 'stylesheet';
head.appendChild(css);
head.appendChild(css);
}
}

Expand Down Expand Up @@ -183,14 +186,15 @@
this.resizeFrame = function(height){
easymarkletDiv.style.height = height + "px";
easymarkletDiv.getElementsByTagName("iframe")[0].style.height = height + "px";
easymarkletDiv.getElementsByTagName("iframe")[0].style.width = "100%";
}

} // Easymarklet.Consumer = function(){


// Now expose the Easymarklet to the global object
window.Easymarklet = Easymarklet;


})();

0 comments on commit 2528709

Please sign in to comment.