function onEndShowScripts(Action $action)
 {
     $action->inlineScript('var infinite_scroll_on_next_only = ' . ($this->on_next_only ? 'true' : 'false') . ';');
     $action->inlineScript('var ajax_loader_url = "' . $this->path('ajax-loader.gif') . '";');
     $action->script($this->path('jquery.infinitescroll.js'));
     $action->script($this->path('infinitescroll.js'));
 }
 /**
  * Load JS at runtime if we're logged in.
  *
  * @param Action $action
  * @return boolean hook result
  */
 function onEndShowScripts($action)
 {
     $user = common_current_user();
     if ($user && common_config('attachments', 'process_links')) {
         $action->script($this->path('linkpreview.min.js'));
         $data = json_encode(array('api' => common_local_url('oembedproxy'), 'width' => common_config('attachments', 'thumbwidth'), 'height' => common_config('attachments', 'thumbheight')));
         $action->inlineScript('$(function() {SN.Init.LinkPreview && SN.Init.LinkPreview(' . $data . ');})');
     }
     return true;
 }
示例#3
0
 /**
  * Output the bits of JavaScript code to show Adsense
  *
  * @param Action  $action Action being shown
  * @param integer $width  Width of the block
  * @param integer $height Height of the block
  * @param string  $slot   Slot identifier
  *
  * @return void
  */
 protected function showAdsenseCode($action, $width, $height, $slot)
 {
     $code = 'google_ad_client = "' . $this->client . '"; ';
     $code .= 'google_ad_slot = "' . $slot . '"; ';
     $code .= 'google_ad_width = ' . $width . '; ';
     $code .= 'google_ad_height = ' . $height . '; ';
     $action->inlineScript($code);
     $action->script($this->adScript);
 }
    /**
     * Called when all scripts have been shown
     *
     * @param Action $action Current action
     *
     * @return boolean ignored
     */
    function onEndShowScripts($action)
    {
        $piwikCode1 = <<<ENDOFPIWIK
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->piwikroot}" : "http://{$this->piwikroot}");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
ENDOFPIWIK;
        $piwikCode2 = <<<ENDOFPIWIK
try {
    var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$this->piwikId});
    piwikTracker.trackPageView();
    piwikTracker.enableLinkTracking();
} catch( err ) {}
ENDOFPIWIK;
        $action->inlineScript($piwikCode1);
        $action->inlineScript($piwikCode2);
        return true;
    }
 /**
  * Hook for adding extra JavaScript
  *
  * This makes sure our scripts get loaded for map-related pages
  *
  * @param Action $action Action object for the page
  *
  * @return boolean event handler return
  */
 function onEndShowScripts($action)
 {
     $actionName = $action->trimmed('action');
     if (!in_array($actionName, array('showstream', 'all', 'usermap', 'allmap'))) {
         return true;
     }
     switch ($this->provider) {
         case 'cloudmade':
             $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
             break;
         case 'google':
             $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s', urlencode($this->apikey)));
             break;
         case 'microsoft':
             $action->script((GNUsocial::isHTTPS() ? 'https' : 'http') + '://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
             break;
         case 'openlayers':
             // Use our included stripped & minified OpenLayers.
             $action->script($this->path('OpenLayers/OpenLayers.js'));
             break;
         case 'yahoo':
             $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s', urlencode($this->apikey)));
             break;
         case 'geocommons':
             // don't support this yet
         // don't support this yet
         default:
             return true;
     }
     $action->script(sprintf('%s?(%s)', $this->path('js/mxn.js'), $this->provider));
     $action->script($this->path('usermap.js'));
     $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
     // usermap and allmap handle this themselves
     if (in_array($actionName, array('showstream', 'all'))) {
         $action->inlineScript('$(document).ready(function() { ' . ' var user = null; ' . ($actionName == 'showstream' ? ' user = scrapeUser(); ' : '') . ' var notices = scrapeNotices(user); ' . ' var canvas = $("#map_canvas")[0]; ' . ' if (typeof(canvas) != "undefined") { showMapstraction(canvas, notices); } ' . '});');
     }
     return true;
 }
示例#6
0
    /**
     * Show an ad using OpenX
     *
     * @param Action  $action Action being shown
     * @param integer $zone   Zone to show
     *
     * @return void
     */
    protected function showAd($action, $zone)
    {
        $scr = <<<ENDOFSCRIPT
var m3_u = '%s';
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=%d");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'><\\/scr"+"ipt>");
ENDOFSCRIPT;
        $action->inlineScript(sprintf($scr, $this->adScript, $zone));
        return true;
    }
示例#7
0
    /**
     * Add Disqus comment count script to the end of the scripts section
     *
     * @param Action $action the current action
     *
     */
    function onEndShowScripts($action)
    {
        // fugly
        $script = <<<ENDOFSCRIPT
var disqus_shortname = '%s';
(function () {
  var s = document.createElement('script'); s.async = true;
  s.src = 'http://disqus.com/forums/%s/count.js';
  (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
ENDOFSCRIPT;
        $action->inlineScript(sprintf($script, $this->shortname, $this->shortname));
    }
示例#8
0
 /**
  * Hook for adding extra JavaScript
  *
  * This makes sure our scripts get loaded for map-related pages
  *
  * @param Action $action Action object for the page
  *
  * @return boolean event handler return
  */
 function onEndShowScripts($action)
 {
     $actionName = $action->trimmed('action');
     if (!in_array($actionName, array('showstream', 'all', 'usermap', 'allmap'))) {
         return true;
     }
     switch ($this->provider) {
         case 'cloudmade':
             $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
             break;
         case 'google':
             $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s', urlencode($this->apikey)));
             break;
         case 'microsoft':
             $action->script('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
             break;
         case 'openlayers':
             // XXX: is this not nice...?
             $action->script('http://openlayers.org/api/OpenLayers.js');
             break;
         case 'yahoo':
             $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s', urlencode($this->apikey)));
             break;
         case 'geocommons':
             // don't support this yet
         // don't support this yet
         default:
             return true;
     }
     $action->script(sprintf('%s?(%s)', common_path('plugins/Mapstraction/js/mxn.js'), $this->provider));
     $action->script(common_path('plugins/Mapstraction/usermap.js'));
     $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
     // usermap and allmap handle this themselves
     if (in_array($actionName, array('showstream', 'all'))) {
         $action->inlineScript('$(document).ready(function() { ' . ' var user = null; ' . ($actionName == 'showstream' ? ' user = scrapeUser(); ' : '') . ' var notices = scrapeNotices(user); ' . ' showMapstraction($("#map_canvas"), notices); ' . '});');
     }
     return true;
 }
示例#9
0
 /**
  * Initialize any flagging buttons on the page
  *
  * @param Action $action action being shown
  *
  * @return boolean hook result
  */
 function onEndShowScripts($action)
 {
     $action->inlineScript('if ($(".form_entity_flag").length > 0) { ' . '$(".form_entity_flag").bind("click", function() {' . 'SN.U.FormXHR($(this)); return false; }); }');
     return true;
 }
示例#10
0
    /**
     * Called when all scripts have been shown
     *
     * @param Action $action Current action
     *
     * @return boolean ignored
     */
    function onEndShowScripts($action)
    {
        // Slight modification to the default code.
        // Loading the piwik.js file from a <script> created in a document.write
        // meant that the browser had no way to preload it, ensuring that its
        // loading will be synchronous, blocking further page rendering.
        //
        // User-agents understand protocol-relative links, so instead of the
        // URL produced in JS we can just give a universal one. Since it's
        // sitting there in the DOM ready to go, the browser can preload the
        // file for us and we're less likely to have to wait for it.
        $piwikUrl = '//' . $this->piwikroot . 'piwik.js';
        $piwikCode = <<<ENDOFPIWIK
try {
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->piwikroot}" : "http://{$this->piwikroot}");
    var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$this->piwikId});
    piwikTracker.trackPageView();
    piwikTracker.enableLinkTracking();
} catch( err ) {}
ENDOFPIWIK;
        // Don't use $action->script() here; it'll try to preface the URL.
        $action->element('script', array('type' => 'text/javascript', 'src' => $piwikUrl), ' ');
        $action->inlineScript($piwikCode);
        return true;
    }
 public function onEndShowScripts(Action $action)
 {
     // @todo FIXME: "Show Navigation" / "Hide Navigation" needs i18n
     $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;
             });
             $("#navtoggle").click(function () {
                       $("#site_nav_local_views").fadeToggle();
                       var text = $("#navtoggle").text();
                       $("#navtoggle").text(
                       text == "Show Navigation" ? "Hide Navigation" : "Show Navigation");
             });
         });');
     if ($this->serveMobile) {
         $action->inlineScript('$(function() { $(".checkbox-wrapper").unbind("click"); });');
     }
 }