{"size": 3085, "ext": "js", "max_stars_repo_path": "dist/examples/english/tinymce/plugins/jqueryspellchecker/editor_plugin.js", "max_stars_repo_name": "linuxscout/jquery-spellchecker", "max_stars_repo_stars_event_min_datetime": "2016-12-18T13:42:29.000Z", "max_stars_repo_stars_event_max_datetime": "2016-12-18T13:42:29.000Z", "max_issues_repo_path": "src/examples/english/tinymce/plugins/jqueryspellchecker/editor_plugin.js", "max_issues_repo_name": "linuxscout/jquery-spellchecker", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/examples/english/tinymce/plugins/jqueryspellchecker/editor_plugin.js", "max_forks_repo_name": "linuxscout/jquery-spellchecker", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.7083333333, "max_line_length": 92, "alphanum_fraction": 0.5536466775}
/*
 * jQuery Spellchecker - TinyMCE Plugin - v0.2.1
 * https://github.com/badsyntax/jquery-spellchecker
 * Copyright (c) 2012 Richard Willis; Licensed MIT
 */

(function() {

  tinymce.create('tinymce.plugins.jQuerySpellcheckerPlugin', {

    getInfo : function() {
      return {
        longname : 'jQuery Spellchecker',
        author : 'Richard Willis',
        authorurl : 'http://badsyntax.co',
        infourl : 'https://github.com/badsyntax/jquery-spellchecker',
        version : '0.1.0'
      };
    },

    init : function(ed, url) {
      this.editor = ed;
      ed.addCommand('mcejQuerySpellCheck', $.proxy(this, '_onCheck'));
    },

    _onCheck: function() {

      var t = this;

      if (!t.spellchecker) {
        t.createSpellchecker();
        t.spellchecker.check();
        t.editor.controlManager.setActive('jqueryspellchecker', true);
      } else {
        t.spellchecker.destroy();
        t.spellchecker = null;
        t.editor.controlManager.setActive('jqueryspellchecker', false);
      }
    },

    createSpellchecker: function() {

      var t = this;
      var ed = t.editor;

      t.spellchecker = new $.SpellChecker(ed.getBody(), {
        lang: 'en',
        parser: 'html',
        webservice: {
          path: "/php/spellchecker.php",
          driver: 'pspell'
        },
        suggestBox: {
          position: 'below',
          appendTo: 'body',
          position: this.positionSuggestBox()
        }
      });

      t.spellchecker.on('check.success', function() {
        alert('There are no incorrectly spelt words.');
        t._onCheck();
      });
      t.spellchecker.on('check.start', function() {
        ed.setProgressState(1);
      });
      t.spellchecker.on('check.complete', function() {
        ed.setProgressState(0);
      });
      t.spellchecker.on('select.word', function(e) {
        return tinymce.dom.Event.cancel(e);
      });
      t.spellchecker.on('replace.word', function() {
        if (t.spellchecker.parser.incorrectWords.length === 0) {
          t._onCheck();
        }
      });
    },

    positionSuggestBox: function() {

      var t = this;

      return function() {

        var ed = t.editor;
        var dom = ed.dom;
        var vp = dom.getViewPort(ed.getWin());
        var word = (this.wordElement.data('firstElement') || this.wordElement)[0];

        var p1 = $(ed.getContentAreaContainer()).offset();
        var offset_top = p1.top;
        var offset_left = p1.left;

        var p2 = $(word).offset();
        var left = p2.left + offset_left;
        var top = p2.top - vp.y + offset_top + word.offsetHeight;

        this.container.css({ 
          top: top, 
          left: left 
        });
      };
    },

    createControl : function(n, cm) {
      if (n == 'jqueryspellchecker') {
        return cm.createButton(n, {
          title : 'spellchecker.desc', 
          cmd : 'mcejQuerySpellCheck', 
          scope : this
        });
      }
    }
  });

  // Register plugin
  tinymce.PluginManager.add('jqueryspellchecker', tinymce.plugins.jQuerySpellcheckerPlugin);
})();
