From: Brion Vibber Date: Tue, 22 Feb 2011 00:10:07 +0000 (-0800) Subject: Partial implementation for ticket #2442: MobileProfile plugin should allow manual... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2a42dac72aa3000aa4b442ee722a13e12dda3319;p=quix0rs-gnu-social.git Partial implementation for ticket #2442: MobileProfile plugin should allow manual switching between regular and mobile rendering modes http://status.net/open-source/issues/2442 Notes: * Mapstraction causes JavaScript errors in XHTML mode, breaking our code if we're run later so the link doesn't work to get back to Desktop. * not 100% sure how safe feature detection is here? * Currently will be useless but visible links if no JS available; need to fall back to server-side for limited browsers --- diff --git a/lib/action.php b/lib/action.php index 26ebd20932..173e2c2a58 100644 --- a/lib/action.php +++ b/lib/action.php @@ -854,8 +854,11 @@ class Action extends HTMLOutputter // lawsuit function showFooter() { $this->elementStart('div', array('id' => 'footer')); - $this->showSecondaryNav(); - $this->showLicenses(); + if (Event::handle('StartShowInsideFooter', array($this))) { + $this->showSecondaryNav(); + $this->showLicenses(); + Event::handle('EndShowInsideFooter', array($this)); + } $this->elementEnd('div'); } diff --git a/plugins/MobileProfile/MobileProfilePlugin.php b/plugins/MobileProfile/MobileProfilePlugin.php index b9c25ab998..ec08fa1e2c 100644 --- a/plugins/MobileProfile/MobileProfilePlugin.php +++ b/plugins/MobileProfile/MobileProfilePlugin.php @@ -68,6 +68,9 @@ class MobileProfilePlugin extends WAP20Plugin $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { $this->serveMobile = true; + } else if (isset($_COOKIE['MobileOverride'])) { + // Cookie override is controlled by link at bottom. + $this->serveMobile = (bool)$_COOKIE['MobileOverride']; } else { // If they like the WAP 2.0 mimetype, serve them MP // @fixme $type is undefined, making this if case useless and spewing errors. @@ -381,9 +384,40 @@ class MobileProfilePlugin extends WAP20Plugin } } - function onStartShowScripts($action) + function onEndShowScripts($action) { + $action->inlineScript(' + $(function() { + $("#mobile-toggle-disable").click(function() { + $.cookie("MobileOverride", "0", {path: "/"}); + window.location.reload(); + return false; + }); + $("#mobile-toggle-enable").click(function() { + $.cookie("MobileOverride", "1", {path: "/"}); + window.location.reload(); + return false; + }); + });' + ); + } + + function onEndShowInsideFooter($action) + { + if ($this->serveMobile) { + // TRANS: Link to switch site layout from mobile to desktop mode. Appears at very bottom of page. + $linkText = _m('Switch to desktop site layout.'); + $key = 'mobile-toggle-disable'; + } else { + // TRANS: Link to switch site layout from desktop to mobile mode. Appears at very bottom of page. + $linkText = _m('Switch to mobile site layout.'); + $key = 'mobile-toggle-enable'; + } + $action->elementStart('p'); + $action->element('a', array('href' => '#', 'id' => $key), $linkText); + $action->elementEnd('p'); + return true; } function _common_path($relative, $ssl=false)