Changeset - b55cc3e8ac74
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 13 years ago 2012-11-27 23:46:25
ohnobinki@ohnopublishing.net
Fix sharing dialogue to give links to the currently selected permutation/tab, fixing bug #92.
3 files changed with 27 insertions and 9 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
@@ -117,49 +117,49 @@ class page
 
   *     - 'semester': The semester to use instead of the autodetected one.
 
   */
 
  protected function __construct($ntitle, $nscripts = array(), $immediate = TRUE, array $options = array())
 
  {
 
    /* Begin tracking generation time */
 
    $this->pageGenTime = round(microtime(),4);
 

	
 
    global $ga_trackers;
 

	
 
    require_once('school.inc');
 

	
 
    /* Scripts and styles available for inclusion */
 

	
 
    $this->headCode['jQuery'] = '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>';
 
    $this->headCode['jQueryUI'] = '<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script><link rel="stylesheet" href="styles/jqueryui.css" type="text/css" media="screen" charset="utf-8" />';
 
    $this->headCode['jValidate'] = '<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.pack.js"></script>';
 
    $this->headCode['jAddress'] = '<script type="text/javascript" src="http://js.ohnopub.net/js/jquery.address-1.3.2.min.js"></script>';
 
    $this->headCode['jQuery.cuteTime'] = '<script type="text/javascript" src="http://js.ohnopub.net/js/ohnobinki/2011.04.19/jquery.cuteTime.min.js"></script>';
 
    $this->headCode['qTip'] = '<script type="text/javascript" src="http://js.ohnopub.net/js/jquery.qtip-1.0.min.js"></script>';
 
    $this->headCode['qTip2'] = '<script type="text/javascript" src="http://js.ohnopub.net/js/2011.03.21/jquery.qtip.min.js"></script><link rel="stylesheet" href="http://js.ohnopub.net/js/2011.03.21/jquery.qtip.min.css" type="text/css" media="screen" />';
 
    $this->headCode['schedInput'] = '<script type="text/javascript" src="scripts/scheduleInput.js"></script>';
 
    $this->headCode['outputPrintStyle'] = '<link rel="stylesheet" href="styles/print.css" type="text/css" media="screen" charset="utf-8" />';
 
    $this->headCode['outputStyle'] = '<link rel="stylesheet" href="styles/output.css" type="text/css" media="screen" charset="utf-8" />'; 
 
    $this->headCode['gliderHeadcode'] = '<link rel="stylesheet" href="styles/glider.css" type="text/css" media="screen" charset="utf-8" />'; 
 
    $this->headCode['uiTabsKeyboard'] = '<script type="text/javascript" src="scripts/uiTabsKeyboard.js"></script>';
 
    $this->headCode['uiTabsKeyboard'] = '<script type="text/javascript" src="scripts/uiTabsKeyboard.js?v=20121128h"></script>';
 
    $this->headCode['displayTables'] = '<script type="text/javascript" src="scripts/displayTables.js"></script>';
 

	
 
    $this->pagetitle = $ntitle;
 
    $this->scripts = $nscripts;
 
    $this->meta = array(
 
      'msapplication-starturl' => self::uri_resolve(''),
 
      'msapplication-task' => 'name=Create Schedule; action-uri=' . self::uri_resolve('input.php') . '; icon-uri=' . self::uri_resolve('images/favicon_96.png'),
 
      'msapplication-tooltip' => 'Find the semester schedule which works for you!',
 
    );
 

	
 
   /* Compliant browsers which care, such as gecko, explicitly request xhtml: */
 
   if(empty($_SERVER['HTTP_ACCEPT'])  /* then the browser doesn't care :-) */
 
      || strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') !== FALSE)
 
       $this->xhtml = TRUE;
 

	
 
   if (count($ga_trackers))
 
     {
 
       $ga_www = 'http://www.';
 
       if ($_SERVER['SERVER_PORT'] != 80)
 
	 $ga_www = 'https://ssl.';
 

	
 
       $this->trackingcode = '<script type="text/javascript" src="' . $ga_www . 'google-analytics.com/ga.js" />' . "\n"
 
	 . $this->trackingcode
 
	 . '  <script type="text/javascript">' . "\n"
inc/class.schedule.php
Show inline comments
 
@@ -441,104 +441,104 @@ class Schedule
 
    $page = 0;
 
    if (isset($_REQUEST['page']))
 
      $page = $_REQUEST['page'];
 
    /*
 
     * only display the ``this page doesn't exist'' 404 if there is at
 
     * least one permutation. Otherwise, we give an irrelevant 404 for
 
     * users with no permutations.
 
     */
 
    if ($this->nPermutations && $page >= $npages)
 
      Page::show_404('Unable to find page ' . $page . ', there are only ' . $this->nPermutations . ' non-conflicting permutations, for a total of ' . $npages . ' pages.');
 
    /* zero-based */
 
    $first_permutation = $page * SP_PERMUTATIONS_PER_PAGE;
 
    $last_permutation = min($this->nPermutations, $first_permutation + SP_PERMUTATIONS_PER_PAGE);
 

	
 
    $footcloser = '';
 

	
 
    $headcode = array('jQuery', 'jQueryUI', 'uiTabsKeyboard', 'displayTables', 'outputStyle', 'jQuery.cuteTime', 'qTip2');
 
    if(!empty($_REQUEST['print']))
 
      array_push($headcode, 'outputPrintStyle');
 
    else
 
      array_push($headcode, 'jAddress');
 

	
 
    $outputPage = page::page_create(htmlentities($this->getName()), $headcode,
 
				    array('school' => $this->school_get(), 'semester' => $this->semester_get()));
 
    $outputPage->headcode_add('schedule_share_links', $outputPage->script_wrap(
 
      'var share_facebook_template = ' . json_encode('https://facebook.com/sharer.php?t=' . rawurlencode($this->scheduleName) . '&u=' . $outputPage->gen_share_url($this->id_get())) . ";\n"
 
      . 'var share_url_template = ' . json_encode($outputPage->gen_share_url($this->id_get())) . ';'),
 
                              TRUE);
 
    $outputPage->conversion();
 
    if (!empty($this->created))
 
      $outputPage->meta('dcterms.created', gmdate(DATE_W3C, $this->created));
 

	
 
      if ($schedule_store !== NULL
 
	  && $this->parent_get() !== NULL
 
	  && ($parent_schedule = schedule_store_retrieve($schedule_store, $this->parent_get())) !== NULL)
 
        {
 
          $parent_uri = $parent_schedule->my_url();
 
          $outputPage->meta('dcterms.relation', $parent_uri);
 
          $outputPage->meta('dcterms.replaces', $parent_uri);
 
        }
 

	
 
    $outputPage->head();
 

	
 

	
 

	
 
    if(!empty($_REQUEST['print']))
 
      {
 
	$script = ''
 
	  . 'jQuery(document).ready( function() {' . PHP_EOL
 
	  . '  window.print();' . PHP_EOL
 
	  . '});';
 
	echo $outputPage->script_wrap($script);
 
	echo '<p><a href="'.$_SERVER['SCRIPT_NAME'].'?s=' . $this->id_get() . '">&laquo; Return to normal view</a> </p>';
 
    }
 
    else {
 
      echo '        <script type="text/javascript">';
 
      echo '  jQuery(document).ready( function() {';
 
      echo '    jQuery("#tabs").tabs();';
 
      echo '    jQuery.address.change(function(event){';
 
      echo '      jQuery("#tabs").tabs( "select" , window.location.hash );';
 
      echo '    });';
 
      echo '    jQuery("#tabs").bind("tabsselect", function(event, ui) {';
 
      echo '      window.location.hash = ui.tab.hash;';
 
      echo '    });';
 

	
 

	
 
      echo '    jQuery("#sharedialog").dialog({ modal: true, width: 550, resizable: false, draggable: false, autoOpen: false });';
 
      echo '    jQuery("#share").click( function() {
 
                  jQuery("#sharedialog").dialog("open");
 
                });';
 
      echo '    jQuery(\'#printItems\').click( function() {
 
		  window.location = "'.$_SERVER['SCRIPT_NAME'].'?s='.$this->id_get().'&amp;print=" + (jQuery(\'#tabs\').tabs(\'option\',\'selected\') + 1);
 
	        });
 
	        jQuery(\'#cancelItems\').click( function() {
 
		  jQuery(\'#selectItemsInput\').hide();
 
	        });'
 
	. '    ' . PHP_EOL
 
	. '    jQuery(\'.cute-time\').cuteTime();' . PHP_EOL
 
	. '  });' . PHP_EOL
 
	. '        </script>' . PHP_EOL;
 

	
 
      echo '        <div id="sharedialog" title="Share Schedule">' . PHP_EOL
 
	. '          <p class="indent"><img alt="[fb]" class="noborder" src="http://facebook.com/favicon.ico" /> <a href="http://www.facebook.com/sharer.php?u=' . urlencode(htmlentities($outputPage->gen_share_url($this->id_get()))) .'&amp;t=My%20Schedule">Share on Facebook</a></p>
 
		     <p class="indent"><img alt="[sp]" class="noborder" src="images/favicon.svg" style="margin-right: 5px; width: 16px; height: 16px;"/><span class="clicktoclipboard"><a href="#">Share with URL</a><span class="toclipboard hidden"><p>Copy the share URL below:<br /><em class="centeredtext smallurl">' . htmlentities($outputPage->gen_share_url($this->id_get())) . '</em></p></span></span></p>' . PHP_EOL
 
	. '          <p class="indent"><img alt="[fb]" class="noborder" src="http://facebook.com/favicon.ico" /> <a id="share-fb-a" href="http://www.facebook.com/sharer.php?u=' . urlencode(htmlentities($outputPage->gen_share_url($this->id_get()))) .'&amp;t=' . rawurlencode($this->scheduleName) . '">Share on Facebook</a></p>
 
		     <p class="indent"><img alt="[sp]" class="noborder" src="images/favicon.svg" style="margin-right: 5px; width: 16px; height: 16px;"/><span class="clicktoclipboard"><a href="#">Share with URL</a><span class="toclipboard hidden"><p>Copy the share URL below:<br /><em id="share-url-em" class="centeredtext smallurl">' . htmlentities($outputPage->gen_share_url($this->id_get())) . '</em></p></span></span></p>' . PHP_EOL
 
	. '        </div>' . PHP_EOL
 
	. '        <p>' . PHP_EOL
 
	. '          <a href="input.php?s='.$this->id.'" class="button">Edit</a>' . PHP_EOL
 
	. '          <span id="printItems"><a href="#" class="button">Print</a></span>' . PHP_EOL
 
	. '          <span id="share"><a href="#" class="button">Share</a></span>' . PHP_EOL;
 

	
 

	
 
      if (!empty($parent_schedule))
 
        {
 
          echo '          <a class="button" href="' . htmlentities($parent_uri, ENT_QUOTES) . '" title="Parent schedule: ' . htmlentities($parent_schedule->getName()) . '">Parent</a>' . PHP_EOL;
 
        }
 

	
 
      echo '          <a class="button" href="input.php">Home</a>' . PHP_EOL
 
	. '        </p>'. PHP_EOL
 
	. '        <p class="centeredtext">Having problems? <a href="feedback.php">Let us know</a>.</p>' . PHP_EOL
 
	. '        <p class="centeredtext graytext"><em>Keyboard Shortcut: Left and right arrow keys switch between schedules</em></p>' . PHP_EOL;
 
    }		
 

	
 
    echo "\n";
 

	
 
    if($this->nPermutations > 0)
 
      {
 
	/*
 
	 * Figure out if we have to deal with Saturday and then deal
scripts/uiTabsKeyboard.js
Show inline comments
 
/*
 
 * Copyright 2010 Nathan Gelderloos, Ethan Zonca, Nathan Phillip Brink
 
/* -*- tab-width: 4; -*-
 
 * Copyright 2012 Nathan Gelderloos, Ethan Zonca, Nathan Phillip Brink
 
 *
 
 * This file is part of SlatePermutate.
 
 *
 
 * SlatePermutate is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * SlatePermutate is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with SlatePermutate.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
jQuery(document).ready( function() {
 
	var share_facebook_a_obj = jQuery('#share-fb-a');
 
	var share_url_em_obj = jQuery('#share-url-em');
 

	
 
  jQuery(document).keydown(function(e) {
 

	
 
    var direction = null;
 

	
 
   // handle cursor keys
 
   if (e.keyCode == 37) {
 
     // slide left
 
     direction = 'prev';
 
   } else if (e.keyCode == 39) {
 
     // slide right
 
     direction = 'next';
 
   }
 
   if (direction != null) {
 
     var totaltabs = jQuery('#tabs').tabs('length'); //gettting the total # of tabs
 
     var selected = jQuery('#tabs').tabs('option', 'selected');//getting the currently selected tab
 
 
 
     if (direction == 'next') {
 
       if (selected <= totaltabs - 1)
 
       jQuery('#tabs').tabs('select',selected + 1)
 
    }
 
    else {
 
      if (selected != 0)
 
      jQuery('#tabs').tabs('select',selected - 1)
 
    }
 
  }
 
 });
 

	
 
	function share_update_uris(hash)
 
	{
 
		share_facebook_a_obj.attr('href', share_facebook_template + hash.replace('#', '%23'));
 
		share_url_em_obj.text(share_url_template + hash);		
 
	}
 
	share_update_uris(window.location.hash);
 

	
 
	jQuery('#tabs').bind('tabsselect', function(event, ui) {
 
		window.location.hash = ui.tab.hash;
 
		/*
 
		 * Update some links to be specific to the current bug (bug
 
		 * #92).
 
		 */
 
		share_update_uris(ui.tab.hash);
 
	});
 
});
0 comments (0 inline, 0 general)