Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set a function for Block's helpURL? #641

Closed
pouyakary opened this issue Sep 26, 2016 · 3 comments
Closed

How to set a function for Block's helpURL? #641

pouyakary opened this issue Sep 26, 2016 · 3 comments

Comments

@pouyakary
Copy link

Hy everyone.

I'm making a custom blockly language to replace RegEx's syntax:


You may find it here

Now as you may have noticed it runs inside of Electron hence I can't set a URL for it. So about the only thing I knew to make it work was to insert some JavaScript into the URL:

this.setHelpUrl(`javascript: void openHelpWindowAtReferenceId("${ block_id }")`);

But what happens is that nothing happens. I tried to see what goes wrong and did this:

this.setHelpUrl(`javascript: void ( ( ) => {
   try {
      openHelpWindowAtReferenceId("${ block_id }");
   } catch ( err ) {
      alert( err );
   }
})( )`);

And what I got was openHelpWindowAtReferenceId. So it was in the global namespace at first and changed it's place to be initialized before Blockly and changed the loading process so that could be loaded first. But still it's not defined.

All the basic JavaScript functions are available but none of my functions works there.

Why is that so? Is Blockly using any XSS blocker for URLs? What can I do to set a function for the block's Help property?

@NeilFraser
Copy link
Contributor

Just set the help URL to be a function. The function should return the URL of the help page. Within the function this is the block in question.

this.setHelpUrl(function () {return 'http://example.com?' + this.id;});

@pouyakary
Copy link
Author

No the problem is not with the block properties, Infact it works well:

screen shot 2016-09-26 at 3 11 42 pm

I have a help window that opens separately:

screen shot 2016-09-26 at 9 32 04 am

Now I can't open this window with a URL. I have to open it myself. So I want to set a function instead of a URL string. And as I can't set an onclick event the only thing I could imagine was to use <a href="javascript: someFunction( );"></a> and it works with native JavaScript functions and tools, but when it comes to custom functions it says that the function is not defined and my question is that how can I call my functions there. What's the problem that keeps my functions from being available in the href?

@pouyakary
Copy link
Author

pouyakary commented Sep 26, 2016

Okay I think I found a workflow. It's to override this in Line 637 of Blockly SVG module:

Blockly.BlockSvg.prototype.showHelp_ = function ( ) {
    ...
};

The only problem is that you'll start needing to build blackly again. but well

help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants