<commit_before>/**
 * Dialog.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

/**
 * @class tinymce.image.ui.Dialog
 * @private
 */
define(
  'tinymce.plugins.image.ui.Dialog',
  [
    'tinymce.core.Env',
    'tinymce.core.util.JSON',
    'tinymce.core.util.Tools',
    'tinymce.core.util.XHR',
    'tinymce.core.ui.Throbber',
    'tinymce.plugins.image.core.Uploader',
    'tinymce.plugins.image.core.Utils',
    'global!Math',
    'global!RegExp',
    'global!document'
  ],
  function (Env, JSON, Tools, XHR, Throbber, Uploader, Utils, Math, RegExp, document) {

    return function (editor) {
      function createImageList(callback) {
        var imageList = editor.settings.image_list;

        if (typeof imageList == "string") {
          XHR.send({
            url: imageList,
            success: function (text) {
              callback(JSON.parse(text));
            }
          });
        } else if (typeof imageList == "function") {
          imageList(callback);
        } else {
          callback(imageList);
        }
      }

      function showDialog(imageList) {
        var win, data = {}, imgElm, figureElm, dom = editor.dom, settings = editor.settings;
        var width, height, imageListCtrl, classListCtrl, imageDimensions = settings.image_dimensions !== false;


        function onFileInput() {
          var throbber = new Throbber(win.getEl());
          var file = this.value();

          var uploader = new Uploader({
            url: settings.images_upload_url,
            basePath: settings.images_upload_base_path,
            credentials: settings.images_upload_credentials,
            handler: settings.images_upload_handler
          });

          // we do not need to add this to editors blobCache, so we fake bare minimum
          var blobInfo = editor.editorUpload.blobCache.create({
            blob: file,
            name: file.name.replace(/\.[^\.]+$/, ''), // strip extension
            base64: 'data:image/fake;base64,=' // without this create() will throw exception
          });

          var finalize = function () {
            throbber.hide();
            URL.revokeObjectURL(blobInfo.blobUri()); // in theory we could fake blobUri too, but until it's legitimate, we have too revoke it manually
          };

          throbber.show();<commit_msg>TINY-1110, image: make sure that blob has name property, before trying to strip extension<commit_after>/**
 * Dialog.js
 *
 * Released under LGPL License.
 * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
 *
 * License: http://www.tinymce.com/license
 * Contributing: http://www.tinymce.com/contributing
 */

/**
 * @class tinymce.image.ui.Dialog
 * @private
 */
define(
  'tinymce.plugins.image.ui.Dialog',
  [
    'tinymce.core.Env',
    'tinymce.core.util.JSON',
    'tinymce.core.util.Tools',
    'tinymce.core.util.XHR',
    'tinymce.core.ui.Throbber',
    'tinymce.plugins.image.core.Uploader',
    'tinymce.plugins.image.core.Utils',
    'global!Math',
    'global!RegExp',
    'global!document'
  ],
  function (Env, JSON, Tools, XHR, Throbber, Uploader, Utils, Math, RegExp, document) {

    return function (editor) {
      function createImageList(callback) {
        var imageList = editor.settings.image_list;

        if (typeof imageList == "string") {
          XHR.send({
            url: imageList,
            success: function (text) {
              callback(JSON.parse(text));
            }
          });
        } else if (typeof imageList == "function") {
          imageList(callback);
        } else {
          callback(imageList);
        }
      }

      function showDialog(imageList) {
        var win, data = {}, imgElm, figureElm, dom = editor.dom, settings = editor.settings;
        var width, height, imageListCtrl, classListCtrl, imageDimensions = settings.image_dimensions !== false;


        function onFileInput() {
          var throbber = new Throbber(win.getEl());
          var file = this.value();

          var uploader = new Uploader({
            url: settings.images_upload_url,
            basePath: settings.images_upload_base_path,
            credentials: settings.images_upload_credentials,
            handler: settings.images_upload_handler
          });

          // we do not need to add this to editors blobCache, so we fake bare minimum
          var blobInfo = editor.editorUpload.blobCache.create({
            blob: file,
            name: file.name ? file.name.replace(/\.[^\.]+$/, '') : null, // strip extension
            base64: 'data:image/fake;base64,=' // without this create() will throw exception
          });

          var finalize = function () {
            throbber.hide();
            URL.revokeObjectURL(blobInfo.blobUri()); // in theory we could fake blobUri too, but until it's legitimate, we have too revoke it manually
          };

          throbber.show();
{'fraction_non_alphanumeric': 0.125024925224327, 'fraction_numerical': 0.0055832502492522435, 'mean_word_length': 2.2784313725490195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6949217', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1467, 'n_words': 346}