Example #1
0
    it("works in single condition", function () {
        var html = '<form>' +
                '<div><input type="text" name="a" value="1" id="a" /></div>' +
                '<div><input type="text" name="b" value="2" id="b" /></div>' +
                '<div><input type="hidden" name="c" value="3" id="c" /></div>' +
                '<div>' +
                '<textarea name="d" rows="8" cols="40">4</textarea>' +
                '</div>' +
                '<div>' +
                // empty select! #297
                '<select name="empty">' +
                '</select>' +
                '<select name="e">' +
                '<option value="5" selected="selected">5</option>' +
                '<option value="6">6</option>' +
                '<option value="7">7</option>' +
                '</select>' +
                '</div>' +
                '<div>' +
                '<input type="checkbox" name="f" value="8" id="f" />' +
                '</div>' +
                '<div>' +
                '<input type="submit" name="g" value="Submit" id="g" />' +
                '</div>' +
                '</form>',
            form = $(html).appendTo('body'),
            ret = io.serialize(form);

        expect(ret).toBe("a=1&b=2&c=3&d=4&e=5");

        expect(io.serialize(form.all('input'))).toBe("a=1&b=2&c=3");

        expect(io.serialize(form.all('input'), true)).toBe("a=1&b=2&c=3");

        form.remove();
    });
Example #2
0
    bindUI: function () {
        var self = this,
            form,
            prefixCls = self.get('prefixCls'),
            textarea = self.get('textarea');

        if (self.get('attachForm') &&
            (form = textarea[0].form) &&
            (form = $(form))) {
            form.on('submit', self.sync, self);
        }

        function docReady() {
            self.detach('docReady', docReady);
            // 是否自动focus
            if (self.get('focused')) {
                self.focus();
            } else {
                //否则清空选择区域
                var sel = self.getSelection();
                if (sel) {
                    sel.removeAllRanges();
                }
            }
        }

        self.on('docReady', docReady);

        self.on('blur', function () {
            self.$el.removeClass(prefixCls + 'editor-focused');
        });

        self.on('focus', function () {
            self.$el.addClass(prefixCls + 'editor-focused');
        });
    },
Example #3
0
 setTimeout(function () {
     var link = findAWithImg(img), linkVal = util.trim(valInput(self.imgLink)), sel = self.editor.getSelection(), target = self.imgLinkBlank.attr('checked') ? '_blank' : '_self', linkTarget, skip = 0, prev, next, bs;
     if (link) {
         linkTarget = link.attr('target') || '_self';
         if (linkVal !== link.attr('href') || linkTarget !== target) {
             img._4eBreakParent(link);
             if ((prev = img.prev()) && prev.nodeName() === 'a' && !prev[0].childNodes.length) {
                 prev.remove();
             }
             if ((next = img.next()) && next.nodeName() === 'a' && !next[0].childNodes.length) {
                 next.remove();
             }
         } else {
             skip = 1;
         }
     }
     if (!skip && linkVal) {
         // 新增需要 bookmark,标记
         if (!self.selectedEl) {
             bs = sel.createBookmarks();
         }
         link = $('<a>');
         link.attr('_ke_saved_href', linkVal).attr('href', linkVal).attr('target', target);
         var t = img[0];
         t.parentNode.replaceChild(link[0], t);
         link.append(t);
     }
     if (bs) {
         sel.selectBookmarks(bs);
     } else if (self.selectedEl) {
         self.editor.getSelection().selectElement(self.selectedEl);
     }
     if (!skip) {
         self.editor.execCommand('save');
     }
 }, 100);
Example #4
0
 function showing(ev) {
     var self = this;
     self.set('currentTrigger', $(ev.target));
     self.show();
 }
Example #5
0
KISSY.add('editor-plugins/lib/code/dialog',["util","editor","menubutton","dom","../dialog","node","ua"],function(S ,require, exports, module) {function e(e){this.editor=e}var t=require("util"),i=require("editor"),o=require("menubutton"),r=i.XHTML_DTD,a=require("dom").NodeType,l=i.Walker.whitespaces(!0),s=require("../dialog"),n=require("node"),d=require("ua"),c=[["ActionScript3","as3"],["Bash/Shell","bash"],["C/C++","cpp"],["Css","css"],["CodeFunction","cf"],["C#","c#"],["Delphi","delphi"],["Diff","diff"],["Erlang","erlang"],["Groovy","groovy"],["HTML","html"],["Java","java"],["JavaFx","jfx"],["Javascript","js"],["Perl","pl"],["Php","php"],["Plain Text","plain"],["PowerShell","ps"],["Python","python"],["Ruby","ruby"],["Scala","scala"],["Sql","sql"],["Vb","vb"],["Xml","xml"]],p='<div class="{prefixCls}code-wrap"><table class="{prefixCls}code-table"><tr><td class="{prefixCls}code-label"><label for="ks-editor-code-type">类型:</label></td><td class="{prefixCls}code-content"><select id="ks-editor-code-type"  class="{prefixCls}code-type">'+t.map(c,function(e){return'<option value="'+e[1]+'">'+e[0]+"</option>"})+'</select></td></tr><tr><td><label for="ks-editor-code-textarea">代码:</label></td><td><textarea id="ks-editor-code-textarea"  class="{prefixCls}code-textarea {prefixCls}input"></textarea></td></tr></table></div>',u='<div class="{prefixCls}code-table-action"><a href="javascript:void(\'插入\')" class="{prefixCls}code-insert {prefixCls}button">插入</a><a href="javascript:void(\'取消\')" class="{prefixCls}code-cancel {prefixCls}button">取消</a></td></div>',f='<pre class="prettyprint ks-editor-code brush:{type};toolbar:false;">{code}</pre>';t.augment(e,{initDialog:function(){var e,i,r=this,a=r.editor.get("prefixCls")+"editor-";i=r.dialog=new s({width:500,mask:!0,headerContent:"插入代码",bodyContent:t.substitute(p,{prefixCls:a}),footerContent:t.substitute(u,{prefixCls:a})}).render(),e=i.get("el"),r.insert=e.one("."+a+"code-insert"),r.cancel=e.one("."+a+"code-cancel"),r.type=o.Select.decorate(e.one("."+a+"code-type"),{prefixCls:a+"big-",width:150,menuCfg:{prefixCls:a,height:320,render:i.get("contentEl")}}),r.code=e.one("."+a+"code-textarea"),r.insert.on("click",r._insert,r),r.cancel.on("click",r.hide,r)},hide:function(){this.dialog.hide()},_insert:function(){var e,i=this,o=i.editor,s=i.code;if(!t.trim(e=s.val()))return void alert("请输入代码!");var c=n(t.substitute(f,{type:i.type.get("value"),code:t.escapeHtml(e)}),o.get("document")[0]);i.dialog.hide(),o.insertElement(c);var p=o.getSelection().getRanges()[0],u=c.next(l,1),h=u&&u[0].nodeType===a.ELEMENT_NODE&&u.nodeName();h&&r.$block[h]&&r[h]["#text"]||(u=n("<p></p>",o.get("document")[0]),d.ie||u._4eAppendBogus(),c.after(u)),p.moveToElementEditablePosition(u),o.getSelection().selectRanges([p])},show:function(){this.dialog||this.initDialog(),this.dialog.show()}}),module.exports=e;});
Example #6
0
 align: function (refNode, points, offset, overflow) {
     refNode = $(refNode || win);
     offset = offset && [].concat(offset) || [
         0,
         0
     ];
     overflow = overflow || {};
     var self = this, el = self.$el, fail = 0;    // 当前节点可以被放置的显示区域
     // 当前节点可以被放置的显示区域
     var visibleRect = getVisibleRectForElement(el[0]);    // 当前节点所占的区域, left/top/width/height
     // 当前节点所占的区域, left/top/width/height
     var elRegion = getRegion(el);    // 参照节点所占的区域, left/top/width/height
     // 参照节点所占的区域, left/top/width/height
     var refNodeRegion = getRegion(refNode);    // 当前节点将要被放置的位置
     // 当前节点将要被放置的位置
     var elFuturePos = getElFuturePos(elRegion, refNodeRegion, points, offset);    // 当前节点将要所处的区域
     // 当前节点将要所处的区域
     var newElRegion = util.merge(elRegion, elFuturePos);    // 如果可视区域不能完全放置当前节点时允许调整
     // 如果可视区域不能完全放置当前节点时允许调整
     if (visibleRect && (overflow.adjustX || overflow.adjustY)) {
         // 如果横向不能放下
         if (isFailX(elFuturePos, elRegion, visibleRect)) {
             fail = 1;    // 对齐位置反下
             // 对齐位置反下
             points = flip(points, /[lr]/gi, {
                 l: 'r',
                 r: 'l'
             });    // 偏移量也反下
             // 偏移量也反下
             offset = flipOffset(offset, 0);
         }    // 如果纵向不能放下
         // 如果纵向不能放下
         if (isFailY(elFuturePos, elRegion, visibleRect)) {
             fail = 1;    // 对齐位置反下
             // 对齐位置反下
             points = flip(points, /[tb]/gi, {
                 t: 'b',
                 b: 't'
             });    // 偏移量也反下
             // 偏移量也反下
             offset = flipOffset(offset, 1);
         }    // 如果失败,重新计算当前节点将要被放置的位置
         // 如果失败,重新计算当前节点将要被放置的位置
         if (fail) {
             elFuturePos = getElFuturePos(elRegion, refNodeRegion, points, offset);
             util.mix(newElRegion, elFuturePos);
         }
         var newOverflowCfg = {};    // 检查反下后的位置是否可以放下了
                                     // 如果仍然放不下只有指定了可以调整当前方向才调整
         // 检查反下后的位置是否可以放下了
         // 如果仍然放不下只有指定了可以调整当前方向才调整
         newOverflowCfg.adjustX = overflow.adjustX && isFailX(elFuturePos, elRegion, visibleRect);
         newOverflowCfg.adjustY = overflow.adjustY && isFailY(elFuturePos, elRegion, visibleRect);    // 确实要调整,甚至可能会调整高度宽度
         // 确实要调整,甚至可能会调整高度宽度
         if (newOverflowCfg.adjustX || newOverflowCfg.adjustY) {
             newElRegion = adjustForViewport(elFuturePos, elRegion, visibleRect, newOverflowCfg);
         }
     }    // https://github.com/kissyteam/kissy/issues/190
          // http://localhost:8888/kissy/src/overlay/demo/other/relative_align/align.html
          // 相对于屏幕位置没变,而 left/top 变了
          // 例如 <div 'relative'><el absolute></div>
     // https://github.com/kissyteam/kissy/issues/190
     // http://localhost:8888/kissy/src/overlay/demo/other/relative_align/align.html
     // 相对于屏幕位置没变,而 left/top 变了
     // 例如 <div 'relative'><el absolute></div>
     self.set({
         x: newElRegion.left,
         y: newElRegion.top
     }, { force: 1 });    // need judge to in case set fixed with in css on height auto element
     // need judge to in case set fixed with in css on height auto element
     if (newElRegion.width !== elRegion.width) {
         self.set('width', el.width() + newElRegion.width - elRegion.width);
     }
     if (newElRegion.height !== elRegion.height) {
         self.set('height', el.height() + newElRegion.height - elRegion.height);
     }
     return self;
 },
        arrayToList: function (listArray, database, baseIndex, paragraphMode) {
            if (!baseIndex) {
                baseIndex = 0;
            }
            if (!listArray || listArray.length < baseIndex + 1) {
                return null;
            }
            var doc = listArray[ baseIndex ].parent[0].ownerDocument,
                retval = doc.createDocumentFragment(),
                rootNode = null,
                i,
                currentIndex = baseIndex,
                indentLevel = Math.max(listArray[ baseIndex ].indent, 0),
                currentListItem = null;
            //,paragraphName = paragraphMode;

            while (true) {
                var item = listArray[ currentIndex ];
                if (item.indent === indentLevel) {
                    if (!rootNode ||
                        //用于替换标签,ul->ol ,ol->ul
                        listArray[ currentIndex ].parent.nodeName() !== rootNode.nodeName()) {
                        rootNode = listArray[ currentIndex ].parent.clone(false);
                        retval.appendChild(rootNode[0]);
                    }
                    currentListItem = rootNode[0].appendChild(item.element.clone(false)[0]);
                    for (i = 0; i < item.contents.length; i++) {
                        currentListItem.appendChild(item.contents[i].clone(true)[0]);
                    }
                    currentIndex++;
                } else if (item.indent === Math.max(indentLevel, 0) + 1) {
                    //进入一个li里面,里面的嵌套li递归构造父亲ul/ol
                    var listData = list.arrayToList(listArray, null,
                        currentIndex, paragraphMode);
                    currentListItem.appendChild(listData.listNode);
                    currentIndex = listData.nextIndex;
                } else if (item.indent === -1 && !baseIndex &&
                    item.grandparent) {

                    if (listNodeNames[ item.grandparent.nodeName() ]) {
                        currentListItem = item.element.clone(false)[0];
                    } else {
                        // Create completely new blocks here, attributes are dropped.
                        //为什么要把属性去掉???#3857
                        if (item.grandparent.nodeName() !== 'td') {
                            currentListItem = doc.createElement(paragraphMode);
                            item.element._4eCopyAttributes($(currentListItem));
                        }
                        else {
                            currentListItem = doc.createDocumentFragment();
                        }
                    }

                    for (i = 0; i < item.contents.length; i++) {
                        var ic = item.contents[i].clone(true);
                        //如果是list中,应该只退出ul,保留margin-left
                        if (currentListItem.nodeType === NodeType.DOCUMENT_FRAGMENT_NODE) {
                            item.element._4eCopyAttributes($(ic));
                        }
                        currentListItem.appendChild(ic[0]);
                    }

                    if (currentListItem.nodeType === NodeType.DOCUMENT_FRAGMENT_NODE && currentIndex !== listArray.length - 1) {
                        if (currentListItem.lastChild &&
                            currentListItem.lastChild.nodeType === Dom.NodeType.ELEMENT_NODE &&
                            currentListItem.lastChild.getAttribute('type') === '_moz') {
                            Dom._4eRemove(currentListItem.lastChild);
                        }
                        Dom._4eAppendBogus(currentListItem);
                    }

                    if (currentListItem.nodeType === Dom.NodeType.ELEMENT_NODE &&
                        Dom.nodeName(currentListItem) === paragraphMode &&
                        currentListItem.firstChild) {
                        Dom._4eTrim(currentListItem);
                        var firstChild = currentListItem.firstChild;
                        if (firstChild.nodeType === Dom.NodeType.ELEMENT_NODE &&
                            Dom._4eIsBlockBoundary(firstChild)) {
                            var tmp = doc.createDocumentFragment();
                            Dom._4eMoveChildren(currentListItem, tmp);
                            currentListItem = tmp;
                        }
                    }

                    var currentListItemName = Dom.nodeName(currentListItem);
                    if (!UA.ie && ( currentListItemName === 'div' ||
                        currentListItemName === 'p' )) {
                        Dom._4eAppendBogus(currentListItem);
                    }
                    retval.appendChild(currentListItem);
                    rootNode = null;
                    currentIndex++;
                }
                else {
                    return null;
                }
                if (listArray.length <= currentIndex ||
                    Math.max(listArray[ currentIndex ].indent, 0) < indentLevel) {
                    break;
                }
            }

            // Clear marker attributes for the new list tree made of cloned nodes, if any.
            if (database) {
                var currentNode = $(retval.firstChild);
                while (currentNode && currentNode[0]) {
                    if (currentNode[0].nodeType === Dom.NodeType.ELEMENT_NODE) {
                        currentNode._4eClearMarkers(database, true);
                    }
                    currentNode = currentNode._4eNextSourceNode();
                }
            }

            return { listNode: retval, nextIndex: currentIndex };
        }
Example #8
0
        it("works in all cases", function () {
            var div = $("<div>" +
                "<b></b>" +
                "<span>1" +
                "<span _ke_bookmark=1 class='bookmark'>x</span>" +
                "2345" +
                "<span _ke_bookmark=1 class='bookmark'>y</span>" +
                "6</span>" +
                "</div>");
            div.appendTo('body');

            var span = div.first("span");

            var b = div.first("b");


            var range = new Range(document);
            range.setStartBefore(div);
            range.setEndAfter(div);

            range.shrink(SHRINK_ELEMENT);

            expect(range.startContainer[0]).toBe(div[0]);
            expect(range.endContainer[0]).toBe(div[0]);
            expect(range.startOffset).toBe(0);
            expect(range.endOffset).toBe(2);

            range.setStartBefore(div);
            range.setEndAfter(div);

            range.shrink(SHRINK_ELEMENT, 1);

            expect(range.startContainer[0]).toBe(b[0]);
            expect(range.endContainer[0]).toBe(span[0]);
            expect(range.startOffset).toBe(0);
            expect(range.endOffset).toBe(span[0].childNodes.length);


            var textStart = $(span[0].firstChild),
                textEnd = $(span[0].lastChild);

            range.setStartBefore(div);
            range.setEndAfter(div);

            range.shrink(SHRINK_TEXT);

            expect(range.startContainer[0]).toBe(document.body);
            expect(range.endContainer[0]).toBe(span[0]);
            expect(range.startOffset).toBe(div._4eIndex());
            expect(range.endOffset).toBe(span[0].childNodes.length);


            range.shrink(SHRINK_TEXT, 1);

            expect(range.startContainer[0]).toBe(document.body);
            expect(range.endContainer[0]).toBe(textEnd[0]);
            expect(range.startOffset).toBe(div._4eIndex());
            expect(range.endOffset).toBe(textEnd[0].nodeValue.length);


            range.setStartAfter(b);
            range.setEndAfter(div);

            range.shrink(SHRINK_TEXT);

            expect(range.startContainer[0]).toBe(span[0]);
            expect(range.endContainer[0]).toBe(span[0]);
            expect(range.startOffset).toBe(0);
            expect(range.endOffset).toBe(span[0].childNodes.length);


            range.shrink(SHRINK_TEXT, 1);

            expect(range.startContainer[0]).toBe(textStart[0]);
            expect(range.endContainer[0]).toBe(textEnd[0]);
            expect(range.startOffset).toBe(0);
            expect(range.endOffset).toBe(textEnd[0].nodeValue.length);

            div.remove();
        });
Example #9
0
        it("works for complex text node", function () {

            // d
            //    a
            //    span
            //           b
            //           span-start
            //                 123456789
            //           c
            //    d
            //    span
            //           e
            //           span-end
            //                 123456789
            //           f
            //    g

            var div = $("<div>" +
                "a" +
                "<span>" +
                "b" +
                "<span id=\"start\">" +
                "123456789" +
                "</span>" +
                "c" +
                "</span>" +
                "d" +
                "<span id=\"marker\">" +
                "e" +
                "<span id=\"end\">" +
                "123456789" +
                "</span>" +
                "f" +
                "</span>" +
                "g</div>").appendTo('body', undefined);

            var range = new Range(document);
            var textStart = $($("#start")[0].firstChild);
            var textEnd = $($("#end")[0].firstChild);
            range.setStart(textStart, 2);
            range.setEnd(textEnd, 5);

            var f = range.deleteContents();

            expect(f).toBeUndefined();

            var ret = "a" +
                "<span>" +
                "b" +
                "<span id=\"start\">" +
                "12" +
                "</span>" +
                "</span>" +
                "<span id=\"marker\">" +
                "<span id=\"end\">" +
                "6789" +
                "</span>" +
                "f" +
                "</span>" +
                "g";

            expect(myHTML(div)).toBe(ret);


            expect(range.startContainer[0]).toBe(div[0]);
            expect(range.collapsed).toBe(true);
            expect(range.startOffset).toBe(2);

            div.remove();

        });
Example #10
0
            it('works for touch events', function () {
                var d = $('<div style="position:absolute;left:0;top:0;width: 100px;height: 100px"></div>');
                d.appendTo(document.body);
                var start = 0;
                var move = 0;
                var end = 0;

                d.on(PanGesture.PAN_START, function (e) {
                    expect(e.gestureType).toBe('touch');
                    start = 1;
                    expect(e.pageX).toBe(14);
                    expect(e.pageY).toBe(14);
                    e.preventDefault();
                });

                d.on(PanGesture.PAN, function (e) {
                    expect(e.gestureType).toBe('touch');
                    move = 1;
                    expect(e.pageX).toBe(16);
                    expect(e.pageY).toBe(16);
                    e.preventDefault();
                });

                d.on(PanGesture.PAN_END, function (e) {
                    expect(e.gestureType).toBe('touch');
                    end = 1;
                    expect(e.pageX).toBe(16);
                    expect(e.pageY).toBe(16);
                    expect(e.velocityX).not.toBe(0);
                    expect(e.velocityY).not.toBe(0);
                });
                runs(function () {
                    jasmine.simulate(d[0], 'touchstart', {
                        touches: [
                            {
                                pageX: 10,
                                pageY: 10
                            }
                        ],
                        changedTouches: [
                            {
                                pageX: 10,
                                pageY: 10
                            }
                        ],
                        targetTouches: [
                            {
                                pageX: 10,
                                pageY: 10
                            }
                        ]
                    });
                });

                waits(30);
                runs(function () {
                    jasmine.simulate(d[0], 'touchmove', {
                        touches: [
                            {
                                pageX: 11,
                                pageY: 11
                            }
                        ],
                        changedTouches: [
                            {
                                pageX: 11,
                                pageY: 11
                            }
                        ],
                        targetTouches: [
                            {
                                pageX: 11,
                                pageY: 11
                            }
                        ]
                    });
                });

                waits(30);
                runs(function () {
                    jasmine.simulate(d[0], 'touchmove', {
                        touches: [
                            {
                                pageX: 14,
                                pageY: 14
                            }
                        ],
                        changedTouches: [
                            {
                                pageX: 14,
                                pageY: 14
                            }
                        ],
                        targetTouches: [
                            {
                                pageX: 14,
                                pageY: 14
                            }
                        ]
                    });
                });

                waits(100);
                runs(function () {
                    jasmine.simulate(d[0], 'touchmove', {
                        touches: [
                            {
                                pageX: 16,
                                pageY: 16
                            }
                        ],
                        changedTouches: [
                            {
                                pageX: 16,
                                pageY: 16
                            }
                        ],
                        targetTouches: [
                            {
                                pageX: 16,
                                pageY: 16
                            }
                        ]
                    });
                });

                waits(300);
                runs(function () {
                    jasmine.simulate(d[0], 'touchend', {
                        touches: [
                            {
                                pageX: 26,
                                pageY: 26
                            }
                        ],
                        changedTouches: [
                            {
                                pageX: 26,
                                pageY: 26
                            }
                        ],
                        targetTouches: [
                            {
                                pageX: 26,
                                pageY: 26
                            }
                        ]
                    });
                });

                waits(300);
                runs(function () {
                    expect(start).toBe(1);
                    expect(move).toBe(1);
                    expect(end).toBe(1);
                    d.remove();
                });
            });
Example #11
0
            it('works for mouse', function () {
                var d = $('<div style="position:absolute;left:0;top:0;width: 100px;height: 100px"></div>');
                d.appendTo(document.body);
                var start = 0;
                var move = 0;
                var end = 0;

                d.on(PanGesture.PAN_START, function (e) {
                    expect(e.gestureType||'mouse').toBe('mouse');
                    start = 1;
                    expect(e.pageX).toBe(14);
                    expect(e.pageY).toBe(14);
                    e.preventDefault();
                });

                d.on(PanGesture.PAN, function (e) {
                    expect(e.gestureType||'mouse').toBe('mouse');
                    move = 1;
                    expect(e.pageX).toBe(16);
                    expect(e.pageY).toBe(16);
                    e.preventDefault();
                });

                d.on(PanGesture.PAN_END, function (e) {
                    expect(e.gestureType||'mouse').toBe('mouse');
                    end = 1;
                    expect(e.pageX).toBe(16);
                    expect(e.pageY).toBe(16);
                    expect(e.velocityX).not.toBe(0);
                    expect(e.velocityY).not.toBe(0);
                });

                runs(function () {
                    jasmine.simulate(d[0], 'mousedown', {
                        clientX: 10,
                        clientY: 10
                    });
                });

                waits(30);
                runs(function () {
                    jasmine.simulate(document, 'mousemove', {
                        clientX: 11,
                        clientY: 11
                    });
                });

                waits(30);
                runs(function () {
                    // 3px distance
                    jasmine.simulate(document, 'mousemove', {
                        clientX: 14,
                        clientY: 14
                    });
                });

                waits(10);
                runs(function () {
                    jasmine.simulate(document, 'mousemove', {
                        clientX: 16,
                        clientY: 16
                    });
                });


                waits(30);
                runs(function () {
                    jasmine.simulate(document, 'mouseup', {
                        clientX: 26,
                        clientY: 26
                    });
                });

                waits(300);
                runs(function () {
                    expect(start).toBe(1);
                    expect(move).toBe(1);
                    expect(end).toBe(1);
                    d.remove();
                });
            });
Example #12
0
 valueFn: function () {
     return $(WIN);
 },
Example #13
0
KISSY.add('kg/editor-plugins/1.1.0/table',["editor","./dialog-loader","./contextmenu","./button","util","ua","dom","node"],function(S ,require, exports, module) {function e(e){function t(e){o.length>0||e[0].nodeType===b.NodeType.ELEMENT_NODE&&C.test(e.nodeName())&&!e.data("selected_cell")&&(e._4eSetMarker(a,"selected_cell",!0,void 0),o.push(e))}for(var n=e.createBookmarks(),r=e.getRanges(),o=[],a={},l=0;l<r.length;l++){var i=r[l];if(i.collapsed){var d=i.getCommonAncestor(),s=d.closest("td",void 0)||d.closest("th",void 0);s&&o.push(s)}else{var c,v=new f(i);for(v.guard=t;c=v.next();){var h=c.parent();h&&C.test(h.nodeName())&&!h.data("selected_cell")&&(h._4eSetMarker(a,"selected_cell",!0,void 0),o.push(h))}}}return u.Utils.clearAllMarkers(a),e.selectBookmarks(n),o}function t(e){for(var t=e.cells,n=0;n<t.length;n++)t[n].innerHTML="",S||p(t[n])._4eAppendBogus(void 0)}function n(e,n){var r=e.getStartElement().parent("tr");if(r){var o=r.clone(!0);o.insertBefore(r),t(n?o[0]:r[0])}}function r(t){var n;if(t instanceof u.Selection){for(var o,a,l,i,d=e(t),s=d.length,c=[],v=0;s>v;v++){l=d[v].parent();var f=l[0].rowIndex;v||(a=f-1),c[f]=l,v===s-1&&(i=f+1)}n=l.parent("table");var h=n[0].rows,m=h.length;for(o=p(m>i&&n[0].rows[i]||a>0&&n[0].rows[a]||n[0].parentNode),v=c.length;v>=0;v--)c[v]&&r(c[v]);return o}return t instanceof p&&(n=t.parent("table"),1===n[0].rows.length?n.remove():t.remove()),0}function o(e,t){var n=e.getStartElement(),r=n.closest("td",void 0)||n.closest("th",void 0);if(r)for(var o=r.parent("table"),a=r[0].cellIndex,l=0;l<o[0].rows.length;l++){var i=o[0].rows[l];if(!(i.cells.length<a+1)){r=p(i.cells[a].cloneNode(void 0)),S||r._4eAppendBogus(void 0);var d=p(i.cells[a]);t?r.insertBefore(d):r.insertAfter(d)}}}function a(e){var t,n,r,o,a=[],l=e[0]&&e[0].parent("table");for(t=0,n=e.length;n>t;t++)a.push(e[t][0].cellIndex);for(a.sort(),t=1,n=a.length;n>t;t++)if(a[t]-a[t-1]>1){r=a[t-1]+1;break}r||(r=a[0]>0?a[0]-1:a[a.length-1]+1);var i=l[0].rows;for(t=0,n=i.length;n>t&&!(o=i[t].cells[r]);t++);return o?p(o):l.prev()}function l(t){var n;if(t instanceof u.Selection){var o=e(t),i=a(o);for(n=o.length-1;n>=0;n--)o[n]&&l(o[n]);return i}if(t instanceof p){var d=t.parent("table");if(!d)return null;var s=t[0].cellIndex;for(n=d[0].rows.length-1;n>=0;n--){var c=p(d[0].rows[n]);s||1!==c[0].cells.length?c[0].cells[s]&&c[0].removeChild(c[0].cells[s]):r(c)}}return null}function i(e,t){var n=new u.Range(e[0].ownerDocument);n.moveToElementEditablePosition(e,t?!0:void 0)||(n.selectNodeContents(e),n.collapse(t?!1:!0)),n.select(!0)}function d(e){var t=e.getSelection(),n=t&&t.getStartElement(),r=n&&n.closest("table",void 0);if(!r)return void 0;var o=n.closest(function(e){var t=b.nodeName(e);return r.contains(e)&&("td"===t||"th"===t)},void 0),a=n.closest(function(e){var t=b.nodeName(e);return r.contains(e)&&"tr"===t},void 0);return{table:r,td:o,tr:a}}function s(e){var t=d(e);return t&&t.td}function c(e){var t=d(e);return t&&t.tr}function v(e){this.config=e||{}}var u=require("editor"),f=u.Walker,h=require("./dialog-loader");require("./contextmenu"),require("./button");var m=require("util"),g=require("ua"),b=require("dom"),p=require("node"),x=["tr","th","td","tbody","table"],C=/^(?:td|th)$/,S=g.ieMode<11,w={"表格属性":d,"删除表格":s,"删除列":s,"删除行":c,"在上方插入行":c,"在下方插入行":c,"在左侧插入列":s,"在右侧插入列":s},N="ke_show_border",k=(6===g.ie?["table.%2,","table.%2 td, table.%2 th,","{","border : #d3d3d3 1px dotted","}"]:[" table.%2,"," table.%2 > tr > td,  table.%2 > tr > th,"," table.%2 > tbody > tr > td,  table.%2 > tbody > tr > th,"," table.%2 > thead > tr > td,  table.%2 > thead > tr > th,"," table.%2 > tfoot > tr > td,  table.%2 > tfoot > tr > th","{","border : #d3d3d3 1px dotted","}"]).join(""),A=k.replace(/%2/g,N),E={tags:{table:function(e){var t=e.getAttribute("class"),n=parseInt(e.getAttribute("border"),10);(!n||0>=n)&&e.setAttribute("class",m.trim((t||"")+" "+N))}}},_={tags:{table:function(e){var t,n=e.getAttribute("class");n&&(t=m.trim(n.replace(N,"")),t?e.setAttribute("class",t):e.removeAttribute("class"))}}};m.augment(v,{pluginRenderUI:function(e){e.addCustomStyle(A);var t=e.htmlDataProcessor,a=t&&t.dataFilter,s=t&&t.htmlFilter;a.addRules(E),s.addRules(_);var c=this,v={"表格属性":function(){this.hide();var t=d(e);t&&h.useDialog(e,"table",c.config,{selectedTable:t.table,selectedTd:t.td})},"删除表格":function(){this.hide();var t=e.getSelection(),n=t&&t.getStartElement(),r=n&&n.closest("table",void 0);if(r){e.execCommand("save"),t.selectElement(r);var o=t.getRanges()[0];o.collapse(),t.selectRanges([o]);var a=r.parent();1===a[0].childNodes.length&&"body"!==a.nodeName()&&"td"!==a.nodeName()?a.remove():r.remove(),e.execCommand("save")}},"删除行 ":function(){this.hide(),e.execCommand("save");var t=e.getSelection();i(r(t),void 0),e.execCommand("save")},"删除列 ":function(){this.hide(),e.execCommand("save");var t=e.getSelection(),n=l(t);n&&i(n,!0),e.execCommand("save")},"在上方插入行":function(){this.hide(),e.execCommand("save");var t=e.getSelection();n(t,!0),e.execCommand("save")},"在下方插入行":function(){this.hide(),e.execCommand("save");var t=e.getSelection();n(t,void 0),e.execCommand("save")},"在左侧插入列":function(){this.hide(),e.execCommand("save");var t=e.getSelection();o(t,!0),e.execCommand("save")},"在右侧插入列":function(){this.hide(),e.execCommand("save");var t=e.getSelection();o(t,void 0),e.execCommand("save")}},f=[];m.each(v,function(e,t){f.push({content:t})}),e.addContextMenu("table",function(e){return m.inArray(b.nodeName(e),x)?!0:void 0},{width:"120px",children:f,listeners:{click:function(e){var t=e.target.get("content");v[t]&&v[t].apply(this)},beforeVisibleChange:function(e){if(e.newVal){var t=this,n=t.get("children"),r=t.get("editor");m.each(n,function(e){var n=e.get("content");!w[n]||w[n].call(t,r)?e.set("disabled",!1):e.set("disabled",!0)})}}}}),e.addButton("table",{mode:u.Mode.WYSIWYG_MODE,listeners:{click:function(){h.useDialog(e,"table",c.config,{selectedTable:0,selectedTd:0})}},tooltip:"插入表格"})}}),module.exports=v;});
Example #14
0
KISSY.add('editor-plugins/lib/draft',["editor","json","event/dom","./local-storage","overlay","./menubutton","util","node"],function(S ,require, exports, module) {function e(e,t,n){for(e+="";e.length<t;)e=n+e;return e}function t(t){return"number"==typeof t&&(t=new Date(t)),t instanceof Date?[t.getFullYear(),"-",e(t.getMonth()+1,2,"0"),"-",e(t.getDate(),2,"0")," ",e(t.getHours(),2,"0"),":",e(t.getMinutes(),2,"0"),":",e(t.getSeconds(),2,"0")].join(""):t}function n(e,t){this.editor=e,this.config=t,this._init()}function r(e,t){var r=new n(e,t);e.on("destroy",function(){r.destroy()})}function a(e){this.config=e||{}}var i=require("editor"),o=require("json"),l=require("event/dom"),s=require("./local-storage"),d=require("overlay"),f=require("./menubutton"),p=require("util"),c=require("node"),u=5,h=5,v="ks-editor-draft-save20110503",g=i.Utils.addRes,m=i.Utils.destroyRes;p.augment(n,{_getSaveKey:function(){var e=this,t=e.config;return t.draft&&t.draft.saveKey||v},_getDrafts:function(){var e=this;if(!e.drafts){var t=s.getItem(e._getSaveKey()),n=[];t&&(n=s===window.localStorage?o.parse(p.urlDecode(t)):t),e.drafts=n}return e.drafts},_init:function(){var e=this,t=e.editor,n=t.get("prefixCls"),r=t.get("statusBarEl"),a=this.config;a.draft=a.draft||{},e.draftInterval=a.draft.interval=a.draft.interval||h,e.draftLimit=a.draft.limit=a.draft.limit||u;var o=c('<div class="'+n+'editor-draft"><span class="'+n+'editor-draft-title">内容正文每'+a.draft.interval+"分钟自动保存一次。</span></div>").appendTo(r);e.timeTip=c('<span class="'+n+'editor-draft-time"/>').appendTo(o);var s=c(p.substitute('<a href="#" onclick="return false;" class="{prefixCls}editor-button {prefixCls}editor-draft-save-btn ks-inline-block" style="vertical-align:middle;padding:1px 9px;"><span class="{prefixCls}editor-draft-save"></span><span>立即保存</span></a>',{prefixCls:n})).unselectable(void 0).appendTo(o),d=new f({render:o,collapseOnClick:!0,width:"100px",prefixCls:n+"editor-",menu:{width:"225px",align:{points:["tr","br"]}},matchElWidth:!1,content:"恢复编辑历史"}).render();e.versions=d,d.on("beforeCollapsedChange",function b(t){t.newValue||(d.detach("beforeCollapsedChange",b),e.sync())}),s.on("click",function(t){e.save(!1),t.halt()}),g.call(e,s),t.get("textarea")[0].form&&!function(){function n(){e.save(!0)}var r=t.get("textarea"),a=r[0].form;l.on(a,"submit",n),g.call(e,function(){l.remove(a,"submit",n)})}();var v=setInterval(function(){e.save(!0)},60*e.draftInterval*1e3);if(g.call(e,function(){clearInterval(v)}),d.on("click",e.recover,e),g.call(e,d),e.holder=o,a.draft.helpHTML){var m=c('<a tabindex="0" hidefocus="hidefocus" class="'+n+'editor-draft-help" title="点击查看帮助" href="javascript:void(\'点击查看帮助 \')">点击查看帮助</a>').unselectable(void 0).appendTo(o);m.on("click",function(){m[0].focus(),e.helpPopup&&e.helpPopup.get("visible")?e.helpPopup.hide():e._prepareHelp()}),m.on("blur",function(){e.helpPopup&&e.helpPopup.hide()}),e.helpBtn=m,g.call(e,m),i.Utils.lazyRun(e,"_prepareHelp","_realHelp")}g.call(e,o)},_prepareHelp:function(){var e=this,t=e.editor,n=t.get("prefixCls"),r=e.config,a=r.draft,o=c(a.helpHTML||""),l="height:0;position:absolute;font-size:0;width:0;border:8px #000 solid;border-color:#000 transparent transparent transparent;border-style:solid dashed dashed dashed;",s=c('<div style="'+l+'border-top-color:#CED5E0;"><div style="'+l+'left:-8px;top:-10px;border-top-color:white;"></div></div>');o.append(s),o.css({border:"1px solid #ACB4BE","text-align":"left"}),e.helpPopup=new d({content:o,prefixCls:n+"editor-",width:o.width()+"px",zIndex:i.baseZIndex(i.ZIndexManager.OVERLAY),mask:!1}).render(),e.helpPopup.get("el").css("border","none"),e.helpPopup.arrow=s},_realHelp:function(){var e=this.helpPopup,t=this.helpBtn,n=e.arrow;e.show();var r=t.offset();e.get("el").offset({left:r.left-e.get("el").width()+17,top:r.top-e.get("el").height()-7}),n.offset({left:r.left-2,top:r.top-8})},disable:function(){this.holder.css("visibility","hidden")},enable:function(){this.holder.css("visibility","")},sync:function(){var e,n,r,a=this,i=a.draftLimit,l=a.timeTip,d=a.versions,f=a._getDrafts();for(f.length>i&&f.splice(0,f.length-i),d.removeItems(!0),e=0;e<f.length;e++)n=f[e],r=(n.auto?"自动":"手动")+"保存于 : "+t(n.date),d.addItem({content:r,value:e});f.length||d.addItem({disabled:!0,content:"尚无历史",value:""}),l.html(r),s.setItem(a._getSaveKey(),s===window.localStorage?encodeURIComponent(o.stringify(f)):f)},save:function(e){var t=this,n=t._getDrafts(),r=t.editor,a=r.getFormatData();a&&(n[n.length-1]&&a===n[n.length-1].content&&(n.length-=1),t.drafts=n.concat({content:a,date:(new Date).getTime(),auto:e}),t.sync())},recover:function(e){var n=this,r=n.editor,a=n._getDrafts(),i=e.target.get("value");window.confirm("确认恢复 "+t(a[i].date)+" 的编辑历史?")&&(r.execCommand("save"),r.setData(a[i].content),r.execCommand("save")),e.halt()},destroy:function(){m.call(this)}}),p.augment(a,{pluginRenderUI:function(e){var t=this.config;s.ready?s.ready(function(){r(e,t)}):r(e,t)}}),module.exports=a;});
Example #15
0
 function checkLink(lastElement) {
     lastElement = $(lastElement);
     return lastElement.closest('a', undefined);
 }
Example #16
0
 it("slice works", function () {
     expect($('body').slice(0 - 1)[0]).toBe(document.body);
     expect($(".context-test-3").slice(0 - 2).length).toBe(2);
     expect($(".context-test-3").slice(0 - 2, -1).length).toBe(1);
 });
Example #17
0
        it("works for complex node", function () {

            // d
            //    a
            //    span
            //           b
            //           span-start
            //                 123456789
            //           c
            //    d
            //    span
            //           e
            //           span-end
            //                 123456789
            //           f
            //    g


            var div = $("<div>" +
                "a" +
                "<span>" +
                "b" +
                "<span id=\"start\">" +
                "123456789" +
                "</span>" +
                "c" +
                "</span>" +
                "d" +
                "<span>" +
                "e" +
                "<span id=\"end\">" +
                "123456789" +
                "</span>" +
                "f" +
                "</span>" +
                "g</div>").appendTo('body', undefined);


            var range = new Range(document);
            var textStart = $("#start");
            var textEnd = $("#end");


            range.setStartBefore(textStart);
            range.setEndAfter(textEnd);

            var f = range.extractContents();

            var newDiv = $("<div>").appendTo('body');

            newDiv.append(f);

            expect(myHTML(newDiv)).toBe("<span>" +
                "<span id=\"start\">" +
                "123456789" +
                "</span>" +
                "c" +
                "</span>" +
                "d" +
                "<span>" +
                "e" +
                "<span id=\"end\">" +
                "123456789" +
                "</span>" +
                "</span>");


            expect(myHTML(div)).toBe("a<span>b</span><span>f</span>g");

            expect(range.collapsed).toBe(true);
            expect(range.startContainer[0]).toBe(div[0]);
            expect(range.startOffset).toBe(2);

            div.remove();

            newDiv.remove();

        });
KISSY.add('editor-plugins/lib/word-filter',["html-parser","util","node","ua"],function(S ,require, exports, module) {function e(e){e=e.toUpperCase();for(var t=w.length,i=0,r=0;t>r;++r)for(var n=w[r],l=n[1].length;e.substr(0,l)===n[1];e=e.substr(l))i+=n[0];return i}function t(e){e=e.toUpperCase();for(var t=x.length,i=1,r=1;e.length>0;r*=t)i+=x.indexOf(e.charAt(e.length-1))*r,e=e.substr(0,e.length-1);return i}function i(e,t){t?e.setAttribute("style",t):e.removeAttribute("style")}function r(e){var t=e.childNodes||[],i=t.length,r=1===i&&t[0];return r||null}function n(e,t){for(var i,r=e.childNodes||[],l=[],a=0;a<r.length;a++)i=r[a],i.nodeName&&(i.nodeName===t&&(l.push(i),r.splice(a--,1)),l=l.concat(n(i,t)));return l}function l(e,t){for(var i=e.parentNode;i&&(!i.nodeName||!i.nodeName.match(t));)i=i.parentNode;return i}function a(e,t){var i,r,n=e.childNodes||[];for(r=0;r<n.length;r++){if(i=n[r],t(i))return i;if(i.nodeName&&(i=a(i,t)))return i}return null}function s(e,t,r,n){var l,a,s="";if("string"==typeof r)s+=t+":"+r+";";else{if("object"==typeof t)for(a in t)s+=a+":"+t[a]+";";else s+=t;n=r}l=e.getAttribute("style"),l=(n?[s,l]:[l,s]).join(";"),i(e,l.replace(/^;|;(?=;)/,""))}function o(e){var t,i={};for(t in p)-1===t.indexOf("$")&&p[t][e]&&(i[t]=1);return i}function u(e){var t,r,n,l=e.childNodes||[],a=l.length,o=/list-style-type:(.*?)(?:;|$)/,u=S.stylesFilter;if(!o.exec(e.getAttribute("style"))){for(var c=0;a>c;c++)if(t=l[c],t.getAttribute("value")&&Number(t.getAttribute("value"))===c+1&&t.removeAttribute("value"),r=o.exec(t.getAttribute("style"))){if(r[1]!==n&&n){n=null;break}n=r[1]}if(n){for(c=0;a>c;c++){var f=l[c].getAttribute("style");f&&(f=u([["list-style-type"]])(f),i(l[c],f))}s(e,"list-style-type",n)}}}var c,f=require("html-parser"),d=require("util"),m=require("node"),g=require("ua"),p=f.DTD,h=new f.Filter,b=/^([.\d]*)+(em|ex|px|gd|rem|vw|vh|vm|ch|mm|cm|in|pt|pc|deg|rad|ms|s|hz|khz){1}?/i,v=/^(?:\b0[^\s]*\s*){1,4}$/,y="^m{0,4}(cm|cd|d?c{0,3})(xc|xl|l?x{0,3})(ix|iv|v?i{0,3})$",A=new RegExp(y),N=new RegExp(y.toUpperCase()),k={decimal:/\d+/,"lower-roman":A,"upper-roman":N,"lower-alpha":/^[a-z]+$/,"upper-alpha":/^[A-Z]+$/},$={disc:/[l\u00B7\u2002]/,circle:/[\u006F\u00D8]/,square:/[\u006E\u25C6]/},C={ol:k,ul:$},w=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],x="ABCDEFGHIJKLMNOPQRSTUVWXYZ",T=function(){var e;return function(t){return e||(e=m('<div style="position:absolute;left:-9999px;top:-9999px;margin:0px;padding:0px;border:0px;"></div>').prependTo("body")),/%$/.test(t)?t:(e.css("width",t),e[0].clientWidth)}}(),L=0,F=null,S={flattenList:function(e,t){t="number"==typeof t?t:1;var i;switch(e.getAttribute("type")){case"a":i="lower-alpha";break;case"1":i="decimal"}for(var r,n=e.childNodes||[],l=0;l<n.length;l++)if(r=n[l],r.nodeName in p.$listItem){var a=r.childNodes||[],s=a.length,o=a[s-1];o.nodeName in p.$list&&(e.insertAfter(r),--a.length||e.removeChild(n[l--])),r.setTagName("ke:li"),e.getAttribute("start")&&!l&&e.setAttribute("value",e.getAttribute("start")),S.stylesFilter([["tab-stops",null,function(e){var t=e.split(" ")[1].match(b);t&&(F=T(t[0]))}],1===t?["mso-list",null,function(e){e=e.split(" ");var t=Number(e[0].match(/\d+/));t!==c&&r.setAttribute("ke:reset",1),c=t}]:null])(r.getAttribute("style")),r.setAttribute("ke:indent",t),r.setAttribute("ke:listtype",e.nodeName),r.setAttribute("ke:list-style-type",i)}else if(r.nodeName in p.$list){arguments.callee.apply(this,[r,t+1]),n=n.slice(0,l).concat(r.childNodes).concat(n.slice(l+1)),e.empty();for(var u=0,f=n.length;f>u;u++)e.appendChild(n[u])}e.nodeName=e.tagName=null,e.setAttribute("ke:list",1)},assembleList:function(i){for(var r,n,l,a,o,c,m,g,p,h,b,v,y=i.childNodes||[],A=[],N=0;N<y.length;N++)if(r=y[N],"ke:li"===r.nodeName){if(r.setTagName("li"),n=r,p=n.getAttribute("ke:listsymbol"),p=p&&p.match(/^(?:[(]?)([^\s]+?)([.)]?)$/),h=b=v=null,n.getAttribute("ke:ignored")){y.splice(N--,1);continue}if(n.getAttribute("ke:reset")&&(c=a=o=null),l=Number(n.getAttribute("ke:indent")),l!==a&&(g=m=null),p){if(g&&C[g][m].test(p[1]))h=g,b=m;else for(var k in C)for(var $ in C[k])if(C[k][$].test(p[1])){if("ol"!==k||!/alpha|roman/.test($)){h=k,b=$;break}var w=/roman/.test($)?e(p[1]):t(p[1]);(!v||v>w)&&(v=w,h=k,b=$)}h||(h=p[2]?"ol":"ul")}else h=n.getAttribute("ke:listtype")||"ol",b=n.getAttribute("ke:list-style-type");if(g=h,m=b||("ol"===h?"decimal":"disc"),b&&b!==("ol"===h?"decimal":"disc")&&s(n,"list-style-type",b),"ol"===h&&p){switch(b){case"decimal":v=Number(p[1]);break;case"lower-roman":case"upper-roman":v=e(p[1]);break;case"lower-alpha":case"upper-alpha":v=t(p[1])}n.setAttribute("value",v)}if(c){if(l>a)A.push(c=new f.Tag(h)),c.appendChild(n),o.appendChild(c);else if(a>l){for(var x,T=a-l;T--&&(x=c.parentNode);)c=x.parentNode;c.appendChild(n)}else c.appendChild(n);y.splice(N--,1)}else A.push(c=new f.Tag(h)),c.appendChild(n),i.replaceChild(c,y[N]);o=n,a=l}else c&&(3!==r.nodeType||d.trim(r.nodeValue))&&(c=a=o=null);for(N=0;N<A.length;N++)u(A[N])},falsyFilter:function(){return!1},stylesFilter:function(e,t){return function(i,r){var n=[];(i||"").replace(/&quot;/g,'"').replace(/\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g,function(i,l,a){l=l.toLowerCase(),"font-family"===l&&(a=a.replace(/['']/g,""));for(var s,o,u,c,f=0;f<e.length;f++)if(e[f]&&(s=e[f][0],o=e[f][1],u=e[f][2],c=e[f][3],l.match(s)&&(!o||a.match(o))))return l=c||l,t&&(u=u||a),"function"==typeof u&&(u=u(a,r,l)),u&&u.push&&(l=u[0],u=u[1]),void("string"==typeof u&&n.push([l,u]));t||n.push([l,a])});for(var l=0;l<n.length;l++)n[l]=n[l].join(":");return n.length?n.join(";")+";":!1}},applyStyleFilter:null},D={createListBulletMarker:function(e,t){var i=new f.Tag("ke:listbullet");return i.setAttribute("ke:listsymbol",e[0]),i.appendChild(new f.Text(t)),i},isListBulletIndicator:function(e){var t=e.getAttribute("style");return/mso-list\s*:\s*Ignore/i.test(t)?!0:void 0},isContainingOnlySpaces:function(e){var t;return(t=r(e))&&/^(:?\s|&nbsp;)+$/.test(t.nodeValue)},resolveList:function(e){var t;if((t=n(e,"ke:listbullet"))&&t.length&&(t=t[0])){if(e.setTagName("ke:li"),e.getAttribute("style")){var r=S.stylesFilter([["text-indent"],["line-height"],[/^margin(:?-left)?$/,null,function(t){var i=t.split(" ");t=T(i[3]||i[1]||i[0]),!L&&null!==F&&t>F&&(L=t-F),F=t,L&&e.setAttribute("ke:indent",L&&Math.ceil(t/L)+1||1)}],[/^mso-list$/,null,function(t){t=t.split(" ");var i=Number(t[0].match(/\d+/)),r=Number(t[1].match(/\d+/));1===r&&(i!==c&&e.setAttribute("ke:reset",1),c=i),e.setAttribute("ke:indent",r)}]])(e.getAttribute("style"),e);i(e,r)}return e.getAttribute("ke:indent")||(F=0,e.setAttribute("ke:indent",1)),d.each(t.attributes,function(t){e.setAttribute(t.name,t.value)}),!0}return c=F=L=null,!1},getStyleComponents:function(){var e=m('<div style="position:absolute;left:-9999px;top:-9999px;"></div>').prependTo("body");return function(t,i,r){e.css(t,i);for(var n={},l=r.length,a=0;l>a;a++)n[r[a]]=e.css(r[a]);return n}}(),listDtdParents:o("ol")};!function(){var e=d.merge(p.$block,p.$listItem,p.$tableContent),t=S.falsyFilter,n=S.stylesFilter,o=D.createListBulletMarker,u=S.flattenList,c=S.assembleList,m=D.isListBulletIndicator,b=D.isContainingOnlySpaces,y=D.resolveList,A=function(e){return e=T(e),isNaN(e)?e:e+"px"},N=D.getStyleComponents,k=D.listDtdParents;h.addRules({tagNames:[[/meta|link|script/,""]],root:function(e){e.filterChildren(),c(e)},tags:{"^":function(e){var t;g.gecko&&(t=S.applyStyleFilter)&&t(e)},$:function(t){var r=t.nodeName||"";if(r in e&&t.getAttribute("style")&&i(t,n([[/^(:?width|height)$/,null,A]])(t.getAttribute("style"))),r.match(/h\d/)){if(t.filterChildren(),y(t))return}else if(r in p.$inline)t.filterChildren(),b(t)&&t.setTagName(null);else if(-1!==r.indexOf(":")&&-1===r.indexOf("ke")){if(t.filterChildren(),"v:imagedata"===r){var l=t.getAttribute("o:href");return l&&t.setAttribute("src",l),void t.setTagName("img")}t.setTagName(null)}r in k&&(t.filterChildren(),c(t))},style:function(e){if(g.gecko){var t=r(e).nodeValue.match(/\/\* Style Definitions \*\/([\s\S]*?)\/\*/),i=t&&t[1],n={};i&&(i.replace(/[\n\r]/g,"").replace(/(.+?)\{(.+?)\}/g,function(e,t,i){t=t.split(",");for(var r=t.length,l=0;r>l;l++)d.trim(t[l]).replace(/^(\w+)(\.[\w-]+)?$/g,function(e,t,r){t=t||"*",r=r.substring(1,r.length),r.match(/MsoNormal/)||(n[t]||(n[t]={}),r?n[t][r]=i:n[t]=i)})}),S.applyStyleFilter=function(e){var t,i=n["*"]?"*":e.nodeName,r=e.getAttribute("class");i in n&&(t=n[i],"object"==typeof t&&(t=t[r]),t&&s(e,t,!0))})}return!1},p:function(e){if(/MsoListParagraph/.exec(e.getAttribute("class"))){var t=a(e,function(e){return 3===e.nodeType&&!b(e.parentNode)}),i=t&&t.parentNode;i&&!i.getAttribute("style")&&i.setAttribute("style","mso-list: Ignore;")}e.filterChildren(),y(e)},div:function(e){var t=r(e);if(t&&"table"===t.nodeName){var i=e.attributes;d.each(i,function(e){t.setAttribute(e.name,e.value)}),e.getAttribute("style")&&s(t,e.getAttribute("style"));var n=new f.Tag("div");s(n,"clear","both"),e.appendChild(n),e.setTagName(null)}},td:function(e){l(e,"thead")&&e.setTagName("th")},ol:u,ul:u,dl:u,font:function(e){if(m(e.parentNode))return void e.setTagName(null);e.filterChildren();var t=e.getAttribute("style"),i=e.parentNode;if("font"===i.name)d.each(e.attributes,function(e){i.setAttribute(e.name,e.value)}),t&&s(i,t),e.setTagName(null);else{t=t||"",e.getAttribute("color")&&("#000000"!==e.getAttribute("color")&&(t+="color:"+e.getAttribute("color")+";"),e.removeAttribute("color")),e.getAttribute("face")&&(t+="font-family:"+e.getAttribute("face")+";",e.removeAttribute("face"));var r=e.getAttribute("size");r&&(t+="font-size:"+(r>3?"large":3>r?"small":"medium")+";",e.removeAttribute("size")),e.setTagName("span"),s(e,t)}},span:function(e){if(m(e.parentNode))return!1;if(e.filterChildren(),b(e))return e.setTagName(null),null;if(m(e)){var t=a(e,function(e){return e.nodeValue||"img"===e.nodeName}),r=t&&(t.nodeValue||"l."),s=r&&r.match(/^(?:[(]?)([^\s]+?)([.)]?)$/);if(s){var u=o(s,r),c=l(e,"span");return c&&/ mso-hide:\s*all|display:\s*none /.test(c.getAttribute("style"))&&u.setAttribute("ke:ignored",1),u}}var f=e.getAttribute("style");f&&i(e,n([[/^line-height$/],[/^font-family$/],[/^font-size$/],[/^color$/],[/^background-color$/]])(f,e))},a:function(e){var t;!(t=e.getAttribute("href"))&&e.getAttribute("name")?e.setTagName(null):g.webkit&&t&&t.match(/file:\/\/\/[\S]+#/i)&&e.setAttribute("href",t.replace(/file:\/\/\/[^#]+/i,""))},"ke:listbullet":function(e){l(e,/h\d/)&&e.setTagName(null)}},attributeNames:[[/^onmouse(:?out|over)/,""],[/^onload$/,""],[/(?:v|o):\w+/,""],[/^lang/,""]],attributes:{style:n([[/^list-style-type$/],[/^margin$|^margin-(?!bottom|top)/,null,function(e,t,i){if(t.nodeName in{p:1,div:1}){var r="margin-left";if("margin"===i)e=N(i,e,[r])[r];else if(i!==r)return null;if(e&&!v.test(e))return[r,e]}return null}],[/^clear$/],[/^border.*|margin.*|vertical-align|float$/,null,function(e,t){return"img"===t.nodeName?e:void 0}],[/^width|height$/,null,function(e,t){return t.nodeName in{table:1,td:1,th:1,img:1}?e:void 0}]],1),width:function(e,t){return t.nodeName in p.$tableContent?!1:void 0},border:function(e,t){return t.nodeName in p.$tableContent?!1:void 0},"class":t,bgcolor:t,valign:function(e,t){return s(t,"vertical-align",e),!1}},comment:g.ie?function(e,t){var i=e.match(/<img.*?>/),r=e.match(/^\[if !supportLists\]([\s\S]*?)\[endif\]$/);if(r){var n=r[1]||i&&"l.",l=n&&n.match(/>(?:[(]?)([^\s]+?)([.)]?)</);return o(l,n)}if(g.gecko&&i){var a=new f.Parser(i[0]).parse().childNodes[0],s=t.previousSibling,u=s&&s.toHtml().match(/<v:imagedata[^>]*o:href=[''](.*?)['']/),c=u&&u[1];return c&&a.setAttribute("src",c),a}return!1}:t})}(),module.exports={toDataFormat:function(e,t){return g.gecko&&(e=e.replace(/(<!--\[if[^<]*?\])-->([\S\s]*?)<!--(\[endif\]-->)/gi,"$1$2$3")),e=t.htmlDataProcessor.toDataFormat(e,h)}};});
Example #19
0
        it("works for complex text node", function () {

            // d
            //    a
            //    span
            //           b
            //           span-start
            //                 123456789
            //           c
            //    d
            //    span
            //           e
            //           span-end
            //                 123456789
            //           f
            //    g


            var div = $("<div>" +
                "a" +
                "<span>" +
                "b" +
                "<span id=\"start\">" +
                "123456789" +
                "</span>" +
                "c" +
                "</span>" +
                "d" +
                "<span>" +
                "e" +
                "<span id=\"end\">" +
                "123456789" +
                "</span>" +
                "f" +
                "</span>" +
                "g</div>").appendTo('body', undefined);

            var range = new Range(document);
            var textStart = $($("#start")[0].firstChild);
            var textEnd = $($("#end")[0].firstChild);
            range.setStart(textStart, 2);
            range.setEnd(textEnd, 5);

            var f = range.cloneContents();

            var newDiv = $("<div>").appendTo('body');

            newDiv.append(f);

            expect(myHTML(newDiv)).toBe("<span>" +
                "<span id=\"start\">" +
                "3456789" +
                "</span>" +
                "c" +
                "</span>" +
                "d" +
                "<span>" +
                "e" +
                "<span id=\"end\">" +
                "12345" +
                "</span>" +
                "</span>");

            expect(textStart.parent()[0].childNodes.length).toBe(1);

            expect(textStart.parent()[0].firstChild).toBe(textStart[0]);

            expect(textStart[0].nodeValue).toBe("123456789");


            expect(textEnd.parent()[0].childNodes.length).toBe(1);

            expect(textEnd.parent()[0].firstChild).toBe(textEnd[0]);

            expect(textEnd[0].nodeValue).toBe("123456789");

            div.remove();
            newDiv.remove();

        });
Example #20
0
File: xdr.js Project: Snger/kissy
            it("should works for any domain", function () {
                var v1;

                var iframe = $('<iframe></iframe>');
                iframe.on('load', function () {

                    io({
                        headers: {
                            // cross domain 设置 header ie 无效
                            // 原生 chrome.firefox 可行
                            yiminghe: 'oo'
                        },
                        cache: false,
                        dataType: 'json',
                        url: testUrl,
                        xhrFields: {
                            // Cannot use wildcard in Access-Control-Allow-Origin
                            // when credentials flag is true.
                            // Access-Control-Allow-Origin:http://localhost
                            // 必须设置完全 hostname 匹配

                            // firefox , chrome 携带 cookie
                            withCredentials: true
                        },
                        xdr: {
                            // 强制用 flash,ie 可携带cookie
                            // use: 'flash',
                            // force to use native xhr no sub domain proxy
                            subDomain: {
                                proxy: false
                            }
                        },
                        data: {
                            action: 'x'
                        },
                        success: function (d, s, r) {
                            // body 都可读
                            expect(d.action).toBe('x');

                            // ie6-7 flash 不可读
                            // ie8-9 XDomainRequest 不可读
                            // header ie10 ,chrome, firefox 可读
                            if (UA.ie && UA.ie < 10) {
                                expect(typeof  d.yiminghe).toBe('undefined');
                                expect(typeof  d['X-Requested-With']).toBe('undefined');
                            } else {
                                expect(d.yiminghe).toBe('oo');
                                expect(d['X-Requested-With']).toBe('XMLHttpRequest');
                            }

                            // ie8-9 XDomainRequest 不可读
                            // header ie10 ,chrome, firefox 可读
                            // ie6-7 flash 可读
                            if (UA.ie && UA.ie >= 8 && UA.ie <= 9) {
                                expect(typeof d.cors).toBe('undefined');
                            } else {
                                expect(d.cors).toBe('ok');
                            }

                            // 原生 chrome.firefox 响应头不能读
                            // ie6-7 flash 不可读
                            // ie8-9 XDomainRequest 不可读
                            // ie10 可以读
                            if (UA.ie >= 10) {
                                expect(r.getResponseHeader("X-Powered-By")).toBe('Express');
                            } else {
                                expect(r.getResponseHeader("X-Powered-By")).toBeNull();
                            }

                            v1 = 1;
                        }
                    });

                });

                iframe[0].src = 'http://' + url + '/kissy/src/' +
                    'io/tests/others/xdr/set-cookie.html';
                iframe.appendTo('body');

                waitsFor(function () {
                    return v1 === 1;
                }, 5000, "xdr should return!");

                waits(100);
                runs(function () {
                    iframe.remove();
                });
            });
    function indentList(range, listNode, type) {
        // Our starting and ending points of the range might be inside some blocks under a list item...
        // So before playing with the iterator, we need to expand the block to include the list items.

        var startContainer = range.startContainer,
            endContainer = range.endContainer;
        while (startContainer && !startContainer.parent().equals(listNode)) {
            startContainer = startContainer.parent();
        }
        while (endContainer && !endContainer.parent().equals(listNode)) {
            endContainer = endContainer.parent();
        }

        if (!startContainer || !endContainer) {
            return;
        }

        // Now we can iterate over the individual items on the same tree depth.
        var block = startContainer,
            itemsToMove = [],
            stopFlag = false;
        while (!stopFlag) {
            if (block.equals(endContainer)) {
                stopFlag = true;
            }
            itemsToMove.push(block);
            block = block.next();
        }
        if (itemsToMove.length < 1) {
            return;
        }

        // Do indent or outdent operations on the array model of the list, not the
        // list's Dom tree itself. The array model demands that it knows as much as
        // possible about the surrounding lists, we need to feed it the further
        // ancestor node that is still a list.
        var listParents = listNode._4eParents(true, undefined);

        listParents.each(function (n, i) {
            listParents[i] = n;
        });

        for (var i = 0; i < listParents.length; i++) {
            if (listNodeNames[ listParents[i].nodeName() ]) {
                listNode = listParents[i];
                break;
            }
        }
        var indentOffset = type === 'indent' ? 1 : -1,
            startItem = itemsToMove[0],
            lastItem = itemsToMove[ itemsToMove.length - 1 ],
            database = {};

        // Convert the list Dom tree into a one dimensional array.
        var listArray = ListUtils.listToArray(listNode, database);

        // Apply indenting or outdenting on the array.
        // listarray_index 为 item 在数组中的下标,方便计算
        var baseIndent = listArray[ lastItem.data('listarray_index') ].indent;
        for (i = startItem.data('listarray_index');
             i <= lastItem.data('listarray_index'); i++) {
            listArray[ i ].indent += indentOffset;
            // Make sure the newly created sublist get a brand-new element of the same type. (#5372)
            var listRoot = listArray[ i ].parent;
            listArray[ i ].parent =
                $(listRoot[0].ownerDocument.createElement(listRoot.nodeName()));
        }
        /*
         嵌到下层的li
         <li>鼠标所在开始</li>
         <li>ss鼠标所在结束ss
         <ul>
         <li></li>
         <li></li>
         </ul>
         </li>
         baseIndent 为鼠标所在结束的嵌套层次,
         如果下面的比结束li的indent大,那么证明是嵌在结束li里面的,也要缩进
         一直处理到大于或等于,跳出了当前嵌套
         */
        for (i = lastItem.data('listarray_index') + 1;
             i < listArray.length && listArray[i].indent > baseIndent; i++) {
            listArray[i].indent += indentOffset;
        }

        // Convert the array back to a Dom forest (yes we might have a few subtrees now).
        // And replace the old list with the new forest.
        var newList = ListUtils.arrayToList(listArray, database, null, 'p');

        // Avoid nested <li> after outdent even they're visually same,
        // recording them for later refactoring.(#3982)
        var pendingList = [];
        var parentLiElement;
        if (type === 'outdent') {

            if (( parentLiElement = listNode.parent() ) &&
                parentLiElement.nodeName() === 'li') {
                var children = newList.listNode.childNodes, count = children.length,
                    child;

                for (i = count - 1; i >= 0; i--) {
                    if (( child = $(children[i]) ) &&
                        child.nodeName() === 'li') {
                        pendingList.push(child);
                    }
                }
            }
        }

        if (newList) {
            Dom.insertBefore(newList.listNode[0] || newList.listNode,
                listNode[0] || listNode);
            listNode.remove();
        }
        // Move the nested <li> to be appeared after the parent.
        if (pendingList && pendingList.length) {
            for (i = 0; i < pendingList.length; i++) {
                var li = pendingList[ i ],
                    followingList = li;

                // Nest preceding <ul>/<ol> inside current <li> if any.
                while (( followingList = followingList.next() ) &&

                    followingList.nodeName() in listNodeNames) {
                    // IE requires a filler NBSP for nested list inside empty list item,
                    // otherwise the list item will be inaccessiable. (#4476)
                    /*jshint loopfunc:true*/
                    if (UA.ie && !li.first(function (node) {
                        return isNotWhitespaces(node) && isNotBookmark(node);
                    }, 1)) {
                        li[0].appendChild(range.document.createTextNode('\u00a0'));
                    }
                    li[0].appendChild(followingList[0]);
                }
                Dom.insertAfter(li[0], parentLiElement[0]);
            }
        }

        // Clean up the markers.
        Editor.Utils.clearAllMarkers(database);
    }
Example #22
0
 var ret = nodes.filter(function (n, i) {
     return $(n).hasClass('z') && i === 2;
 });
Example #23
0
 _init: function () {
     var self = this, editor = self.editor, prefixCls = editor.get('prefixCls'), statusbar = editor.get('statusBarEl'), cfg = this.config;
     cfg.draft = cfg.draft || {};
     self.draftInterval = cfg.draft.interval = cfg.draft.interval || INTERVAL;
     self.draftLimit = cfg.draft.limit = cfg.draft.limit || LIMIT;
     var holder = $('<div class="' + prefixCls + 'editor-draft">' + '<span class="' + prefixCls + 'editor-draft-title">' + '\u5185\u5BB9\u6B63\u6587\u6BCF' + cfg.draft.interval + '\u5206\u949F\u81EA\u52A8\u4FDD\u5B58\u4E00\u6B21\u3002' + '</span>' + '</div>').appendTo(statusbar);
     self.timeTip = $('<span class="' + prefixCls + 'editor-draft-time"/>').appendTo(holder);
     var save = $(util.substitute('<a href="#" ' + 'onclick="return false;" ' + 'class="{prefixCls}editor-button ' + '{prefixCls}editor-draft-save-btn ks-inline-block" ' + 'style="' + 'vertical-align:middle;' + 'padding:1px 9px;' + '">' + '<span class="{prefixCls}editor-draft-save">' + '</span>' + '<span>\u7ACB\u5373\u4FDD\u5B58</span>' + '</a>', { prefixCls: prefixCls })).unselectable(undefined).appendTo(holder), versions = new MenuButton({
             render: holder,
             collapseOnClick: true,
             width: '100px',
             prefixCls: prefixCls + 'editor-',
             menu: {
                 width: '225px',
                 align: {
                     points: [
                         'tr',
                         'br'
                     ]
                 }
             },
             matchElWidth: false,
             content: '\u6062\u590D\u7F16\u8F91\u5386\u53F2'
         }).render();
     self.versions = versions;    // 点击才开始 parse
     // 点击才开始 parse
     versions.on('beforeCollapsedChange', function beforeCollapsedChange(e) {
         if (!e.newValue) {
             versions.detach('beforeCollapsedChange', beforeCollapsedChange);
             self.sync();
         }
     });
     save.on('click', function (ev) {
         self.save(false);    //如果不阻止,部分页面在ie6下会莫名奇妙把其他input的值丢掉!
         //如果不阻止,部分页面在ie6下会莫名奇妙把其他input的值丢掉!
         ev.halt();
     });
     addRes.call(self, save);    /*
  监控form提交,每次提交前保存一次,防止出错
  */
     /*
  监控form提交,每次提交前保存一次,防止出错
  */
     if (editor.get('textarea')[0].form) {
         (function () {
             var textarea = editor.get('textarea'), form = textarea[0].form;
             function saveF() {
                 self.save(true);
             }
             Event.on(form, 'submit', saveF);
             addRes.call(self, function () {
                 Event.remove(form, 'submit', saveF);
             });
         }());
     }
     var timer = setInterval(function () {
             self.save(true);
         }, self.draftInterval * 60 * 1000);
     addRes.call(self, function () {
         clearInterval(timer);
     });
     versions.on('click', self.recover, self);
     addRes.call(self, versions);
     self.holder = holder;
     if (cfg.draft.helpHTML) {
         var help = $('<a ' + 'tabindex="0" ' + 'hidefocus="hidefocus" ' + 'class="' + prefixCls + 'editor-draft-help" ' + 'title="\u70B9\u51FB\u67E5\u770B\u5E2E\u52A9" ' + 'href="javascript:void(\'\u70B9\u51FB\u67E5\u770B\u5E2E\u52A9 \')">\u70B9\u51FB\u67E5\u770B\u5E2E\u52A9</a>').unselectable(undefined).appendTo(holder);
         help.on('click', function () {
             help[0].focus();
             if (self.helpPopup && self.helpPopup.get('visible')) {
                 self.helpPopup.hide();
             } else {
                 self._prepareHelp();
             }
         });
         help.on('blur', function () {
             if (self.helpPopup) {
                 self.helpPopup.hide();
             }
         });
         self.helpBtn = help;
         addRes.call(self, help);
         Editor.Utils.lazyRun(self, '_prepareHelp', '_realHelp');
     }
     addRes.call(self, holder);
 },
Example #24
0
 it('node is not plainObject', function () {
     expect(util.isPlainObject($('body'))).toBe(false);
     expect(util.isPlainObject($('#ee'))).toBe(false);
     expect(util.isPlainObject($(document.body))).toBe(false);
 });
Example #25
0
 pluginRenderUI: function (editor) {
     $('<span ' + 'class="' + editor.get('prefixCls') + 'editor-toolbar-separator">&nbsp;' + '</span>').appendTo(editor.get('toolBarEl'));
 }
Example #26
0
describe("selector context", function () {
    var html = $(
            "<div id='context-test-1' class='context-test'>" +
            "<div class='context-test-3' id='context-test-2'></div>" +
            "</div>" +
            "<div class='context-test-3' id='context-test-4'></div>" +
            "<div class='context-test'>" +
            "<div class='context-test'>" +
            "<div class='context-test-3' id='context-test-5'>" +
            "</div>" +
            "</div>" +
            "</div>").appendTo('body');

    it("should support #id", function () {
        expect($(".context-test-3", "#context-test-1").length).toBe(1);
        expect($(".context-test-3").length).toBe(3);
        expect($(".context-test-3", "#context-test-1").attr('id')).toBe("context-test-2");
    });

    it("should support other string form selector and unique works", function () {
        expect($(".context-test-3", ".context-test").length).toBe(2);
    });


    it("should support node array form selector and unique works", function () {
        var c3 = $(".context-test-3");
        expect(c3.length).toBe(3);
        var c = $(".context-test");
        expect(c.length).toBe(3);
        expect($(c3, ".context-test").length).toBe(2);
        expect($(".context-test-3", c).length).toBe(2);
        expect($(c3, c).length).toBe(2);
        expect($(".context-test-3", ".context-test").length).toBe(2);

        expect(c.all(".context-test-3").length).toBe(2);
        expect(c.all(c3).length).toBe(2);

    });

    // #85
    it("slice works", function () {
        expect($('body').slice(0 - 1)[0]).toBe(document.body);
        expect($(".context-test-3").slice(0 - 2).length).toBe(2);
        expect($(".context-test-3").slice(0 - 2, -1).length).toBe(1);
    });

    it('index works', function () {

        var div = $('<ul class="index-ul">' +
            '<li class="index-li">0</li>' +
            '<li class="index-li">1</li>' +
            '<li class="index-li">2</li>' +
            '</ul>').appendTo('body');

        // 单个节点
        expect($('.index-li').index($('.index-li')[1])).toBe(1);

        // 取第一个节点
        expect($('.index-li').index($('.index-li'))).toBe(0);

        // 第一个节点在 parent 中找
        expect($('.index-li').index()).toBe(0);

        expect($('.index-li').item(1).index()).toBe(1);

        // selector 集合中找当前第一个节点
        expect($('.index-li').item(1).index('.index-li')).toBe(1);

        expect($('body').index('.index-li')).toBe(-1);

        div.remove();

    });

    runs(function () {
        html.remove();
    });
});
        _genTable: function () {
            var self = this,
                d = self.dialog,
                html = '<table ',
                i,
                cols = parseInt(d.tcols.val(),10) || 1,
                rows = parseInt(d.trows.val(),10) || 1,
            //firefox 需要 br 才能得以放置焦点
            //cellPad = UA.ie ? '&nbsp;' : '&nbsp;<br/>',
                cellPad = OLD_IE ? '' : '<br/>',
                editor = self.editor;

            if (valid(d.talign.get('value'))) {
                html += 'align="' + trim(d.talign.get('value')) + '" ';
            }

            if (valid(d.tborder.val())) {
                html += 'border="' + trim(d.tborder.val()) + '" ';
            }

            var styles = [];


            if (valid(d.twidth.val())) {
                styles.push('width:' + trim(d.twidth.val()) + d.twidthunit.get('value') + ';');
            }

            if (valid(d.theight.val())) {
                styles.push('height:' + trim(d.theight.val()) + 'px;');
            }

            if (styles.length) {
                html += 'style="' + styles.join('') + '" ';
            }

            var classes = [];

            if (!valid(d.tborder.val()) || String(trim(d.tborder.val())) === '0') {
                classes.push(showBorderClassName);
            }

            if (d.tcollapse[0].checked) {
                classes.push(collapseTableClass);
            }
            if (classes.length) {
                html += 'class="' + classes.join(' ') + '" ';
            }

            html += '>';
            if (valid(d.tcaption.val())) {
                html += '<caption><span>' + util.escapeHtml(trim(d.tcaption.val())) + '</span></caption>';
            }
            if (d.thead.get('value')) {
                html += '<thead>';
                html += '<tr>';
                for (i = 0; i < cols; i++) {
                    html += '<th>' + cellPad + '</th>';
                }
                html += '</tr>';
                html += '</thead>';
                rows -= 1;
            }

            html += '<tbody>';
            for (var r = 0; r < rows; r++) {
                html += '<tr>';
                for (i = 0; i < cols; i++) {
                    html += '<td>' + cellPad + '</td>';
                }
                html += '</tr>';
            }
            html += '</tbody>';
            html += '</table>';

            var table = $(html, editor.get('document')[0]);
            editor.insertElement(table);
        },
Example #28
0
 it("should support #id", function () {
     expect($(".context-test-3", "#context-test-1").length).toBe(1);
     expect($(".context-test-3").length).toBe(3);
     expect($(".context-test-3", "#context-test-1").attr('id')).toBe("context-test-2");
 });
Example #29
0
 setter: function (v) {
     return $(v);
 }
Example #30
0
 it("should support other string form selector and unique works", function () {
     expect($(".context-test-3", ".context-test").length).toBe(2);
 });