Daily Lucky Numbers:
1
14
21
30
38
41

jquery draggble issue

Started by SA, December 27, 2013, 06:22:28 PM

Previous topic - Next topic

SA

well here goes
im using
function selectmouse(){

        jQuery.noConflict()(function($){
  $(\'.msg_win\').draggable({
drag: function(event, ui) {
    x1 = event.clientX;
                            y1 = event.clientY;
            x3 = parseInt($(this).css(\'left\'));
                            y3 = parseInt($(this).css(\'top\'));
    x2 = ui.position.left;
                            y2 = ui.position.top;

            distX = x2 - x1;
                            distY = y2 - y1;
                            newX = x3 + distX;
                            newY = y3 + distY;

            $(this).css(\'left\', newX);
                            $(this).css(\'top\', newY);

zdex = (zdex+1);
            $(this).css(\'zIndex\', zdex);


                            cgobj = $(this).attr(\'id\')
        gadid = cgobj.substr(6);
                            gadFix = cgobj.substr(0, 6);
                               
                            if (gadFix == \'Gadget\') {
        var myArray = [];
            myArray[0] = \'2sichat_gadget\';
            myArray[1] = cgobj;
            myArray[2] = gadid;
            myArray[3] = newX;
            myArray[4] = newY;

           $.cookie(\'2sichat_gadget\'+gadid, escape(myArray.join(\',\')));
       }
       else{
           var myArray = [];
                               myArray[0] = \'2sichat\';
           myArray[1] = \'msg_win\'+cgobj;
               myArray[2] = cgobj;
           myArray[3] = newX;
           myArray[4] = newY;
                               jQuery.noConflict()(function($){
               $.cookie(\'2sichat\'+cgobj, escape(myArray.join(\',\')));
   
          });
      }
 
                       }
                  }); 
     });
      }
           
  jQuery.noConflict()(function($){
          $(document).mousedown(function(){
                  selectmouse();
              });
          });


to drag chat and gadget windows in my chat bar mod the problem im havig is i have to double click for it to move should be a single click but i cant figar this one out have been trying to figar this myself for weeks now have any ideas ud?
http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

Chen Zhen



function selectmouse()
{
jQuery.noConflict()(function($){
$(\'.msg_win\').draggable({
drag: function(event, ui) {
x1 = event.clientX;
                y1 = event.clientY;
        x3 = parseInt($(this).css(\'left\'));
                y3 = parseInt($(this).css(\'top\'));
x2 = ui.position.left;
y2 = ui.position.top;
distX = x2 - x1;
                distY = y2 - y1;
newX = x3 + distX;
newY = y3 + distY;
        $(this).css(\'left\', newX);
$(this).css(\'top\', newY);
zdex = (zdex+1);
        $(this).css(\'zIndex\', zdex);
        cgobj = $(this).attr(\'id\')
        gadid = cgobj.substr(6);
gadFix = cgobj.substr(0, 6);
                                if (gadFix == \'Gadget\')
{
var myArray = [];
        myArray[0] = \'2sichat_gadget\';
        myArray[1] = cgobj;
        myArray[2] = gadid;
        myArray[3] = newX;
        myArray[4] = newY;
$.cookie(\'2sichat_gadget\'+gadid, escape(myArray.join(\',\')));
}
else
{
var myArray = [];
myArray[0] = \'2sichat\';
        myArray[1] = \'msg_win\'+cgobj;
        myArray[2] = cgobj;
        myArray[3] = newX;
        myArray[4] = newY;
jQuery.noConflict()(function($){
$.cookie(\'2sichat\'+cgobj, escape(myArray.join(\',\')));
});
}
}
}); 
});
}
jQuery.noConflict().click(function($){
$(document).mousedown(function(){
        selectmouse();
        });
});


window.onload might be necessary for the last function that calls selectmouse() to ensure it's waiting for a mouseclick upon page load... If this does not work use tiny upload to give me a copy of the SA Chat beta version you are working on & I will use some trial & error to figure it out. My js skills are pretty good but I have only tinkered with jQuery libraries a tiny bit at this point.

SA

thanks ud will try this after dinner my js and jquery skills are pretty bad lol had many late nights trying to figar this one out
http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

SA

http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

SA

think i got it now the problem seems to be this part of the last function

$(document).mousedown(function(){
    selectmouse();
});


change it to

$(document).load(selectmouse());

now it seems to work like it should
it is always somthing simple eh
http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

Chen Zhen

#5
SA,

  Or maybe something like:

window.onload = function() {selectmouse();}

.. which fires after everything has loaded on the page including images.

perhaps this might have worked as well:

$(document).ready(selectmouse());

.. which fires prior to the page fully loading.


  The second one may actually help me with the page indexing I use in Battle. Perhaps I can have it index to that battle title prior to all things loading on the page using it somehow.. going to have to mess around with it. This requires having it use a jQuery library though.

  I am glad to hear you got it sorted.


SA

#6
$(window).load(selectmouse());
and
$(document).load(selectmouse()); //no worky in ie

is the jquery equvilent to

window.onload = function() {selectmouse();}

this is what i could gather from google

they both work for me

so does this 
$(document).ready(selectmouse());
not sure on the js equvilent of that one tho

QuoteThis requires having it use a jQuery library though.

not a bad thing surly from what ive learnt so far with jquery we can do things with a lot less code least that what i done with sa chat with cookies and div dragging also has better coss brouser support the dragging now works in ie was always sketchy before and didnt work in compat mode


now i just need to fix the postion of the windows it very slitly off meaning you move the window i saves the pos in a cookie you reload it slitly off from were you moved it to
http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

SA

#7
turn out i didnt realy need them calcualtions to get the pos just needed

newX = ui.offset.left;
newY = ui.offset.top;


https://github.com/SAMods/SAChatBar
http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

Chen Zhen

#8
Ya top left works. I used that as default with the premiumbeat mod container (using a popup) although I allowed for settings to change its position. It worked for me with specific coordinates as well though which is why I allowed those settings in that mods config.


window.moveTo(targetX,targetY);


SA

#9
do you see any thing wrong with this apart from the formating  lol

function updatemsg(id){
if (document.getElementById(\'cmsg\'+id)) {
jQuery.noConflict()(function($){
$.ajax({
url: \''.$boardurl.'/sachat/index.php\',
data: \''.$thjs.'update=\'+id,
dataType: "json",
cache: false,
timeout: '.$modSettings['2sichat_cw_heart'].',
success: function(data){
if (data.DATA != null) {
if (msgArray[id] && msgArray[id] < data.ID && data.ID != null || msgArray[id] == undefined && data.ID != null) {
var newdiv = document.createElement(\'div\');
newdiv.setAttribute(\'dir\',\'ltr\');
newdiv.innerHTML = data.DATA;
document.getElementById(\'cmsg\'+id).insertBefore(newdiv, document.getElementById(\'cmsg\'+id).firstChild);
loadsnd(\'rec_msg\');
msgArray[id] = data.ID;
}
}
if (data != null && data.CONLINE != null) {
        $("#cfriends").text(\'(\'+data.CONLINE+\')\');
    }
    if (data != null && data.ONLINE != null) {
    $("#friends").html(data.ONLINE);
    }
}
});
});
}
}


jQuery 1.8.1 that function works well but with the latest jQuery v1.10.2 thaat function seem to loose msgArray[id] after a a few messages i just cant figar this one out i know it looses msgArray[id] from using console.log(msgArray[id]; another annoying one got me stumped

basicly that function should upodate the messages and disply new ones

if i remove if (msgArray[id] && msgArray[id] < data.ID && data.ID != null || msgArray[id] == undefined && data.ID != null)
it then works but display the same messages over and over i have tryed chaging the logic there but to no avail i just dont see why a jquery update will effect that even tryd witht the jquery migrate plugin that doesnt show any errors tho so it must be compatable

i got it now i modifyed the php function now it seems to work still dont get why that would happen though
http://samods.github.io/SAChatBar/

Customizer @ SimpleMachines

Skhilled