Reputation: 21
For Jquery Eric Martin's SimpleModal 1.4.1 I'd like the popup to be draggable so I tried this
$('#basic-modal-content').modal({
onShow: function(dialog) {
dialog.container.draggable({ handle: 'div' });
}
});
the popup displays but I get an error of "object does not support property of method"
I've got jquery-ui-1.8.10 added as a script ref and class="ui-widget-content" in the div.
Ideas?
EDIT: removing handle: 'div' does nothing new, same error, can't move dialog
These two do not work, error "object does not support property of method"
$('#basic-modal-content').modal({
onShow: function(dialog) { $(dialog.container).draggable(); }
});
$('#basic-modal-content').modal({
onShow: function(dialog) { $(dialog.container).draggable({handle: 'div'}); }
});
console.log($(dialog.container));
Result :[object Object]
Upvotes: 2
Views: 4304
Reputation: 1
SimpleModal does not have those features built-in... But you can do using JQuery..
$j('#simplemodal-container').draggable({ containment: "#masterpageBody" });
simplemodal-container
--> Is your container div id
masterpageBody
--> Is master body id
.
we must use 'containment', to not drag beyond the screen.
Upvotes: 0
Reputation: 716
If you don't actually need to utilize the JQuery UI library, you can use the following code I found on jsfiddle at http://jsfiddle.net/mkUJf/666/ "div#modalbox-container" could be anything. I just chose to use the outer container of the modal.
//make modal draggable
$(function () {
$('body').on('mousedown', 'div#modalbox-container', function () {
$(this).addClass('draggable').parents().on('mousemove', function (e) {
$('.draggable').offset({
top: e.pageY - $('.draggable').outerHeight() / 2,
left: e.pageX - $('.draggable').outerWidth() / 2
}).on('mouseup', function () {
$(this).removeClass('draggable');
});
});
e.preventDefault();
}).on('mouseup', function () {
$('.draggable').removeClass('draggable');
});
});
Or you can add a jquery plugin like the following: ref: https://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/
(function($) {
$.fn.drags = function(opt) {
opt = $.extend({handle:"",cursor:"move"}, opt);
if(opt.handle === "") {
var $el = this;
} else {
var $el = this.find(opt.handle);
}
return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
if(opt.handle === "") {
var $drag = $(this).addClass('draggable');
} else {
var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
}
var z_idx = $drag.css('z-index'),
drg_h = $drag.outerHeight(),
drg_w = $drag.outerWidth(),
pos_y = $drag.offset().top + drg_h - e.pageY,
pos_x = $drag.offset().left + drg_w - e.pageX;
$drag.css('z-index', 1000).parents().on("mousemove", function(e) {
$('.draggable').offset({
top:e.pageY + pos_y - drg_h,
left:e.pageX + pos_x - drg_w
}).on("mouseup", function() {
$(this).removeClass('draggable').css('z-index', z_idx);
});
});
e.preventDefault(); // disable selection
}).on("mouseup", function() {
if(opt.handle === "") {
$(this).removeClass('draggable');
} else {
$(this).removeClass('active-handle').parent().removeClass('draggable');
}
});
}
})(jQuery);
Both pieces of code are pretty much plug and play.
Upvotes: 0
Reputation: 3350
Hi I confirm my comment :), use this:
jQuery(function ($) {
// Load dialog on page load
//$('#basic-modal-content').modal();
// Load dialog on click
$('#basic-modal .basic').click(function (e) {
$('#basic-modal-content').modal({
onShow: function(dialog) {
console.log($(dialog));
$(dialog.container).draggable();
}
});
return false;
});
});
You must point a DOM element !
EDIT: I have add the entry code I use.
Upvotes: 1