How can I add a delete button to FancyBox - php

How can I include a delete button in FancyBox when displaying images from a mySQL database using PHP and jQuery?
$("[data-fancybox]").fancybox();
$.fancybox.defaults.buttons = [
'slideShow',
'fullScreen',
'thumbs',
'delete', // this one is the new button
'close'
];
$('body').on('click', '[data-fancybox-delete]', function(e) {
var src = $('.fancybox-slide--current .fancybox-image').attr('src'); // src of the currently showing slide
var idx = $('a[href="' + src + '"]')[0]; // My Tag
});
$('body').on('click', '[data-fancybox-delete]', function(e) {
var src = $.fancybox.getInstance().current.src;
var idx = $.fancybox.getInstance().current.opts.$orig;
});

If anyone lands here from Google, here's how to actually add a custom button to the fullscreen gallery, when you initialize FancyBox via Javascript :
$('[data-fancybox="gallery"]').fancybox({
buttons: [
"zoom",
"slideShow",
"thumbs",
"close",
"delete" //this is the name of my custom button
],
btnTpl: {
//and this is where I defined it
delete:
'<a download data-fancybox-delete class="fancybox-button fancybox-button--delete" title="Delete" href="#">' +
'<i class="fas fa-trash-alt"></i>' +
"</a>"
}
});
From the official documentation.

I see that you are using image to be shown to fancybox. why dont you try showing an actual div that is hidden. and adding the hidden div to your fancy box. here's a link I've implemented on https://clientsnb.com/proyectos/equipamiento-integral-renault/ try clicking on the button PREGUNTANOS and it shows a form from a hidden content.

Related

How to initialize href using jQuery

I'm trying to append my href attribute values by using the below code
$(document).ready(function() {
jQuery("#help_url").click(function(){
var href = $(this).attr('href');
alert(href);
var txt_api_key = $('#txt_api_key').val();
var txt_postcode = $('#txt_postcode').val();
var txt_countrycode = $('#txt_countrycode').val();
$('a#help_url').attr('href', href+txt_postcode+"/"+txt_countrycode+"?api_key="+txt_api_key);
});
});
This is working perfect. But the issue is after the first click the link will become http://api.fastway.org/v1/psc/pickuprf/2148/1?api_key=5340c900251a6105a19a58a1590472bb and on the next click after I changing the "txt_countrycode" value or if not chnaging any value it becomes http://api.fastway.org/v1/psc/pickuprf/2148/1?api_key=5340c900251a6105a19a58a1590472bb2148/1?api_key=5340c900251a6105a19a58a1590472bb
ie, again adding "href+txt_postcode+"/"+txt_countrycode+"?api_key="+txt_api_key"
How can I solve this?
One easy solution is to read the value of the href in dom ready and use it in the click handler, so that the href will have a non updated value
$(document).ready(function () {
var href = jQuery('#help_url').attr('href');
jQuery("#help_url").click(function () {
alert(href);
var txt_api_key = $('#txt_api_key').val();
var txt_postcode = $('#txt_postcode').val();
var txt_countrycode = $('#txt_countrycode').val();
$('a#help_url').attr('href', href + txt_postcode + "/" + txt_countrycode + "?api_key=" + txt_api_key);
});
});
When you click the button the click event will call .
the click event function have concatenation with existing url.So the existing url is append with country code

Simple Modal opens PHP records based on ID

I'm trying to open a php record inside of simple modal box. I already tried to open a record using fancybox.
In fancybox just like this
<td><a class="fancybox" href="url.php?id='.$row["id"].'"><img src=".png"></a></td>
How to do that in simple modal?
SimpleModal
$("myElement").addEvent("click", function(){
var SM = new SimpleModal({"width":600});
SM.addButton("Action button", "btn primary", function(){
this.hide();
});
SM.addButton("Cancel", "btn");
SM.show({
"model":"modal-ajax",
"title":"Title",
"param":{
"url":"ajax-content.php",
"onRequestComplete": function(){ /* Action on request complete */ }
}
});
});
<li class="example-item" id="modal-ajax">
<img src=".jpg">
Modal Ajax</li>

Create a jquery ajax image organizer

I want to create a button on imperavi's redactor, that will display uploaded files (only photos) in a modal, that i previously uploaded, and i will allow the user, to organize this photos, order their order and organize them in folders, and create folders. And when the user select the photo, the tag is inserted in the text field (redactor).
I rely want a place to begin, or a already existing solution, my knowledge with php is big but my jquery and ajax is very small
I don't want to display the computer folder, i want to display the images int the database
Sorry for the bad English.
Where do i begin?
edit 1:
I manged to add the button
if (typeof RedactorPlugins === 'undefined') var RedactorPlugins = {};
RedactorPlugins.myPlugin = {
init: function() {
this.addBtn('myMethod', 'Add Image', function(obj) {
obj.myMethod();
});
},
myMethod: function()
{
// callback (optional)
var callback = $.proxy(function()
{
return 1;
}, this);
var modal = String() +
'<div id="redactor_modal_content">' +
'<div class="modal-body">' +
'<p>One fine body...</p>' +
'</div>' +
'<div id="redactor_modal_footer">' +
'Close' +
'Save changes' +
'</div>' +
'</div>';
// 500 it is the width of the window in pixels
// or call a modal with a code
this.modalInit('<h3>Modal header</h3>', modal, 500, callback);
// call a modal from element with ID #mymodal
//this.modalInit('<h3>Modal header</h3>', '#mymodal', 500, callback);
}
}

jCarousel initializing/refreshing/reloading each time clicked on image

I am making a picture preview with jCarousel (http://sorgalla.com/projects/jcarousel/), but faced with one problem: I do not know how could I reload/refresh jCarousel dynamic list.
I have few categories of images. When I click on a picture in one of that, I need that the list would be created and preview start with that element. I have some code, but do not know how to make it re-create all list after clicking on other image that preview start with other image.
Here are my code:
$(document).ready(function(){
$("ul#stage li").live('click', function() {
var ul = $(this).parent();
var index = +(ul.children().index(this))+1;
var mycarousel_itemList = [ ];
$('li[data-id]').each(function () {
var $this = $(this);
mycarousel_itemList.push({
url : $this.attr("data-img"),
title : $this.attr("data-title")
});
});
function mycarousel_itemLoadCallback(carousel, state) {
for (var i = carousel.first; i <= carousel.last; i++) {
if (carousel.has(i)) {
continue;
}
if (i > mycarousel_itemList.length) {
break;
}
carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[i-1]));
}
};
function mycarousel_getItemHTML(item) {
return '<img src="' + item.url + '" width="800" height="600" alt="' + item.url + '" />';
};
alert(index);
jQuery('#mycarousel').jcarousel({
itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback},
size: mycarousel_itemList.length,
scroll: 1,
start: index,
wrap: 'last',
animation: 'fast',
visible: 1
});
document.getElementById('popup-content').style.background='url('+$(this).attr("data-img")+') no-repeat center';
document.getElementById('fades').style.display='block';
document.getElementById("light").style.display = "block";
$("#light").fadeTo("slow", 1);
});
});
Everything is like that: there are images > I click on one of those > popup shows with jCarousel and one visible image and then I could scroll through all other images.
It is working good, but just a first time. When I click on other image (after closing popup), the view starts with that image which was opened last.
If something are not clear enough - please, ask. I will try to make it more precisely.
Thanks for your help!
You can recreate jCarousel, first use $('#mycarousel').remove(); and next init jCarousel again. I didn't really understand what you're trying to do, but this can help in most cases, of course jCarousel should have Destroy method but it hasn't.
And why you don't use jquery selectors in some cases?

Reload Jquery UI Parent Dialog

All,
When I click a link on a web page, a JQuery UI Dialog opens up and it loads some ajax content into it. If I click a link inside this dialog, it opens up a child dialog. When I click "OK" in the child dialog, I want the child dialog to close and refresh the ajax content in the parent dialog.
Do you already have the code that closes the child dialog ? Is it an alert() call ? If so, simply add a
location.reload();
after the alert call. If it's something more complicated like a link, try
$('a.link-that-closes-dialog').click(function(){
//Code to close the dialog
location.reload();
});
i use this script for choose if show/hide any content.
After clicking button "Ritira" in the dialog, the page redirect me in the same page but whit a querystring (ex. www.mypage.ext?t=yes).
The script work, but I wish at the click of the button "Check Out" there is a refresh of the page.
I tried to enter the location.reload but did not work:
$(function() {
$(document).ready(function() {
$(".dialog-ritira").dialog({
autoOpen: false,
modal: true
});
});
$(".ritira").click(function(e) {
e.preventDefault();
var targetUrl = $(this).attr("href");
$(".dialog-ritira").dialog({
buttons : {
"Ritira" : function() {
window.location.href = targetUrl;
location.reload();
},
"Annulla" : function() {
$(this).dialog("close");
}
}
});
$(".dialog-ritira").dialog("open");
});
});
Thanks

Categories