[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/js/core/ -> behavior-drag-and-drop-textarea.js (source)

   1  /**
   2   * @provides javelin-behavior-aphront-drag-and-drop-textarea
   3   * @requires javelin-behavior
   4   *           javelin-dom
   5   *           phabricator-drag-and-drop-file-upload
   6   *           phabricator-textareautils
   7   */
   8  
   9  JX.behavior('aphront-drag-and-drop-textarea', function(config) {
  10  
  11    var target = JX.$(config.target);
  12  
  13    function onupload(f) {
  14      var text = JX.TextAreaUtils.getSelectionText(target);
  15      var ref = '{F' + f.getID() + '}';
  16  
  17      // If the user has dragged and dropped multiple files, we'll get an event
  18      // each time an upload completes. Rather than overwriting the first
  19      // reference, append the new reference if the selected text looks like an
  20      // existing file reference.
  21      if (text.match(/^\{F/)) {
  22        ref = text + '\n\n' + ref;
  23      }
  24  
  25      JX.TextAreaUtils.setSelectionText(target, ref);
  26    }
  27  
  28    if (JX.PhabricatorDragAndDropFileUpload.isSupported()) {
  29      var drop = new JX.PhabricatorDragAndDropFileUpload(target)
  30        .setURI(config.uri);
  31      drop.listen('didBeginDrag', function() {
  32        JX.DOM.alterClass(target, config.activatedClass, true);
  33      });
  34      drop.listen('didEndDrag', function() {
  35        JX.DOM.alterClass(target, config.activatedClass, false);
  36      });
  37      drop.listen('didUpload', onupload);
  38      drop.start();
  39    }
  40  
  41  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1