Ajaxy popups with CMSMS - Using jQuery & Facebox

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by hexdj »

I had been trying to find a way to create inline or even AJAXY popups with CMS Made Simple for a while, something that the end users of the sites could add themselves.

What's the end result of this guide?
It will allow you to display cms pages inside popups that are non-obtrusive, by using Facebox. You can also display images.

Putting it together:
** Download jQueryand Facebox
** In your template (this is the template for the pages from which the popups will be triggered) add the following lines in the

Code: Select all

{literal}
<__script__ type="text/javascript" src="path/to/jquery1.2.6-pack.js"></__script>
<__script__ type="text/javascript" src="path/to/facebox.js"></__script>

<__script__ type="text/javascript">
jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox()  
<!---### NOTICE THIS MEANS POPUPS ARE TRIGGERED FOR <a> tags with the rel="facebox" ATTRIBUTE ### ---->
}) 
</__script>
{/literal}
** Add a stylesheet (Layout>Stylesheets in CMS) and associate it with your template, name it Facebox (for clarity) and paste the CSS from Facebook.css that came with the Facebox package
** In the Facebox stylesheet go and change the path to the images that came with Facebox to where you actually saved them
** You will also need to edit Facebox.js and change manually the path for closelabel.gif and loading.gif files
** To make things a little easier for the user, we'll have to edit one of TinyMCE's Advanced options, manua\lly: Find this file:
modules/TinyMCE/tinymce/jscripts/tiny_mce/plugins/advlink/link.htm and go to aprox. line 200 and add this line:

Code: Select all

<option value="facebox">facebox</option>
** Save everything (Templates, Stylesheet, link.htm) etc

Adding a popup in CMS
**Open a page that u want to trigger a popup from, pick a word for the link and ad any CMSMS link (yeah with the orange palm tree button) then while on that same word that just became a link click on the regular chain button in the TinyMCE toolbar and you'll see the Insert/Edit link box, go to the Advanced tab and from Relationship from page to target select Facebox :)
** This will trigger a Facebox popup to any of your internal CMS pages (though not limited to that) but I suggest you only link to page that you explicitly will be using as popups, then you can make a Template just for popup pages

Notes:
** This method should work with Greybox too, as it uses the rel attribute to trigger the popups. I used facebox because it uses jQuery which I had already been using on my website, so adding facebox was just 12kb more, as opposed to Greybox (44kb)
** You can set the dimmensions for your popup template in your css and it will be applied to the popup
      ** You can even have multiple Popup templates if you want (say Small, Medium, Large) just assign the right one the the page that will pop up
** Thickbox is also jQuery based but it does not use attribs for triggering popups it instead uses a long sting of stuff right next to the href="" link that's why I didn't go for it.

Things that would be nice to figure out
** Making the whole background underneath the popup fade (like greybox does)
    -> This  was actually very easy: simply set the opacity in facebox.js (has to be a value between 0 and 1)
** Make pages that are using the Popup template load differently if the user comes from another site (this means the popup call won't be triggered) Kinda like the main issue Frames had a while back. But I think this is just a CSS workaround.
** It would be neat to be able to add more TinyMCE instances when adding a page (and have those blocks wrapped by the correct code) so inline popups could be triggered as well. But I haven't been able to figure it out, PageBlocks might work, but haven't really tried it.
** Haven't tried adding a multiple picture album, but I think it shouldn't be too hard, will update this post when I know more.
Last edited by hexdj on Fri Aug 22, 2008 3:20 am, edited 1 time in total.
tosd
Forum Members
Forum Members
Posts: 52
Joined: Thu Jan 11, 2007 1:02 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by tosd »

Hello hexdj,

This contribution looks very useful. Thank you for your work and detailed explanation. I found it quite easy to follow but unfortunately I can't get any Facebox popup at all. The Facebox Relationship option is appearing in TinyMCE OK but even after selecting it clicking the link just takes me to the page in the normal way.

One thing I did notice is that the reference for the jquery filename you have in the header code is different to the filename I have. Mine is "jquery-1.2.6.pack.js" - note the different position of the hyphen. Even after making the change to reference the correct filename though I still get no popup.

Any suggestions?
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by hexdj »

tosd: sorry to hear it's not working for you. let's see...

The jQuery filename is not relevant at all, just make sure that it does live on your server and it's referenced correctly. You can always rename this file, makes no difference.

I think I made a mistake in my explanation, please try to modify, line 200+:
modules/TinyMCE/tinymce/jscripts/tiny_mce/plugins/advlink/link.htm
and change line to:

Code: Select all

<option value="facebox">facebox</option>
Notice the value is lowercase now, not capitalized, I believe facebox is case sensitive. Let me know if this works for u.
Last edited by hexdj on Thu Aug 21, 2008 7:20 pm, edited 1 time in total.
tosd
Forum Members
Forum Members
Posts: 52
Joined: Thu Jan 11, 2007 1:02 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by tosd »

Yes, that was it hexdj. Thank you very much. I am really impressed with this plugin and see a lot of use for it. I still have one odd problem though ...

Clicking the link now pops up the window as expected. If the window is then closed, and the link is clicked again, the content is rendered in the facebox window twice! And if you repeat the exercise it is doubled again etc. I have set the page with the link to not cache but to no avail.

Any further suggestions would be appreciated. I think you will find that this will be a very popular addition to CMS Made Simple.
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by hexdj »

Hey tosd, I am not sure why the popup is being called twice. I tried my site and it works as expected. I am wondering though: do you use the same template for the popup pages that u use for pages where the popus are being triggered from? if you do this then that means jQuery and Facebox are being called twice and that might be the cause of this behavior.

This is why I recomended that popups have their own templates (not loading jquery and facebox).
tosd
Forum Members
Forum Members
Posts: 52
Joined: Thu Jan 11, 2007 1:02 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by tosd »

Problem solved hexdj. I was using a separate clean template for the popup content page but stupidly I had posted the into the header of that one as well  :-[ -  I must stop working on these things when my eyes are hanging out of my head!
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by hexdj »

Glad it's working now!
;D
newagekat
Forum Members
Forum Members
Posts: 161
Joined: Mon Feb 06, 2006 6:06 pm

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by newagekat »

Hexdj:

thank you for the very clear information.  I have a question. 

I looked at your website on Firefox 3.5.2 using Mac os 10.5.  when I click on some of your portfolio images, i am taken back to the home page, while others open in a new window - no popup.  I wanted to implement galleriffic, a jquery plugin on my site and experienced the same issue.  i have used that plugin on static sites, and it worked very well, but not in CMSMS.  i'm still on cmsms v1.4.1. 

any ideas why I cannot get the popup on your site to work?

thanks for your time

kp
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Ajaxy popups with CMSMS - Using jQuery & Facebox

Post by hexdj »

@newagekat

Thanks for noticing, I myself hadn't even realized. I will look into it and report back with a fix.
Locked

Return to “Tips and Tricks”