 |
|
|
| How to call obscured JS function given its name (Events_CreateEvent)? |
|
|
Hello guys,
i have a problem - I'm raising an event from JavaScript to the server via Events_CreateEvent - and that works nice while obscuration is disabled. When I enable it, Events_CreateEvent become something like f124() - so my JS code fails. Obviously I don't want to hardcode obscurated function name in my JS file. Is there a way to find obscured function name given its "real" name, some kind of dictionary???
Thank you,
Alexey |
|
|
|
 |  |
|
|
| Re: How to call obscured JS function given its name (Events_CreateEvent)? |
|
|
Hello Alexey!
If you want to invoke JS functions in VWG from your own JS code, you need to use the VWG Client-Client-Invocation. To learn how, click here.
If you want to invoke JS in VWG from server-side, you need to use VWG Server-Client-Invocation. To learn how, click here.
Regards,
Ori Cohen
The Visual WebGui team |
|
|
|
 |  |
|
|
| Re: How to call obscured JS function given its name (Events_CreateEvent)? |
|
|
Hello Ori,
thanks for the reply. I actually read those articles earlier - they are indeed a great help for various JS-based tasks. However, my case is not covered there :( I need Client-Server invocation :) Let me please explain a bit here:
I have a custom plugin for the FCKEditor - so when a user clicks a toolbar button, I need VWG-dialog to show up - and when that dialog is closed, I need some data to be passed to the FCKEditor. The latter is simple - Server-Client invocation, as you said, and it works fine. The former, however, was a bit of challenge to implement - but it also turned out to be relatively easy:
1. In FCKEditor.cs file register custom handler for the plugin:
Config["vlinkpopupfunction"] = "fnCallOpenVLinkPopup(editorinstance, '" + Guid + "');";
- notice, we pass Guid here!
2. In plugin's javascript file just call this function:
vLinkCommand.Execute=function() { //open a popup window when the button is clicked if(FCKConfig.vlinkpopupfunction){ var _fnCallOpenVLinkPopup = new Function('editorinstance', FCKConfig.vlinkpopupfunction); _fnCallOpenVLinkPopup(FCK); } }
and that function, in turn, calls server:
function fnCallOpenVLinkPopup(editorinstance, strGuid) { var objEvent = Events_CreateEvent(strGuid, "FCK_Editor_OpenVlinkPopupDialog", null, true); Events_RaiseEvents(); }
is it a proper way to implement such functionality? look legitimate to me...
So, my question was - when JS obscuring in ON:
Events_CreateEvent/Events_RaiseEvents DO NOT exist - instead, we have something like f123/f456, right? So how can I call them in this case? I don't want just to hardcode something like "f123()" there. Is there a way to get obscured function name given its real name? I would think about JS dictionary, so I can say
var fnEvents_CreateEvent = VWG_OBSCURED_FUNCTIONS["Events_CreateEvent"]; fnEvents_CreateEvent(strGuid, "FCK_Editor_OpenVlinkPopupDialog", null, true);
does it make sense?
Thanks,
Alexey
|
|
|
|
 |  |
|
|
| Re: How to call obscured JS function given its name (Events_CreateEvent)? |
|
|
Hello Alexey!
Nicely done.
My best suggestion for you would be to allow your custom control's JS to become obscured. When it will be obscured, you be able to access all of the other obscured functions without a problem.
To have your JS obscured, you need to do two things:
- Have all your JS functions begin with the name of your custom control and a '_' character like so: "MyCustomControl_MyJsFunction()"
- Correctly format your JS code and have a ';' character in the end of every command.
That's it. Please keep me updated. I would like to know how things went.
Regards,
Ori Cohen
The Visual WebGui team |
|
|
|
 |  |
|
|
| Re: How to call obscured JS function given its name (Events_CreateEvent)? |
|
|
Hello Ori,
I realized we a bit stacked here. If I do what you suggest - yes, that will obscure my javascript functions too - but how my external JS code will know which function to call then? So it is egg and chicken problem in a sense...
let me please describe my problem one more time.
1. I have a custom FCK Editor plugin - it is pure JavaScript code.
2. This plugin required some data from my VWG application to initialize itself, plus it produces some data when a user clicks "OK" button on it. This data should go back to VWG application. So I need a way to trigger VWG server event from arbitrary external JS code.
3. I don't have any programmatic control over FCKEditor buttons (I don't want to go that deep inside it sources). When a user clicks my plugin's button on the toolbar, plugin's JS code is executed - and I do have control over it. So in order to get an event inside VWG, I added Events_CreateEvent / Events_RaiseEvents calls in the plugin's JS code to raise an event for VWG FCKEditor.FireEvent() function.
All these works well. Until obscuring is on - because Events_CreateEvent / Events_RaiseEvents functions do not exist anymore.
According to your advise - I can not add plugin's JS file into my project - because it has to be executed in the FCKEditor's namespace - and even if I do, still I need to call my create/raise event function somewhere from javascript - plugin does this. But if it's name is obscured the plugin won't know what the name to call.
Here are my questions:
1. Is my scenario a valid one? 2. If so, am I right that there is no way right now to make this working with obscuring? 3. If so, would you agree that some kind of name translation function is required in VWG javascript code? 4. If so - should I create an issue, or you will do that?
-----------------------------------------------------
And apart from that - let me ask you another question. If I do as you said, and will add JS file into the project, and will name functions as "MyCustomControl_MyJsFunction()" - then will
this.InvokeMethodWithId("MyCustomControl_MyJsFunction", ...);
work? And if it does - then how? Do you have a names map somewhere inside server-side VWG assemblies? then I can probably use it to pass obscured names to my JS function as a parameters.
Thanks a lot for your time and patience :)
Alexey
|
|
|
|
|  |