GIF not moving when referenced in my HTML code - javascript

What I'm trying to do is to display a process bar when a user clicks on submit. the gifs works if I just open it in my web browser but when I add a reference to it in my HTML code it doesn't work. My dialog appears with the GIF but the gif doesn't move. Here is my code:
<div id="progressDialog" title="Importing Welcome Kit Rules" style="display: none;">
<img src="#Url.Content("~/Content/Images/AjaxProgress.gif")" alt="Processing" />
<p>Please wait while your request is processed.</p>
</div>
$(document).ready(function () {
// Hide the "busy" Gif at load:
if ($('#progressDialog').dialog('isOpen')) {
$('#progressDialog').dialog('close');
}
// Handle the form submit event, and make the Ajax request:
$("#myform").on("submit", function (event) {
// Show the "busy" Gif:
$("#progressDialog").dialog({
autoOpen: false,
modal: true,
bgiframe: true
});
$('#progressDialog').dialog('open');
});
});

Related

Initializing Magnific Popup with form element (input)

What I want:
I want to initialize a modal Magnific Popup from a radio button on an HTML form. The popup will then display the "send" button.
Actually, I want to initialize the popup by clicking on the label of the radio input because I'll replace the radio elements with custom CSS radio buttons.
I'm using Zepto because it's lighter and I wouldn't use jQuery otherwise.
What's the problem:
If I click on a label, I do get a Magnific modal, but the radio option doesn't get selected.
If I click on the radio button itself, the option does get selected and the modal appears. But, if I dismiss the modal to choose another option, the modal appears without changing the option. (This is not usable anyway because I'll hide the stock radio buttons — as previously mentioned).
My code: (http://jsfiddle.net/Nkc5X/)
HTML:
<form action="#">
<label>
<input type="radio" name="whatside" title="Left" value="Left">
<span>Left</span>
</label>
<label>
<input type="radio" name="whatside" title="Right" value="Right">
<span>Right</span>
</label>
<div id="modal" class="white-popup-block mfp-hide">
<h2>Modal dialog</h2>
<button type="submit" value="Send">Send</button>
<a class="popup-modal-dismiss" href="#">Dismiss</a>
</div>
</form>
JavaScript:
$(function () {
$('label').magnificPopup({
type: 'inline',
items: {src: '#modal'},
preloader: false,
modal: true
});
$(document).on('click', '.popup-modal-dismiss', function (e) {
e.preventDefault();
$.magnificPopup.close();
});
});
What I've tried:
I've several tried variations on my html/javascript to no avail. I've tried initializing the popup using different selectors (label and input elements, class, id).
Okay, I left this problem simmer for a while and finally found a solution.
I initialize the popup from the input element: $('input').magnificPopup, which allows me to select the option when clicking on the label.
I reset the form controls using native JavaScript, using the method described in this SO answer: $('form')[0].reset();
Working JSFiddle here: http://jsfiddle.net/Nkc5X/1/
$(document).ready(function() {
$('input').magnificPopup({
type: 'inline',
items: {src: '#modal'},
preloader: false,
modal: true
});
$(document).on('click', '.popup-modal-dismiss', function (e) {
e.preventDefault();
$.magnificPopup.close();
$('form')[0].reset();
});
});
You can do it like this
$.magnificPopup.open({
items: {
src: '<div class="my-container">here is the content of the html you want to popup</div>'
},
callbacks: {//this is optional
close: function () {
//do something on exit
}
}
});

How to Window.Open inside a jQuery Modal

I have my Modal Div as:
<div id="dialog-modal" title="Open File">
<img alt="progress" src="images/ajax-loader.gif"/>
</div>
On Click of Button I am able to see Modal and then see the progress icon.
<script type="text/javascript">
$(function () {
$('#button1').click(function () {
$('#dialog-modal').dialog("open");
});
$("#dialog-modal").dialog({
autoOpen: false,
height: 140,
modal: true,
});
});
</script>
But How can I do a operation or function on Load of Modal Window??
Let's say , I want to download a file from server , when the modal window appears (..showing the progress icon)
You can hook into the dialogopen function:
$( "#dialog-modal" ).on( "dialogopen", function( event, ui ) {
console.log('Wayhay!!');
window.open("http://www.google.com");
} );
See jsFiddle:
http://jsfiddle.net/3Y63f/1/
Further info here:
http://api.jqueryui.com/dialog/#event-open

PHP How to upload image from popup

I want to upload image from popup but not getting proper solution.
what i wanted to do
1. On button click open popup
2. In that popup open form for browse image
3. After uploading image i want to show image in same popup and user can crop it
4. After completed cropping save image to database and folder and want to show profile pic
What i did
1.I have completed all code in core php but without using popup
for popup
2. I can open popup on button click, browse file and action goes to controller.
Code
View page
// open popup
<div class="profile-pic fl">
<div class="txtc">
<?php echo $this->tag->image(array("img/profile_pic_default.jpg","class"=>"profile_img")) ; ?>
</div>
<div class="txtc mrgt2">
<button id="openPopup" onclick="upload_action();">Upload Image</button>
</div>
</div>
//iamge upload form
<div id="up-image" style="display: none">
<div style="margin:0 auto; width:600px">
<div id="thumbs" style="padding:5px; width:600px"></div>
<div id="crop-image" style="width:600px">
<?php echo $this->tag->form(array("personaldetails/uploadImage","id"=>"cropimage",'enctype'=>"multipart/form-data"))?>
Upload your image <input type="file" name="photoimg" id="photoimg" />
</form>
</div>
</div>
Script to open popup and send data
<script type="text/javascript">
$(document).ready(function() {
$edit_dialog = $("#up-image").dialog({
autoOpen:false,
title:"Upload image",
modal:true,
height: 300,
width: 600,
buttons:[
{text: "Submit", click: function() { $('form',$(this)).submit(); }},
{text: "Cancel", click: function() { $(this).dialog("close"); }}
],
create: function(event, ui)
{
$(this).parents(".ui-dialog").css("margin-left", 350);
$(this).parents(".ui-dialog").css("margin-top", 50);
}
});
//Submit action for dialog form
$("#up-image form").submit(function() {
var formData = new FormData($('form')[0]);
$.post($(this).attr('action'), $(this).serialize(),function(formData)
{
alert('done'+data);
$("#up-image").dialog('close');
},'json');
//stop default form submit action
return false;
});
//attach action to edit links
});
function upload_action()
{
$edit_dialog.dialog('open');
}
Controller action
public function uploadImageAction()
{
echo "<pre>";print_r($_FILES);echo "<pre>";exit; // not able to get request
}
You can use jcrop plugin for that:
http://deepliquid.com/projects/Jcrop/demos/crop.php
http://deepliquid.com/content/Jcrop.html
For fullfill your requirement you have to use:
AjaxUpload and JCrop together.
Ajaxupload will upload image to server and jcrop helps you to crop image.
After croppping you have to need old image and save cropped image in DB and folder.
add form in a hidden div and set position absolute or fixed
animate or fade in hidden div on-clik function
set z-index for div ordering

Jquery tools overlay redirect page on button click

I have an age confirmation box that pops up on page load
If the user clicks yes, then the overlay should just close, but if the user clicks no I would like to close the overlay and redirect the user to another page.
This is the code I have
$(document).ready(function() {
$("#confirmage").overlay({
// custom top position
top: 260,
mask: {
color: '#fff',
loadSpeed: 200,
opacity: 0.9
},
closeOnClick: false,
api: true,
load: true
});
});
$('.link-no').click(function () {
$("#confirmage").overlay().close();
window.location.href = 'insert_page_here';
});
And on the .html I have this
<div id="confirmage">
<div>
<h2>Are you older than 18 years old?</h2>
<p>
<button class="close">Yes</button>
<button class="link-no close">No</button>
</p>
</div>
</div>
Right now, when the user clicks No the overlay just closes but it doesnt redirect the user to the page.
Thanks a lot in advance

How to dynamically load content from an external url, inside of a jquery ui modal dialog widget?

I asked this question before, but I don't think I explained properly for what I am trying to accomplish.
There are multiple links on my website and I want to open the content from the link in a jquery ui modal dialog widget.
I'm trying to use 'this' to reference the link that the user selects dynamically.
What am I doing wrong here?
The code I'm using is below:
comment #1
comment #2
comment #3
<div id="somediv"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#somediv").load(this.getTrigger().attr("href")).dialog({
autoOpen: false,
width: 400,
modal: true
});
$("#test").click(function(){$( "#somediv" ).dialog( "open" );});
});
</script>
http://jsfiddle.net/qp7NP/
A couple changes: changed ID to Class and used IFrame.
comment #1<br>
comment #2<br>
<a href="http://ask.com/" class="test" >comment #3</a><br>
<div id="somediv" title="this is a dialog" style="display:none;">
<iframe id="thedialog" width="350" height="350"></iframe>
</div>
<script>
$(document).ready(function () {
$(".test").click(function () {
$("#thedialog").attr('src', $(this).attr("href"));
$("#somediv").dialog({
width: 400,
height: 450,
modal: true,
close: function () {
$("#thedialog").attr('src', "about:blank");
}
});
return false;
});
});
</script>
In case you want to pull in the HTML instead of IFrame, you will have to use Ajax (XMLHttpRequest), something like this: http://jsfiddle.net/qp7NP/1/
You can't have multiple elements with the same Id.
Change your links to to class="test" instead and therefore your click event to $('.test').click().
Also if you still have problems, and I remember I had some similar issues because how JQUery Dialog behaves itself with the DOM. It will literally rip your #somediv out of content and append it to the bottom of a page to display that dialog. I solved my dynamic dialog loading issues with wrapping it in another div.
<div id="somediv-wrap">
<div id="somediv">
</div>
</div>
<script>
$(document).ready(function() {
$("#somediv-wrap").dialog({
autoOpen: false,
width: 400,
height:200,
modal: true
});
$(".test").click(function(event)
{
event.preventDefault();
var link = $(this).attr('href');
$("#somediv").load(link,function(){
$( "#somediv-wrap" ).dialog( "open" );
});
});
});
</script>

Categories