Ticket #1552 (closed enhancement: no action needed)

Opened 3 years ago

Last modified 3 years ago

linkValidator config option

Reported by: guest Owned by: gogo
Priority: normal Milestone:
Component: Xinha Core Version: trunk
Severity: normal Keywords:
Cc: ethan.jucovy@…

Description

My application uses Xinha as an editing frontend to a backend that also uses a ((double paren wiki syntax)) for internal page links. The user's input is treated as HTML, but ((wiki links)) are also processed by the backend. We also allow the user to create HTML links in their documents using Xinha.

We've built a [custom Linker-replacement plugin] which includes complex, application-specific validation to prevent the user from inserting an HTML link within a ((wiki link)). If the validation fails, the user receives an alert and the link-creation dialog box does not pop up.

Aside from this validator, our plugin is identical to the Linker.

It would be nice to have a config option for passing in a linkValidator function. This function would be called by both Linker and by InsertLink. That way Xinha users could provide custom link validators without having to build whole plugins, and the validators could be attached to the link-creation action regardless of which linker is being used.

I've attached an implementation with documentation.

I'm curious whether there is a better approach -- like listening to a generic "button has been pressed" event and conditionally cancelling the action?

Attachments

linkValidator.diff (2.0 kB) - added by guest 3 years ago.
add XinhaConfig?.linkValidator option, used in Linker and CreateLink?
wicked_validator.js (12.8 kB) - added by guest 3 years ago.
sample implementation of linkValidator function
opencore.html (7.8 kB) - added by guest 3 years ago.
sample/test configuration using wicked_validator.js linkValidator

Change History

Changed 3 years ago by guest

add XinhaConfig?.linkValidator option, used in Linker and CreateLink?

Changed 3 years ago by guest

sample implementation of linkValidator function

Changed 3 years ago by guest

sample/test configuration using wicked_validator.js linkValidator

Changed 3 years ago by guest

I've also attached our application's ((wiki link)) validator as a linkValidator function, and a sample Xinha configuration that uses/tests that validator.

Changed 3 years ago by guest

Actually, there is a much better approach -- defining an event listener for onExecCommand("createlink") which does the desired validation, fires an error if necessary, and returns true if the validation failed, to stop further processing of the command.

This is preferable because it uses the existing infrastructure rather than growing a dedicated config option for a very specific need.

It's also preferable because it doesn't require explicit cooperation from the link-creating plugins -- they don't need to know how to check for and deal with config.linkValidator. If someone builds a new link-creating plugin, that would be a problem.

This approach depends on #1553 though -- because, in trunk, there is no standard execCommand("createlink") behavior. I have attached a working patch on #1553 to address that.

Changed 3 years ago by ejucovy

  • status changed from new to closed
  • resolution set to fixed

I've committed the needed patch on #1553. No more action needed on this ticket.

To do this, you'd make a plugin (or Event) that looks something like

MyPlugin.prototype.onExecCommand = function(cmdID, UI, param) {                                                                                                         
  if( cmdID != "createlink" ) return false;                                                                                                                                        
  var error = my_custom_validation_function(this.error, param);
  if( error ) {                                                                                                                                                                    
    // if the validator has a problem it will return an error message                                                                                                                                             
    // so we'll pop it up for the user, and then abort further events                                                                                                              
    alert(error);                                                                                                                                                                  
    return true;                                                                                                                                                                   
  }                                                                                                                                                                                
  return false;                                                                                                                                                                    
};  

Changed 3 years ago by ejucovy

  • status changed from closed to reopened
  • resolution deleted

Changed 3 years ago by ejucovy

  • status changed from reopened to closed
  • resolution set to no action needed

Re-closing with a better resolution.

Note: See TracTickets for help on using tickets.