Jump to content

TinyMCE + Insert image + Modal window


nikola
 Share

Recommended Posts

Would it be possible to add another checkbox beside "Link to larger version?" that would call fancybox or some similar script "in "Edit image" modal window that appears after you select your image in "Select image" modal window?

It would also need some sort of input field somewhere where you can define what class or rel triggers that script.

I want to avoid using bramus cssextras plugin for tinymce...

Link to comment
Share on other sites

Let's say I'm adding an image, then I set width and height and then I check "Link to larger version?".

This way image is opening in normal browser window. I would like to have an extra checkbox, for example "Use Fancybox" and when this is checked it would assign specified class or rel to that image so it can open in Fancybox window or with similar script.

An input field would exist somewhere where I would specify class or rel applied to an image.

Thx Ryan.

Link to comment
Share on other sites

The "link to larger version" is actually intended to be without implementation so that you can implement it with a lightbox of your choice. Rarely in my sites do I actually leave it as literally linking to the larger version. Instead, I'll usually put in some javascript like this:

$(document).ready(function() {
    $("#bodycopy a:has(img)").fancybox();
}); 

Or if you want to add some attributes and do it that way:

$(document).ready(function() {
    $("#bodycopy a:has(img)").addClass('lightbox').attr('rel', 'gallery'); 
    $("a.lightbox").fancybox(); 
}); 

Now if you want to be able to support more then one way of linking to a large image (i.e. have one link to the larger version and another opening in a lightbox) then you'd probably need to take another approach (or maybe make a module). Let me know if that is your need.

  • Like 2
Link to comment
Share on other sites

I actually thought about that approach, but it would apply fancybox or similar effect to all image links throughout the content area (bodycopy). For instance, if I have an image linking to some url, page or file, the effect would be applied nevertheless to that link.

Link to comment
Share on other sites

That's not a problem, you can just tell jQuery to only target <a> links that have an href pointing to your site's files. Something like this should work, though could be taken further too.

$(document).ready(function() {
    $("#bodycopy a[href*=site/assets/]:has(img)").fancybox();
}); 
Link to comment
Share on other sites

  • 10 months later...

The "link to larger version" is actually intended to be without implementation so that you can implement it with a lightbox of your choice. Rarely in my sites do I actually leave it as literally linking to the larger version. Instead, I'll usually put in some javascript like this:

$(document).ready(function() {
$("#bodycopy a:has(img)").fancybox();
}); 

Or if you want to add some attributes and do it that way:

$(document).ready(function() {
$("#bodycopy a:has(img)").addClass('lightbox').attr('rel', 'gallery');
$("a.lightbox").fancybox();
}); 

Now if you want to be able to support more then one way of linking to a large image (i.e. have one link to the larger version and another opening in a lightbox) then you'd probably need to take another approach (or maybe make a module). Let me know if that is your need.

Thanks Ryan, this really helped me out, is there anything your not good at?! :)

Is there anyway of passing a php variable to set the "rel" attribute. Ie: the $page->name and maybe the image description for the a "title" tag?

Link to comment
Share on other sites

Is there anyway of passing a php variable to set the "rel" attribute. Ie: the $page->name?

You can put this on the header of the page:

<?php echo "<script><!-- define variables for JS -->
  var pageName = {$page->name},
  pageTitle = {$page->title},
  pageWhatever = {$page->whatever};
</script>"; ?>

and on your script:

$("#bodycopy a:has(img)").addClass('lightbox').attr('rel', pageName);
Link to comment
Share on other sites

sorry, I should have mentioned that you have to put it before calling the javascript file:

<?php echo "<script><!-- define variables for JS -->
var pageName = '{$page->name}',
pageTitle = '{$page->title}',
pageWhatever = '{$page->whatever}';
</script>"; ?>

<script type="text/javascript" src="<?php echo $config->urls->templates?>scripts/main.js"></script>

edit: corrected the order and added quotation marks

Link to comment
Share on other sites

It's before, already updated the post...

Thanks I've no idea why this won't work though.

Code in full:

Within <head> tag:

<?php echo "<script><!-- define variables for JS -->
 var pageName = {$page->name}
</script>"; ?>

<script type="text/javascript" src="<?php echo $config->urls->templates?>scripts/scripts.js"></script>

In scripts.js:

$(document).ready(function() {
   $(".body_copy a:has(img)").addClass('fancy').attr({
    rel: pageName,
    title: pageName
   }); 
});

I also tried a single attribute but the values don't get passed to the anchor tag.

Strange

Link to comment
Share on other sites

Ok, spotted! I forgot the quotation marks on javascript. Already corrected on the above code.

Perfect! Thanks, think the first var still needs the quotes, thanks for your assistance as ever Mr Diogo :)

Sorry to bug you....

Any idea how to pass the images description field to the a title attr?

These are images from within the body...

I have this currently on the scripts page

$(document).ready(function() {

var title = $(".body_copy a:has(img) img").attr("alt");

   $(".body_copy a:has(img)").addClass('fancy').attr({
    rel: pageName,
    title: title
   }); 

}); 

Which sort of works but it always passes the first image description to each anchor tag...

Link to comment
Share on other sites

This seems to have done the trick

$(document).ready(function() {

$(".body_copy a:has(img)").addClass('fancy').attr({
rel: pageName,
title: "title"
});

$(".body_copy a:has(img)").attr("title", function() {
return $(this).find("img").attr("alt");
});
});

I'm sure it can be shortened and prettified but it's seems to be working - I really need to invest some time in learning jQuery!

Based on here:

http://stackoverflow...following-eleme

Link to comment
Share on other sites

You are selecting twice the same element, and defining twice the same attribute. Not very efficient... Try this:

$(document).ready(function() {

$(".body_copy a:has(img)").addClass('fancy').attr({
       rel: pageName,
       title: function() {
                       return $(this).find("img").attr("alt");
               }
   });
});

note: I didn't test it

Link to comment
Share on other sites

You are selecting twice the same element, and defining twice the same attribute. Not very efficient... Try this:

$(document).ready(function() {

$(".body_copy a:has(img)").addClass('fancy').attr({
rel: pageName,
title: function() {
return $(this).find("img").attr("alt");
}
});

note: I didn't test it

Thanks that's better though think it's lacking a });

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...