Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
16 app.rb
@@ -1,9 +1,21 @@
require 'sinatra'
-get '/iframe_content' do
- erb :iframe_content
+get '/iframe_content_borked' do
+ erb :iframe_content_borked
+end
+
+get '/iframe_content_fixed' do
+ erb :iframe_content_fixed
end
get '/' do
erb :index
end
+
+get '/broken' do
+ erb :index
+end
+
+get '/fixed' do
+ erb :index_working
+end
View
7 public/basic.js
@@ -9,15 +9,18 @@ crunch.pubsub.unsubscribe = crunch.pubsub.unbind;
$(function() {
$('.replace-it').click(function() {
- $('iframe')[0].contentWindow.location.reload();
+ var iframe = $('iframe').first();
+
+ // reloads the iframe content
+ iframe.attr('src', iframe.attr('src'));
});
$('.send-it').click(function() {
crunch.pubsub.publish("MSG", "What's UP!");
});
crunch.pubsub.subscribe('all', function(msg) {
- console.log("MAIN", arguments);
+ console.log("MAIN", msg);
});
});
View
9 public/iframe.js
@@ -1,12 +1,5 @@
$(function() {
- var test = function(msg) {
+ parent.crunch.pubsub.subscribe('MSG', function(msg) {
console.log('IFRAME', msg);
- }
-
- parent.crunch.pubsub.subscribe('MSG', test);
-
-
- $(window).bind('beforeunload', function() {
- parent.crunch.pubsub.unsubscribe();
});
})
View
29 public/iframe_fixed.js
@@ -0,0 +1,29 @@
+$(function() {
+ crunch.pubsub = (function(pubsub){
+ var proxy = {}
+ , localEvents = _.extend({}, Backbone.Events)
+ ;
+
+ proxy.subscribe = _.bind(localEvents.bind, localEvents);
+ proxy.unsubscribe = _.bind(localEvents.unbind, localEvents);
+ proxy.publish = _.bind(localEvents.trigger, localEvents);
+
+ var proxyEvent = function() {
+ console.log('MSG PROXY:', arguments);
+ localEvents.trigger.apply(localEvents, arguments);
+ }
+
+ pubsub.bind('all', proxyEvent);
+ $(window).bind("beforeunload", function() {
+ pubsub.unbind('all', proxyEvent);
+ console.log("PROXY UNLOADED");
+ });
+
+ return proxy;
+ }(parent.crunch.pubsub));
+
+ crunch.pubsub.subscribe('MSG', function(msg) {
+ console.log('IFRAME', msg);
+ })
+
+})
View
0 views/iframe_content.erb → views/iframe_content_borked.erb
File renamed without changes.
View
20 views/iframe_content_fixed.erb
@@ -0,0 +1,20 @@
+<!doctype html>
+<html>
+<head>
+ <title>Iframe</title>
+ <script type="text/javascript" src="jquery.js"></script>
+ <script type="text/javascript" src="underscore-min.js"></script>
+ <script type="text/javascript" src="backbone-min.js"></script>
+ <script type="text/javascript" src="basic.js"></script>
+
+ <script type="text/javascript" src="iframe_fixed.js"></script>
+</head>
+<body>
+
+<h1>Iframe Working!</h1>
+
+<p>What can I say? Nothing to see here.</p>
+
+<a href="#send" class="send-it">Send It!</a>
+
+</body>
View
11 views/index.erb
@@ -8,11 +8,18 @@
<script type="text/javascript" src="basic.js"></script>
</head>
<body>
-<h1>Main Page</h1>
+<h1>Broken Example</h1>
+<hr/>
+<a href="/fixed">Working Example</a>
-<iframe src="/iframe_content"></iframe>
+<br/><br/>
+
+<iframe src="/iframe_content_borked"></iframe>
<br/>
<a href="#close" class="replace-it">Clear Out / Refresh</a>
<a href="#close" class="send-it">Send</a>
+
+
+
</body>
View
23 views/index_working.erb
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+<head>
+ <title>Main</title>
+ <script type="text/javascript" src="jquery.js"></script>
+ <script type="text/javascript" src="underscore-min.js"></script>
+ <script type="text/javascript" src="backbone-min.js"></script>
+ <script type="text/javascript" src="basic.js"></script>
+</head>
+<body>
+<h1>Fixed Example</h1>
+<hr/>
+<a href="/broken">Broken Example</a>
+
+<br/><br/>
+
+<iframe src="/iframe_content_fixed"></iframe>
+<br/>
+
+<a href="#close" class="replace-it">Clear Out / Refresh</a>
+<a href="#close" class="send-it">Send</a>
+
+</body>

No commit comments for this range

Something went wrong with that request. Please try again.