Jump to content

Jquery Event Trigger


Awang

Recommended Posts

Hy guys!

 

I tried to call a jquery event on my browser with executeBrowserJavascript() command, but exatly, nothing happened :/

This is, how I tried:
 

executeBrowserJavascript(bboxweb, "$().trigger('onEditBoxCall',['editbox','password']);" )
     <script src="js/jquery-3.1.1.min.js"></script>
<script>
    $(document).ready(function(){  
    var eventName ="";
    var text = "";
    $(this).on("onEditBoxGetValue",function()
    {
    text = $("#box").val();
    mta.triggerEvent("onEditBoxValue"+eventName,text);
    });
        onEditBoxCall = ,function(event,name,type)
                   {
            eventName = name;
           $('#box').attr('type',''+type+'');
        }       
});    
    </script>

I tried to write kind of a guieditbox script, where I can declare in Lua, what type of editbox I want to call, and after get this value.


Hope, you guys can help me.

Link to comment

I changed my code a little bit, because as you can see, I have made some big mistakes in the last version.
@LopSided_ I tried to use, but nothing is happening :( I have no errors...

 

<script>
    $(document).ready(function(){  
    var eventName ="";
    var text = "";
    $(this).on("onEditBoxGetValue",function()
    {
    text = $("#box").val();
    mta.triggerEvent("onEditBoxValue"+eventName,text);
    });
        $(this).on('onEditBoxCall',function(event,name,type){
            eventName = name;
           $('#box').attr('type',''+type+'');            
        }) ;   
});    
    </script>
function dxEditbox(xb,yb,wb,hb,name,types)
local boxweb = guiCreateBrowser(xb,yb,wb,hb,true,true,false)
local bboxweb = guiGetBrowser( boxweb ) 
addEventHandler("onClientBrowserCreated", bboxweb, 
	function()
		loadBrowserURL(bboxweb, "http://mta/ts_dx_core/web/editbox.html")
	end
)
addEventHandler ( "onClientBrowserDocumentReady" , bboxweb ,function () 
executeBrowserJavascript(bboxweb, "$(this).trigger('onEditBoxCall',['"..name.."','"..types.."']);" )
end)

return boxweb
end

 

Edit: Everythings work, because in executeBrowserJavascript()'s jquery command I used 'this' instead of 'document'...
Thank you @LopSided_ 
:D 

 

Edited by Awang
I solve the problem
Link to comment

And a come back with a problem :D

I can trigger "onEditBoxGetValue" in Js and it's handled, but

 mta.triggerEvent("onEditBoxValue"+eventName,text)

doesn't do anything... I tried also just with 

mta.triggerEvent("onEditBoxValue");

but also not working :crybaby:

Link to comment

Okay, I have 2 Lua resource, ones contains dx functions, what I call in different res:
 

function dxEditbox(xb,yb,wb,hb,name,types)
local boxweb = guiCreateBrowser(xb,yb,wb,hb,true,true,false)
local bboxweb = guiGetBrowser( boxweb ) 
addEventHandler("onClientBrowserCreated", bboxweb, 
	function()
		loadBrowserURL(bboxweb, "http://mta/ts_dx_core/web/editbox.html")
	end
)
addEventHandler ( "onClientBrowserDocumentReady" , bboxweb ,function () 
executeBrowserJavascript(bboxweb, "$(document).trigger('onEditBoxCall',['"..name.."','password']);" )
end)

return boxweb
end

function dxGetEditbox(wbox,name)
local asd = guiGetBrowser( wbox ) 
executeBrowserJavascript(asd, "$(document).trigger('onEditBoxGetValue');"  )
return edittext
end

So, in a Login system, I want to call these functions. Because, it's work in progress, I just bind the dxGetEditbox function on a key: 
 

addEventHandler("onPasswordPanelCall",root,function()
	start = getTickCount()
	movex1,movex2 = movex2,-1500
setTimer(function()
	removeEventHandler("onClientClick",root,userchoose)
	removeEventHandler("onClientRender",root,loginpanel)
	addEventHandler("onClientRender",root,passwordpanel)
	movex1,movex2 = 1920,700
	start = getTickCount()
	boxweb = exports['ts_dx_core']:dxEditbox(1920,550,300,150,"password","password")
	
end,2000,1)
end)

bindKey("n","up",function()
addEventHandler("onEditBoxValue",root,function(backtext)
	outputChatBox(backtext)
end)
exports['ts_dx_core']:dxGetEditbox(boxweb,"password")

end)

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...