Is it possible to add a shadowbox.tpl.php file to the theme so that any url's loaded within the shadowbox use this tpl instead of the main page.tpl.php?

Alternatively, is there a way to detect if the shadowbox is being used or not?

Comments

nicholas.alipaz’s picture

you mean a tpl to use for iframed shadowbox content? So that one could have a modal version of the content for viewing within the shadowbox window?

iancawthorne’s picture

Yep exactly what I was thinking. Is it possible?

nicholas.alipaz’s picture

you can add as many tpl's as you like to your theme, you just need to add a template suggestion. Example:

function MYTHEME_preprocess_page(&$vars) {
  // a global to allow for setting modal display via php
  global $shadowbox_load_modal;
  // check for alternate page-node-XX-shadowbox.tpl.php files, allowing override of page tpl for modal windows
  if ($vars['node']->nid != "" && module_exists('shadowbox')) {
    $vars['template_files'][] = "page-node-" . $vars['node']->nid . "-shadowbox";
  }
  // check for a query string of ?load_mode=modal and use the page-shadowbox-modal.tpl.php file for rendering
  //   EX: <a href="/node/22?load_mode=modal"... would open with this tpl.php
  // we also check for our global $shadowbox_load_modal to see if it has been set somewhere.
  else if ($_GET['load_mode'] == 'modal' || $shadowbox_load_modal == TRUE) {
    $vars['template_files'][] = 'page-shadowbox-modal';
  }
}

Let me know if that solves your issue.

--
Los Angeles Web Design and development for Drupal.

iancawthorne’s picture

That's for looking at this. It seems pretty close, the only part that is not quite right for me is the detection.

The snippet above seems to detect if a variable has been set in the $_GET.

I was hoping to detect to use the correct tpl file if the shadowbox is active, unless I have misunderstood?

nicholas.alipaz’s picture

I am not too sure of a way to really do what you are asking. What I suggest is creating content type called say, "Shadowbox Page" (namespace "shadowbox_page") and you can apply a custom theme to those pages.

function MYTHEME_preprocess_page(&$vars) {
  // allow template files for page-node-[node_type_namespace].tpl.php
  if ($vars['node']->type != "") {
    $vars['template_files'][] = "page-node-" . $vars['node']->type;
  }
}

Then just create a page-node-shadowbox_page.tpl.php and all of these pages will show in a shadowbox. Unfortunately I don't know of any way for javascript to essentially tell PHP which template to use, which is what you are kind of asking for.

--
Los Angeles Web Design and development for Drupal.

nicholas.alipaz’s picture

Actually the more I think about it, I bet we could just use some jQuery to tack on the variable in the $_GET whenever the links is set to open in a shadowbox. That would keep you from having to alter your links via hard code. Let me know if that seems like an adequate solution for you.

--
Los Angeles Web Design and development for Drupal.

iancawthorne’s picture

Thanks for getting back on this.

The ideal solution would be to detect if the page is within the shadowbox or not but it sounds like the jquery to add on the variable would do the trick as a work around solution. Then you can pick and choose virtually anything.

Could you give an example of how to add the variable on using jquery?

Most of my requirements are for .form-submit as the click event.

nicholas.alipaz’s picture

Some variation of the code I used in #770990: Possible to exclude certain elements? (views galleriffic compatibility problem) should work:

$(document).ready(function() {
  $(".MYSELECTOR, .MYOTHERSELECTOR, #ANOTHERCOOLSELECTOR").each(function() {
    this.href += "?load_mode=modal";
  });
});

--
Los Angeles Web Design and development for Drupal.

iancawthorne’s picture

Thanks, that works perfect on hyper links.

Is there a way to apply this to form buttons?

nicholas.alipaz’s picture

$(".button").each(function() {
  $(this).click(function(){
    // put something here
  });
});

Now I am not completely sure what it is your button is programmed to do, so I don't know what to put in the middle of that code. Hopefully this should give you some headway on usage however.

--
Los Angeles Web Design and development for Drupal.

iancawthorne’s picture

Sorry, I should have been more specific.

The main usage is for node add / edit forms and comment forms (attempting to use shadowbox like the overlay module works in Drupal 7).