fancybox 2 and form with response in same page - forms

I'd like to use Fancybox 2 with jQuery to open a page via Ajax, form_page.php and then get the response in the same fancybox window...
I use this as js:
$(document).ready(function() {
$(".various").fancybox({
maxWidth : 550,
maxHeight : 450,
fitToView : false,
width : '70%',
height : '70%',
autoSize : false,
closeClick : false,
openEffect : 'none',
closeEffect : 'none'
});
});
html is:
<a class="various fancybox.ajax" href="/form_page.php">Ajax</a>
I just need that the POST is loaded in the same /form_page.php inside Fancybox.

I use the iframe variation when putting forms in Fancybox. This allows me to do regular posts, etc. When the form is successfully processed, I use JavaScript to close the Fancybox "pop-up" and refresh the calling parent document.
Fancybox "Pop-up" Forms:
$('a.popup').fancybox({
'type':'iframe',
'hideOnContentClick':false,
'overlayShow':true,
'speedIn':100,
'speedOut':50,
'width':600,
'height':500,
'padding':0,
'margin':0,
'onClosed':function(){window.location.reload();},
'onComplete':function(){$('input.focus:last').focus();}
});
Close "Pop-up":
if (window.self !== window.top) {
// is nested
parent.$.fancybox.close();
}

I think you can try to declare your fancybox and use the option afterShow to bind your form:
$('.various').fancybox({
closeClick: false,
afterShow: function() {
$("form#user_new").bind('ajax:success', function(evt, data, status, xhr) {
// When your form will be submitted and successfull,
// You can try to open a fancybox here with your result here
}
}
});
That's not really a code to copy/paste because I didn't give exactly what you want, for the simple reason that I don't know as well ;) but if it can help.

Related

Perform action after TinyMCE rendered in DOM

I'm using TinyMCE 4 and setting it up as follows:
tinyMCE.init({
mode : "specific_textareas",
editor_selector : "basicTinyMCE",
theme : "modern",
readonly : false,
...});
I want to call a function after it has been rendered in the DOM.
I came across this and tried:
tinyMCE.init({
mode : "specific_textareas",
editor_selector : "basicTinyMCE",
theme : "modern",
readonly : false,
setup : function(ed) {
ed.onPostRender.add(function(ed,cm) {
console.log('After render: ' + ed.id);
});
}
});
I get the following error:
SCRIPT5007: Unable to get property 'add' of undefined or null reference
Any ideas if this is the correct way to achieve what I want?
And if so, why is the error appearing?
You've got two options:
Use configuration init_instance_callback http://www.tinymce.com/wiki.php/Configuration:init_instance_callback
Use new way to add callbacks
ed.on('postRender', function(e) {
console.log('postRender');
});
I found the "Dirty" event was what I wanted, only triggered after the user makes a change to the contents of the editor
https://www.tiny.cloud/docs/advanced/events/

Fancybox open twice programmatically 2.06

I am trying to open fancybox programmatically. Not through link. Once user click addform and i create form manually and show the form in fancybox. sout variable contains the form html.
$.fancybox({
openEffect : "none",
closeEffect : "none",
autoDimensions : false,
width : 620,
height : "auto",
content : sOut
});
Then call this
$.fancybox.close();
My problem now is when i clcked same button the fancybox not showing up again. if you have done this let me know. How to close properly fancybox so i can reopen.
Probably, you must remove the below command in fancybox code:
'hideOnContentClick': true

Can't control width and height of video in fancy box

I eventually want to create a photo gallery... clicking on a picture will launch a You Tube video. I am using fancybox 2.0.
I have the video opening up inline but I cannot control its dimensions. Could you please take a look at this page for me and see where I am fouling up.
http://www.bytebrothers.com/bb_tester/Video_lightbox_test.htm
Thank you,
darrell#bytebrothers.com
This is how your script looks like right now
$(document).ready(function() {
$('.fancyYouTube').fancybox({
width : 400,
height : 300,
autoSize : false,
type : 'swf'
})
and this is how it should look like
$(document).ready(function() {
$('.fancyYouTube').fancybox({
width : 400,
height : 300,
autoSize : false
});
});
you are missing some closing brackets.
On the other hand, if you are using fancybox-media, you don't need to specify type:'swf'
UPDATE: when targeting youtube videos in embed (youtube iframe mode) mode, add the class fancybox.iframe to your anchor so this
<a class="fancyYouTube" href="http://www.youtube.com/embed/dx6TZgUSquY">
should be this
<a class="fancyYouTube fancybox.iframe" href="http://www.youtube.com/embed/dx6TZgUSquY">

Current plugins for padding in TinyMCE

I've been looking for hours to find a plugin that would add somthing like "padding: 5px" to an image. Does everyone do this through plain html? Our customer need a way to add this simply with the use of a button or right click context menu. Any suggestions/solutions or do I have to develop this myself?
Suggestions concerning other products than TinyMCE is not necessary.
The easiest to use is to add a custom stylesheet which only need to be set as a parameter (content_css). Example code snippet for the tinymce configuration:
...
theme: 'advanced',
content_css: "http://my_server/my_css/my_custom_css_file.css",
...
This css should contain something like the following
img {
padding-left: 5px;
}
The code for the tinymce button is a bit more complex (but if wised i can post it as well) and the css gets set using the following
$(ed.get('my_editor_id').getBody()).find('img').css('padding-left','5px');
UPDATE: Button code:
tinyMCE.init({
...
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
ed.addButton ('wrap_div', {
'title' : 'my title',
'image' : 'my_image.png',
'onclick' : function () {
ed.getBody().find('img').css('padding-left','5px');
}
});
});
}
});

Fancybox resize

I am using a fancy box which displays images, youtube video link and other videos. The user can navigate in the fancy box to go to next display or previous display. My problem is the fancy box doesn't get re-sized based on the displayed content. My code is as below:
$.fancybox(href,{
'autoScale': true,
'autoDimensions': true,
'padding': 30,
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'iframe', //'iframe', //'image',
'changeFade': 300,
'cyclic': false,
});
I have tried solving this issue by calling a function in "onComplete" but no success till now. Please provide few inputs on this.
Thanks
setting "autoScale" to false should work...
I'm not a web developer by any means, but the documentation says:
$.fancybox.resize Auto-resizes FancyBox height to match height of content
Is that what you want?
You need to call a new fancybox within the old one. If you "open" a new fancybox from within the first one, it will resize itself. Try:
<script type="text/javascript">
$(document).ready(function() {
var content = '
<div id="nextbox">Box 1</div>
<script type="text/javascript">
$("#nextbox").click(function() {
$.fancybox('Box2',{
'autoDimensions': false,
'height' : 400,
'width' :400
});
});
</script>
';
$.fancybox(content,{
'autoDimensions': false,
'height' : 200,
'width' : 200
});
</script>
This will open up a fancybox that says "Box 1". When you click on "Box 1" it will resize from 200px by 200px to 400px by 400px and change text to "Box 2". And you can keep on doing this for as many boxes as you want.
I see the question is old, but hope someone can use this as I struggled a long time myself finding out how to resize fancybox once it was initiated.
In my case while using Fancybox 2 the setting was called fitToView
set it to true
here is what I use to launch fancybox, you do not need to put it in ready
(function($){
$(document).on('click','.fancybox',function(e){
//don't follow link
e.preventDefault();
//update fancybox image registry for gallery and open it
var fbox = $('.fancybox');
//this always opens the first image first
$.fancybox(fbox,{
index: fbox.index(this),
padding: 5,
live: false,
helpers : {
overlay : {
css : {
'background-color' : 'rgba(17, 17, 17, 0.3)',
},
closeClick: true,
showEarly : true,
locked : false //if true, causes background to jump
},
thumbs : {
width : 140,
height : 100,
source : function(item) {
var href = $(item.element).data('thumb');
if(typeof href === 'undefined'){
if (item.element) {
href = $(item.element).find('img').attr('src');
}
if (!href && item.type === 'image' && item.href) {
href = item.href;
}
}
return href;
}
}
},
scrolling: 'visible',
fitToView: true,
iframe:{
scrolling : 'auto',
preload : false
}
});
});
})(jQuery);