Permalink
Browse files

Merge pull request #1 from coreyti/add-support-for-version-1x

Add support for Fluid version 1x
  • Loading branch information...
2 parents 947648b + 8c4f40d commit ffb8d2164ac42880d625df2e2edeb4ddbba30cdd @sj26 committed Dec 6, 2011
Showing with 29 additions and 19 deletions.
  1. +6 −0 README.md
  2. +23 −19 dotjs.user.js
View
6 README.md
@@ -7,6 +7,12 @@ Userscript to put [dotjs][dotjs] into your [Fluid][fluid] browsers. It may also
1. Make sure you've already installed [dotjs][dotjs] (it doesn't matter if you haven't installed the chrome extension).
2. [Download jQuery][jquery.js] into ~/.js/jquery.js (minified is fine)
3. Add [userscript][dotjs.user.js] to Fluid
+ * For Fluid version 1.x (tested with v1.2):
+ 1. Open your Fluid browser.
+ 2. From the menu, select "Window" -> "Userscripts".
+ 3. Add a new userscript config using "*" for the URL pattern.
+ 4. Paste [the userscript][dotjs.user.js] into the editor.
+ * For earlier versions of Fluid:
1. Open your Fluid browser.
2. From the menu, select the script icon -> "Open Userscripts Folder" (Ctrl + Command + O).
3. Put [the userscript][dotjs.user.js] inside the opened folder.
View
42 dotjs.user.js
@@ -4,36 +4,40 @@
// @description Run dotjs scripts via userscript for fluid apps
// @include *
// @author Samuel Cochran
+// @author Corey Innis
// ==/UserScript==
(function () {
+ function getScript(uri, callback) {
+ var script = document.createElement('script');
+ var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
+
+ script.async = 'async';
+ script.src = uri;
+ script.onload = function onload() {
+ jQuery.noConflict();
+ callback();
+ };
+
+ head.insertBefore(script, head.firstChild);
+ }
+
function dotjs($) {
$.ajax({
url: 'http://localhost:3131/' + window.location.host.replace('www.','') + '.js',
dataType: 'text',
success: function(d){
- $(function(){ eval(d) })
+ $(function(){ eval(d); });
},
error: function(){
- console.log('no dotjs server found at localhost:3131')
+ console.log('no dotjs server found at localhost:3131');
}
})
}
-
- if (!jQuery) {
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState == 4) {
- if (this.status < 200 || this.status >= 300) {
- return console.log('no dotjs server found at localhost:3131, or missing jquery')
- }
- eval(xhr.responseText)
- jQuery.noConflict()(dotjs)
- }
- }
- xhr.open('GET', "http://localhost:3131/jquery.js");
- xhr.send();
- } else {
- jQuery(dotjs)
+
+ if (!window.jQuery) {
+ getScript('http://localhost:3131/jquery.js', function() {
+ dotjs(jQuery);
+ });
}
-})()
+})();

0 comments on commit ffb8d21

Please sign in to comment.