Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #3717: InPlaceEditorSubmitOnBlurCrashOnSafari.diff

File InPlaceEditorSubmitOnBlurCrashOnSafari.diff, 1.3 kB (added by ishikawa_takanori, 1 year ago)

Added InPlaceEditor#onBlur

  • src/controls.js

    old new  
    669669      var size = this.options.size || this.options.cols || 0; 
    670670      if (size != 0) textField.size = size; 
    671671      if (this.options.submitOnBlur) 
    672         textField.onblur = this.onSubmit.bind(this); 
     672        textField.onblur = this.onBlur.bind(this); 
    673673      this.editField = textField; 
    674674    } else { 
    675675      this.options.textarea = true; 
     
    681681      textArea.cols = this.options.cols || 40; 
    682682      textArea.className = 'editor_field';       
    683683      if (this.options.submitOnBlur) 
    684         textArea.onblur = this.onSubmit.bind(this); 
     684        textArea.onblur = this.onBlur.bind(this); 
    685685      this.editField = textArea; 
    686686    } 
    687687     
     
    723723    } 
    724724    return false; 
    725725  }, 
     726  onBlur: function() { 
     727    // needed to prevent crash on Safari when clicking focus ring. 
     728    setTimeout(function() { 
     729      // Both okButton and cancelLink fires onblur event (cause duplicate submit),  
     730      // so sanity check before submitting.  
     731      if (!this.form || this.saving) return false; 
     732      this.onSubmit(); 
     733    }.bind(this), 100); 
     734  }, 
    726735  onSubmit: function() { 
    727736    // onLoading resets these so we need to save them away for the Ajax call 
    728737    var form = this.form;