id = $id;
$this->stepCount = 0;
$this->steps = array();
$this->pages = array();
$this->current_page_slug = '_';
if ( isset($_GET['page']) ) $this->current_page_slug = $_GET['page'];
}
function tourOn(){
if( isset( $_POST['restart-tour-'.$this->id] ) ) {
$this->resetTour();
return true;
}
//check if tour should be loaded
return get_option( 'tiptour_on_'.$this->id , 1 ) == 1 ? true : false;
}
function resetTour(){
unset( $_GET['tour_step'] ); //this makes sure we start the tour at 0, even if we've previously gotten to a higher step without leaving the page
update_option( 'tiptour_on_'.$this->id , 1 );
}
function resetTourButton(){
return '
';
}
function toggleTour( $toggle ){ /* true or false */
if( !is_bool( $toggle ) ) $toggle = false;
$toggle = $toggle ? 1 : 0;
$done = update_option( 'tiptour_on_'.$this->id , $toggle );
}
function loadTour(){
if( !$this->tourOn() ) return;
//check pages - only load on appropriate pages
global $pagenow;
if( isset( $this->pages[$pagenow] ) && isset( $this->pages[$pagenow][$this->current_page_slug] ) ){
add_action( 'admin_enqueue_scripts', array( &$this , 'loadStyles' ) );
add_action( 'admin_enqueue_scripts', array( &$this , 'loadScripts' ) );
//add_action( 'admin_head', array( &$this, 'admin_head' ) );
add_action( 'admin_print_footer_scripts', array( &$this, 'printPointers' ), 99 );
//echo '
loaded';
add_action( 'wp_ajax_end_tiptour_'.$this->id, array( $this, 'endTour' ) , 10 , 0 ); //TODO
}
}
function addStep( $step ){
$this->steps[$this->stepCount] = $step;
$step->step_index = $this->stepCount;
if( !isset( $this->pages[$step->page] ) ) $this->pages[$step->page] = array();
if( !isset( $this->pages[$step->page][$step->page_slug] ) ) $this->pages[$step->page][$step->page_slug] = array();
$this->pages[$step->page][$step->page_slug][] = $this->stepCount;
$this->stepCount++;
}
function endTour(){
check_ajax_referer( $this->nonceAction() , 'security' );
//update option to disable tour
$this->toggleTour( false );
die(); // this is required to return a proper result
}
function loadStyles(){
wp_enqueue_style( 'wp-pointer' );
}
function loadScripts(){
wp_enqueue_script( 'jquery-ui' );
wp_enqueue_script( 'wp-pointer' );
wp_enqueue_script( 'utils' );
}
function printPointers(){
global $pagenow;
$tour_step = isset( $_GET['tour_step'] ) ? $_GET['tour_step'] : 0;
if( isset( $this->pages[$pagenow] ) && isset( $this->pages[$pagenow][$this->current_page_slug] ) ){
//For the first step, only load the pointers for this page if step 2 is also on this page
if( $tour_step == 0 &&
( $this->steps[1]->page != $pagenow ||
$this->steps[1]->page_slug != $this->current_page_slug ) ) {
$this->pagePointers = array( 0 );
}
else{
unset( $this->pages[$pagenow][$this->current_page_slug][0] );
$this->pagePointers = $this->pages[$pagenow][$this->current_page_slug];
}
?>
steps[$k]; //$this->pagePointers[$k]];
//$this->steps[$step_index];
$step_index = $step->step_index;
//Stay on the same page
$href = '#';
//if( count( $this->pagePointers ) > $k+1 ){
//If the next step is also on this page
if( in_array( $k+1 , $this->pagePointers ) ){
//Open the next pointer
$href = '#';
$jump = false;
}
//Move onto the next page
else{
//redirect to the next page, if it exists
if( isset( $this->steps[$step_index+1] ) ){
$nextPointer = $this->steps[$step_index+1];
$href = $nextPointer->getURL();
$jump = true;
}
else{
$done = true;
$jump = false;
}
}
?>
// Start Step
var options = {
content: 'content ); ?>'
,position: {
edge: 'position; ?>',
offset: 'offset; ?>'
}
,buttons: function( event, t ) {
var $buttonClose = jQuery('End Tour');
$buttonClose.bind( 'click.pointer', function() {
var data = {
action: 'end_tiptour_id; ?>',
security: 'nonceAction() ); ?>',
};
$.post(ajaxurl, data, function(response) {
//console.log(response);
});
t.element.pointer('close');
});
var $buttonNext = $('nextText; ?>');
$buttonNext.bind( 'click.pointer', function(){
t.element.pointer('close');
buildPointerJS( $k+1 );
}
?>
});
var buttons = $('