Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Created January 14, 2012 14:51

Revisions

  1. chrismytton revised this gist Feb 18, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion 01_basic.js
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,10 @@

    // Create an iframe element and set some attributes.
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', iframeSrc);

    // Pass the current url across to the space.
    iframe.setAttribute('src', iframeSrc + '?custom1=' + encodeURIComponent(window.location.href));

    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', iframeStyle);

  2. chrismytton revised this gist Feb 18, 2012. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  3. chrismytton revised this gist Feb 18, 2012. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions 03_scraper.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    /**
    * Scraper bookmarklet template.
    *
    * This is an example of scraping the page for the first image, then posting that
    * across to the space. As with the AJAX example, you could scrape anything from
    * the page, or multiple things, and post them all to the space.
    */
    (function() {

    var iframeSrc = 'http://hectic.rusic.com/ideas/new';
    var iframeStyle = 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden; background-color: white;';

    // Scrape the first image from the page and grab it's `src` attribute.
    var firstImage = document.querySelectorAll('img')[0].src;

    var iframe = document.createElement('iframe');

    // Send the firstImage to the iframe in the src attribute.
    iframe.setAttribute('src', iframeSrc + '?custom1=' + encodeURIComponent(firstImage));
    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', iframeStyle);

    // Inject the iframe into the host page.
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(iframe);


    }).call(this);
  4. chrismytton revised this gist Feb 18, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 02_ajax.js
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@
    var iframe = document.createElement('iframe');

    // Send the videoId to the space in the src attribute of the iframe.
    iframe.setAttribute('src', iframeSrc + '?custom1=' + videoId);
    iframe.setAttribute('src', iframeSrc + '?custom1=' + encodeURIComponent(videoId));

    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', iframeStyle);
  5. chrismytton revised this gist Feb 18, 2012. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion 01_basic.js
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    (function() {

    // This is the page that will display inside the iframe.
    var iframeSrc = 'http://hq.rusic.com/ideas/new';
    var iframeSrc = 'http://hectic.rusic.com/ideas/new';

    // Styles for the iframe.
    var iframeStyle = 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden; background-color: white;';
    2 changes: 1 addition & 1 deletion 02_ajax.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    */
    (function() {

    var iframeSrc = 'http://hq.rusic.com/ideas/new';
    var iframeSrc = 'http://hectic.rusic.com/ideas/new';
    var iframeStyle = 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden; background-color: white;';

    // Grab the video id from the vimeo oembed api, then post it across to the space.
  6. chrismytton revised this gist Feb 18, 2012. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions 02_ajax.js
    Original file line number Diff line number Diff line change
    @@ -12,22 +12,26 @@
    */
    (function() {

    // This is the page that will display inside the iframe.
    var iframeSrc = 'http://hq.rusic.com/ideas/new';

    // Styles for the iframe.
    var iframeStyle = 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden; background-color: white;';

    // Grab the video id from the vimeo oembed api, then post it across to the space.

    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {

    // Get the video_id from the JSON response.
    var videoId = JSON.parse(xhr.responseText).video_id

    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', iframeSrc + '?custom1=' + JSON.parse(xhr.responseText).video_id);

    // Send the videoId to the space in the src attribute of the iframe.
    iframe.setAttribute('src', iframeSrc + '?custom1=' + videoId);

    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', iframeStyle);

    var body = document.getElementsByTagName('body')[0];
    body.appendChild(iframe);
    }
  7. chrismytton revised this gist Feb 18, 2012. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  8. chrismytton revised this gist Feb 18, 2012. 2 changed files with 39 additions and 21 deletions.
    39 changes: 39 additions & 0 deletions ajax.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    /**
    * AJAX Vimeo OEmbed bookmarklet template.
    *
    * Vimeo provides an OEmbed API, this looks up the video metadata based on
    * the url, then posts the video_id across to rusic as a custom field. This
    * can be read in your theme in order to embed the video.
    *
    * This could be changed to lookup pretty much anything that is exposed over
    * a JSONP or CORS compatible API.
    *
    * Bear in mind that you can post more than one piece of custom data.
    */
    (function() {

    // This is the page that will display inside the iframe.
    var iframeSrc = 'http://hq.rusic.com/ideas/new';

    // Styles for the iframe.
    var iframeStyle = 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden; background-color: white;';

    // Grab the video id from the vimeo oembed api, then post it across to the space.

    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', iframeSrc + '?custom1=' + JSON.parse(xhr.responseText).video_id);
    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', iframeStyle);
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(iframe);
    }
    };

    xhr.open('GET', 'http://vimeo.com/api/oembed.json?url=' + encodeURIComponent(window.location.href), true);
    xhr.send(null);

    }).call(this);
    21 changes: 0 additions & 21 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +0,0 @@
    (function(document) {

    // Grab the video id from the vimeo oembed api, then post it across to the space.

    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', 'http://hectic.rusic.com/ideas/new?custom1=' + JSON.parse(xhr.responseText).video_id);
    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden;');
    body = document.getElementsByTagName('body')[0];
    body.appendChild(iframe);
    }
    };

    xhr.open('GET', 'http://vimeo.com/api/oembed.json?url=' + encodeURIComponent(window.location.href), true);
    xhr.send(null);

    })(document);
  9. chrismytton revised this gist Feb 18, 2012. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions basic.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    /**
    * Basic bookmarklet template.
    *
    * Change the `iframeSrc` variable to point to your space's new idea
    * page. You can adjust the iframe styles and position using the
    * `iframeStyle` variable.
    *
    * For turning this script into a bookmarklet, you should probably take
    * a look at https://gist.github.com/1856012.
    */
    (function() {

    // This is the page that will display inside the iframe.
    var iframeSrc = 'http://hq.rusic.com/ideas/new';

    // Styles for the iframe.
    var iframeStyle = 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden; background-color: white;';

    // Create an iframe element and set some attributes.
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', iframeSrc);
    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', iframeStyle);

    // Inject the iframe into the host page.
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(iframe);

    }).call(this);
  10. chrismytton created this gist Jan 14, 2012.
    21 changes: 21 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    (function(document) {

    // Grab the video id from the vimeo oembed api, then post it across to the space.

    var xhr = new XMLHttpRequest();

    xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute('src', 'http://hectic.rusic.com/ideas/new?custom1=' + JSON.parse(xhr.responseText).video_id);
    iframe.setAttribute('id', 'rusic-modal');
    iframe.setAttribute('style', 'position: fixed; z-index: 999999; width: 500px; height: 300px; right: 0; top: 0; border: none; overflow: hidden;');
    body = document.getElementsByTagName('body')[0];
    body.appendChild(iframe);
    }
    };

    xhr.open('GET', 'http://vimeo.com/api/oembed.json?url=' + encodeURIComponent(window.location.href), true);
    xhr.send(null);

    })(document);