Exemplo n.º 1
0
        applyOperand: function () {

                // 偏移量
            var offset = 0,
                // 操作数
                operands = arguments,
                // 操作对象最大高度
                maxHeight = 0,
                cached = [];

            kity.Utils.each( operands, function ( operand ) {

                var box = operand.getRenderBox();

                cached.push( box );
                maxHeight = Math.max( box.height, maxHeight );

            } );

            kity.Utils.each( operands, function ( operand, index ) {

                var box = cached[ index ];

                operand.translate( offset - box.x, ( maxHeight - ( box.y + box.height ) ) / 2 );

                offset += box.width;

            } );

        }
Exemplo n.º 2
0
        applyOperand: function ( leftOperand, rightOperand ) {

            var operator = this,
                operatorBox = operator.getRenderBox(),
                // 操作数特殊处理
                leftOperandBox = kity.Utils.extend( leftOperand.getRenderBox(), {
                    height: leftOperand.getBaseHeight()
                } ),
                rightOperandBox = kity.Utils.extend( rightOperand.getRenderBox(), {
                    height: rightOperand.getBaseHeight()
                } ),

                // 偏移量
                offset = 0,

                // 操作对象最大高度
                maxHeight = Math.max( leftOperandBox.height, rightOperandBox.height, operatorBox.height );

            // 左操作数
            leftOperand.translate( offset, ( maxHeight - leftOperandBox.height ) / 2 );

            // 操作符
            offset += leftOperandBox.width + leftOperandBox.x;
            operator.translate( offset, ( maxHeight - operatorBox.height ) / 2 );

            // 右操作数
            offset += operatorBox.width + operatorBox.x;
            rightOperand.translate( offset, ( maxHeight - rightOperandBox.height ) / 2 );

        }
Exemplo n.º 3
0
    ( function () {

        var tmp = [],
            otherImageSrc = "assets/images/toolbar/other.png",
            currentConf = [];

        kity.Utils.each( config, function ( conf ) {

            if ( conf.type === UI_ELE_TYPE.DELIMITER ) {
                return;
            }

            conf = conf.options.box.group;

            tmp = tmp.concat( conf );

        } );

        kity.Utils.each( tmp, function ( conf ) {

            conf = conf.items;

            for ( var i = 0, len = conf.length; i < len; i++ ) {
                currentConf = currentConf.concat( conf[ i ].content );
            }

        } );

        // 添加定位信息
        kity.Utils.each( currentConf, function ( conf ) {

            var data = OTHER_POSITION[ conf.item.val ];

            if ( !data ) {
                return;
            }
            /*
             在other-position.data.js中,若添加sprite这个键
             则表明不使用other.png这个默认的sprite图,而使用其他的sprite
            */
            if (data.hasOwnProperty('sprite')) {
                if (data.sprite == 'all'){
                    conf.item.img = "assets/images/toolbar/all_formula.png";
                }
                if (data.sprite == 'preset'){
                    conf.item.img ="assets/images/toolbar/preset_formula.png";
                }
            }
            else {
                conf.item.img = otherImageSrc;
            }
            conf.item.pos = data.pos;
            conf.item.size = data.size;

        } );

    } )();
Exemplo n.º 4
0
            getGroupContent: function ( groupId ) {

                var groupInfo = this.objTree.mapping[ groupId ],
                    content = [],
                    operands = groupInfo.objGroup.operands,
                    offset = operands.length - 1,
                    isLtr = groupInfo.strGroup.traversal !== "rtl";

                kity.Utils.each( operands, function ( operand, i ) {

                    if ( isLtr ) {
                        content.push( operand.node );
                    } else {
                        content[ offset - i ] = operand.node;
                    }

                } );

                return {
                    id: groupId,
                    traversal: groupInfo.strGroup.traversal || "ltr",
                    groupObj: groupInfo.objGroup.node,
                    content: content
                };

            },
Exemplo n.º 5
0
    ( function () {

        kity.Utils.each( CONF, function ( fontData ) {
            FONT_LIST[ fontData.meta.fontFamily ] = fontData;
        } );

    } )();
Exemplo n.º 6
0
            constructor: function ( doc, options ) {

                this.options = kity.Utils.extend( {}, DEFAULT_OPTIONS, options );

                // 事件状态, 是否已经初始化
                this.eventState = false;
                this.toolbar = null;
                this.displayState = false;
                this.fixOffset = options.fixOffset || false;

                this.doc = doc;

                this.element = this.createButton();
                this.disabled = true;

                // 挂载的对象
                this.mountElement = null;

                this.icon = this.createIcon();
                this.label = this.createLabel();
                this.sign = this.createSign();
                this.mountPoint = this.createMountPoint();

                this.mergeElement();

            },
Exemplo n.º 7
0
            enableToolbar: function () {

                kity.Utils.each( this.elements, function ( ele ) {
                    ele.enable && ele.enable();
                } );

            },
Exemplo n.º 8
0
    function getContents ( data ) {

        var result = [],
            path = data.path,
            values = data.values;

        kity.Utils.each( values, function ( value ) {

            var img = value,
                val = value;

            if ( typeof value !== "string" ) {
                img = value.img;
                val = value.key;
            } else {
                val = "\\" + value;
            }

            result.push( {
                item: {
                    show: '' + path + img.toLowerCase() +'.png',
                    val: val
                }
            } );

        } );

        return result;

    }
Exemplo n.º 9
0
    function initContentShape () {

        var match = null,
            content = this.contentText,
            chars = [];

        while ( match = /^([^\\]*)(\\[^\\]+\\)([\s\S]*)/.exec( content ) ) {

            content = match[3];
            chars = chars.concat( match[1].split( "" ) );
            chars.push( match[2] );

        }

        chars = chars.concat( content.split( "" ) );

        // 字符数组
        this.chars = chars;

        kity.Utils.each( chars, function ( charData, index ) {

            var charShape = new Char( charData, "roman" );

            this.contentShape.addShape( charShape );

        }, this );

    }
Exemplo n.º 10
0
                kity.Utils.each( this.options.group, function ( group, i ) {

                    result.title.push( group.title || "" );
                    itemGroup = [];

                    kity.Utils.each( group.items, function ( item ) {

                        groupNode = groupNode.cloneNode( false );
                        itemContainer = itemContainer.cloneNode( false );

                        groupTitle = $$.ele( doc, "div", {
                            className: PREFIX + "box-group-title",
                            content: item.title
                        } );

                        groupNode.appendChild( groupTitle );
                        groupNode.appendChild( itemContainer );

                        kity.Utils.each( createItems( doc, item.content, itemType ), function ( boxItem ) {

                            boxItem.appendTo( itemContainer );

                        } );

                        itemGroup.push( groupNode );

                    } );

                    result.items.push( itemGroup );

                } );
Exemplo n.º 11
0
    EditorWrapper.prototype._trigger = function () {

        var editor = this.editor;

        kity.Utils.each( this._callbacks, function ( cb ) {
            cb.call( editor, editor );
        } );

    };
Exemplo n.º 12
0
    ( function () {

        var tmp = [],
            otherImageSrc = "assets/images/toolbar/other.png",
            currentConf = [];

        kity.Utils.each( config, function ( conf ) {

            if ( conf.type === UI_ELE_TYPE.DELIMITER ) {
                return;
            }

            conf = conf.options.box.group;

            tmp = tmp.concat( conf );

        } );

        kity.Utils.each( tmp, function ( conf ) {

            conf = conf.items;

            for ( var i = 0, len = conf.length; i < len; i++ ) {
                currentConf = currentConf.concat( conf[ i ].content );
            }

        } );

        // 添加定位信息
        kity.Utils.each( currentConf, function ( conf ) {

            var data = OTHER_POSITION[ conf.item.val ];

            if ( !data ) {
                return;
            }

            conf.item.img = otherImageSrc;
            conf.item.pos = data.pos;
            conf.item.size = data.size;

        } );

    } )();
Exemplo n.º 13
0
        applyOperand: function () {

                // 偏移量
            var offsetX = 0,
                // 操作数
                operands = arguments,
                // 操作对象最大高度
                maxHeight = 0,
                // 垂直距离最大偏移
                maxOffsetTop = 0,
                maxOffsetBottom = 0,
                cached = [],
                // 偏移集合
                offsets = [];

            kity.Utils.each( operands, function ( operand ) {

                var box = operand.getFixRenderBox(),
                    offsetY = operand.getOffset();

                box.height -= offsetY.top + offsetY.bottom;
                cached.push( box );
                offsets.push( offsetY );
                maxOffsetTop = Math.max( offsetY.top, maxOffsetTop );
                maxOffsetBottom = Math.max( offsetY.bottom, maxOffsetBottom );
                maxHeight = Math.max( box.height, maxHeight );

            } );

            kity.Utils.each( operands, function ( operand, index ) {

                var box = cached[ index ];

                operand.translate( offsetX - box.x, ( maxHeight - ( box.y + box.height ) ) / 2 + maxOffsetBottom - offsets[ index ].bottom );

                offsetX += box.width;

            } );

            this.parentExpression.setOffset( maxOffsetTop, maxOffsetBottom );
            this.parentExpression.updateBoxSize();

        }
Exemplo n.º 14
0
            createGroup: function () {

                var doc = this.doc,
                    itemGroup = [],
                    result = {
                        title: [],
                        items: []
                    },
                    groupNode = null,
                    groupTitle = null,
                    itemType = BOX_TYPE.DETACHED === this.options.type ? ITEM_TYPE.BIG : ITEM_TYPE.SMALL,
                    itemContainer = null;

                groupNode = $$.ele( this.doc, "div", {
                    className: PREFIX + "box-group"
                } );

                itemContainer = groupNode.cloneNode( false );
                itemContainer.className = PREFIX + "box-group-item-container";

                kity.Utils.each( this.options.group, function ( group, i ) {

                    result.title.push( group.title || "" );
                    itemGroup = [];

                    kity.Utils.each( group.items, function ( item ) {

                        groupNode = groupNode.cloneNode( false );
                        itemContainer = itemContainer.cloneNode( false );

                        groupTitle = $$.ele( doc, "div", {
                            className: PREFIX + "box-group-title",
                            content: item.title
                        } );

                        groupNode.appendChild( groupTitle );
                        groupNode.appendChild( itemContainer );

                        kity.Utils.each( createItems( doc, item.content, itemType ), function ( boxItem ) {

                            boxItem.appendTo( itemContainer );

                        } );

                        itemGroup.push( groupNode );

                    } );

                    result.items.push( itemGroup );

                } );

                return result;

            },
Exemplo n.º 15
0
            closeElement: function ( exception ) {

                kity.Utils.each( this.elements, function ( ele ) {

                    if ( ele != exception ) {
                        ele.hide && ele.hide();
                    }

                } );

            },
Exemplo n.º 16
0
            clearExpressions: function () {

                kity.Utils.each( this.expressions, function ( exp ) {

                    exp.remove();

                } );

                this.expressions = [];

            },
Exemplo n.º 17
0
            mergeElement: function () {

                var groupContainer = this.groupContainer;

                this.element.appendChild( groupContainer );

                kity.Utils.each( this.itemGroups, function ( group ) {

                    groupContainer.appendChild( group );

                } );

            },
Exemplo n.º 18
0
            constructor: function ( container, config ) {

                this.callBase( container );
                this.expressions = [];
                this.fontInstaller = new FontInstaller( this );

                this.config = kity.Utils.extend( {}, DEFAULT_OPTIONS, config );

                this.initEnvironment();

                this.initInnerFont();

            },
Exemplo n.º 19
0
    function createItems ( doc, group, type ) {

        var items = [];

        kity.Utils.each( group, function ( itemVal, i ) {

            items.push( new BoxItem( type, doc, itemVal) );

        } );

        return items;

    }
Exemplo n.º 20
0
                kity.Utils.each( itemGroup.items, function ( itemArr, index ) {

                    var itemWrapNode = wrapNode.cloneNode( false );

                    kity.Utils.each( itemArr, function ( item ) {

                        itemWrapNode.appendChild( item );

                    } );

                    itemGroup.items[ index ] = itemWrapNode;

                } );
Exemplo n.º 21
0
            initToolbarElements: function () {

                var elements = this.elements,
                    doc = this.uiComponent.toolbarContainer.ownerDocument,
                    _self = this;

                kity.Utils.each( this.elementList, function ( eleInfo, i ) {

                    var ele = createElement( eleInfo.type, doc, eleInfo.options );
                    elements.push( ele );
                    _self.appendElement( ele );

                } );

            },
Exemplo n.º 22
0
        addedCall: function () {

            var offset = 0;

            kity.Utils.each( this.chars, function ( charData, index ) {

                var charShape = this.contentShape.getItem( index );

                charShape.translate( offset, 0 );

                offset += charShape.getBoxWidth() + 1;

            }, this );

        }
Exemplo n.º 23
0
            getGroupList: function () {

                var lists = [];

                kity.Utils.each( this.options.group, function ( group, index ) {

                    lists.push( group.title );

                } );

                return {
                    width: 150,
                    items: lists
                };

            },
Exemplo n.º 24
0
                kity.Utils.each( items, function ( item ) {

                    var contents = item.content;

                    kity.Utils.each( contents, function ( currentContent, index ) {

                        lineno = Math.floor( count / lineMaxCount );
                        colno = count % lineMaxCount;
                        count++;

                        style = "top: " + ( lineno * 33 + 5 ) + "px; left: " + ( colno * 32 + 5 ) + "px;" ;

                        newContent.push( '<div class="'+ PREFIX +'area-item" data-value="'+ currentContent.key +'" style="'+ style +'"><div class="'+ PREFIX +'area-item-inner"><div class="'+ PREFIX +'area-item-img" style="background: url('+ currentContent.img +') no-repeat '+ -currentContent.pos.x + 'px ' + -currentContent.pos.y +'px;"></div></div></div>' );

                    } );

                } );
Exemplo n.º 25
0
            updateContent: function () {

                var items = this.boxObject.getOverlapContent(),
                    count = 0,
                    style = null,
                    lineno = 0,
                    colno = 0,
                    lineMaxCount = this.lineMaxCount,
                    newContent = [];

                // 清空原有内容
                this.panel.innerHTML = "";

                kity.Utils.each( items, function ( item ) {

                    var contents = item.content;

                    kity.Utils.each( contents, function ( currentContent, index ) {

                        lineno = Math.floor( count / lineMaxCount );
                        colno = count % lineMaxCount;
                        count++;

                        style = "top: " + ( lineno * 33 + 5 ) + "px; left: " + ( colno * 32 + 5 ) + "px;" ;

                        newContent.push( '<div class="'+ PREFIX +'area-item" data-value="'+ currentContent.key +'" style="'+ style +'"><div class="'+ PREFIX +'area-item-inner"><div class="'+ PREFIX +'area-item-img" style="background: url('+ currentContent.img +') no-repeat '+ -currentContent.pos.x + 'px ' + -currentContent.pos.y +'px;"></div></div></div>' );

                    } );

                } );


                this.currentItemCount = count;
                this.panelIndex = 0;
                this.panel.style.top = 0;
                this.panel.innerHTML = newContent.join( "" );

                this.checkMaxPanelIndex();
                this.updatePanelButtonState();

            },
Exemplo n.º 26
0
    function getIconContents ( keySet, imgSrc ) {

        var result = [];

        kity.Utils.each( keySet, function ( key ) {

            if ( key.length > 1 ) {
                key = "\\" + key;
            }

            result.push( {
                key: key,
                img: imgSrc,
                pos: CHAR_POSITION[ key ]
            } );

        } );

        return result;

    }
Exemplo n.º 27
0
    // 调整表达式之间的偏移
    function correctOffset () {

        var exprOffset = 0;

        kity.Utils.each( this.expressions, function ( expr ) {

            var box = null;

            if ( !expr ) {
                return;
            }

            expr.setTransform( new kity.Matrix( 1, 0, 0, 1, 0, 0 ) );
            box = expr.getRenderBox();
            expr.translate( 0 - box.x, exprOffset );

            exprOffset += box.height + EXPRESSION_INTERVAL;

        } );

        return this;

    }
Exemplo n.º 28
0
            initInnerFont: function () {

                var fontList = FontManager.getFontList(),
                    _self = this;

                kity.Utils.each( fontList, function ( fontInfo ) {
                    createFontStyle( fontInfo );
                } );

                function createFontStyle ( fontInfo ) {

                    var stylesheet = _self.doc.createElement( "style" ),
                        tpl = '@font-face{font-family: "${fontFamily}";font-style: normal;src: url("${src}") format("woff");}';

                    stylesheet.setAttribute( "type", "text/css" );
                    stylesheet.innerHTML = tpl.replace( '${fontFamily}', fontInfo.meta.fontFamily )
                        .replace( '${src}', fontInfo.meta.src );

                    _self.resourceNode.appendChild( stylesheet );

                }

            },
Exemplo n.º 29
0
            getCursorRecord: function () {

                return kity.Utils.extend( {}, this.record.cursor ) || null;

            },
Exemplo n.º 30
0
            createOverlapGroup: function ( itemGroup ) {

                var classifyList = itemGroup.title,
                    _self = this,
                    overlapContainer = createOverlapContainer( this.doc),
                    overlapButtonObject = createOverlapButton( this.doc, {
                        fixOffset: this.options.fixOffset
                    } ),
                    overlapListObject = createOverlapList( this.doc, {
                        width: 150,
                        items: classifyList
                    } ),
                    wrapNode = $$.ele( this.doc, "div", {
                        className: PREFIX + "wrap-group"
                    } );

                this.overlapButtonObject = overlapButtonObject;

                // 组合选择组件
                overlapButtonObject.mount( overlapListObject );

                overlapButtonObject.initEvent();
                overlapListObject.initEvent();

                // 合并box的内容
                kity.Utils.each( itemGroup.items, function ( itemArr, index ) {

                    var itemWrapNode = wrapNode.cloneNode( false );

                    kity.Utils.each( itemArr, function ( item ) {

                        itemWrapNode.appendChild( item );

                    } );

                    itemGroup.items[ index ] = itemWrapNode;

                } );

                this.itemPanels = itemGroup.items;

                // 切换面板处理器
                overlapListObject.setSelectHandler( function ( index, oldIndex ) {

                    _self.overlapIndex = index;

                    overlapButtonObject.setLabel( classifyList[index] );
                    overlapButtonObject.hideMount();

                    // 切换内容
                    itemGroup.items[ oldIndex ].style.display = "none";
                    itemGroup.items[ index ].style.display = "block";

                    if ( index !== oldIndex ) {
                        _self.updateSize();
                    }

                    _self.onchangeHandler( index );

                } );

                overlapContainer.appendChild( overlapButtonObject.getNode() );

                kity.Utils.each( itemGroup.items, function ( group, index ) {

                    if ( index > 0 ) {
                        group.style.display = "none";
                    }

                    overlapContainer.appendChild( group );

                } );

                overlapListObject.select( 0 );

                return [ overlapContainer ];

            },