Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## HEAD

* Only load faye.js if the Faye object is not already present (thanks vollnhals)

## 1.0.3 (August 20, 2012)

* fixed Faye startup error (thanks gitt) - issue #40
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ Next, start up Faye using the rackup file that was generated.
rackup private_pub.ru -s thin -E production
```

**In Rails 3.1** add the JavaScript file to your application.js file manifest.
**In Rails 3.1 and above** add the JavaScript files to your application.js file manifest.

```javascript
//= require faye
//= require private_pub
```

`faye.js` will be automatically loaded if you haven't added it to your `application.js` manifest.

**In Rails 3.0** add the generated private_pub.js file to your layout.

```rhtml
Expand Down
20 changes: 11 additions & 9 deletions app/assets/javascripts/private_pub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function buildPrivatePub(doc) {
var PrivatePub = (function (doc) {
var self = {
connecting: false,
fayeClient: null,
Expand All @@ -13,11 +13,15 @@ function buildPrivatePub(doc) {
self.fayeCallbacks.push(callback);
if (self.subscriptions.server && !self.connecting) {
self.connecting = true;
var script = doc.createElement("script");
script.type = "text/javascript";
script.src = self.subscriptions.server + ".js";
script.onload = self.connectToFaye;
doc.documentElement.appendChild(script);
if (typeof Faye === 'undefined') {
var script = doc.createElement("script");
script.type = "text/javascript";
script.src = self.subscriptions.server + ".js";
script.onload = self.connectToFaye;
doc.documentElement.appendChild(script);
} else {
self.connectToFaye();
}
}
}
},
Expand Down Expand Up @@ -67,6 +71,4 @@ function buildPrivatePub(doc) {
}
};
return self;
}

var PrivatePub = buildPrivatePub(document);
}(document));