便捷式编辑器

这里写图片描述

Math.uuid = (function() {
    var $ = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
    return function(_, G) {
        var C = $,
        F = [],
        D = Math.random;
        G = G || C.length;
        if (_) {
            for (var B = 0; B < _; B++) F[B] = C[0 | D() * G]
        } else {
            var A = 0,
            E;
            F[8] = F[13] = F[18] = F[23] = "-";
            F[14] = "4";
            for (B = 0; B < 36; B++)
             if (!F[B]) {
                E = 0 | D() * 16;
                F[B] = C[(B == 19) ? (E & 3) | 8: E & 15]
            }
        }
        return F.join("")
    }
})();
var randomUUID = Math.uuid;
function POEditor(opt) {
    opt.rangy.init();
    $.extend(this, opt || {},
    {
        rangy: opt.rangy,
        fileSize: 1024,
        POID: Math.uuid(),
        itemColors: ["#FF0000", "#0000FF", "#000000"]
    });
    var self = this;
    this.POEvent();
    this.editorArea = this.editContainer();
    this.delNode = $(".delNode", this.editorArea);
    this.poeWin = $(".poeWin", this.editorArea);
    this.poeWinLine = $(".poeWinLine", this.editorArea);
    this.msg = $(".poeMsg", this.editorArea);
    this.menu = new Menu(this);
    this.menuContainer = this.menu.initMenu();
    this.init();
}
POEditor.prototype.init = function() {
    var div = $("<div/>");
    var cssDiv = $("<div/>");
    div.append(this.menuContainer).append(this.editorArea).append(cssDiv);
    if (this.container) {
        this.container.append(this.niurenStyleNode());
        if (this.template && this.template != "") {
            $("head").append("<link class='linkInsert' type='' rel='stylesheet' href='" + this.menu.cssPath + this.template + ".css'/>");
            $('.linkInsert').attr('type', 'text/css')
        }
    } else {
        if ($("head .POStyle").length == 0) {
            $("head").append(this.niurenStyleNode());
        }
    }
    this.container = this.container || $(document.body);
    div.hide().show();
    $(this.container).append(div);
}
POEditor.prototype.editContainer = function() {
    var containerCls,
    tourSection;
    if (this.template == "niuren" || this.template == "unniuren") {
        containerCls = {
            border: "1px solid #C5C5C5",
            borderTop: "none",
            padding: "2px",
            margin: "0 0 5px",
            minWidth: "756px",
            maxHeight: "600px",
            overflowY: "auto",
            background: "url('/plugin/tuniu/css/POEditor/images/logo.gif') left bottom #FFF no-repeat",
            minHeight: "250px"
        };
        this.tourSection = tourSection = $("<div class='tourSection_" + this.template + "' />");
    } else if (this.template == "base") {
        containerCls = {
            border: "1px solid #C5C5C5",
            borderTop: "none",
            padding: "2px",
            margin: "0 0 5px",
            minWidth: "756px",
            maxHeight: "600px",
            overflowY: "auto",
            background: "url('/plugin/tuniu/css/POEditor/images/logo.gif') left bottom #FFF no-repeat",
            minHeight: "50px"
        }
        this.tourSection = tourSection = $("<div class='baseSection' contentEditable='true' style='min-height:60px;cursor:auto;' />");
    }
    var delNode = $("<div class='delNode' style='display:none;position:absolute;font-size:13px;cursor:pointer;padding:3px;border:1px solid #CCC;background-color:#FFF;'>鍒犻櫎</div>");
    var win = $("<div class='poeWin' style='display:none;position:absolute;border:1px solid #999;background-color:#FFF;padding:5px;z-index:100'></div>");
    var winLine = $("<div class='poeWinLine' style='display:none;position:absolute;height:1px;background-color:#FFF;z-index:100'></div>");
    var poeMsg = $("<div class='poeMsg' style='font-size:13px;display:none;position:absolute;height:20px;opacity:0.9;width:auto;background-color:#000;padding: 2px  20px;text-align:center;color:#FFF;'></div>");
    return $("<div/>").css(containerCls).append(tourSection).append(delNode).append(win).append(winLine).append(poeMsg);
}
POEditor.prototype.POEvent = function() {
    var self = this;
    $(this.container).unbind("keypress").bind("keypress",
    function(ev) {
        window.event ? e = window.event: e = ev;
        window.event ? e.target = window.event.srcElement: e.target = ev.target;
        window.event ? e.charCode = window.event.keyCode: e.charCode = ev.charCode;
        if (e.ctrlKey && e.shiftKey && e.charCode == 83) {
            self.setLocalStorage.call(self);
            self.menu.save_flag = true;
        }
    });
    $(this.container).unbind("paste").bind("paste",
    function(e) {
        var rng = self.menu.getFirstRange();
        e = window.event || e;
        if (e.target.nodeName === 'INPUT') return true;
        if (!window.clipboardData) {
            if (self.menu.saveSel) {
                rangy.removeMarkers(self.menu.saveSel);
                $('.rangySelectionBoundary').remove()
                 $('br[type="_moz"]').remove()
            }
            self.menu.savedSelActiveElement = document.activeElement;
            self.menu.saveSel = self.rangy.saveSelection();
            var contentDiv = $('#tempDivForClipboard');
            if (!contentDiv.length) {
                contentDiv = $('<div id="tempDivForClipboard" style="overflow:hidden;position:absolute; top: 0; left: 0; width:1px; height:1px; border:#000 1px solid" contenteditable="true">originalText</div>');
                contentDiv.css('top', $(rng.rang.startContainer.parentNode).offset().top)
                 $('body').append(contentDiv);
            }
            contentDiv.html('')
             contentDiv.focus()
             setTimeout(function() {
                $('div', contentDiv).replaceWith(function() {
                    return $(this).html() + '\n';
                });
                contentDiv.html(contentDiv.html().replace(/(\s*<br>\s*)+/g, '\n'))
                 var clip = $.trim(contentDiv.text()).split(/\s*\n+\s*/) || [];
                if (clip.length > 0) {
                    var rng = self.menu.getFirstRange(true);
                    var createTextNode,
                    brNode;
                    for (var i = 0; i < clip.length; i++) {
                        createTextNode = document.createTextNode(clip[i]);
                        rng.rang.deleteContents();
                        rng.rang.insertNode(createTextNode);
                        rng.rang.collapseAfter(createTextNode);
                        if (i != clip.length - 1) {
                            brNode = document.createElement('br');
                            rng.rang.insertNode(brNode);
                            rng.rang.collapseAfter(brNode);
                        }
                        rng.sel.setSingleRange(rng.rang);
                    };
                    contentDiv.remove();
                    return true;
                } else {
                    contentDiv.remove();
                    return false;
                }
            },
            0)
             return true;
        } else {
            var clip = self.getClip() || '';
            self.setClip(clip)
             return true;
        }
    });
    $(this.container).unbind("click").click(function(e) {
        self.hideWin();
        Event.fireEvent("hideWindow");
    });
    $(window).unload(function() {
        self.clearLocalStorage.call(self);
    })
}
POEditor.prototype.msgShow = function(title, flag) {
    this.msg.html(title || "");
    this.msg.css({
        top: this.menuContainer.position().top + 28,
        left: this.menuContainer.position().left + 1
    });
    if (!flag) {
        this.msg.fadeIn(1000).fadeOut(3000);
    } else {
        this.msg.fadeIn(1000);
    }
}
POEditor.prototype.msgHide = function() {
    this.msg.hide();
}
POEditor.prototype.setLocalStorage = function() {
    try {
        if (!localStorage) {
            alert("鎮ㄦ墍浣跨敤鐨勬祻瑙堝櫒鏆傛湭鏀寔鏈湴瀛樺偍锛岃浣跨敤Firefox 7.0.1浠ヤ笂鐗堟湰鐨勬祻瑙堝櫒");
            return;
        }
        localStorage[this.POID] = this.getPOHtml(true);
        this.msgShow("缂栬緫鍐呭宸蹭繚瀛橈紝娉ㄦ剰锛氶〉闈㈠埛鏂板悗缂栬緫鍐呭灏嗚娓呴櫎銆�");
    } catch(e) {
        return;
    }
}
POEditor.prototype.getLocalStorage = function() {
    try {
        if (!localStorage) {
            alert("鎮ㄦ墍浣跨敤鐨勬祻瑙堝櫒鏆傛湭鏀寔鏈湴瀛樺偍锛岃浣跨敤Firefox 7.0.1浠ヤ笂鐗堟湰鐨勬祻瑙堝櫒");
            return;
        }
    } catch(e) {
        return;
    }
    return localStorage[this.POID];
}
POEditor.prototype.clearLocalStorage = function() {
    try {
        if (!localStorage[this.POID])
         delete localStorage[this.POID]
    } catch(e) {
        return;
    }
}
POEditor.prototype.setClip = function(text) {
    if (window.clipboardData) {
        return window.clipboardData.setData("Text", text);
    } else {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch(e) {
                alert("鎮ㄧ殑Firefox瀹夊叏闄愬埗闄愬埗鎮ㄨ繘琛屽壀璐存澘鎿嶄綔锛岃鎸夊涓嬫楠よ繘琛岃缃細\n1.璇峰湪娴忚鍣ㄥ湴鍧€鏍忎腑杈撳叆'about:config'銆俓n2.鍦ㄨ繃婊ゅ櫒涓緭鍏"signed.applets.codebase_principal_support\"骞舵寜鍥炶溅銆俓n3.榧犳爣鍙屽嚮鍊硷紝灏嗗€艰缃负'true'涔嬪悗閲嶈瘯銆�");
                return false;
            }
            var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
            if (!clip) {
                return false;
            }
            var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
            if (!trans) {
                return false;
            }
            trans.addDataFlavor("text/unicode");
            var str = new Object();
            var len = new Object();
            var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
            str.data = text;
            trans.setTransferData("text/unicode", str, text.length * 2);
            clip.setData(trans, null, clip.kGlobalClipboard);
            var str = new Object();
            var strLength = new Object();
            try
             {
                trans.getTransferData("text/unicode", str, strLength);
                if (str) {
                    str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
                }
                if (str) {
                    return str.data.substring(0, strLength.value / 2);
                }
            } catch(e)
             {
                return "";
            }
        }
    }
}
POEditor.prototype.getClip = function() {
    if (window.clipboardData) {
        var tempStr = window.clipboardData.getData("Text");
        var createTextNode = document.createTextNode(tempStr);
        return createTextNode.data;
    } else {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch(e) {
                alert("鎮ㄧ殑Firefox瀹夊叏闄愬埗闄愬埗鎮ㄨ繘琛屽壀璐存澘鎿嶄綔锛岃鎸夊涓嬫楠よ繘琛岃缃細\n1.璇峰湪娴忚鍣ㄥ湴鍧€鏍忎腑杈撳叆'about:config'銆俓n2.鍦ㄨ繃婊ゅ櫒涓緭鍏"signed.applets.codebase_principal_support\"骞舵寜鍥炶溅銆俓n3.榧犳爣鍙屽嚮鍊硷紝灏嗗€艰缃负'true'涔嬪悗閲嶈瘯銆�");
                return false;
            }
            var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
            if (!clip) {
                return false;
            }
            var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
            if (!trans) {
                return false;
            }
            trans.addDataFlavor("text/unicode");
            clip.getData(trans, clip.kGlobalClipboard);
            var str = new Object();
            var strLength = new Object();
            try
             {
                trans.getTransferData("text/unicode", str, strLength);
                if (str) {
                    str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
                }
                if (str) {
                    return str.data.substring(0, strLength.value / 2);
                }
            } catch(e)
             {
                return "";
            }
        }
    }
}
POEditor.prototype.niurenStyleNode = function() {
    var str = ".tourSection_" + this.template + " .day_title_new h3 div{border-bottom:1px dashed  #000;min-width:500px;width:700px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .day_title_new div.tour_line{border-bottom:1px dashed  #000;min-width:500px;width:720px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .time_box_inner .time_num div.tour_con{border-bottom:1px dashed  #000;min-width:65px;width:65px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .time_box_inner .time_do_new div.tour_con{border-bottom:1px dashed  #000;min-width:500px;width:720px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .time_box_inner .time_do_new div.tour_description{border-bottom:1px dashed  #000;min-width:500px;width:720px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .time_box_inner .time_do_new div.tour_con_h4{border-bottom:1px dashed  #000;min-width:500px;width:720px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .tour_food .tour_item div{border-bottom:1px dashed  #000;min-width:500px;height:auto;min-height:22px;}";
    str += ".tourSection_" + this.template + " .time_box_inner .time_img_photo li div{border-bottom:1px dashed  #000;min-width:100px;width:auto;height:auto;min-height:22px;}";
    str += "*._FF0000{color:#FF0000}*._0000FF{color:#0000FF}*._000000{color:#000000}";
    str += "*.poeLink{color:blue;cursor:pointer;}";
    str += ".link_span{}";
    str += ".cgrey{ color:#666; text-decoration:underline;}";
    str += this.container.selector + " img{ -webkit-user-drag:none;}";
    var style = $('<style class="POStyle">' + str + '</style>')
     return style;
}
POEditor.prototype.getPOHtml = function(isClear) {
    if (this.template == "base") {
        return $('.baseSection', this.container).clone().html();
    } else {
        var div = $("<div/>").append(this.tourSection.clone());
        if (!isClear) {
            this.clearHtml(div);
        }
        return div.html();
    }
}
POEditor.prototype.setPOHtml = function(obj) {
    var self = this;
    this.tourSection.empty();
    if (this.template == "base") {
        $('.baseSection', this.container).empty().append(obj);
    } else {
        this.menu.day = 0;
        this.day = 0;
        var div = $("<div/>").append(obj);
        var html = $(".tourSection_" + this.template, div).html();
        if (this[this.template + "ReloadBindEvent"]) {
            this[this.template + "ReloadBindEvent"](html);
        } else {
            this.menu[this.template + "ReloadBindEvent"](html);
        }
    }
}
POEditor.prototype.getPOHtmlByDay = function() {
    var obj = {};
    $(".tourContent_new", this.tourSection).each(function(i, n) {
        obj[i + 1] = $(n).html();
    })
     return obj;
}
POEditor.prototype.getPOText = function(flag) {
    if (!flag) {
        return this.tourSection.text();
    } else {
        var obj = {};
        $(".tourContent_new", this.tourSection).each(function(i, n) {
            obj[i + 1] = $(n).text();
        })
         return obj;
    }
}
POEditor.prototype.clearHtml = function(node) {
    $("*[contentEditable]", node).removeAttr("contentEditable");
}
POEditor.prototype.showWin = function(e, html) {
    var self = this;
    window.event ? e.target = window.event.srcElement: e.target;
    this.poeWin.append(html || "");
    this.poeWin.css({
        left: $(e.target).position().left - 1,
        top: $(e.target).position().top + $(e.target).height() - 1
    }).show().data("target", $(e.target).parent());
    var overRightBorder = $(e.target).offset().left + this.poeWin.width() - $(window).width() + 30
    if (overRightBorder > 0) {
        this.poeWin.css({
            left: "-=" + (overRightBorder + 10)
        });
    }
    var width = $(e.target).width();
    if (width <= 8) {
        width = 20;
    } else {
        width = $(e.target).width() + 2
    }
    this.poeWinLine.css({
        left: $(e.target).position().left - 1,
        top: $(e.target).position().top + $(e.target).height() - 1,
        width: width,
        marginLeft: "1px"
    }).show();
    $(e.target).parent().css({
        border: "1px solid #999",
        backgroundColor: "#FFF",
        margin: "0px"
    });
    this.poeWin.click(function(e) {
        e.stopPropagation ? e.stopPropagation() : window.event.cancelBubble = true;
    })
}
POEditor.prototype.hideWin = function(e) {
    this.poeWin.hide();
    this.poeWin.children().hide();
    this.poeWinLine.hide();
    this.poeWin.data("target") && this.poeWin.data("target").css({
        border: "0px solid #999",
        backgroundColor: "transparent",
        margin: "1px"
    })
}
POEditor.prototype.onUploadImgChange = function(e, imgList, fn) {}
POEditor.prototype.checkFileType = function(files) {
    if (!files.match(/.jpg|.gif|.png|.bmp|.jpeg/i)) {
        return false;
    }
    return true;
}
POEditor.prototype.checkFileSize = function(fileSize) {
    if (fileSize > parseInt(this.fileSize) * 1024) {
        return false;
    }
    return true;
}
POEditor.prototype.autoSizePreview = function(objPre, originalWidth, originalHeight) {
    var zoomParam = this.clacImgZoomParam(150, 150, originalWidth, originalHeight);
    objPre.style.width = zoomParam.width + 'px';
    objPre.style.height = zoomParam.height + 'px';
    objPre.style.marginTop = zoomParam.top + 'px';
    objPre.style.marginLeft = zoomParam.left + 'px';
}
POEditor.prototype.clacImgZoomParam = function(maxWidth, maxHeight, width, height) {
    var param = {
        width: width,
        height: height,
        top: 0,
        left: 0
    };
    if (width > maxWidth || height > maxHeight) {
        rateWidth = width / maxWidth;
        rateHeight = height / maxHeight;
        if (rateWidth > rateHeight) {
            param.width = maxWidth;
            param.height = height / rateWidth;
        } else {
            param.width = width / rateHeight;
            param.height = maxHeight;
        }
    }
    param.left = (maxWidth - param.width) / 2;
    param.top = (maxHeight - param.height) / 2;
    return param;
}
function Menu(opt) {
    $.extend(this, opt || {},
    {
        doc: document,
        day: 0,
        imagePath: "/Plugin/tuniu/css/POEditor/images/",
        cssPath: "/Plugin/tuniu/css/POEditor/",
        imageUri: "http://img.tuniucdn.com/icons/route/",
        imageHref: "http://jingdian.tuniu.com/fengjing/",
        shopping_store_id: 0,
        save_flag: false
    });
    this.tlp = new Template(this);
}
var $m = Menu.prototype;
$m.publicMenu = {
    "Save": {
        name: "淇濆瓨",
        iconCls: "poe_save",
        position: "-640px 0",
        action: "poe_Save"
    },
    "History": {
        name: "杩斿洖鏈€杩戜竴娆$殑淇濆瓨鍐呭",
        iconCls: "poe_history",
        position: "-260px 0",
        action: "poe_History"
    },
    "Bold": {
        name: "绮椾綋",
        iconCls: "poe_bold",
        position: "-140px 0",
        action: "poe_Bold"
    },
    "Color": {
        name: "棰滆壊",
        iconCls: "poe_color",
        position: "-220px 0",
        action: "",
        mouseover: "poe_Color"
    },
    "Link": {
        name: "瓒呴摼鎺�",
        iconCls: "poe_link",
        position: "-380px 0",
        action: "",
        mouseover: "poe_Link"
    },
    "Bus": {
        name: "姹借溅",
        iconCls: "poe_bus",
        position: "-670px 0",
        action: "poe_Traffic"
    },
    "Plain": {
        name: "椋炴満",
        iconCls: "poe_plain",
        position: "-690px 0",
        action: "poe_Traffic"
    },
    "Train": {
        name: "鐏溅",
        iconCls: "poe_train",
        position: "-730px 0",
        action: "poe_Traffic"
    },
    "Ship": {
        name: "杞埞",
        iconCls: "poe_ship",
        position: "-710px 0",
        action: "poe_Traffic"
    },
    "Preview": {
        name: "棰勮",
        iconCls: "poe_preview",
        position: "-580px 0",
        action: "poe_Preview"
    }
}
$m.publicMenuAction = {
    poe_Save: function(e) {
        this.setLocalStorage.call(this);
        this.save_flag = true;
    },
    poe_Bold: function(e) {
        try {
            this.doc.execCommand("bold", false, null);
        } catch(e) {}
    },
    poe_History: function() {
        if (this.save_flag) {
            var node = this.getLocalStorage();
            this.setPOHtml(node);
        } else {
            this.msgShow('鎮ㄥ皻鏈繚瀛橈紝璇峰厛淇濆瓨', false);
        }
    },
    poe_Color: function(e) {
        var self = this;
        var colorBtn = "width:20px;height:10px;border:1px solid #CCC;margin:2px;cursor:pointer;float:left;"
        var html = $("<div class='poe_win_selectColor'></div>");
        var hitemColors = "",
        css = "";
        $.each(this.itemColors,
        function(i, n) {
            hitemColors += "<div val='" + n + "' style='" + colorBtn + "background-color:" + n + ";'></div>";
            css += "*._" + n.substring(1) + "{color:" + n + "}";
        });
        html.html(hitemColors);
        if ($(".poe_win_selectColor", this.poeWin).length == 0) {
            this.poeWin.append(html);
            $(".poe_win_selectColor", this.poeWin).siblings().hide();
            this.showWin(e);
        } else {
            $(".poe_win_selectColor", this.poeWin).show();
            $(".poe_win_selectColor", this.poeWin).siblings().hide();
            this.showWin(e);
            return;
        }
        $(".poe_win_selectColor div", this.poeWin).each(function(i, n) {
            $(n).bind('mousedown',
            function(e) {
                var color = $(this).attr("val");
                var colorSelecter = self.rangy.createCssClassApplier('colorSelecter_span', true);
                colorSelecter.applyToSelection();
                $('.colorSelecter_span').removeClass().addClass("_" + color.substring(1));
            })
        });
        return false;
    },
    poe_Link: function(e) {
        var self = this;
        var linkAppliers = [];
        var rng,
        linkSpanApplier,
        saveLinkSel = null,
        savedSelActiveElement;
        var colorBtn = "width:20px;height:10px;border:1px solid #CCC;margin:2px;cursor:pointer;float:left;"
        var html = $("<div class='poe_win_insertLink' style='font-size:13px;'>閾炬帴鍦板潃锛�<input type='text' value='http://' style='width:200px;'/><div style='text-align:right;margin:10px 0 5px;'><input type='button' class='tuniubtn' id='oklink' value='娣诲姞閾炬帴' /><input style='margin-left:3px;' type='button' class='tuniubtn' id='cancellink' value='娓呴櫎閾炬帴' /></div></div>");
        if ($("#POEStyleByLink").length == 0) $("head").append("<style id='POEStyleByLink'>*.poeLink{color:blue;cursor:pointer;}</style>");
        if ($(".poe_win_insertLink", this.poeWin).length == 0) {
            this.poeWin.append(html);
            $(".poe_win_insertLink", this.poeWin).siblings().hide();
            this.showWin(e);
        } else {
            $(".poe_win_insertLink", this.poeWin).show();
            $(".poe_win_insertLink", this.poeWin).siblings().hide();
            this.showWin(e);
            return;
        }
        $('input[type=text]', html).mousedown(function(e) {
            try {
                rng = self.getFirstRange();
                if (rng.sel.isCollapsed == false && $(rng.rang.startContainer).attr('id') != 'tempDivForClipboard') {
                    $('.rangySelectionBoundary').remove()
                     $('br[type="_moz"]').remove()
                     saveLinkSel = self.rangy.saveSelection();
                }
                savedSelActiveElement = document.activeElement;
            } catch(ex) {}
        });
        $("#oklink", html).mousedown(function(e) {
            var tempValue = $("input", html).val();
            var div = $('<div />').append(tempValue).clone();
            var slinkValue = div.text().replace(/javascript\s*:/g, '').replace(/<[\/\s]*script\s*/g, '');
            if (saveLinkSel != null) {
                self.rangy.restoreSelection(saveLinkSel, false);
                saveLinkSel = null;
                window.setTimeout(function() {
                    if (savedSelActiveElement && typeof savedSelActiveElement.focus != "undefined") {
                        savedSelActiveElement.focus();
                    }
                },
                1);
            }
            if (slinkValue != "" && slinkValue != "http://") {
                if (!/^[\s\S](\w+):\/\//.test(slinkValue)) slinkValue = 'http://' + slinkValue;
                try {
                    if (self.doc.execCommand("createLink", false, slinkValue)) {
                        var rng = self.getFirstRange();
                        var nodesList = rng.rang.getNodes();
                        for (var i in nodesList) {
                            if (nodesList[i].parentNode.nodeName == 'A')
                             $(nodesList[i].parentNode).attr('target', '_blank');
                        }
                    }
                } catch(e) {}
            }
            self.hideWin(e);
            Event.fireEvent("hideWindow");
        });
        $("#cancellink", html).mousedown(function(e) {
            var rng = self.getFirstRange();
            if (rng.rang.collapsed && rng.rang.startContainer.parentNode.nodeName == 'A') {
                rng.sel.selectAllChildren(rng.rang.startContainer.parentNode)
            }
            try {
                self.doc.execCommand("unlink", false, true);
            } catch(e) {}
            self.hideWin(e);
            Event.fireEvent("hideWindow");
        });
        return false;
    },
    poe_Traffic: function(e, item) {
        var img = $("<img src='" + this.imageUri + item.toLowerCase() + ".gif'/>");
        var rng = this.getFirstRange();
        var day_title_new,
        parentElement;
        if (rng.rang.startContainer.parentElement) {
            parentElement = rng.rang.startContainer.parentElement;
        } else {
            parentElement = rng.rang.startContainer.parentNode;
        }
        if ($(rng.rang.startContainer).children().size() == 0) {
            day_title_new = parentElement.parentNode.parentNode;
        } else {
            day_title_new = parentElement.parentNode;
        }
        if (day_title_new.className != "day_title_new") {
            return;
        }
        if (rng.rang) {
            rng.rang.deleteContents();
            rng.rang.insertNode(img[0]);
            if (rng.rang.endContainer.nodeName == "DIV") {
                rng.rang.endContainer.focus();
                rng.sel.collapse(rng.rang.endContainer, rng.rang.endOffset + 1);
            } else {
                parentElement.focus();
                rng.sel.collapseToEnd();
            }
        }
    },
    poe_Preview: function() {
        var win = window.open("about:blank");
        win.document.write("<html><head><link rel='stylesheet' href='" + this.cssPath + this.template + ".css?v=20130904' type='text/css'/></head><body>" + this.getPOHtml() + "</body></html>");
    }
}
$m.base = {
    menu: {
        "Star": {
            name: "鈽�",
            iconCls: "",
            action: "poe_Star"
        }
    },
    action: {
        poe_Star: function() {
            var spn = $("<span>鈽�</span>");
            var rng = this.getFirstRange();
            var base_Section,
            parentElement;
            base_Section = rng.rang.startContainer;
            if (($(base_Section).hasClass('baseSection')) || (($(base_Section).parentsUntil('.baseSection').length > 0) && ($(base_Section).parentsUntil('.baseSection').last().get(0).nodeName != "HTML")) || ($(base_Section).parent().hasClass('baseSection'))) {
                if (rng.rang) {
                    rng.rang.deleteContents();
                    rng.rang.insertNode(spn[0]);
                    base_Section.focus();
                    rng.sel.collapse(rng.rang.endContainer, rng.rang.endOffset + 1);
                }
            }
        }
    }
}
$m.niuren = {
    menu: {
        "poe_Journey": {
            name: "娣诲姞琛岀▼",
            iconCls: "",
            action: "poe_niuren_Journey"
        },
        "poe_Description": {
            name: "琛岀▼鎻忚堪",
            iconCls: "",
            action: "poe_niuren_Description"
        },
        "poe_FParagraph": {
            name: "鏃堕棿娈�",
            iconCls: "",
            action: "poe_niuren_FParagraph"
        },
        "poe_STitle": {
            name: "灏忔爣棰�",
            iconCls: "",
            action: "poe_niuren_STitle"
        },
        "poe_SParagraph": {
            name: "灏忔爣棰樻鏂�",
            iconCls: "",
            action: "poe_niuren_SParagraph"
        },
        "poe_Picture": {
            name: "娣诲姞鍥剧墖",
            iconCls: "",
            action: "",
            mouseover: "poe_niuren_over_Picture"
        },
        "poe_Dining": {
            name: "鐢ㄩ",
            iconCls: "",
            action: "poe_niuren_Dining"
        },
        "poe_Accommodation": {
            name: "浣忓",
            iconCls: "",
            action: "poe_niuren_Accommodation"
        },
        "poe_ShoppingStores": {
            name: "璐墿搴�",
            iconCls: "",
            action: "",
            mouseover: "poe_niuren_ShoppingStores"
        }
    },
    action: {
        poe_niuren_Journey: function(title, em, flag) {
            var self = this;
            this.day = $('.tourContent_new', self.container).length + 1;
            var journey = this.tlp["tlp" + this.template].poe_Journey().replace(/{day}/g, this.day);
            journey = $(journey);
            if (!window.getSelection) {
                self.menuContainer.bind('click',
                function() {
                    $("*[contenteditable='true']", self.editorArea).bind('click',
                    function(e) {
                        try {
                            if (self.saveSel) {
                                rangy.removeMarkers(self.saveSel);
                                $('.rangySelectionBoundary').remove()
                                 $('br[type="_moz"]').remove()
                            }
                            if ($(self.rangy.getSelection().getRangeAt(0).startContainer).text() == '') {
                                var textNode = document.createTextNode(' ')
                                 $(self.rangy.getSelection().getRangeAt(0).startContainer).html(textNode);
                                self.rangy.setEndAfter(textNode)
                            }
                            self.saveSel = self.rangy.saveSelection();
                        } catch(ex) {}
                    });
                    $("*[contenteditable='true']", self.editorArea).unbind('keypress').bind('keypress',
                    function(e) {
                        try {
                            if (self.saveSel) {
                                rangy.removeMarkers(self.saveSel);
                                $('.rangySelectionBoundary').remove()
                                 $('br[type="_moz"]').remove()
                            }
                            if ($(self.rangy.getSelection().getRangeAt(0).startContainer).text() == '') {
                                var textNode = document.createTextNode(' ')
                                 $(self.rangy.getSelection().getRangeAt(0).startContainer).html(textNode);
                                self.rangy.setEndAfter(textNode)
                            }
                            self.saveSel = self.rangy.saveSelection();
                        } catch(ex) {}
                    })
                })
            }
            this.tourSection.append(journey);
            if (arguments.length == 3 && title && em && flag) {
                $(".day_title_new h3 em", journey).html(em);
                $(".day_title_new h3 div", journey).html(title);
            }
            $(".day_title_new:last div", this.tourSection).bind("focus",
            function() {
                self.setActiveElement();
            })
             $(".day_title_new:last div", this.tourSection).focus();
            var rng = this.getFirstRange();
            rng.sel.selectAllChildren($(".day_title_new:last div", this.tourSection)[0]);
            this.setActiveElement();
            $(".day_title_new h3 em", this.tourSection).each(function(i, n) {
                self[self.template + "DelContent"].poe_niuren_del_Journey.call(self, i, n, $(n).parent().parent().parent());
            });
        },
        poe_niuren_Description: function(cnt) {
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var description = $(this.tlp["tlp" + this.template].poe_Description());
            if (arguments.length == 1 && cnt) {
                description.html(cnt);
            }
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            if (day_title_new[0].className == "day_title_new") {
                day_title_new.append(description);
            } else {
                if (day_title_new[0].className == "time_box_inner clearfix") {
                    day_title_new.parent().children().first().children().last().after(description);
                } else {
                    $(activeElm).after(description);
                }
            }
            $("div.tour_line", $(day_title_new)).unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            })
             description.focus();
            try {
                rng.sel.selectAllChildren(description[0]);
                self.setActiveElement();
            } catch(e) {}
            $("div.tour_line", $(this.tourSection)).each(function(i, n) {
                self[self.template + "DelContent"].poe_niuren_del_Description.call(self, i, n, n);
            });
        },
        poe_niuren_FParagraph: function(cnt) {
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var time_do_new = $(activeElm).parent();
            var insertNodeParent = $(activeElm).parent().parent();
            var tourContent_new = $(activeElm).parent().parent().parent();
            var time_num = $(this.tlp["tlp" + this.template].poe_FParagraph());
            if (arguments.length == 1 && cnt) {
                var cnthtml = cnt.split("%^&");
                var tourconhtml = cnthtml[0];
                var tourdeschtml = cnthtml[1];
                $(".tour_con", time_num).html(tourconhtml);
                $(".tour_description", time_num).html(tourdeschtml);
            }
            if ((insertNodeParent.length > 0 && insertNodeParent[0].className != "day_title_new") && (time_do_new.length > 0 && time_do_new[0].className != "time_num" && time_do_new[0].className != "time_do_new" && activeElm.className != "tour_line")) {
                return;
            }
            if (activeElm && activeElm.className == "tour_line") {
                insertNodeParent = $(activeElm).parent();
            }
            if (insertNodeParent.length > 0 && insertNodeParent[0].className == "day_title_new") {
                if (insertNodeParent.nextAll().last().length > 0) {
                    insertNodeParent.nextAll().last().after(time_num);
                } else {
                    insertNodeParent.after(time_num);
                }
            } else {
                $(insertNodeParent).after(time_num);
            }
            $("div.tour_con", time_num).unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            })
             $("div.tour_con", time_num).focus();
            $("div.tour_description", time_num).unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            })
             try {
                rng.sel.selectAllChildren($("div.tour_con", time_num)[0]);
                self.setActiveElement();
            } catch(e) {}
            $("div.tour_con", $(time_num, this.tourSection)).each(function(i, n) {
                self[self.template + "DelContent"].poe_niuren_del_FParagraph.call(self, i, n, $(n).parent().parent());
            });
        },
        poe_niuren_STitle: function(cnt) {
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var time_do_new = $(activeElm).parent();
            var time_box_inner = $(activeElm).parent().parent();
            var h4 = $(this.tlp["tlp" + this.template].poe_STitle());
            if (arguments.length == 1 && cnt) {
                h4.html(cnt);
            } else {
                if (time_do_new.length == 0) return;
                if (time_do_new.length > 0 && time_do_new[0].className != "time_num" && time_do_new[0].className != "time_do_new" && time_do_new[0].nodeName != "LI") {
                    return;
                }
            }
            if (time_do_new[0].className == "time_num") {
                time_do_new.next().append(h4);
            } else if (time_do_new[0].nodeName == "LI") {
                time_do_new.parent().after(h4);
            } else {
                $(activeElm).after(h4);
            }
            $("div.tour_con_h4", $(time_box_inner)).unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            })
             $(h4).focus();
            try {
                rng.sel.selectAllChildren(h4[0]);
                self.setActiveElement();
            } catch(e) {}
            $("div.tour_con_h4", $(h4).parent()).each(function(i, n) {
                self[self.template + "DelContent"].poe_niuren_del_STitle.call(self, i, n, n);
            });
        },
        poe_niuren_SParagraph: function(cnt) {
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var time_do_new = $(activeElm).parent();
            var time_box_inner = $(activeElm).parent().parent();
            var p = $(this.tlp["tlp" + this.template].poe_SParagraph());
            if (arguments.length == 1 && cnt) {
                p.html(cnt);
            } else {
                if (time_do_new.length == 0) return;
                if (time_do_new.length > 0 && time_do_new[0].className != "time_num" && time_do_new[0].className != "time_do_new" && time_do_new[0].nodeName != "LI") {
                    return;
                }
            }
            if (time_do_new[0].className == "time_num") {
                time_do_new.next().append(p);
            } else if (time_do_new[0].nodeName == "LI") {
                time_do_new.parent().after(p);
            } else {
                $(activeElm).after(p);
            }
            $("div.tour_con", $(time_box_inner)).unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            });
            p.focus();
            try {
                rng.sel.selectAllChildren(p[0]);
                self.setActiveElement();
            } catch(e) {}
            $("div.tour_con", $(p).parent()).each(function(i, n) {
                self[self.template + "DelContent"].poe_niuren_del_SParagraph.call(self, i, n, n);
            });
        },
        poe_niuren_over_Picture: function(e) {
            var self = this;
            var spanBtn = "position: relative;border:1px solid #999;padding:2px 3px;margin:3px;float:left;display:block;cursor: pointer;line-height:18px;";
            var html = $("<div class='poe_win_selectImages'></span><div style='margin-bottom:5px;'><div id='uploadBtn' style='margin-right: 20px;display: inline-block;'></div><a id='uploadPics' class='tuniubtn btn-primary' style='font-size:12px;margin-left:-60px;'><i class='icon-search'></i>閫夋嫨璧勬簮搴撳浘鐗�</a><a style='margin-left: 40px;' id='clear'>娓呯┖棰勮</a></div><!-- <div style='margin:3px;font-size:13px;display:none;' class='picSource'>鍥剧墖ID锛�<input style='border:1px solid #ccc;' type='text'/><button>鍥剧墖璇诲彇</button></div> --><div class='poe_win_imgList' style='font-size:13px;'><div style='border:1px solid #CCC;width:auto;padding-bottom:0px;margin-bottom:0px;'><div style='width:400px;height:180px;overflow-y:auto;'><ul style='list-style:none;margin:0;padding:0;'></ul></div></div><div style='text-align:left;padding-top:5px;'><button id='insertImg' type='button' style='font-size:12px;' class='tuniubtn btn-primary'><i class='icon-plus'></i>娣诲姞</button></div></div></div>");
            $("#clear", html).unbind("click").click(function() {
                $("ul", html).empty();
            });
            var oldUrlHash = location.hash;
            var uploadFile = new UploadFile({
                renderTo: $("#uploadBtn", html),
                system: "Lines",
                folder: "LinesEdit",
                cnd: "0",
                url: nb.subSystem + "Plugin/tuniu/net/upload.ashx",
                complete: function(str) {
                    location.hash = oldUrlHash + '&';
                    //var temp = str.url.split(/\/(?!\/)/);
                    //var srcValue = str.url;
                    //var imgName = temp[temp.length - 1].split('.')[0] + "_w320_h240_c1_t0." + temp[temp.length - 1].split('.')[1];
                    //temp[temp.length - 1] = imgName;
                    var imgName = str.url;
                    var li = $("<li style='margin-left:3px;margin-bottom:6px;position:relative' class='span3'><div class='thumbnail'><a class='thumbnail'><img width='160' height='120' style='height:51px;' src='" + imgName + "'/></a><div class='caption' style='padding:0px;'></div></div></li>");
                    li.unbind("mouseenter").mouseenter(function() {
                        var a = $('<a class="close" style="z-index:2;opacity:0.7;filter:alpha(opacity=70);background-color:#FFF;position:absolute;top:8px;left:10px;">脳</a>');
                        $(this).append(a);
                        a.unbind("click").click(function() {
                            li.remove();
                        });
                    }).unbind("mouseleave").mouseleave(function() {
                        $("a.close", li).remove();
                    });
                    $("ul", html).append(li);
                    var nn = 1;
                    $('img', li).error(function(e) {
                        if (nn == 1) {
                            var img = $(this);
                            img.attr('src', img.attr('src').replace(/\?\d+$/, '') + '?' + new Date().getTime()).removeAttr('alt');
                            nn++;
                        } else {
                            return false;
                        }
                    });
                }
            });
            if ($(".poe_win_selectImages", this.poeWin).length == 0) {
                this.poeWin.append(html);
                $(".poe_win_selectImages", this.poeWin).siblings().hide();
                this.showWin(e);
            } else {
                $(".poe_win_selectImages", this.poeWin).show();
                $(".poe_win_selectImages", this.poeWin).siblings().hide();
                this.showWin(e);
                return;
            }
            $("#insertImg", html).unbind("click").click(function(e) {
                if ($("#innerCancelUploadFile").length != 0) {
                    $("#innerCancelUploadFile").click();
                }
                var arrImgUrl = [];
                $.each($("ul li img", html),
                function(i, n) {
                    arrImgUrl.push({
                        src: $(this).attr("src"),
                        name: $(this).attr("title")
                    });
                });
                $.each(arrImgUrl,
                function(i, n) {
                    insertImg.call(self, e, n.src, n.name);
                });
            });
            function insertImg(e, imgUrl, imgName) {
                var self = this;
                window.event ? e.target = window.event.srcElement: e.target;
                var rng = self.getFirstRange();
                var activeElm = self.getActiveElement();
                var ul = $(self.tlp["tlp" + self.template].poe_ImgList());
                var li = $(self.tlp["tlp" + self.template].poe_ImgListItem(imgName));
                var img = $("<img />").attr("src", imgUrl).removeAttr("style").css({
                    "width": "320px",
                    "height": "240px"
                });
                var imgTitle = $("div", li);
                $("a", li).append(img);
                var aLink = $('a img', li).attr('src');
                $("a", li).attr('href', imgUrl).addClass('niuren_light');
                if ($(activeElm).parent().length == 0) {
                    if (imgUrl == $("ul li img:last", html).attr("src")) {
                        self.msgShow("璇烽€夋嫨琛岀▼缂栬緫鍣ㄦ坊鍔犲浘鐗囩殑浣嶇疆锛�");
                    };
                    return;
                }
                if (!($(activeElm).parent()[0].className == "time_do_new" || $(activeElm).parent()[0].className == "day_title_new") && $(activeElm).parent()[0].nodeName != "LI") {
                    if (imgUrl == $("ul li img:last", html).attr("src")) {
                        self.msgShow("璇烽€夋嫨琛岀▼缂栬緫鍣ㄦ坊鍔犲浘鐗囩殑浣嶇疆锛�");
                    };
                    return;
                }
                if ($(activeElm).next().length == 0 || ($(activeElm).next().length > 0 && $(activeElm).next()[0].nodeName != "UL")) {
                    if ($(activeElm).parent()[0].nodeName != "LI") {
                        $(activeElm).after(ul);
                        if($(activeElm).parent()[0].className == "day_title_new"){
                           $(activeElm).next().wrap("<div></div>");
                        }   
                        if (ul.children().length >= 7) {
                            if (imgUrl == $("ul li img:last", html).attr("src")) {
                                self.msgShow("姣忚绋嬫椂闂存鍐呮渶澶氬彧鑳芥坊鍔�8寮犲浘鐗囷紒");
                            };
                            return;
                        };
                        ul.append(li);
                    } else {
                        if ($(activeElm).parent().index() >= 7) {
                            if (imgUrl == $("ul li img:last", html).attr("src")) {
                                self.msgShow("姣忚绋嬫椂闂存鍐呮渶澶氬彧鑳芥坊鍔�8寮犲浘鐗囷紒");
                            };
                            return;
                        }
                        $(activeElm).parent().after(li);
                    }
                } else {
                    if ($(activeElm).next().children().length >= 7) {
                        if (imgUrl == $("ul li img:last", html).attr("src")) {
                            self.msgShow("姣忚绋嬫椂闂存鍐呮渶澶氬彧鑳芥坊鍔�8寮犲浘鐗囷紒");
                        };
                        return;
                    }
                    $(activeElm).next().append(li);
                }
                $("li div", $(activeElm).parent()).unbind("focus").bind("focus",
                function() {
                    self.setActiveElement();
                });
                imgTitle.focus();
                rng.sel.selectAllChildren(imgTitle[0]);
                self.setActiveElement();
                self[self.template + "DelContent"].poe_niuren_del_over_Picture.call(self, 0, img, li);
                $('.niuren_light').click(function(e) {
                    e.preventDefault ? e.preventDefault() : window.event.returnValue = false;
                });
            }
            $("#uploadPics", html).unbind('click').click(function() {
                self.noty = new Noty();
                var addHtml = $('<div id="imgInfo" style="min-height:200px;max-height:480px;overflow-x:hidden;overflow-y: auto;"><div class="alert alert-warning">娉ㄦ剰锛氭瘡琛岀▼鏃堕棿娈靛唴鏈€澶氭敮鎸佹坊鍔� <strong>8 寮�</strong>鍥剧墖銆�</div><div class="row"><div class="span6 ml0"><select class="keytype" name="keytype"><option value="1">鏈嚎璺浘鐗�</option><option value="2">绾胯矾鍥惧簱</option><option value="3">閰掑簵鍥惧簱</option><option value="4">鏅偣鍥惧簱</option><option value="5">鍟嗗煄鍥惧簱</option><option value="6">绉熻溅鍥惧簱</option></select> <input class="key" type="text" placeholder="璇疯緭鍏ュ叧閿瘝" name="key" /><a style="margin-left:10px;" id="searchBtn" class="tuniubtn btn-primary"><i class="icon-search"></i>鎼滅储</a></div></div><div class="poe_win_imgList" style="font-size:13px;"><fieldset><legend>鍥剧墖棰勮</legend><ul id="imgPreviewList" style="list-style:none;margin:0;padding:0;"></ul></fieldset></div></div>');
                $('.typeahead', addHtml).keyup(function(e) {
                    e = window.event || e;
                    if (e.keyCode == 13) {
                        $('#searchBtn', addHtml).click();
                    }
                });
                setTimeout(function() {
                    $('.typeahead', addHtml).focus();
                },
                10);
                var win = self.win_1 = new WinForm({
                    title: "鍥剧墖淇℃伅",
                    node: addHtml,
                    css: {
                        top: "20%",
                        width: "84%",
                        left: "6%"
                    },
                    cancelText: "鍏抽棴",
                    submit: function() {
                        var arrImgUrl = [];
                        $.each($("input[type='checkbox']", addHtml),
                        function(i, n) {
                            if ($(this)[0].checked) {
                                arrImgUrl.push({
                                    src: $(this).attr("imgUrl"),
                                    name: $(this).parent().text()
                                });
                            }
                        });
                        if (arrImgUrl.length == 0) {
                            self.noty.error("璇烽€夋嫨瑕佹坊鍔犵殑鍥剧墖锛�");
                            return;
                        }
                        if (arrImgUrl.length > 8) {}
                        win.hide();
                        $.each(arrImgUrl,
                        function(i, n) {
                            var li = $("<li style='margin-left:3px;margin-bottom:6px;position:relative;' class='span3'><div class='thumbnail'><a class='thumbnail'><img width='200' height='150' style='height:51px;' src='" + arrImgUrl[i].src + "' title='" + arrImgUrl[i].name + "'/></a><div class='caption' style='padding:0px;'></div></div></li>");
                            li.unbind("mouseenter").mouseenter(function() {
                                var a = $('<a class="close" style="z-index:2;opacity:0.7;filter:alpha(opacity=70);background-color:#FFF;position:absolute;top:8px;left:10px;">脳</a>');
                                $(this).append(a);
                                a.unbind("click").click(function() {
                                    li.remove();
                                });
                            }).unbind("mouseleave").mouseleave(function() {
                                $("a.close", li).remove();
                            });
                            $("ul", html).append(li);
                        });
                    }
                });
                win.show();
                $("#searchBtn", addHtml).unbind("click").click(function() {
                    var flag = true;

                    var spinner;
                    var limitNum = 20;
                    tn.ajax.request({
                        type: "GET",
                        url: self.imageUrl,
                        data: {
                            q: $('.key', addHtml).val(),
                            tag: $('.keytype', addHtml).val(),
                            lid: $('#Lid').val(),
                            limit: limitNum
                        },
                        listener: {
                            beforerequest: function() {
                                $('#searchBtn', addHtml).attr('disable')
                                 if ($.browser.msie && $.browser.version == "8.0") {} else {
                                    spinner = new Spinner(SpinnerOpts).spin($("#imgPreviewList", addHtml));
                                }
                            },
                            success: function(json) {
                                if (json.success) {
                                    if ($.browser.msie && $.browser.version == "8.0") {} else {
                                        spinner.stop();
                                    }
                                    self.photosUrlArr = [];
                                    $("#imgPreviewList", addHtml).empty();
                                    if (!json.data.count > 0) {
                                        $("#imgPreviewList", addHtml).html("瀵逛笉璧凤紝鏃犵浉鍏冲浘鐗囷紝璇烽噸鏂版悳绱紒");
                                        $('.typeahead', addHtml).val("").removeAttr("id").focus();
                                    } else {
                                        var totalCount = 1,
                                        arr = [],
                                        otherAddFlag = false;
                                        $.each(json.data.rows,
                                        function(i, n) {
                                            for (var j in n.picUrl) {
                                                if (totalCount <= 12) {
                                                    var temp = n.picUrl[j];

                                                    var li = $("<li style='height: 200px;margin-left:3px;margin-bottom:3px;' class='span3'><div class='thumbnail'><a class='thumbnail'  style='min-height:150px;'><img width='200' height='150' style='width:200px;height:150px;' src='" + temp + "'/></a><div class='caption ellipsis' style='padding:0px;' title='鍚嶇О锛�" + n.name + "'><label style='display:inline'><input type='checkbox' imgUrl='" + temp + "' placeholder='' />" + n.name + "</label></div></div></li>");
                                                    $('img', li).error(function(e) {
                                                        var img = $(this);
                                                        var div = $('<div style="">鍥剧墖杞藉叆澶辫触锛岀偣鍑婚噸璇�</div>').css({
                                                            "position": "absolute",
                                                            "text-align": "center",
                                                            "top": img.position().top + 70,
                                                            "width": img.parent().width(),
                                                            "left": img.parent().position().left
                                                        });
                                                        img.before(div);
                                                        div.unbind('mousedown').mousedown(function() {
                                                            $(this).remove()
                                                             img.attr('src', img.attr('src').replace(/\?\d+$/, '') + '?' + new Date().getTime()).removeAttr('alt')
                                                        })
                                                    });
                                                    $("img", li).unbind("click").click(function(e) {
                                                        var input = $("input", $(this).parents('li:first'))[0];
                                                        if (input.checked) {
                                                            input.checked = false;
                                                        } else {
                                                            input.checked = true;
                                                        }
                                                    });
                                                    $("#imgPreviewList", addHtml).append(li);
                                                } else {
                                                    var num = (totalCount - 1) % 4;
                                                    if (num == 0) {
                                                        if (arr.length != 0) {
                                                            self.photosUrlArr.push(arr);
                                                            otherAddFlag = true;
                                                        }
                                                        arr = [];
                                                    } else {
                                                        otherAddFlag = false;
                                                    }
                                                    arr.push({
                                                        url: n.picUrl[j],
                                                        name: n.name,
                                                        showFlag: 0
                                                    });
                                                }
                                                totalCount++;
                                            }
                                        });
                                        if (otherAddFlag == true)
                                         self.photosUrlArr.push(arr);
                                        if (json.data.count > limitNum) {
                                            $('#imgInfo').scrollTop(0)
                                        } else {
                                            $('#imgInfo').scrollTop(0)
                                        }
                                        var t = 0;
                                        $("#imgInfo").scroll(function() {
                                            var nowTop = $(this).scrollTop();
                                            if (nowTop && nowTop > 0) {
                                                if (t < self.photosUrlArr.length && nowTop > $('#imgInfo .poe_win_imgList').height() - $(this).height() - 10) {
                                                    $.each(self.photosUrlArr[t],
                                                    function(i, n) {
                                                        if (n.showFlag == 0) {
                                                            var temp = n.url;
                                                            var li = $("<li style='height: 200px;margin-left:3px;margin-bottom:3px;' class='span3'><div class='thumbnail'><a class='thumbnail'  style='min-height:150px;'><img width='200' height='150' style='width:200px;height:150px;' src='" + temp + "'/></a><div class='caption ellipsis' style='padding:0px;' title='鏅偣鍚嶇О锛�" + n.name + "'><label style='display:inline'><input type='checkbox' imgUrl='" + temp + "' placeholder='' />" + n.name + "</label></div></div></li>");
                                                            $('img', li).error(function(e) {
                                                                var img = $(this);
                                                                var div = $('<div style="">鍥剧墖杞藉叆澶辫触锛岀偣鍑婚噸璇�</div>').css({
                                                                    "position": "absolute",
                                                                    "text-align": "center",
                                                                    "top": img.position().top + 70,
                                                                    "width": img.parent().width(),
                                                                    "left": img.parent().position().left
                                                                });
                                                                img.before(div);
                                                                div.unbind('mousedown').mousedown(function() {
                                                                    $(this).remove()
                                                                     img.attr('src', img.attr('src').replace(/\?\d+$/, '') + '?' + new Date().getTime()).removeAttr('alt')
                                                                })
                                                            });
                                                            $("img", li).unbind("click").click(function(e) {
                                                                var input = $("input", $(this).parents('li:first'))[0];
                                                                if (input.checked) {
                                                                    input.checked = false;
                                                                } else {
                                                                    input.checked = true;
                                                                }
                                                            });
                                                            $("#imgPreviewList", addHtml).append(li);
                                                            n.showFlag = 1;
                                                        }
                                                    });
                                                    t++;
                                                }
                                            }
                                        });
                                    }
                                }
                            }
                        }
                    });
                });
            });
            function addGreylay(flag) {
                if (flag == true) {
                    $('.poe_win_imgList', html).after("<div id='greylay' style='position:absolute;top:56px;left:16px;background:black;opacity:0.3;z-index:9999;width:400px;height:165px;'></div>");
                } else if (flag == false) {
                    $('#greylay').remove();
                }
            }
            function checkUploadBtnForFileinput() {
                var flag_b = !!$('.poe_win_imgList', html).has('img').length;
                if (flag_b) {
                    $('#uploadPics', html).css({
                        'color': 'black',
                        'cursor': 'pointer'
                    });
                    $("#uploadPics", html).unbind('click').bind('click', uploadAction);
                } else {
                    $('#uploadPics', html).css({
                        'color': 'grey',
                        'cursor': 'default'
                    });
                    $("#uploadPics", html).unbind('click').unbind('click');
                }
            }
        },
        poe_niuren_Dining: function(cnt, template) {
            var template = template && template != "poe_Dining" ? template: this.template;
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var insertNode;
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            var tourfood = $(this.tlp["tlp" + template].poe_Tourfood());
            var dining = $(this.tlp["tlp" + template].poe_Dining());
            if (arguments.length == 1 && cnt) {
                dining.html(cnt);
            }
            if (arguments.length == 2 && typeof cnt == "string" && template == "niuren") {
                dining.html(cnt);
            }
            if (day_title_new[0].className == "tourContent_new") {
                insertNode = day_title_new;
            } else {
                insertNode = day_title_new.parent();
            }
            if ($('.tour_shop', insertNode).length > 0 && $(".tour_food", insertNode).size() == 0) {
                tourfood.append(dining);
                $('.tour_shop', insertNode).before(tourfood);
            } else {
                if ($(".tour_food", insertNode).size() == 0) {
                    tourfood.append(dining);
                    insertNode.append(tourfood);
                } else {
                    $(".tour_food", insertNode).append(dining);
                }
            }
            $("div", dining).attr('contenteditable', 'true');
            $("div", dining).focus();
            try {
                rng.sel.selectAllChildren($('.po_dining_diy', dining)[0]);
            } catch(e) {}
            $("div.tour_item em", $(insertNode)).each(function(i, n) {
                self[template + "DelContent"].poe_niuren_del_Dining.call(self, i, n, $(n).parent());
            });
        },
        poe_niuren_Accommodation: function(cnt, template) {
            var template = template && template != "poe_Accommodation" ? template: this.template;
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var insertNode;
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            var tourfood = $(this.tlp["tlp" + template].poe_Tourfood());
            var accommodation = $(this.tlp["tlp" + template].poe_Accommodation());
            if (day_title_new[0].className == "tourContent_new") {
                insertNode = day_title_new;
            } else {
                insertNode = day_title_new.parent();
            }
            if ($(".tour_food", insertNode).size() == 0) {
                tourfood.append(accommodation);
                insertNode.append(tourfood);
            } else {
                $(".tour_food", insertNode).append(accommodation);
            }
            $("div", accommodation).focus();
            try {
                rng.sel.selectAllChildren($("div", accommodation)[0]);
            } catch(e) {}
            $("div.tour_item em", $(insertNode)).each(function(i, n) {
                self[template + "DelContent"].poe_niuren_del_Accommodation.call(self, i, n, $(n).parent());
            });
        },
        poe_niuren_ShoppingStores: function(e, template) {
            var template = template && template != "poe_ShoppingStores" ? template: this.template;
            var self = this;
            var spanBtn = "position: relative;border:1px solid #999;padding:2px 3px;margin:3px;float:left;display:block;cursor: pointer;line-height:18px;";
            var html = $("<div id='poe_win_addShoppingStores'><div><a class='tuniubtn btn-info' href='javascript:void(0);' style='display:none;font-size:12px;height:19px;' id='addTotable'><i class='icon-ok'></i>娣诲姞琛�</a></div><div id='sp_searchHint' style='position:absolute; top:28px;left:5px;width:250px;background:#fff;border:1px solid grey;display:none;font-size:12px;'><ul style='margin:0;padding:0;list-style:none;'><li style='padding:2px;'>abcde</li><li style='padding:2px;'>bcdef</li><li style='padding:2px;'>cdefg</li></ul></div><div><table id='shopppingStoreTable_" + self.shopping_store_id + "' border='1' bordercolor='#ddd' cellspacing='0' cellpadding='4' style='border-collapse:collapse;font-size:12px;'><tr><th style='width:90px;background-color: #F6F6F6;padding: 2px;text-align: center;'>鍚嶇О</th><th style='width:140px;background-color: #F6F6F6;padding: 2px;text-align: center;'>钀ヤ笟浜у搧</th><th style='width:100px;background-color: #F6F6F6;padding: 2px;text-align: center;'>鍋滅暀鏃堕棿</th><th style='width:240px;background-color: #F6F6F6;padding: 2px;text-align: center;'>璇存槑</th><th style='width:52px;background-color: #F6F6F6;padding: 2px;text-align: center;'>鎿嶄綔</th></tr></table></div><div style='text-align:left;padding-top:5px;'><button class='tuniubtn btn-primary' type='button' id='insertShoppingStore' style='font-size:12px;'><i class='icon-plus'></i>娣诲姞</button></div></div>");
            if ($("#poe_win_addShoppingStores").length == 0) {
                this.poeWin.append(html);
                $("#poe_win_addShoppingStores").siblings().hide();
                this.showWin(e);
            } else {
                $("#poe_win_addShoppingStores").show();
                $("#poe_win_addShoppingStores").siblings().hide();
                this.showWin(e);
                return;
            }
            var shoppingStoreData;
            var suggest = new Search($('#sp_searchbox', html), {
                url: nb.subSystem + "restful/product-schedule/shop-list",
                width: 217,
                showKey: "shopName",
                searchParam: "shopName",
                attrs: ["shopId", "shopName", "mainBussinessProduct", "howLong", "description"],
                autoComplete: true
            });
            $('#sp_searchbox', html).blur(function() {
                if ($(this).attr("shopid") && $(this).attr("shopid") != -1) {
                    $("#addTotable", html).css("display", "inline-block");
                    $("#addTotable_0", html).css("display", "none");
                }
            });
            $('#addTotable', html).click(function(e) {
                var data = {};
//              data.shopName = $('#sp_searchbox', html).attr("shopname");
//              data.mainBussinessProduct = $('#sp_searchbox', html).attr("mainbussinessproduct");
//              data.howLong = $('#sp_searchbox', html).attr("howLong");
//              data.description = $('#sp_searchbox', html).attr("description");
                data.shopName="&nbsp;";
                data.mainBussinessProduct="&nbsp;";
                data.howLong="&nbsp;";
                data.description="&nbsp;";
                if ($('#sp_searchbox', html).attr("shopid") != -1) {
                    addToTable(data);
                    $(this).css("display", "none");
                    $("#addTotable_0", html).css("display", "inline-block");
                }
            });

            function addToTable(data) {
                if ( !! data) {
                    $('#shopppingStoreTable_' + self.shopping_store_id).append("<tr><td>" + data.shopName + "</td><td>" + data.mainBussinessProduct + "</td><td>" + data.howLong + "</td><td>" + data.description + "</td><td><a href='javascript:void(0)'>鍒犻櫎</a></td></tr>");
                    $('#shopppingStoreTable_' + self.shopping_store_id + ' a').click(function(e) {
                        window.event ? e.target = window.event.srcElement: e.target;
                        $(e.target).parent().parent().remove();
                    });
                } else if (data == undefined) {
                    var index;
                    for (var i in shoppingStoreData) {
                        if (shoppingStoreData[i].id == $('#shoppingStoreId_box').val()) {
                            index = i;
                            break;
                        } else {
                            index = -1;
                        }
                    }
                    $('#shopppingStoreTable_' + self.shopping_store_id).append("<tr><td>" + shoppingStoreData[i].name + "</td><td>" + shoppingStoreData[i].products + "</td><td>" + shoppingStoreData[i].times + "</td><td>" + shoppingStoreData[i].details + "</td><td><a href='javascript:void(0)'>鍒犻櫎</a></td></tr>");
                    $('#shopppingStoreTable_' + self.shopping_store_id + ' a').click(function(e) {
                        window.event ? e.target = window.event.srcElement: e.target;
                        $(e.target).parent().parent().remove();
                    });
                }
            }
            $('#insertShoppingStore').click(function() {
                self["niuren"].action["poe_niuren_insertShoppingStores"].call(self, null, e);
            });
        },
        poe_niuren_insertShoppingStores: function(cnt, e) {
            var self = this;
            var activeElm = self.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var tourshop = $(self.tlp["tlp" + self.template].poe_ShoppingStore());
            var insertNode;
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            if (day_title_new[0].className == "tourContent_new") {
                insertNode = day_title_new;
            } else {
                insertNode = day_title_new.parent();
            }
            if (arguments.length == 1 && cnt) {
                tourshop.html(cnt);
                insertNode.append(tourshop);
            } else {
                var shopping_store = $('#shopppingStoreTable_' + self.shopping_store_id).find('tr:gt(0)').clone();
                shopping_store.find('td:last-child').remove();
                tourshop.find('tbody').append(shopping_store);
                insertNode.append(tourshop);
                $('#poe_win_addShoppingStores').remove();
                self.hideWin(e);
                self.shopping_store_id++;
            }
            $('.tour_shop').unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            });
            $('.tour_shop').focus();
            $('.tour_shop').removeAttr('contenteditable');
            $('.tour_shop tr td').attr('contenteditable', 'true');
            $('.tour_shop thead').each(function(i, n) {
                self["niurenDelContent"].poe_niuren_ShoppingStores.call(self, i, n, $(n).parent().parent());
            });
            $('.tour_shop tbody tr').each(function(i, n) {
                self["niurenDelContent"].poe_niuren_ShoppingStores.call(self, i, n, $(n));
            });
        }
    }
}
$m.unniuren = {
    menu: {
        "poe_Journey": {
            name: "娣诲姞琛岀▼",
            iconCls: "",
            action: "poe_unniuren_Journey"
        },
        "poe_Description": {
            name: "琛岀▼鎻忚堪",
            iconCls: "",
            action: "poe_unniuren_Description"
        },
        "poe_Picture": {
            name: "琛岀▼鍥剧墖",
            iconCls: "",
            action: "poe_unniuren_Picture",
            mouseover: ""
        },
        "poe_Dining": {
            name: "鐢ㄩ",
            iconCls: "",
            action: "poe_unniuren_Dining"
        },
        "poe_Accommodation": {
            name: "浣忓",
            iconCls: "",
            action: "poe_unniuren_Accommodation"
        },
        "poe_ShoppingStores": {
            name: "璐墿搴�",
            iconCls: "",
            action: "",
            mouseover: "poe_unniuren_ShoppingStores"
        }
    },
    action: {
        poe_unniuren_Journey: function(title) {
            var self = this;
            this.day++;
            var journey = this.tlp["tlp" + this.template].poe_Journey().replace(/{day}/g, this.day);
            journey = $(journey);
            this.tourSection.append(journey);
            if (arguments.length == 1 && title) {
                $(".day_title_new h3 div", journey).html(title);
            }
            $(".day_title_new:last div", this.tourSection).bind("focus",
            function() {
                self.setActiveElement();
            })
             $(".day_title_new:last div", this.tourSection).focus();
            var rng = this.getFirstRange();
            rng.sel.selectAllChildren($(".day_title_new:last div", this.tourSection)[0]);
            this.setActiveElement();
            $(".day_title_new h3 em", this.tourSection).each(function(i, n) {
                self[self.template + "DelContent"].poe_unniuren_del_Journey.call(self, i, n, $(n).parent().parent().parent());
            });
        },
        poe_unniuren_Description: function(cnt) {
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var description = $(this.tlp["tlp" + this.template].poe_Description());
            if (arguments.length == 1 && cnt) {
                description.html(cnt);
            }
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            if (day_title_new[0].className == "day_title_new") {
                day_title_new.append(description);
            } else {
                if (day_title_new[0].className == "time_box_inner clearfix") {
                    day_title_new.parent().children().first().children().last().after(description);
                } else {
                    $(activeElm).after(description);
                }
            }
            $("div.tour_line_f", $(day_title_new)).unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            })
             description.focus();
            try {
                rng.sel.selectAllChildren(description[0]);
                self.setActiveElement();
            } catch(e) {}
            $("div.tour_line_f", $(this.tourSection)).each(function(i, n) {
                self[self.template + "DelContent"].poe_unniuren_del_Description.call(self, i, n, n);
            });
        },
        poe_unniuren_Picture: function(cnt, index) {
            var self = this;
            if ($(".tourContent_new", self.tourSection).size() == 0) return;
            if (arguments.length == 2 && cnt && typeof index !== "string") {
                createImgList(cnt, index);
            } else if (arguments.length == 2 && cnt == '' && typeof index !== "string") {
                return;
            } else {
                this.msgShow("姝e湪璇诲彇鍥剧墖璧勬簮璇风◢鍚�...", true);
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: "/main.php?r=" + Math.random(),
                    data: {
                        'do': 'route_ajax_new',
                        'method': 'matchSchedulePlacePhoto',
                        'schedule_info': this.getPOHtmlByDay()
                    },
                    success: function(data) {
                        if (!$.isEmptyObject(data)) {
                            createImgList(data);
                            self["unniuren"].action["poe_unniuren_BindImgHint"].call(self, null);
                        }
                    }
                });
            }
            function createImgList(data, index) {
                if (typeof data === "string") {
                    var ul = $(self.tlp.tlpunniuren.poe_SImgList());
                    ul.html(data);
                    $(".day_title_new h3", $(".tourContent_new", self.tourSection).eq(index)).after(ul);
                    $("a", $(".day_title_new", $(".tourContent_new", self.tourSection).eq(index))).each(function(i, j) {
                        self[self.template + "DelContent"].poe_unniuren_del_Picture.call(self, i, j, $(j).parent());
                    });
                } else {
                    $(".tourContent_new", self.tourSection).each(function(i, n) {
                        if ($(".day_title_new ul.time_s_photo", n).size() != 0) {
                            $(".day_title_new ul.time_s_photo", n).remove();
                        }
                        if ($(".day_title_new ul.time_s_photo", n).size() == 0) {
                            var ul = $(self.tlp.tlpunniuren.poe_SImgList());
                            if (data[i + 1].length > 0) {
                                $.each(data[i + 1],
                                function(i, m) {
                                    var li = $(self.tlp.tlpunniuren.poe_SImgListItem());
                                    var img = $("<img id='" + m.id + "' src='" + m.imgUrl + "' alt='" + m.address + "' />");
                                    $("a", li).append(img);
                                    var imglink = $('<a class="cgrey" target="_blank" href="' + self.imageHref + m.id + '">' + m.name + '</a>');
                                    $("div", li).append(imglink);
                                    ul.append(li);
                                });
                            }
                            $(".day_title_new h3", n).after(ul);
                            self.msgHide();
                            $("a", $(".day_title_new", n)).each(function(i, j) {
                                self[self.template + "DelContent"].poe_unniuren_del_Picture.call(self, i, j, $(j).parent());
                            });
                        }
                    })
                }
            }
            return false;
        },
        poe_unniuren_Dining: function(cnt, template) {
            var template = template && template != "poe_Dining" ? template: this.template;
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var insertNode;
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            var tourfood = $(this.tlp["tlp" + template].poe_Tourfood());
            var dining = $(this.tlp["tlp" + template].poe_Dining());
            if (arguments.length == 1 && cnt) {
                dining.html(cnt);
            }
            if (arguments.length == 2 && typeof cnt == "string" && template == "unniuren") {
                dining.html(cnt);
            }
            if (day_title_new[0].className == "tourContent_new") {
                insertNode = day_title_new;
            } else {
                insertNode = day_title_new.parent();
            }
            if ($('.tour_shop_f', insertNode).length > 0 && $(".tour_food_f", insertNode).size() == 0) {
                tourfood.append(dining);
                $('.tour_shop_f', insertNode).before(tourfood);
            } else {
                if ($(".tour_food_f", insertNode).size() == 0) {
                    tourfood.append(dining);
                    insertNode.append(tourfood);
                } else {
                    $(".tour_food_f", insertNode).append(dining);
                }
            }
            $("div", dining).attr('contenteditable', 'true');
            $("div", dining).focus();
            try {
                rng.sel.selectAllChildren($('.po_dining_diy', dining)[0]);
            } catch(e) {}
            $("div.tour_item em", $(insertNode)).each(function(i, n) {
                self["niuren" + "DelContent"].poe_niuren_del_Dining.call(self, i, n, $(n).parent());
            });
        },
        poe_unniuren_Accommodation: function(cnt, template) {
            var template = template && template != "poe_Accommodation" ? template: this.template;
            var self = this;
            var rng = this.getFirstRange();
            var activeElm = this.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var insertNode;
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            var tourfood = $(this.tlp["tlp" + template].poe_Tourfood());
            var accommodation = $(this.tlp["tlp" + template].poe_Accommodation());
            if (day_title_new[0].className == "tourContent_new") {
                insertNode = day_title_new;
            } else {
                insertNode = day_title_new.parent();
            }
            if ($(".tour_food_f", insertNode).size() == 0) {
                tourfood.append(accommodation);
                insertNode.append(tourfood);
            } else {
                $(".tour_food_f", insertNode).append(accommodation);
            }
            $("div", accommodation).focus();
            try {
                rng.sel.selectAllChildren($("div", accommodation)[0]);
            } catch(e) {}
            $("div.tour_item em", $(insertNode)).each(function(i, n) {
                self["niuren" + "DelContent"].poe_niuren_del_Accommodation.call(self, i, n, $(n).parent());
            });
        },
        poe_unniuren_ShoppingStores: function(e, template) {
            var template = template && template != "poe_ShoppingStores" ? template: this.template;
            var self = this;
            var spanBtn = "position: relative;border:1px solid #999;padding:2px 3px;margin:3px;float:left;display:block;cursor: pointer;line-height:18px;";
            var html = $("<div id='poe_win_addShoppingStores'><div><input type='text' id='sp_searchbox' name='sp_searchbox' /><input type='hidden' id='shoppingStoreId_box' name='sp_shoppingStoreId' /><button class='tuniubtn' type='button' id='addTotable' disabled='disabled'>纭畾</button><a href='javascript:void(0);' id='searchAllShoppingStores' style='font-size:12px;margin-left:20px;'>鎼滅储</a></div><div id='sp_searchHint' style='position:absolute; top:28px;left:5px;width:250px;background:#fff;border:1px solid grey;display:none;font-size:12px;'><ul style='margin:0;padding:0;list-style:none;'><li style='padding:2px;'>abcde</li><li style='padding:2px;'>bcdef</li><li style='padding:2px;'>cdefg</li></ul></div><div><table id='shopppingStoreTable_" + self.shopping_store_id + "' border='1' bordercolor='#ddd' cellspacing='0' cellpadding='4' style='border-collapse:collapse;font-size:12px;'><tr><th style='width:90px;background-color: #F6F6F6;padding: 2px;text-align: center;'>鍚嶇О</th><th style='width:140px;background-color: #F6F6F6;padding: 2px;text-align: center;'>钀ヤ笟浜у搧</th><th style='width:100px;background-color: #F6F6F6;padding: 2px;text-align: center;'>鍋滅暀鏃堕棿</th><th style='width:240px;background-color: #F6F6F6;padding: 2px;text-align: center;'>璇存槑</th><th style='width:52px;background-color: #F6F6F6;padding: 2px;text-align: center;'>鎿嶄綔</th></tr></table></div><div style='text-align:left;padding-top:5px;'><button class='tuniubtn' type='button' id='insertShoppingStore'>娣诲姞</button></div></div>");
            if ($("#poe_win_addShoppingStores").length == 0) {
                this.poeWin.append(html);
                $("#poe_win_addShoppingStores").siblings().hide();
                this.showWin(e);
            } else {
                $("#poe_win_addShoppingStores").show();
                $("#poe_win_addShoppingStores").siblings().hide();
                this.showWin(e);
                return;
            }
            $('#sp_searchbox').keyup(showHint);
            var shoppingStoreData;
            function showHint() {
                if ( !! $('#sp_searchbox').val()) {
                    $('#sp_searchHint').show();
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "../editor/searchHint.js?r=" + Math.random(),
                        data: $('#sp_searchbox').val(),
                        success: function(data) {
                            shoppingStoreData = data;
                            $('#sp_searchHint ul').empty();
                            for (var i in data) {
                                if (data[i].name != null) {
                                    $('#sp_searchHint ul').append("<li style='padding:2px;'><span id='shoppingStoreName'>" + data[i].name + "</span><span style='visibility:hidden;' id='shoppingStoreID'>" + data[i].id + "</span></li>");
                                }
                            }
                            $('#sp_searchHint ul li').hover(function() {
                                $(this).css({
                                    'background': '#ddd',
                                    'cursor': 'pointer'
                                });
                            },
                            function() {
                                $(this).css({
                                    'background': '#fff',
                                    'cursor': 'default'
                                });
                            });
                            $('#sp_searchHint ul li').click(function() {
                                var searchbox_text = $(this).children('#shoppingStoreName').text();
                                var shoppingStoreId = $(this).children('#shoppingStoreID').text();
                                $('#sp_searchbox').val(searchbox_text);
                                $('#shoppingStoreId_box').val(shoppingStoreId);
                                $('#addTotable').removeAttr('disabled');
                                $('#sp_searchHint').hide();
                            });
                        }
                    });
                } else {
                    $('#sp_searchHint').hide();
                }
            }
            $('#searchAllShoppingStores').click(function() {
                self.noty = new Noty();
                var html = $('<div id="shoppingInfo"><div class="row" id="searchArea"><div class="span0 ml0" style="margin-top:3px;">鍦板尯锛�</div><div class="span4" style="margin-left:0px;"><select style="width:80px;margin:0 10px 0 0"><option>璇烽€夋嫨</option><option>鍥藉唴</option><option>鍥藉</option><option>娓境鍙�</option></select><input style="margin-right:10px;" class="input-mini" type="text" /><input class="input-medium" type="text" /></div><div class="span0" style="margin-top:3px;">绫诲瀷锛�</div><div class="span0" style="margin-left:0px;"><select class="mb0" style="width:80px;"><option>璇烽€夋嫨</option><option>鍥藉唴</option><option>鍥藉</option><option>娓境鍙�</option></select></div><div class="span0"><a id="searchBtn" class="tuniubtn btn-primary"><i class="icon-search"></i>鎼滅储</a></div></div><hr><div class="row"><div class="span4 ml0"><a id="addShopping" class="tuniubtn"><i class="icon-plus"></i>娣诲姞璐墿搴�</a></div></div><div style="border:1px solid #CCC;max-height:400px;"><table id="shoppingGrid" class="table table-striped table-hover mb0"></table></div><div id="winPage" class="pagination pagination-small"><ul><li id="winPrevPage"><a>涓婁竴椤�</a></li><li id="winNextPage"><a>涓嬩竴椤�</a></li></ul></div></div>');
                var gridpanel = getShoppingGridList.call(self, html);
                var win = self.win = new WinForm({
                    title: "璐墿搴椾俊鎭�",
                    node: html,
                    css: {
                        top: "6%",
                        width: "85%",
                        left: "6%"
                    },
                    cancelText: "鍏抽棴",
                    submit: function() {}
                });
                win.show();
                setTimeout(function() {
                    html.parent().next().children().first().hide();
                },
                0);
                $("#addShopping", html).unbind("click").click(function() {
                    var addHtml = $("<div style='position:absolute;background-color:#FFF;top:40px;left:230px;border:1px solid #CCC;z-index: 993;border-radius:6px;'><h4 style='margin-left:10px;'>娣诲姞璐墿搴�</h4><hr><div class='row'><div class='span1'>璐墿搴楀悕锛�</div><div class='span3'><input type='text' name='shopName' /></div></div><div class='row'><div class='span1'>涓昏惀浜у搧锛�</div><div class='span3'><textarea class='mb0' name='mainBussinessProduct_1'></textarea></div></div><div class='row'><div class='span1'>鍏艰惀浜у搧锛�</div><div class='span3'><textarea class='mb0' name='mainBussinessProduct_2'></textarea></div></div><div class='row'><div class='span1'>璇存槑浠嬬粛锛�</div><div class='span3'><textarea class='mb0' name='description'></textarea></div></div><div class='row'><div class='span1'>浜у搧鍒嗙被锛�</div><div class='span6'><select class='mb0' style='width:80px;'><option>璇烽€夋嫨</option><option>鍥藉唴</option><option>鍥藉</option><option>娓境鍙�</option></select><select class='mb0' style='width:80px;margin-left:5px;'><option>璇烽€夋嫨</option></select><select class='mb0' style='width:180px;margin-left:5px;'><option>璇烽€夋嫨</option></select></div></div><div class='row'><div class='span1'>鍟嗗簵绫诲瀷锛�</div><div class='span3'><select class='mb0' style='width:80px;'><option>璇烽€夋嫨</option></select></div></div><div class='row'><div class='span1' style='margin-top:3px;'>鍋滅暀鏃堕棿锛�</div><div class='span3' style='width:100px;'><input type='text' name='waitTime' style='width:80px;' /></div><div class='span0' style='margin:3px 0 0 2px;'>鍒嗛挓</div></div><hr><div class='row'><div class='span1'><a class='tuniubtn btn-primary' id='submitShopping'><i class='icon-ok-sign'></i>鎻愪氦</a></div><div class='span3'><a class='tuniubtn btn-danger' id='cancelBtn'><i class='icon-remove'></i>鍙栨秷</a></div></div></div><div style='z-index: 992; border: medium none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); opacity: 0.2; cursor: default; position: fixed;'></div>");
                    $(this).parent().parent().parent().append(addHtml);
                    $("#cancelBtn", addHtml).unbind("click").click(function() {
                        $(this).parent().parent().parent().next().remove();
                        $(this).parent().parent().parent().remove();
                    });
                    $("#submitShopping", addHtml).unbind("click").click(function() {
                        $(this).parent().parent().parent().next().remove();
                        $(this).parent().parent().parent().remove();
                        self.shoppingList.reload();
                    });
                });
            });
            function getShoppingGridList(html) {
                var self = this;
                var shoppingList = self.shoppingList = new nb.GridPanel({
                    renderTo: $("#shoppingGrid", html),
                    url: "http://yhj.tuniu.org:8080/N-Booking/data/shoppingData.js",
                    data: {
                        isPaied: 2
                    },
                    pageNode: $("#winPage", html),
                    prevNode: $("#winPrevPage", html),
                    nextNode: $("#winNextPage", html),
                    colModel: [{
                        name: "shopId",
                        display: "搴忓垪鍙�",
                        width: 40
                    },
                    {
                        name: "shopName",
                        display: "鍚嶇О",
                        width: 70
                    },
                    {
                        name: "mainBussinessProduct",
                        display: "钀ヤ笟浜у搧",
                        width: 250
                    },
                    {
                        name: "waitTime",
                        display: "鍋滅暀鏃堕棿",
                        width: 60
                    },
                    {
                        name: "description",
                        display: "璇存槑",
                        width: 220
                    },
                    {
                        name: "edit",
                        display: "鎿嶄綔",
                        width: 100,
                        handler: function(v, data, td, tr) {
                            var a = $("<a><i class='icon-ok'></i>閫夋嫨</a>");
                            var b = $("<a style='margin-left:5px;'><i class='icon-edit'></i>缂栬緫</a>");
                            var c = $("<a style='margin-left:5px;'><i class='icon-remove'></i>鍒犻櫎</a>");
                            td.append(a);
                            td.append(b);
                            td.append(c);
                            a.unbind("click").click(function() {
                                addToTable(data);
                                self.win.hide();
                            });
                            b.unbind("click").click(function() {
                                var editHtml = $("<div style='position:absolute;background-color:#FFF;top:40px;left:230px;border:1px solid #CCC;z-index: 993;border-radius:6px;'><h4 style='margin-left:10px;'>缂栬緫璐墿搴�</h4><hr><div class='row'><div class='span1'>璐墿搴楀悕锛�</div><div class='span3'><input type='text' name='shopName' /></div></div><div class='row'><div class='span1'>涓昏惀浜у搧锛�</div><div class='span3'><textarea class='mb0' name='mainBussinessProduct_1'></textarea></div></div><div class='row'><div class='span1'>鍏艰惀浜у搧锛�</div><div class='span3'><textarea class='mb0' name='mainBussinessProduct_2'></textarea></div></div><div class='row'><div class='span1'>璇存槑浠嬬粛锛�</div><div class='span3'><textarea class='mb0' name='description'></textarea></div></div><div class='row'><div class='span1'>浜у搧鍒嗙被锛�</div><div class='span6'><select class='mb0' style='width:80px;'><option>璇烽€夋嫨</option><option>鍥藉唴</option><option>鍥藉</option><option>娓境鍙�</option></select><select class='mb0' style='width:80px;margin-left:5px;'><option>璇烽€夋嫨</option></select><select class='mb0' style='width:180px;margin-left:5px;'><option>璇烽€夋嫨</option></select></div></div><div class='row'><div class='span1'>鍟嗗簵绫诲瀷锛�</div><div class='span3'><select class='mb0' style='width:80px;'><option>璇烽€夋嫨</option></select></div></div><div class='row'><div class='span1' style='margin-top:3px;'>鍋滅暀鏃堕棿锛�</div><div class='span3' style='width:100px;'><input type='text' name='waitTime' style='width:80px;' /></div><div class='span0' style='margin:3px 0 0 2px;'>鍒嗛挓</div></div><hr><div class='row'><div class='span1'><a class='tuniubtn btn-primary' id='submitShopping'><i class='icon-edit'></i>鏇存敼</a></div><div class='span3'><a class='tuniubtn btn-danger' id='cancelBtn'><i class='icon-remove'></i>鍙栨秷</a></div></div></div><div style='z-index: 992; border: medium none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; background-color: rgb(0, 0, 0); opacity: 0.2; cursor: default; position: fixed;'></div>");
                                $("input[name='shopName']", editHtml).val(data.shopName);
                                $("textarea[name='mainBussinessProduct_1']", editHtml).val(data.mainBussinessProduct);
                                $("textarea[name='description']", editHtml).val(data.mainBussinessProduct);
                                $("input[name='waitTime']", editHtml).val(data.waitTime);
                                $(this).parent().parent().parent().append(editHtml);
                                $("#cancelBtn", editHtml).unbind("click").click(function() {
                                    $(this).parent().parent().parent().next().remove();
                                    $(this).parent().parent().parent().remove();
                                });
                                $("#submitShopping", editHtml).unbind("click").click(function() {
                                    $(this).parent().parent().parent().next().remove();
                                    $(this).parent().parent().parent().remove();
                                    self.shoppingList.reload();
                                });
                            });
                            c.unbind("click").click(function() {
                                self.noty.confirm("纭畾瑕佸垹闄よ璐墿搴椾箞锛�", {
                                    type: "tuniubtn btn-primary",
                                    text: "<i class='icon-ok'></i>纭畾",
                                    click: function(noty) {
                                        noty.close();
                                    }
                                });
                            });
                        }
                    }],
                    autoload: true,
                    limit: 5
                });
            }
            $('#addTotable').click(function() {
                addToTable();
                $('#sp_searchbox').val('');
                $('#addTotable').attr('disabled', 'disabled');
            });
            function addToTable(data) {
                if ( !! data) {
                    $('#shopppingStoreTable_' + self.shopping_store_id).append("<tr><td>" + data.shopName + "</td><td>" + data.mainBussinessProduct + "</td><td>" + data.waitTime + "</td><td>" + data.description + "</td><td><a href='javascript:void(0)'>鍒犻櫎</a></td></tr>");
                    $('#shopppingStoreTable_' + self.shopping_store_id + ' a').click(function(e) {
                        window.event ? e.target = window.event.srcElement: e.target;
                        $(e.target).parent().parent().remove();
                    });
                } else if (data == undefined) {
                    var index;
                    for (var i in shoppingStoreData) {
                        if (shoppingStoreData[i].id == $('#shoppingStoreId_box').val()) {
                            index = i;
                            break;
                        } else {
                            index = -1;
                        }
                    }
                    $('#shopppingStoreTable_' + self.shopping_store_id).append("<tr><td>" + shoppingStoreData[i].shopName + "</td><td>" + shoppingStoreData[i].mainBussinessProduct + "</td><td>" + shoppingStoreData[i].waitTime + "</td><td>" + shoppingStoreData[i].description + "</td><td><a href='javascript:void(0)'>鍒犻櫎</a></td></tr>");
                    $('#shopppingStoreTable_' + self.shopping_store_id + ' a').click(function(e) {
                        var e = window.event || e;
                        var srcEL = e.srcElement ? e.srcElement: e.target;
                        $(srcEL).parent().parent().remove();
                    });
                }
            }
            $('#insertShoppingStore').click(function(e) {
                var e = window.event || e;
                self["unniuren"].action["poe_unniuren_insertShoppingStores"].call(self, null, e);
            });
        },
        poe_unniuren_insertShoppingStores: function(cnt, e) {
            var self = this;
            var activeElm = self.getActiveElement();
            var day_title_new = $(activeElm).parent().parent();
            var tourshop = $(self.tlp["tlp" + self.template].poe_ShoppingStore());
            var insertNode;
            if (day_title_new.length == 0) return;
            if (day_title_new.length > 0 && (day_title_new[0].className != "day_title_new" && day_title_new[0].className != "tourContent_new" && day_title_new[0].className != "time_box_inner clearfix" && day_title_new[0].className != "tour_con")) {
                return;
            }
            if (day_title_new[0].className == "tourContent_new") {
                insertNode = day_title_new;
            } else {
                insertNode = day_title_new.parent();
            }
            if (arguments.length == 1 && cnt) {
                tourshop.html(cnt);
                insertNode.append(tourshop);
            } else {
                var shopping_store = $('#shopppingStoreTable_' + self.shopping_store_id).find('tr:gt(0)').clone();
                shopping_store.find('td:last-child').remove();
                tourshop.find('tbody').append(shopping_store);
                insertNode.append(tourshop);
                $('#poe_win_addShoppingStores').remove();
                self.hideWin(e);
                self.shopping_store_id++;
            }
            $('.tour_shop_f').unbind("focus").bind("focus",
            function() {
                self.setActiveElement();
            });
            $('.tour_shop_f').focus();
            $('.tour_shop_f').removeAttr('contenteditable');
            $('.tour_shop_f tr td:even').attr('contenteditable', 'true');
            $('.tour_shop_f thead').each(function(i, n) {
                self["niurenDelContent"].poe_niuren_ShoppingStores.call(self, i, n, $(n).parent().parent());
            });
            $('.tour_shop_f tbody tr').each(function(i, n) {
                self["niurenDelContent"].poe_niuren_ShoppingStores.call(self, i, n, $(n));
            });
        },
        poe_unniuren_BindImgHint: function() {
            var img_m = $("<div style='position:absolute;z-index:99999;border:1px solid #ccc;background:#efefef;display:none'><img src='' style='border:2px solid #fff' /><span style='display:block;text-align:right;font-weight:bold;color:#333;padding-right:10px;'></span></div>");
            $('.day_title_new').append(img_m);
        }
    }
}
$m.niurenDelContent = {
    poe_niuren_del_Journey: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            if (node.attr("class") == "tourContent_new") {
                this.menu.day--;
                var nextall = node.nextAll();
                nextall.each(function(i, n) {
                    var nextday = $(".day_title_new h3 em", n).text();
                    nextday = nextday.substring(1, nextday.length - 1);
                    nextday -= 1;
                    $(".day_title_new h3 em", n).html("绗�" + nextday + "澶�");
                })
            }
        });
    },
    poe_niuren_del_Description: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del);
    },
    poe_niuren_del_FParagraph: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del);
    },
    poe_niuren_del_STitle: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            $m.niurenDelContent.poe_niuren_del_publicByTimeDo.call(this, node);
        });
    },
    poe_niuren_del_SParagraph: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            $m.niurenDelContent.poe_niuren_del_publicByTimeDo.call(this, node);
        });
    },
    poe_niuren_del_Dining: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            $m.niurenDelContent.poe_niuren_del_publicByTourItem.call(this, node);
        });
    },
    poe_niuren_del_Accommodation: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            $m.niurenDelContent.poe_niuren_del_publicByTourItem.call(this, node);
        });
    },
    poe_niuren_ShoppingStores: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            $m.niurenDelContent.poe_niuren_del_publicByTourShop.call(this, node);
        });
    },
    poe_niuren_del_over_Picture: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            if (node.parent().attr("class") == "time_img_photo clearfix") {
                if ($("li", node.parent()).size() == 1) {
                    node.parent().remove();
                }
            }
        });
    },
    poe_niuren_del_publicByTimeDo: function(node) {
        if (node.parent().attr("class") == "time_do_new") {
            node.parent().prev().find("p").focus();
            this.setActiveElement();
        }
    },
    poe_niuren_del_publicByTourItem: function(node) {
        if (node.attr("class") == "tour_item") {
            if ($("em", node.parent()).size() == 1) {
                node.parent().remove();
            }
        }
    },
    poe_niuren_del_publicByTourShop: function(node) {
        if (node.attr("class") == "tour_shop") {
            node.remove();
        }
    }
}
$m.unniurenDelContent = {
    poe_unniuren_del_Journey: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            if (node.attr("class") == "tourContent_new") {
                this.day--;
                var nextall = node.nextAll();
                nextall.each(function(i, n) {
                    var nextday = $(".day_title_new h3 em", n).text();
                    nextday = nextday.substring(1, nextday.length - 1);
                    nextday -= 1;
                    $(".day_title_new h3 em", n).html("绗�" + nextday + "澶�");
                })
            }
        });
    },
    poe_unniuren_del_Description: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del);
    },
    poe_unniuren_del_Picture: function(i, n, del) {
        this.delNodeShow.call(this, i, n, del,
        function(node) {
            if (node.parent().attr("class") == "time_s_photo clearfix") {
                if ($("li", node.parent()).size() == 1) {
                    node.parent().remove();
                }
            }
        });
    }
}
$m.niurenReloadBindEvent = function(html) {
    var self = this;
    var div = $("<div/>").append(html);
    $(".tourContent_new", div).each(function(i, m) {
        var em = $(".day_title_new h3 em", $(m));
        var journey = $(".day_title_new h3 div", $(m));
        var description = $(".day_title_new h3", $(m)).nextAll();
        var stitle = $(".time_box_inner", $(m));
        var food = $(".tour_food", $(m));
        var tourshop = $(".tour_shop", $(m));
        if (journey.length > 0) {
            self["niuren"].action["poe_niuren_Journey"].call(self, journey.html(), em.html(), true);
        }
        if (description.length > 0) {
            description.each(function(i, n) {
                self["niuren"].action["poe_niuren_Description"].call(self, $(n).html());
            });
        }
        if (stitle.length > 0) {
            stitle.each(function(i, n) {
                var activeTime_num = $(".tour_con", n).html();
                var tourdescription = $(".tour_description", n).html();
                var fparagraph = activeTime_num + "%^&" + tourdescription;
                self["niuren"].action["poe_niuren_FParagraph"].call(self, fparagraph);
                var time_do_new = $(".time_do_new", n);
                if (time_do_new.children().length > 0) {
                    var imgs = [];
                    time_do_new.children().each(function(i, n) {
                        if (n.className == "tour_con_h4") {
                            self["niuren"].action["poe_niuren_STitle"].call(self, $(n).html());
                        }
                        if (n.className == "tour_con") {
                            self["niuren"].action["poe_niuren_SParagraph"].call(self, $(n).html());
                        }
                        if (n.className == "time_img_photo clearfix") {
                            imgs.push({
                                index: $(n).index(),
                                node: $(n)
                            });
                        }
                    });
                    if (imgs.length > 0) {
                        var activeElm = self.getActiveElement();
                        $.each(imgs,
                        function(i, n) {
                            $(n.node).find('div').attr('contenteditable', true);
                            if (!$(activeElm).parent().hasClass('time_num')) {
                                $($(activeElm).parent().children()[n.index - 1]).after(n.node);
                            } else {
                                $($(activeElm).parent().siblings('.time_do_new').children()[n.index - 1]).after(n.node);
                            }
                            $('.niuren_light').click(function(e) {
                                e.preventDefault ? e.preventDefault() : window.event.returnValue = false;
                            });
                            $("img", n.node).each(function(i, m) {
                                self[self.template + "DelContent"].poe_niuren_del_over_Picture.call(self, 0, m, $(m).parent().parent());
                                $("div", $(m).parent().parent()).unbind("focus").bind("focus",
                                function() {
                                    self.setActiveElement();
                                });
                            });
                        });
                    }
                }
            });
        }
        if (food.length > 0 && food.children().length > 0) {
            food.children().each(function(i, n) {
                self["niuren"].action["poe_niuren_Dining"].call(self, $(n).html());
            });
        }
        if (tourshop.length > 0) {
            self["niuren"].action["poe_niuren_insertShoppingStores"].call(self, tourshop.html());
        }
    });
    $(document).scrollTop(0);
}
$m.unniurenReloadBindEvent = function(html) {
    var self = this;
    var div = $("<div/>").append(html);
    $(".tourContent_new", div).each(function(i, m) {
        var journey = $(".day_title_new h3 div", $(m));
        var imglist = $(".day_title_new ul", $(m));
        var description = $(".day_title_new .tour_line_f", $(m));
        var food = $(".tour_food_f", $(m));
        var tourshop = $(".tour_shop_f", $(m));
        if (journey.length > 0) {
            self["unniuren"].action["poe_unniuren_Journey"].call(self, journey.html());
        }
        if (imglist.length > 0) {
            self["unniuren"].action["poe_unniuren_Picture"].call(self, $(imglist).html(), i);
            self["unniuren"].action["poe_unniuren_BindImgHint"].call(self, null);
        }
        if (description.length > 0) {
            description.each(function(i, n) {
                self["unniuren"].action["poe_unniuren_Description"].call(self, $(n).html());
            });
        }
        if (food.length > 0 && food.children().length > 0) {
            food.children().each(function(i, n) {
                self["unniuren"].action["poe_unniuren_Dining"].call(self, $(n).html(), "unniuren");
            });
        }
        if (tourshop.length > 0) {
            self["unniuren"].action["poe_unniuren_insertShoppingStores"].call(self, tourshop.html());
        }
    });
    $(document).scrollTop(0);
}
$m.delNodeShow = function(i, n, del, fn) {
    var self = this;
    $(n).unbind("mouseover").mouseover(function(e) {
        var e = window.event || e;
        var srcEL = e.srcElement ? e.srcElement: e.target;
        if (srcEL.nodeName == "SPAN" || srcEL.nodeName == "A") return false;
        if (srcEL.nodeName != "TH" && srcEL.nodeName != "TD") {
            self.delNode.toggle().css({
                left: $(srcEL).position().left - 35 + 1 + "px",
                top: $(srcEL).position().top + 1 + "px"
            }).data("node", $(del));
        } else {
            self.delNode.toggle().css({
                left: $(srcEL).parent().position().left - 35 + 1 + "px",
                top: $(srcEL).parent().position().top + 1 + "px"
            }).data("node", $(del));
        }
        if (fn) {
            self.delNode.data("action", fn);
        }
    }).unbind("mouseout").mouseout(function(e) {
        var e = window.event || e;
        var srcEL = e.srcElement ? e.srcElement: e.target;
        if (srcEL.nodeName == "SPAN" || srcEL.nodeName == "A") return false;
        self.delNode.toggle();
    });
}
$m.initMenu = function() {
    var self = this;
    this.menu = this[this.template] || null;
    var menuBarCls = {
        background: "none repeat scroll 0 0 #f0f0ee",
        height: "26px",
        border: "1px solid #C5C5C5",
        minWidth: "760px",
        margin: "0px",
        padding: "0px"
    },
    menuBarCls_Span = {
        "float": "left",
        margin: "2px",
        fontSize: "13px",
        height: "22px"
    },
    menuBarCls_A = {
        border: "0 none",
        cursor: "pointer",
        display: "inline-block",
        margin: "1px",
        textDecoration: "none",
        background: "none repeat scroll 0 0 transparent"
    },
    menuBarCls_A_Hover = {
        background: "none repeat scroll 0 0 #ffffff",
        border: "1px solid #999999",
        margin: "0px"
    },
    menuBarCls_Icon_Button = {
        cursor: "pointer",
        border: "none",
        display: "block",
        height: "20px",
        margin: "0",
        overflow: "hidden",
        width: "20px",
        background: "url('" + this.imagePath + "icons.gif') no-repeat scroll 20px 20px transparent"
    },
    menuBarCls_Button = {
        cursor: "pointer",
        border: "none",
        display: "block",
        height: "20px",
        margin: "0",
        overflow: "hidden",
        width: "auto",
        background: "none repeat scroll 0 0 transparent",
        padding: "0 1px"
    }
    var menuContainer = this.menuContainer = $("<div/>").css(menuBarCls);
    $.each(this.publicMenu,
    function(i, n) {
        var positionCls = {
            backgroundPosition: n.position
        };
        var span = $("<span><a href='javascript:void(0);' onclick='return false;'><button title='" + n.name + "' class='" + n.iconCls + "'></button></a></span>").css(menuBarCls_Span);
        $("button", span).css(menuBarCls_Icon_Button).css(positionCls).click(function(e) {
            var e = window.event || e;
            self.publicMenuAction[n.action].call(self, e, i);
        });
        if (n.mouseover) {
            $("button", span).css(menuBarCls_Icon_Button).css(positionCls).unbind("click");
            $("button", span).data("mouseover", true);
            $("button", span).css(menuBarCls_Icon_Button).css(positionCls).mouseover(function(e) {
                var e = window.event || e;
                e.stopPropagation ? e.stopPropagation() : window.event.cancelBubble = true;
                self.clearMenuBtnStyle(e);
                self.publicMenuAction[n.mouseover].call(self, e, i);
            });
        }
        menuContainer.append(span);
    });
    if (this.menu) {
        $.each(this.menu.menu,
        function(i, n) {
            var span = $("<span><a href='javascript:void(0);' onclick='return false;'><button id='" + i + "_btn' title='" + n.name + "' class='" + n.iconCls + "'>" + n.name + "</button></a></span>").css(menuBarCls_Span);
            $("button", span).css(menuBarCls_Button).click(function(e) {
                var e = window.event || e;
                self.menu.action[n.action] && self.menu.action[n.action].call(self, e, i);
            });
            if (n.mouseover) {
                $("button", span).css(menuBarCls_Button).unbind("click");
                $("button", span).data("mouseover", true);
                $("button", span).css(menuBarCls_Button).mouseover(function(e) {
                    var e = window.event || e;
                    e.stopPropagation ? e.stopPropagation() : window.event.cancelBubble = true;
                    self.clearMenuBtnStyle(e);
                    self.menu.action[n.mouseover].call(self, e, i);
                });
            }
            menuContainer.append(span);
        });
    }
    if (this.template == "base") {
        $(".poe_bus", menuContainer).parent().parent().remove();
        $(".poe_plain", menuContainer).parent().parent().remove();
        $(".poe_train", menuContainer).parent().parent().remove();
        $(".poe_ship", menuContainer).parent().parent().remove();
        var poe_preview_spn = $(".poe_preview", menuContainer).parent().parent().detach();
        menuContainer.append(poe_preview_spn);
    }
    $("a", menuContainer).css(menuBarCls_A).unbind("mouseover").mouseover(function(e) {
        var e = window.event || e;
        $(this).css(menuBarCls_A_Hover);
    }).unbind("mouseout").mouseout(function(e) {
        var e = window.event || e;
        if (!$("button", $(this)).data("mouseover")) {
            $(this).css(menuBarCls_A);
        }
    });
    this.delNode.mouseover(function(e) {
        var e = window.event || e;
        $(this).show();
        e.stopPropagation ? e.stopPropagation() : window.event.cancelBubble = true;
        $(this).data("node").css({
            border: "1px solid red"
        });
    }).mouseout(function(e) {
        var e = window.event || e;
        $(this).hide();
        e.stopPropagation ? e.stopPropagation() : window.event.cancelBubble = true;
        $(this).data("node").removeAttr("style");
    }).click(function(e) {
        var e = window.event || e;
        $(this).hide();
        if ($(this).data("action")) {
            $(this).data("action").call(self, $(this).data("node"), e);
        }
        $(this).data("node").remove();
    });
    return menuContainer;
}
$m.clearMenuBtnStyle = function(e) {
    var e = window.event || e;
    var srcEL = e.srcElement ? e.srcElement: e.target;
    if (!this.activeMenuByWin) {
        this.activeMenuByWin = srcEL;
    } else {
        if (this.activeMenuByWin.className != srcEL.className && $(this.activeMenuByWin).data("mouseover")) {
            $(this.activeMenuByWin).parent().css({
                border: "0px solid #999",
                backgroundColor: "transparent",
                margin: "1px"
            });
            this.activeMenuByWin = srcEL;
        }
    }
}
$m.getFirstRange = function(flag) {
    var self = this;
    if ((flag || !window.getSelection) && this.saveSel) {
        try {
            this.rangy.restoreSelection(this.saveSel, false);
            this.rangy.removeMarkers(this.saveSel);
            window.setTimeout(function() {
                if (self.savedSelActiveElement && typeof self.savedSelActiveElement.focus != "undefined") {
                    self.savedSelActiveElement.focus();
                }
            },
            1);
        } catch(ex) {}
    }
    var sel = this.rangy.getSelection ? this.rangy.getSelection() : this.rangy.nativeSelection(),
    rng;
    return {
        sel: sel,
        rang: (sel.rangeCount ? sel.getRangeAt(0) : null)
    }
}
$m.setActiveElement = function() {
    this.activeElement = this.doc.activeElement;
}
$m.getActiveElement = function() {
    return this.activeElement;
}
function Template(opt) {
    $.extend(this, opt || {},
    {});
}
var $t = Template.prototype;
$t.tlpniuren = {
    poe_Journey: function() {
        return "<div class='tourContent_new'><div class='day_title_new'><h3><em contentEditable='true'>绗瑊day}澶�</em><div contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼鏍囬</div></h3></div></div>";
    },
    poe_Description: function() {
        return "<div class='tour_line' contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼鎻忚堪锛屽唴瀹瑰彲浠ヤ负\"鑸彮淇℃伅\"銆乗"娓歌璺嚎\"绛夌浉鍏冲唴瀹�</div>";
    },
    poe_FParagraph: function() {
        return "<div class='time_box_inner clearfix'><div class='time_num'><div class='tour_con' contentEditable='true'>杈撳叆鏃堕棿</div></div><div class='time_do_new'><div class='tour_description' contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼鏃堕棿娈垫弿杩�</div></div></div>";
    },
    poe_STitle: function() {
        return "<div class='tour_con_h4' contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼灏忔爣棰�</div>";
    },
    poe_SParagraph: function() {
        return "<div class='tour_con' contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼灏忔爣棰樻鏂�</div>";
    },
    poe_Tourfood: function() {
        return "<div class='tour_food'></div>";
    },
    poe_Dining: function() {
        return "<div class='tour_item'><em>鐢ㄩ</em><div contentEditable='true'>鏃╅锛�<span class='po_dining_diy'>鏁鑷悊</span>&#160;鍗堥锛�<span class='po_dining_diy'>鏁鑷悊</span>&#160;鏅氶锛�<span class='po_dining_diy'>鏁鑷悊</span></div></div>";
    },
    poe_Accommodation: function() {
        return "<div class='tour_item'><em>浣忓</em><div contentEditable='true'>璇峰湪杩欓噷杈撳叆褰撳ぉ浣忓鎯呭喌</div></div>";
    },
    poe_ImgList: function() {
        return "<ul class='time_img_photo clearfix'></ul>";
    },
    poe_ImgListItem: function(name) {
        return "<li><a href='#' onclick='return false;'></a><div contentEditable='true'>" + (name || '鍥剧墖鏍囬') + "</div></li>";
    },
    poe_ShoppingStore: function() {
        return "<div class='tour_shop' contenteditable='true'><p><b>璐墿搴椾俊鎭�</b>锛堝鍥犳父瀹㈣喘鐗╅€犳垚鏃堕棿寤堕暱锛屽欢闀挎椂闂翠笉璁″叆鏃呰绀剧殑瀹㈣瀹夋帓鍋滅暀鏃堕棿锛�</p><table><thead><tr><th class='w160'>鍚嶇О</th><th class='w200'>钀ヤ笟浜у搧</th><th class='w160'>鍋滅暀鏃堕棿 </th><th class='w200'>璇存槑</th></tr></thead><tbody></tbody></table></div>";
    }
}
$t.tlpunniuren = {
    poe_Journey: function() {
        return "<div class='tourContent_new'><div class='day_title_new'><h3><em contentEditable='true'>绗瑊day}澶�</em><div contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼鏍囬</div></h3></div></div>";
    },
    poe_SImgList: function() {
        return "<ul class='time_s_photo clearfix'></ul>";
    },
    poe_SImgListItem: function() {
        return "<li><a href='javascript:void(0);' onclick='return false;' style='cursor:default;'></a><div></div></li>";
    },
    poe_Description: function() {

        return "<div class='tour_line_f' contentEditable='true'>璇峰湪杩欓噷杈撳叆琛岀▼鎻忚堪锛屽唴瀹瑰彲浠ヤ负\"鑸彮淇℃伅\"銆乗"娓歌璺嚎\"绛夌浉鍏冲唴瀹�</div>";
    },
    poe_Tourfood: function() {
        return "<div class='tour_food_f'></div>";
    },
    poe_Dining: function() {
        return "<div class='tour_item'><em>鐢ㄩ</em><div contentEditable='true'>鏃╅锛�<span class='po_dining_diy'>鏁鑷悊</span>&#160;鍗堥锛�<span class='po_dining_diy'>鏁鑷悊</span>&#160;鏅氶锛�<span class='po_dining_diy'>鏁鑷悊</span></div></div>";
    },
    poe_Accommodation: function() {
        return "<div class='tour_item'><em>浣忓</em><div contentEditable='true'>璇峰湪杩欓噷杈撳叆褰撳ぉ浣忓鎯呭喌</div></div>";
    },
    poe_ShoppingStore: function() {
        return "<div class='tour_shop_f' contenteditable='true'><p><b>璐墿搴椾俊鎭�</b>锛堝鍥犳父瀹㈣喘鐗╅€犳垚鏃堕棿寤堕暱锛屽欢闀挎椂闂翠笉璁″叆鏃呰绀剧殑瀹㈣瀹夋帓鍋滅暀鏃堕棿锛�</p><table><thead><tr><th width='160'>鍚嶇О</th><th width='200'>钀ヤ笟浜у搧</th><th width='100'>鍋滅暀鏃堕棿 </th><th>璇存槑</th></tr></thead><tbody></tbody></table></div>";
    }
}
var Event = {
    _listeners: {},
    addEvent: function(type, fn) {
        if (typeof this._listeners[type] === "undefined") {
            this._listeners[type] = [];
        }
        if (typeof fn === "function") {
            this._listeners[type].push(fn);
        }
        return this;
    },
    fireEvent: function(type) {
        var arrayEvent = this._listeners[type];
        if (arrayEvent instanceof Array) {
            for (var i = 0, length = arrayEvent.length; i < length; i += 1) {
                if (typeof arrayEvent[i] === "function") {
                    arrayEvent[i]({
                        type: type
                    });
                }
            }
        }
        return this;
    },
    removeEvent: function(type, fn) {
        var arrayEvent = this._listeners[type];
        if (typeof type === "string" && arrayEvent instanceof Array) {
            if (typeof fn === "function") {
                for (var i = 0, length = arrayEvent.length; i < length; i += 1) {
                    if (arrayEvent[i] === fn) {
                        this._listeners[type].splice(i, 1);
                        break;
                    }
                }
            } else {
                delete this._listeners[type];
            }
        }
        return this;
    }
};
Event.addEvent("hideWindow",
function() {
    if ($('.link_span').length != 0) {
        $('.link_span').each(function(i, n) {
            $(n).after($(n).text());
            $(n).remove();
        });
    }
});
rangy.createModule("SaveRestore",
function(api, module) {
    api.requireModules(["DomUtil", "DomRange", "WrappedRange"]);
    var dom = api.dom;
    var markerTextChar = "\ufeff";
    function gEBI(id, doc) {
        return (doc || document).getElementById(id);
    }
    function insertRangeBoundaryMarker(range, atStart) {
        var markerId = "selectionBoundary_" + ( + new Date()) + "_" + ("" + Math.random()).slice(2);
        var markerEl;
        var doc = dom.getDocument(range.startContainer);
        var boundaryRange = range.cloneRange();
        boundaryRange.collapse(atStart);
        markerEl = doc.createElement("span");
        markerEl.id = markerId;
        markerEl.style.lineHeight = "0";
        markerEl.style.display = "none";
        markerEl.className = "rangySelectionBoundary";
        markerEl.appendChild(doc.createTextNode(markerTextChar));
        boundaryRange.insertNode(markerEl);
        boundaryRange.detach();
        return markerEl;
    }
    function setRangeBoundary(doc, range, markerId, atStart) {
        var markerEl = gEBI(markerId, doc);
        if (markerEl) {
            range[atStart ? "setStartBefore": "setEndBefore"](markerEl);
            markerEl.parentNode.removeChild(markerEl);
        } else {
            module.warn("Marker element has been removed. Cannot restore selection.");
        }
    }
    function compareRanges(r1, r2) {
        return r2.compareBoundaryPoints(r1.START_TO_START, r1);
    }
    function saveSelection(win) {
        win = win || window;
        var doc = win.document;
        if (!api.isSelectionValid(win)) {
            module.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus.");
            return;
        }
        var sel = api.getSelection(win);
        var ranges = sel.getAllRanges();
        var rangeInfos = [],
        startEl,
        endEl,
        range;
        ranges.sort(compareRanges);
        for (var i = 0, len = ranges.length; i < len; ++i) {
            range = ranges[i];
            if (range.collapsed) {
                endEl = insertRangeBoundaryMarker(range, false);
                rangeInfos.push({
                    markerId: endEl.id,
                    collapsed: true
                });
            } else {
                endEl = insertRangeBoundaryMarker(range, false);
                startEl = insertRangeBoundaryMarker(range, true);
                rangeInfos[i] = {
                    startMarkerId: startEl.id,
                    endMarkerId: endEl.id,
                    collapsed: false,
                    backwards: ranges.length == 1 && sel.isBackwards()
                };
            }
        }
        for (i = len - 1; i >= 0; --i) {
            range = ranges[i];
            if (range.collapsed) {
                range.collapseBefore(gEBI(rangeInfos[i].markerId, doc));
            } else {
                range.setEndBefore(gEBI(rangeInfos[i].endMarkerId, doc));
                range.setStartAfter(gEBI(rangeInfos[i].startMarkerId, doc));
            }
        }
        sel.setRanges(ranges);
        return {
            win: win,
            doc: doc,
            rangeInfos: rangeInfos,
            restored: false
        };
    }
    function restoreSelection(savedSelection, preserveDirection) {
        if (!savedSelection.restored) {
            var rangeInfos = savedSelection.rangeInfos;
            var sel = api.getSelection(savedSelection.win);
            var ranges = [];
            for (var len = rangeInfos.length, i = len - 1, rangeInfo, range; i >= 0; --i) {
                rangeInfo = rangeInfos[i];
                range = api.createRange(savedSelection.doc);
                if (rangeInfo.collapsed) {
                    var markerEl = gEBI(rangeInfo.markerId, savedSelection.doc);
                    if (markerEl) {
                        markerEl.style.display = "inline";
                        var previousNode = markerEl.previousSibling;
                        if (previousNode && previousNode.nodeType == 3) {
                            markerEl.parentNode.removeChild(markerEl);
                            range.collapseToPoint(previousNode, previousNode.length);
                        } else {
                            range.collapseBefore(markerEl);
                            markerEl.parentNode.removeChild(markerEl);
                        }
                    } else {
                        module.warn("Marker element has been removed. Cannot restore selection.");
                    }
                } else {
                    setRangeBoundary(savedSelection.doc, range, rangeInfo.startMarkerId, true);
                    setRangeBoundary(savedSelection.doc, range, rangeInfo.endMarkerId, false);
                }
                if (len == 1) {
                    range.normalizeBoundaries();
                }
                ranges[i] = range;
            }
            if (len == 1 && preserveDirection && api.features.selectionHasExtend && rangeInfos[0].backwards) {
                sel.removeAllRanges();
                sel.addRange(ranges[0], true);
            } else {
                sel.setRanges(ranges);
            }
            savedSelection.restored = true;
        }
    }
    function removeMarkerElement(doc, markerId) {
        var markerEl = gEBI(markerId, doc);
        if (markerEl) {
            markerEl.parentNode.removeChild(markerEl);
        }
    }
    function removeMarkers(savedSelection) {
        var rangeInfos = savedSelection.rangeInfos;
        for (var i = 0, len = rangeInfos.length, rangeInfo; i < len; ++i) {
            rangeInfo = rangeInfos[i];
            if (rangeInfo.collapsed) {
                removeMarkerElement(savedSelection.doc, rangeInfo.markerId);
            } else {
                removeMarkerElement(savedSelection.doc, rangeInfo.startMarkerId);
                removeMarkerElement(savedSelection.doc, rangeInfo.endMarkerId);
            }
        }
    }
    api.saveSelection = saveSelection;
    api.restoreSelection = restoreSelection;
    api.removeMarkerElement = removeMarkerElement;
    api.removeMarkers = removeMarkers;
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值