<commit_before><link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">

<polymer-element name="meme-dialog">
  <template>
    <style>
      polymer-ui-card {
        width: 240px;
        height: 240px;
        margin: 20px auto;
        padding: 15px;
        display: block;
      }

      #cards {
        display: flex;
        flex-wrap: wrap;
      }

      paper-toast {
        bottom: 40px;
        left: 10px;
      }

      #image-container {
        display: flex;
      }
    </style>
    <paper-dialog heading="Create A Meme" transition="paper-dialog-transition-center">
    <div id="image-container">
      <canvas width="500" height="500"></canvas>
      <div>
        <paper-input floatingLabel id="topLineText" label="Top line ..."></paper-input><br/>
        <paper-input floatingLabel id="bottomLineText" label="Bottom line ..."></paper-input><br/>
        <paper-input style="display:none;" id="imageTitle"></paper-input>
      </div>
    </div>

    <paper-button label="Cancel" dismissive></paper-button>
    <paper-button id='saveMemeBtn' label="Save" affirmative default></paper-button>

    </paper-dialog>
  </template>
  <script>
    Polymer('meme-dialog', {
      ready: function() {
        this.$.topLineText.inputValue = "";
        this.$.bottomLineText.inputValue = "";
      },
      textChangeListener: function () {
        var parent = document.querySelector('meme-app').$.dialog;
        parent.redrawMeme(parent.$.imageSrc, parent.$.topLineText.inputValue, parent.$.bottomLineText.inputValue);
      },
      show: function(imageURL, imageLabel) {
        var shadowRoot = this.shadowRoot;
        var self = this;
        var image = new Image();
        image.onload = function() {
          self.$.imageSrc = this;
          self.redrawMeme(self.$.imageSrc, null, null);
          shadowRoot.querySelector('paper-dialog').toggle();
        }
        image.src = imageURL;

        var input1 = this.$.topLineText;
        var input2 = this.$.bottomLineText;
        var saveButton = this.$.saveMemeBtn;
        input1.oninput = this.textChangeListener;
        input2.oninput = this.textChangeListener;
        this.$.saveMemeBtn.addEventListener('click', this.saveMeme, false);
        // Clear input text
        this.$.topLineText.inputValue = "";
        this.$.bottomLineText.inputValue = "";
        this.$.imageTitle.inputValue = imageLabel;
      },
      redrawMeme: function(image, topLine, bottomLine) {

        var shadowRoot = this.shadowRoot;
        // Get Canvas2DContext
        var canvas = shadowRoot.querySelector('canvas');
        var ctx = canvas.getContext("2d");
        if (image != null) {
          if (image.width > 1000) {
            canvas.width = image.width / 2;
            canvas.height = image.height / 2;
            ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
          } else {
            canvas.width = image.width;
            canvas.height = image.height;
            ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

          }
        }
        // Text attributes
        ctx.font = '36pt Impact';
        ctx.textAlign = 'center';
        ctx.strokeStyle = 'black';
        ctx.lineWidth = 2;
        ctx.fillStyle = 'white';

        if (topLine != null) {
          ctx.fillText(topLine, canvas.width / 2, 40);
          ctx.strokeText(topLine, canvas.width / 2, 40);
        }

        if (bottomLine != null) {
          ctx.fillText(bottomLine, canvas.width / 2, canvas.height - 20);
          ctx.strokeText(bottomLine, canvas.width / 2, canvas.height - 20);
        }
      },
      errorHandler: function(e) {
        // Convert to toast
        console.log(e);
      },
      saveMeme: function() {
        var parent = document.querySelector('meme-app').$;
        parent.toast2.show();
        var canvas = parent.dialog.$['image-container'].querySelector("canvas");

        //Chrome Packaged App Save file
        var options = {
          type:'saveFile',
          suggestedName: parent.dialog.$.imageTitle.inputValue + '-'+ new Date().getTime() +'.png',
          accepts: [{"mimeTypes":['image/png']}]
        };
        chrome.fileSystem.chooseEntry(options, function(fileEntry){
          fileEntry.createWriter(function(writer){
            writer.onerror = parent.dialog.errorHandler;
            writer.onwriteend = function(e) {
              // Change to toast later
              console.log('write complete');
            }
            writer.write(Util.dataURLToBlob(canvas.toDataURL('image/png')), {type: 'image/png'});
          }, parent.dialog.errorHandler);
        });

      }
    });
  </script>
</polymer-element><commit_msg>Fixed close when you save a meme.<commit_after><link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">

<polymer-element name="meme-dialog">
  <template>
    <style>
      polymer-ui-card {
        width: 240px;
        height: 240px;
        margin: 20px auto;
        padding: 15px;
        display: block;
      }

      #cards {
        display: flex;
        flex-wrap: wrap;
      }

      paper-toast {
        bottom: 40px;
        left: 10px;
      }

      #image-container {
        display: flex;
      }
    </style>
    <paper-dialog heading="Create A Meme" transition="paper-dialog-transition-center">
      <div id="image-container">
        <canvas width="500" height="500"></canvas>
      <div>
        <paper-input floatingLabel id="topLineText" label="Top line ..."></paper-input><br/>
        <paper-input floatingLabel id="bottomLineText" label="Bottom line ..."></paper-input><br/>
        <paper-input style="display:none;" id="imageTitle"></paper-input>
      </div>
    </div>

    <paper-button id='closeMemeBtn' label="Cancel" dismissive></paper-button>
    <paper-button id='saveMemeBtn' label="Save" affirmative default></paper-button>

    </paper-dialog>
  </template>
  <script>
    Polymer('meme-dialog', {
      ready: function() {
        this.$.topLineText.inputValue = "";
        this.$.bottomLineText.inputValue = "";


      },
      textChangeListener: function () {
        var parent = document.querySelector('meme-app').$.dialog;
        parent.redrawMeme(parent.$.imageSrc, parent.$.topLineText.inputValue, parent.$.bottomLineText.inputValue);
      },
      close: function() {
        var app = document.querySelector('meme-app').$;
        app.dialog.shadowRoot.querySelector('paper-dialog').toggle();
      },
      show: function(imageURL, imageLabel) {
        var shadowRoot = this.shadowRoot;
        var self = this;
        var image = new Image();
        image.onload = function() {
          self.$.imageSrc = this;
          self.redrawMeme(self.$.imageSrc, null, null);
          shadowRoot.querySelector('paper-dialog').toggle();
        }
        image.src = imageURL;

        var input1 = this.$.topLineText;
        var input2 = this.$.bottomLineText;
        var saveButton = this.$.saveMemeBtn;
        input1.oninput = this.textChangeListener;
        input2.oninput = this.textChangeListener;
        this.$.saveMemeBtn.addEventListener('click', this.saveMeme, false);
        // Clear input text
        this.$.topLineText.inputValue = "";
        this.$.bottomLineText.inputValue = "";
        this.$.imageTitle.inputValue = imageLabel;
      },
      redrawMeme: function(image, topLine, bottomLine) {

        var shadowRoot = this.shadowRoot;
        // Get Canvas2DContext
        var canvas = shadowRoot.querySelector('canvas');
        var ctx = canvas.getContext("2d");
        if (image != null) {
          if (image.width > 1000) {
            canvas.width = image.width / 2;
            canvas.height = image.height / 2;
            ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
          } else {
            canvas.width = image.width;
            canvas.height = image.height;
            ctx.drawImage(image, 0, 0, canvas.width, canvas.height);

          }
        }
        // Text attributes
        ctx.font = '36pt Impact';
        ctx.textAlign = 'center';
        ctx.strokeStyle = 'black';
        ctx.lineWidth = 2;
        ctx.fillStyle = 'white';

        if (topLine != null) {
          ctx.fillText(topLine, canvas.width / 2, 40);
          ctx.strokeText(topLine, canvas.width / 2, 40);
        }

        if (bottomLine != null) {
          ctx.fillText(bottomLine, canvas.width / 2, canvas.height - 20);
          ctx.strokeText(bottomLine, canvas.width / 2, canvas.height - 20);
        }
      },
      errorHandler: function(e) {
        // Convert to toast
        console.log(e);
      },
      saveMeme: function() {
        var parent = document.querySelector('meme-app').$;
        parent.toast2.show();
        var canvas = parent.dialog.$['image-container'].querySelector("canvas");

        //Chrome Packaged App Save file
        var options = {
          type:'saveFile',
          suggestedName: parent.dialog.$.imageTitle.inputValue + '-'+ new Date().getTime() +'.png',
          accepts: [{"mimeTypes":['image/png']}]
        };
        chrome.fileSystem.chooseEntry(options, function(fileEntry){
          fileEntry.createWriter(function(writer){
            writer.onerror = parent.dialog.errorHandler;
            writer.onwriteend = function(e) {
              // Change to toast later
              console.log('write complete');
              // dirty
              var app = document.querySelector('meme-app').$;
              app.dialog.shadowRoot.querySelector('paper-dialog').toggle();
            }
            writer.write(Util.dataURLToBlob(canvas.toDataURL('image/png')), {type: 'image/png'});
          }, parent.dialog.errorHandler);
        });

      }
    });
  </script>
</polymer-element>
{'fraction_non_alphanumeric': 0.14563878402543215, 'fraction_numerical': 0.010331810053645937, 'mean_word_length': 2.1469209127852453, 'pattern_counts': {'":': 2, '<': 65, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1653851', 'n_tokens_mistral': 2998, 'n_tokens_neox': 2889, 'n_words': 547}