0

I am trying to extend TagOnEnterHandler Plugin to also generate a unique id for each paragraph inserted on pressing enter. Below is some modification I did to this library. But what it does is that it only generates a unique id for the first paragraph tag and pressing enter after that simple copies the same id. It appears to me that the enter handler is splitting the current paragraph into two and shifting the focus to the newly created paragraph tag. Can any one provide me with a solution

 goog.editor.plugins.TagOnEnterHandler.prototype.getNonCollapsingBlankHtml =
 function() {
   if (this.tag == goog.dom.TagName.P) {
     return '<p id="'+this.getId()+'"><br /></p>';
   } else if (this.tag == goog.dom.TagName.DIV) {
     return '<div id="'+this.getId()+'"><br></div>';
   }
   return '<br>';
 };


/**
 * Generated Unique Identifiers.
 * @type {Object.<number>}
 */
 goog.editor.plugins.TagOnEnterHandler.prototype.blockId = {};


/**
 * Generates a unique identifier
 * @return {string} The unique identifier
 */
 goog.editor.plugins.TagOnEnterHandler.prototype.getId = function(){
 var uid;
 do{
    uid = Math.round(65535 * Math.random()).toString(16);
    uid = Array(4 - uid.length + 1).join("0") + uid;
 }while(this.blockId[uid]);
 this.blockId[uid] = 1;
 return uid;
 };
  • 1
    I'm not totally clear on what you're trying to do, but are you aware of `goog.events.getUniqueId` which is already part of Closure? – Tyler Feb 07 '14 at 16:22
  • The problem I have is not with creating unique ID's but how to use it with enter handler to automatically insert unique id when creating new block element after enter is pressed. – Govind Agarwal Feb 08 '14 at 16:59

0 Answers0