modules/moulinette-imagesearch.js
/**
   * @INFO Function is inspired from the one in submodule Tiles
   */
@INFO Function is inspired from the one in submodule Tiles
@INFO Function is inspired from the one in submodule Tiles
onDragStart(event) {
    if(!game.moulinette.applications.MoulinetteDropAsActor) {
      ui.notifications.error(game.i18n.localize("mtte.errorDragDropRequirements"));
      event.preventDefault();
      return;
    }
    const div = event.currentTarget;
    const idx = div.dataset.idx;
    const mode = game.settings.get("moulinette", "tileMode")
    if(!this.searchResults || idx < 0 || idx > this.searchResults.length) return
    const timestamp =  new Date().getTime();
    const image = this.searchResults[idx-1]
    let imageFileName = image.name.replace(/[\W_]+/g,"-").replace(".","")
    imageFileName = (imageFileName.length > 30 ? imageFileName.substring(0, 30) : imageFileName) + "-" + timestamp + "." + image.format
    const tile = {
      filename: imageFileName, 
      type: "img", 
      sas: "", 
      search: image
    }
    let dragData = {}
    if(mode == "tile") {
      dragData = {
        type: "Tile",
        tile: tile,
        pack: { publisher: image.src, name: "Results" },
        tileSize: 100
      };
    } else if(mode == "article") {
      dragData = {
        type: "JournalEntry",
        tile: tile,
        pack: { publisher: image.src, name: "Results" }
      };
    } else if(mode == "actor") {
      dragData = {
        type: "Actor",
        tile: tile,
        pack: { publisher: image.src, name: "Results" }
      };
    }
    dragData.source = "mtte"
    event.dataTransfer.setData("text/plain", JSON.stringify(dragData));
  }
onDragStart ( event ) { if ( ! game . moulinette . applications . MoulinetteDropAsActor ) { ui . notifications . error ( game . i18n . localize ( "mtte.errorDragDropRequirements" ) ) ; event . preventDefault ( ) ; return ; } const div = event . currentTarget ; const idx = div . dataset . idx ; const mode = game . settings . get ( "moulinette" , "tileMode" ) if ( ! this . searchResults || idx < 0 || idx > this . searchResults . length ) return const timestamp = new Date ( ) . getTime ( ) ; const image = this . searchResults [ idx - 1 ] let imageFileName = image . name . replace ( / [\W_]+ / g , "-" ) . replace ( "." , "" ) imageFileName = ( imageFileName . length > 30 ? imageFileName . substring ( 0 , 30 ) : imageFileName ) + "-" + timestamp + "." + image . format const tile = { filename : imageFileName , type : "img" , sas : "" , search : image } let dragData = { } if ( mode == "tile" ) { dragData = { type : "Tile" , tile : tile , pack : { publisher : image . src , name : "Results" } , tileSize : 100 } ; } else if ( mode == "article" ) { dragData = { type : "JournalEntry" , tile : tile , pack : { publisher : image . src , name : "Results" } } ; } else if ( mode == "actor" ) { dragData = { type : "Actor" , tile : tile , pack : { publisher : image . src , name : "Results" } } ; } dragData . source = "mtte" event . dataTransfer . setData ( "text/plain" , JSON . stringify ( dragData ) ) ; }
@INFO Function is inspired from the one in submodule Tiles
@INFO Function is inspired from the one in submodule Tiles
// module moulinette-tiles is required for supporting drag/drop // invalid action // create fake tile