forked from froala/react-froala-wysiwyg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFroalaEditorInput.js
More file actions
1 lines (1 loc) · 3.85 KB
/
FroalaEditorInput.js
File metadata and controls
1 lines (1 loc) · 3.85 KB
1
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.FroalaEditorInput=e(require("react")):t.FroalaEditorInput=e(t.React)}(this,function(t){return function(t){function e(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){t.exports=i(7)},function(e,i){e.exports=t},function(t,e){"use strict";var i={tag:null,defaultTag:"div",listeningEvents:[],$element:null,$editor:null,config:{immediateReactModelUpdate:!1,reactIgnoreAttrs:null},editorInitialized:!1,SPECIAL_TAGS:["img","button","input","a"],INNER_HTML_ATTR:"innerHTML",hasSpecialTag:!1,oldModel:null,componentWillMount:function(){this.tag=this.props.tag||this.defaultTag},componentDidMount:function(){var t=this.refs.el.tagName.toLowerCase();this.SPECIAL_TAGS.indexOf(t)!=-1&&(this.tag=t,this.hasSpecialTag=!0),this.props.onManualControllerReady?this.generateManualController():this.createEditor()},componentWillUnmount:function(){this.destroyEditor()},componentDidUpdate:function(){JSON.stringify(this.oldModel)!=JSON.stringify(this.props.model)&&this.setContent()},createEditor:function(){this.editorInitialized||(this.config=this.props.config||this.config,this.$element=$(this.refs.el),this.setContent(!0),this.registerEvents(),this.$editor=this.$element.froalaEditor(this.config).data("froala.editor").$el,this.initListeners(),this.editorInitialized=!0)},setContent:function(t){(this.editorInitialized||t)&&(this.props.model||""==this.props.model)&&(this.oldModel=this.props.model,this.hasSpecialTag?this.setSpecialTagContent():this.setNormalTagContent(t))},setNormalTagContent:function(t){function e(){i.$element.froalaEditor("html.set",i.props.model||"",!0),i.$element.froalaEditor("undo.reset"),i.$element.froalaEditor("undo.saveStep")}var i=this;t?this.registerEvent(this.$element,"froalaEditor.initialized",function(){e()}):e()},setSpecialTagContent:function(){var t=this.props.model;if(t){for(var e in t)t.hasOwnProperty(e)&&e!=this.INNER_HTML_ATTR&&this.$element.attr(e,t[e]);t.hasOwnProperty(this.INNER_HTML_ATTR)&&(this.$element[0].innerHTML=t[this.INNER_HTML_ATTR])}},destroyEditor:function(){this.$element&&(this.listeningEvents&&this.$element.off(this.listeningEvents.join(" ")),this.$editor.off("keyup"),this.$element.froalaEditor("destroy"),this.listeningEvents.length=0,this.$element=null,this.editorInitialized=!1)},getEditor:function(){return this.$element?this.$element.froalaEditor.bind(this.$element):null},generateManualController:function(){var t={initialize:this.createEditor,destroy:this.destroyEditor,getEditor:this.getEditor};this.props.onManualControllerReady(t)},updateModel:function(){if(this.props.onModelChange){var t="";if(this.hasSpecialTag){for(var e=this.$element[0].attributes,i={},n=0;n<e.length;n++){var o=e[n].name;this.config.reactIgnoreAttrs&&this.config.reactIgnoreAttrs.indexOf(o)!=-1||(i[o]=e[n].value)}this.$element[0].innerHTML&&(i[this.INNER_HTML_ATTR]=this.$element[0].innerHTML),t=i}else{var r=this.$element.froalaEditor("html.get");"string"==typeof r&&(t=r)}this.oldModel=t,this.props.onModelChange(t)}},initListeners:function(){var t=this;this.registerEvent(this.$element,"froalaEditor.contentChanged",function(){t.updateModel()}),this.config.immediateReactModelUpdate&&this.registerEvent(this.$editor,"keyup",function(){t.updateModel()})},registerEvent:function(t,e,i){t&&e&&i&&(this.listeningEvents.push(e),t.on(e,i))},registerEvents:function(){var t=this.config.events;if(t)for(var e in t)t.hasOwnProperty(e)&&this.registerEvent(this.$element,e,t[e])}};t.exports=i},,,,,function(t,e,i){"use strict";var n=i(1),o=i(2),r=n.createClass({displayName:"FroalaEditorInput",mixins:[o],render:function(){return n.createElement("input",{ref:"el"})}});t.exports=r}])});