Opened 4 years ago

Closed 4 years ago

#1552 closed enhancement (no action needed)

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 https://svn.socialplanning.org/svn/oc-js/trunk/opencore/js/thirdparty/xinha/plugins/InternalLink/internal-link.js 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 (3)

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

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by guest

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

Changed 4 years ago by guest

sample implementation of linkValidator function

Changed 4 years ago by guest

sample/test configuration using wicked_validator.js linkValidator

comment:1 Changed 4 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.

comment:2 Changed 4 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.

comment:3 Changed 4 years ago by ejucovy

  • Resolution set to fixed
  • Status changed from new to closed

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;                                                                                                                                                                    
};  

comment:4 Changed 4 years ago by ejucovy

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:5 Changed 4 years ago by ejucovy

  • Resolution set to no action needed
  • Status changed from reopened to closed

Re-closing with a better resolution.

Note: See TracTickets for help on using tickets.