r103213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103212‎ | r103213 | r103214 >
Date:19:30, 15 November 2011
Author:brion
Status:deferred
Tags:
Comment:
Load page in embedded iframe
Modified paths:
  • /trunk/mockups/athena/athena.css (modified) (history)
  • /trunk/mockups/athena/athena.js (modified) (history)
  • /trunk/mockups/athena/index.html (modified) (history)
  • /trunk/mockups/athena/proxy.php (modified) (history)

Diff [purge]

Index: trunk/mockups/athena/athena.css
@@ -7,6 +7,8 @@
88
99 color: white;
1010 background: black;
 11+
 12+ z-index: 9999;
1113 }
1214
1315 #top-bar {
@@ -84,3 +86,15 @@
8587 background-image: url(images/icons/athena_icon_efefef_globe.png);
8688 }
8789
 90+
 91+
 92+#embed {
 93+ position: absolute;
 94+ top: 0;
 95+ left: 0;
 96+ right: 0;
 97+ bottom: 0;
 98+ overflow: auto;
 99+ border: none;
 100+}
 101+
Index: trunk/mockups/athena/proxy.php
@@ -30,7 +30,9 @@
3131 $context = stream_context_create(
3232 array(
3333 'http' => array(
34 - 'user_agent' => 'Wikipedia Mobile (Athena mockup)',
 34+ // fake "iPhone" in there to force a mode where show/hide works
 35+ // this should not be required, grrrr!
 36+ 'user_agent' => 'Wikipedia Mobile (Athena mockup; iPhone)',
3537 ),
3638 )
3739 );
Index: trunk/mockups/athena/index.html
@@ -20,6 +20,8 @@
2121 <button class="button-you">You</button>
2222 </div>
2323
 24+<iframe id="embed" width="100%" height="100%" src="proxy.php?title=While_My_Guitar_Gently_Weeps"></iframe>
 25+
2426 <div id="page-content"></div>
2527
2628 <div id="bottom-bar" class="bar">
Index: trunk/mockups/athena/athena.js
@@ -44,9 +44,63 @@
4545 }
4646 };
4747
 48+var embed = {
 49+ init: function() {
 50+ var $embed = $('#embed');
 51+ $(window).bind('message', function(event) {
 52+ var src = event.originalEvent.source,
 53+ msg = event.originalEvent.data;
 54+ if (src !== $embed[0].contentWindow) {
 55+ // not from our iframe; ignore
 56+ return;
 57+ }
 58+ var key = '[wiki-mobile-embed]';
 59+ if (msg.substr(0, key.length) !== key) {
 60+ // not from our iframe's protocol; ignore
 61+ return;
 62+ }
 63+ var data = JSON.parse(msg.substr(key.length));
 64+ if ('event' in data && typeof data.event === 'string') {
 65+ $embed.trigger('embed:' + data.event, data);
 66+ }
 67+ });
 68+ $embed.bind('embed:navigate', function(event, data) {
 69+ // hack hack hack!
 70+ var matches = data.url.match(/^\/wiki\/(.*)$/);
 71+ if (matches) {
 72+ app.loadPage(decodeURIComponent(matches[1]));
 73+ } else {
 74+ // external!
 75+ document.location = data.url;
 76+ }
 77+ });
 78+ },
 79+
 80+ /**
 81+ * @return promise
 82+ */
 83+ loadPage: function(title) {
 84+ var $embed = $('#embed');
 85+ $embed.attr('src', 'proxy.php?title=' + encodeURIComponent(title.replace(' ', '_')));
 86+ var deferred = new $.Deferred();
 87+ $embed.bind('embed:load', function() {
 88+ deferred.resolve();
 89+ $embed.unbind('embed:load');
 90+ });
 91+ return deferred.promise();
 92+ }
 93+};
 94+
 95+
4896 var app = {
 97+ init: function() {
 98+ embed.init();
 99+ app.loadPage('While My Guitar Gently Weeps');
 100+ },
 101+
49102 loadPage: function(title) {
50103 ui.startSpinner();
 104+ /*
51105 wiki.api({
52106 action: 'query',
53107 prop: 'revisions',
@@ -68,11 +122,15 @@
69123 ui.showPage(page.title, rev['*']);
70124 ui.stopSpinner();
71125 });
72 - },
 126+ */
 127+ embed.loadPage(title).then(function() {
 128+ ui.stopSpinner();
 129+ });
 130+ }
73131 };
74132
75133 $(function() {
76 - app.loadPage('While My Guitar Gently Weeps');
 134+ app.init();
77135 });
78136
79137 })(jQuery);

Status & tagging log