Commit 1c150e3d authored by Akikonata's avatar Akikonata

store

parent 8fb11e29
utils.extend( KityMinder, function () { utils.extend(KityMinder, function() {
var _kityminderUI = {}, var _kityminderUI = {},
_kityminderToolbarUI = {}, _kityminderToolbarUI = {},
_activeWidget = null, _activeWidget = null,
_widgetData = {}, _widgetData = {},
_widgetCallBack = {}; _widgetCallBack = {};
return { return {
registerUI: function ( uiname, fn ) { registerUI: function(uiname, fn) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) { utils.each(uiname.split(/\s+/), function(i, name) {
_kityminderUI[ name ] = fn; _kityminderUI[name] = fn;
} ); });
}, },
registerToolbarUI: function ( uiname, fn ) { registerToolbarUI: function(uiname, fn) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) { utils.each(uiname.split(/\s+/), function(i, name) {
_kityminderToolbarUI[ name ] = fn; _kityminderToolbarUI[name] = fn;
} ); });
}, },
loadUI: function ( km ) { loadUI: function(km) {
utils.each( _kityminderUI, function ( i, fn ) { utils.each(_kityminderUI, function(i, fn) {
fn.call( km ); fn.call(km);
} ); });
}, },
_createUI: function ( id ) { _createUI: function(id) {
var $cont = $( '<div class="kmui-container"></div>' ), var $cont = $('<div class="kmui-container"></div>'),
$toolbar = $.kmuitoolbar(), $toolbar = $.kmuitoolbar(),
$kmbody = $( '<div class="kmui-editor-body"></div>' ), $kmbody = $('<div class="kmui-editor-body"></div>'),
$statusbar = $( '<div class="kmui-statusbar"></div>' ); $statusbar = $('<div class="kmui-statusbar"></div>');
$cont.append( $toolbar ).append( $kmbody ).append( $statusbar ); $cont.append($toolbar).append($kmbody).append($statusbar);
$( utils.isString( id ) ? '#' + id : id ).append( $cont ); $(utils.isString(id) ? '#' + id : id).append($cont);
return { return {
'$container': $cont, '$container': $cont,
...@@ -36,108 +36,109 @@ utils.extend( KityMinder, function () { ...@@ -36,108 +36,109 @@ utils.extend( KityMinder, function () {
'$statusbar': $statusbar '$statusbar': $statusbar
}; };
}, },
_createToolbar: function ( $toolbar, km ) { _createToolbar: function($toolbar, km) {
var toolbars = km.getOptions( 'toolbars' ); var toolbars = km.getOptions('toolbars');
if ( toolbars && toolbars.length ) { if (toolbars && toolbars.length) {
var btns = []; var btns = [];
$.each( toolbars, function ( i, uiNames ) { $.each(toolbars, function(i, uiNames) {
$.each( uiNames.split( /\s+/ ), function ( index, name ) { $.each(uiNames.split(/\s+/), function(index, name) {
if ( name == '|' ) { if (name == '|') {
if ($.kmuiseparator) btns.push( $.kmuiseparator() ); if ($.kmuiseparator) btns.push($.kmuiseparator());
} else { } else {
if ( _kityminderToolbarUI[ name ] ) { if (_kityminderToolbarUI[name]) {
var ui = _kityminderToolbarUI[ name ].call( km, name ); var ui = _kityminderToolbarUI[name].call(km, name);
if (ui) btns.push( ui ); if (ui) btns.push(ui);
} }
} }
} ); });
if (btns.length) $toolbar.kmui().appendToBtnmenu( btns ); if (btns.length) $toolbar.kmui().appendToBtnmenu(btns);
} ); });
$toolbar.append( $( '<div class="kmui-dialog-container"></div>' ) ); $toolbar.append($('<div class="kmui-dialog-container"></div>'));
}else{ } else {
$toolbar.hide(); $toolbar.hide();
} }
}, },
_createStatusbar: function ( $statusbar, km ) { _createStatusbar: function($statusbar, km) {
}, },
getKityMinder: function ( id, options ) { getKityMinder: function(id, options) {
var containers = this._createUI( id );
var km = this.getMinder( containers.$body.get( 0 ), options ); var containers = this._createUI(id);
this._createToolbar( containers.$toolbar, km ); var km = this.getMinder(containers.$body.get(0), options);
this._createStatusbar( containers.$statusbar, km ); this._createToolbar(containers.$toolbar, km);
this._createStatusbar(containers.$statusbar, km);
km.$container = containers.$container; km.$container = containers.$container;
this.loadUI( km ); this.loadUI(km);
return km.fire( 'interactchange' ); return km.fire('interactchange');
}, },
registerWidget: function ( name, pro, cb ) { registerWidget: function(name, pro, cb) {
_widgetData[ name ] = $.extend2( pro, { _widgetData[name] = $.extend2(pro, {
$root: '', $root: '',
_preventDefault: false, _preventDefault: false,
root: function ( $el ) { root: function($el) {
return this.$root || ( this.$root = $el ); return this.$root || (this.$root = $el);
}, },
preventDefault: function () { preventDefault: function() {
this._preventDefault = true; this._preventDefault = true;
}, },
clear: false clear: false
} ); });
if ( cb ) { if (cb) {
_widgetCallBack[ name ] = cb; _widgetCallBack[name] = cb;
} }
}, },
getWidgetData: function ( name ) { getWidgetData: function(name) {
return _widgetData[ name ]; return _widgetData[name];
}, },
setWidgetBody: function ( name, $widget, km ) { setWidgetBody: function(name, $widget, km) {
if ( !km._widgetData ) { if (!km._widgetData) {
utils.extend( km, { utils.extend(km, {
_widgetData: {}, _widgetData: {},
getWidgetData: function ( name ) { getWidgetData: function(name) {
return this._widgetData[ name ]; return this._widgetData[name];
}, },
getWidgetCallback: function ( widgetName ) { getWidgetCallback: function(widgetName) {
var me = this; var me = this;
return function () { return function() {
return _widgetCallBack[ widgetName ].apply( me, [ me, $widget ].concat( utils.argsToArray( arguments, 0 ) ) ); return _widgetCallBack[widgetName].apply(me, [me, $widget].concat(utils.argsToArray(arguments, 0)));
}; };
} }
} ); });
} }
var pro = _widgetData[ name ]; var pro = _widgetData[name];
if ( !pro ) { if (!pro) {
return null; return null;
} }
pro = km._widgetData[ name ]; pro = km._widgetData[name];
if ( !pro ) { if (!pro) {
pro = _widgetData[ name ]; pro = _widgetData[name];
pro = km._widgetData[ name ] = $.type( pro ) == 'function' ? pro : utils.clone( pro ); pro = km._widgetData[name] = $.type(pro) == 'function' ? pro : utils.clone(pro);
} }
pro.root( $widget.kmui().getBodyContainer() ); pro.root($widget.kmui().getBodyContainer());
//清除光标 //清除光标
km.fire('selectionclear'); km.fire('selectionclear');
pro.initContent( km, $widget ); pro.initContent(km, $widget);
//在dialog上阻止键盘冒泡,导致跟编辑输入冲突的问题 //在dialog上阻止键盘冒泡,导致跟编辑输入冲突的问题
$widget.on('keydown keyup keypress',function(e){ $widget.on('keydown keyup keypress', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
if ( !pro._preventDefault ) { if (!pro._preventDefault) {
pro.initEvent( km, $widget ); pro.initEvent(km, $widget);
} }
if (pro.width) $widget.width( pro.width ); if (pro.width) $widget.width(pro.width);
}, },
setActiveWidget: function ( $widget ) { setActiveWidget: function($widget) {
_activeWidget = $widget; _activeWidget = $widget;
} }
}; };
}() ); }());
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment