Public
Snippet $98 authored by Tristan Cavelier

erp5_fckeditor/fckeditor.gadget.js

fckeditor.gadget.js
/*jslint indent: 2 */
/*global window, rJS, RSVP, FCKeditor, FCKeditorAPI */
(function (window, rJS, RSVP) {
  "use strict";

  rJS(window)
    .ready(function (g) {
      console.log("ready");
      g.props = {};
      [].forEach.call(window.document.head.querySelectorAll("base"), function (el) {
        g.props.basePath = el.href.split(/[\?#]/)[0].replace(/[^\/]+$/, "");  // XXX put some comments here
      });
      //var deferred = RSVP.defer();
      //svgCanvas.ready(function () {
      //  deferred.resolve();
      //});
      //return deferred.promise;

    })
    .declareMethod('render', function (options) {
      console.log("render start");
      this.props.key = options.key;

      var oFCKeditor = new FCKeditor(options.key),
          //pathUser   = '/' + path_user + '/',
          rows       = 18;
      //oFCKeditor.BasePath = portal_url + '/';
      oFCKeditor.BasePath = this.props.basePath || "/";
      oFCKeditor.Value    = options.value;

      // set the base url for relative paths
      //oFCKeditor.Config.BaseHref = baseHrefUrl + '/';  // Base url should be defined by the parent gadget

      // set the css for editor area
      oFCKeditor.Config.EditorAreaCSS = "erp5_editor.css";

      // editor appearance
      oFCKeditor.ToolbarSet = "ERP5WebZopeCmf";
      oFCKeditor.Width      = "100%";
      oFCKeditor.Height     = rows * 24;

      // enable Firefox's own spell checker
      oFCKeditor.Config.FirefoxSpellChecker	= true;

      // browsing for links
      oFCKeditor.Config.LinkBrowser = true;  // XXX true only if FCKeditor_viewImageSelectionDialog exists
      oFCKeditor.Config.LinkBrowserURL = "FCKeditor_viewDocumentSelectionDialog";

      // rapid upload activation for links
      oFCKeditor.Config.LinkUpload = false; // XXX should be implemented using portal_contributions

      // browsing for images
      oFCKeditor.Config.ImageBrowser = true;  // XXX true only if FCKeditor_viewImageSelectionDialog exists
      oFCKeditor.Config.ImageBrowserURL = "FCKeditor_viewImageSelectionDialog";

      // rapid upload activation for images
      oFCKeditor.Config.ImageUpload = false; // XXX should be implemented using portal_contributions

      this.props.editor = oFCKeditor;
      window.oFCKeditor = oFCKeditor;

      oFCKeditor.Create();

      //FCKeditorAPI.Instances[options.key].SetData(options.value);
      console.log("render end", oFCKeditor.Value.length);
    })
    //.declareService(function () {
    //  if (/(?:^\?|&)auto_focus=(true|1)(?:&|$)/.test(window.location.search)) {
    //    window.focus();  // should be done by the parent gadget? use FCKeditorAPI.Instance[this.props.key].Focus() ?
    //  }
    //})
    .declareMethod('getContent', function () {
      console.log("getContent staaart");
      // return {};
      //console.log("getContent start", this.props.editor.Value.length);
      // throw Error("TRISTAN");
      var form_data = {};
      form_data[this.props.key] = "couscous";
      //form_data[this.props.key] = FCKeditorAPI.Instances[this.props.key].GetData();  // FCKeditorAPI is undefined ?
      console.log("getContent end");
      return form_data;
    });

}(window, rJS, RSVP));