码迷,mamicode.com
首页 > Web开发 > 详细

《JS弹出页面》

时间:2014-09-03 18:04:37      阅读:612      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   ar   for   文件   div   

一.引入两个文件

1.macco.js

(function ($) {
    var macco = {
        debug: true,
        // arguments : all
        // console.log
        log: function () {
            var a = window.console, b = arguments;
            if (a && a.log) {
                a.log.apply ? a.log.apply(a, b) : a.log(b);
            }
        },
        // arguments : all
        // console.dir
        dir: function () {
            var a = window.console, b = arguments;
            if (a && a.dir) {
                a.dir.apply ? a.dir.apply(a, b) : a.dir(b);
            }
        },
        // arguments : all
        // arguments[0]: obj
        // arguments[n]: str
        // delete obj prototype
        delPrototype: function () {
            var arg = arguments;
            var len = arguments.length;
            if (len > 0) {
                var obj = arg[0];
                if (obj == null) {
                    return "";
                }
                for (var i = 1; i < len; i++) {
                    if (obj.hasOwnProperty(arg[i])) {
                        delete obj[arg[i]];
                    }
                }
                return arg[0];
            }
            return null;
        },
        // obj : obj
        // ps: obj
        // obj extend obj
        extobj: function (obj, ps) {
            if (!obj)
                obj = {};
            if (!ps)
                return obj;
            for (var p in ps) {
                if (!obj[p]) {
                    obj[p] = ps[p];
                }
            }
            return obj;
        },
        // url : str
        // callback : fn
        // ajax get function
        get: function (url, callback) {
            var setting = {
                ‘url‘: url,
                ‘type‘: ‘get‘,
                ‘success‘: callback
            }
            macco.ajax(setting);
        },
        // url : str
        // callback : fn
        // ajax post function
        post: function (url, data, callback) {
            var setting = {
                ‘url‘: url,
                ‘type‘: ‘post‘,
                ‘data‘: data,
                ‘success‘: callback
            };
            macco.ajax(setting);
        },
        //
        decode: function (data) {
            try {
                data = $.parseJSON(data);
                if (data.IsSuccessed != ‘successed‘) {
                    throw data.ErrorMessage;
                }
                return data
            } catch (e) {
                macco.alert({
                    title: "错误信息",
                    content: "解析JSON对象失败!<br>" + data + "错误消息" + e
                })
                macco.log("format JSON error");
            }
        },
        encode: function (object) {
            var type = typeof object;
            if (‘object‘ == type) {
                if (object instanceof Array)
                    type = ‘array‘;
                else if (object instanceof RegExp)
                    type = ‘regexp‘;
                else
                    type = ‘object‘;
            }
            switch (type) {
                case ‘undefined‘:
                case ‘unknown‘:
                    return;
                    break;
                case ‘function‘:
                case ‘boolean‘:
                case ‘regexp‘:
                    return object.toString();
                    break;
                case ‘number‘:
                    return isFinite(object) ? object.toString() : ‘null‘;
                    break;
                case ‘string‘:
                    return ‘"‘ + object.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g, function () {
                        var a = arguments[0];
                        return (a == ‘\n‘) ? ‘\\n‘ : (a == ‘\r‘) ? ‘\\r‘ : (a == ‘\t‘) ? ‘\\t‘ : ""
                    }) + ‘"‘;
                    break;
                case ‘object‘:
                    if (object === null)
                        return ‘null‘;
                    var results = [];
                    for (var property in object) {
                        var value = macco.encode(object[property]);
                        if (value !== undefined)
                            results.push(macco.encode(property) + ‘:‘ + value);
                    }
                    return ‘{‘ + results.join(‘,‘) + ‘}‘;
                    break;
                case ‘array‘:
                    var results = [];
                    for (var i = 0; i < object.length; i++) {
                        var value = macco.encode(object[i]);
                        if (value !== undefined)
                            results.push(value);
                    }
                    return ‘[‘ + results.join(‘,‘) + ‘]‘;
                    break;
            }
        },
        // setting : object
        ajax: function (setting) {
            if (macco.debug) {
                var defSettings = $.ajaxSetup();
                defSettings = $.extend(defSettings, setting);
                var notFoundError = function () {//服务器错误码
                    macco.alert({
                        title: "错误信息",
                        content: "没有页面!",
                        button: [{
                            text: "重新发送",
                            cls: "",
                            val: true
                        }]
                    })
                }
                defSettings.statusCode = {
                    404: notFoundError
                }
                defSettings.success = function (data, textStatus, jqXHR) {//
                    var data = data;
                    try {
                        data = $.parseJSON(data);
                        if (data.IsSuccessed != ‘successed‘) {
                            throw data.ErrorMessage;
                        }
                        (setting.success || $.noop).call(this, data, textStatus, jqXHR);
                    } catch (e) {
                        macco.alert({
                            size: {
                                width: 300,
                                height: 200
                            },
                            title: "错误信息",
                            content: "format JSON error!<br>" + data + "错误消息" + e,
                            button: [{
                                text: "重新发送",
                                cls: "",
                                val: true
                            }, {
                                text: "取消发送",
                                cls: "",
                                val: false
                            }],
                            callback: function (value) {
                                if (value) {
                                    macco.ajax(defSettings);
                                } else {

                                }
                            }
                        })
                        macco.log("format JSON error");
                    }
                }
                $.ajax(defSettings);
            } else {
                $.ajax(setting);
            }

        },
        // size : object
        // info : array
        // button : object
        // callback array
        alert: function (options) {
            var settings = {
                size: {
                    width: 200,
                    height: 150
                },
                title: ‘提示框‘,
                content: ‘‘,
                button: {},
                callback: $.noop,
                complete: $.noop,
                context: null
            }
            $.extend(true, settings, options);
            var title = settings.title;
            var content = settings.content;
            var $maccoAlert = $("#maccoAlert");
            if ($maccoAlert.size()) {
                $maccoAlert.remove();
            }
            var css = {};
            css.width = $.isNumeric(settings.size.width) ? Math.max(settings.size.width, 200) : 200;
            css.height = $.isNumeric(settings.size.height) ? Math.max(settings.size.height, 150) : 150;
            var $maccoAlertLay = $("<div id=‘maccoAlertLayer‘>").appendTo("body");
            var $maccoAlertSwap = $(‘<div id="maccoAlertSpan">‘).appendTo("body");
            $maccoAlert = $(‘<div id="maccoAlert">‘).appendTo($maccoAlertSwap).css(css);
            var $maccoAlertTitle = $(‘<div class="maccoAlertTitle">‘ + ‘<span class="left"></span>‘ + ‘<span class="center">‘ + "<p class=‘title‘>" + settings.title + "</p>" + ‘</span>‘ + ‘<span class="right"></span>‘ + ‘</div>‘).appendTo($maccoAlert);
            var $maccoAlertContent = $(‘<div class="maccoAlertContent">‘ + ‘<span class="center">‘ + settings.content + ‘</span>‘ + ‘<span class="left"></span>‘ + ‘<span class="right"></span>‘ + ‘</div>‘).appendTo($maccoAlert);
            var $maccoAlertClose = $(‘<div class="maccoAlertClose">‘).appendTo($maccoAlertTitle);
            $maccoAlertClose.click(function () {
                $maccoAlertSwap.animate({
                    opacity: 10
                }, 0, function () {
                    $maccoAlertSwap.remove();
                    $("#shade").hide();
                });
                $maccoAlertLay.animate({
                    opacity: 10
                }, 0, function () {
                    $maccoAlertLay.remove()
                });
                $(window).unbind("resize.maccoAlertCenter");
                return false;
            });
            var index = 0;
            var rect = $(‘<div class="rect">‘).appendTo($maccoAlert);
            $(‘<span class="left"></span>‘).appendTo(rect);
            $(‘<span class="center"></span>‘).appendTo(rect);
            $(‘<span class="right"></span>‘).appendTo(rect);
            var $maccoAlertButtons;
            if (!$.isEmptyObject(settings.button)) {
                $maccoAlertButtons = $(‘<div class="maccoAlertButtons">‘).appendTo($maccoAlert);
                $.each(settings.button, function (key, value) {
                    var $maccoAlertButton = $(‘<a class="maccoAlertButton grnBtn"></a>‘).text(key).click(function () {
                        (settings.callback || $.noop)(value);
                        $maccoAlertClose.trigger(‘click‘);
                    }).appendTo($maccoAlertButtons);
                });
                $maccoAlertContent.height(function () {
                    var height = $maccoAlertSwap.outerHeight() - $maccoAlertTitle.outerHeight() - (($maccoAlertButtons || $("")).outerHeight() || 0);
                    return height;
                });
            }
            $(window).bind("resize.maccoAlertCenter", function () {
                $maccoAlertSwap.center();
            })
            $(document).bind("scroll.maccoAlertCenter", function () {
                $maccoAlertSwap.center();
            })
            $maccoAlertSwap.center().animate({
                opacity: 1
            }, 300);
            macco.callback = function (value) {
                $maccoAlertClose.trigger(‘click‘);
                var value = value || [];
                settings.complete.call(settings.context || this, value);
                macco.callback = $.noop;
                $(window).trigger("resize.maccoAlertCenter");
            }
            return $maccoAlertSwap;
        },
        iframe: function (options) {
            var settings = {
                src: "/index.php",
                callback: $.noop,
                close: $.noop
            }
            $.extend(settings, options);
            var $maccoIframe = $("#maccoIframeSwap");
            if ($maccoIframe.size()) {
                $maccoIframe.remove();
            }
            var $maccoIframeLay = $(‘<div id="maccoIframeLayer">‘).appendTo(‘body‘);
            var $maccoIframeSwap = $(‘<div id="maccoIframeSwap">‘).appendTo(‘body‘);
            $maccoIframe = $(‘<iframe id="maccoIframe" src=‘ + settings.src + ‘>‘).appendTo($maccoIframeSwap).load(function () {
                settings.callback.call(this);
            });

            var $maccoIframeClose = $(‘<i id="maccoIframeClose">‘).appendTo($maccoIframeSwap).bind("click.maccoIframe", function () {
                $maccoIframeSwap.animate({
                    opacity: 0
                }, 300, function () {
                    $maccoIframeSwap.remove();
                });
                $maccoIframeLay.animate({
                    opacity: 0
                }, 300, function () {
                    $maccoIframeLay.remove();
                });
                $(window).unbind("resize.maccoIframeCenter");
                settings.close.call(this);
            });
            $(window).bind("resize.maccoIframeCenter", function () {
                $maccoIframeSwap.center();
            })
            $maccoIframeSwap.center().animate({
                opacity: 1
            }, 300);

            return $maccoIframeSwap;
        },
        callback: $.noop,
        ui: {
            alert: function (options) {
                var settings = {
                    size: {
                        width: 255,
                        height: 164
                    },
                    title: ‘提示框‘,
                    content: ‘‘,
                    button: null,
                    callback: $.noop,
                    complete: $.noop,
                    context: null
                }
                $.extend(true, settings, options);
                var title = settings.title;
                var content = settings.content;
                var $maccoAlert = $("#maccoAlert");
                if ($maccoAlert.size()) {
                    $maccoAlert.remove();
                }
                var css = {};
                css.width = $.isNumeric(settings.size.width) ? Math.max(settings.size.width, 200) : 200;
                css.height = $.isNumeric(settings.size.height) ? Math.max(settings.size.height, 150) : 150;
                var $maccoAlertLay = $("<div id=‘maccoAlertLayer‘>").appendTo("body");
                var $maccoAlertSwap = $(‘<div id="maccoAlertSpan">‘).appendTo("body");
                $maccoAlert = $(‘<div id="maccoAlert">‘).appendTo($maccoAlertSwap).css({
                    width: css.width,
                    "min-height": css.height,
                    height: "auto !important"
                });
                var $maccoAlertTitle = $(‘<div class="maccoAlertTitle">‘ + settings.title + ‘</div>‘).appendTo($maccoAlert);
                var $maccoAlertContent = $(‘<div class="maccoAlertContent">‘ + settings.content + ‘</div>‘).appendTo($maccoAlert);
                var $maccoAlertClose = $(‘<div class="maccoAlertClose">‘).appendTo($maccoAlertTitle);
                $maccoAlertClose.click(function () {
                    $maccoAlertSwap.animate({
                        opacity: 10
                    }, 0, function () {
                        $maccoAlertSwap.remove();
                    });
                    $maccoAlertLay.animate({
                        opacity: 10
                    }, 0, function () {
                        $maccoAlertLay.remove()
                    });
                    $("#shade").hide();
                    $("body").unbind(‘mousewheel DOMMouseScroll‘);
                    $(window).unbind("resize.maccoAlertCenter");
                    return false;
                });
                var index = 0;
                var $maccoAlertButtons;
                if (!$.isEmptyObject(settings.button)) {
                    $maccoAlertButtons = $(‘<div class="maccoAlertButtons">‘).appendTo($maccoAlert);
                    $.each(settings.button, function (key, value) {
                        var $maccoAlertButton = $(‘<a class=" + value.cls + "></a>‘).text(value.text).click(function () {
                            (settings.callback || $.noop)(value.val);
                            $maccoAlertClose.trigger(‘click‘);
                        }).appendTo($maccoAlertButtons);
                    });
                }
                $(window).bind("resize.maccoAlertCenter", function () {
                    $maccoAlertSwap.center();
                })
                $(document).bind("scroll.maccoAlertCenter", function () {
                    $maccoAlertSwap.center();
                })
                $maccoAlertSwap.center().animate({
                    opacity: 1
                }, 300);
                macco.callback = function (value) {
                    $maccoAlertClose.trigger(‘click‘);
                    var value = value || [];
                    settings.complete.call(settings.context || this, value);
                    macco.callback = $.noop;
                    $(window).trigger("resize.maccoAlertCenter");
                }

                return $maccoAlertSwap;
            },
            photoLayer: function (options) {
                var settings = {
                    src: "",
                    size: {
                        width: 100,
                        height: 100
                    },
                    localurl: null,
                    addDom: null,
                    change: $.noop,
                    closeback: $.noop,
                    time: 300,
                    callback: $.noop
                };
                $.extend(true, settings, options);
                var num = 0, total = 0;
                var $maccoPhotoWarp = $("#maccoPhotoWarp");
                if ($maccoPhotoWarp.size()) {
                    $maccoPhotoWarp.remove();
                }
                var $maccoPhotoLayer = $("#maccoPhotoLayer");
                if ($maccoPhotoLayer.size()) {
                    $maccoPhotoLayer.remove();
                }
                $maccoPhotoLayer = $("<div id=‘maccoPhotoLayer‘>").appendTo(‘body‘);

                var $addDom = $("<div id=‘appendDom‘/>").append($(settings.addDom));
                var form = $("<form action=‘" + settings.localurl + "‘ method=‘post‘ />").appendTo(‘body‘).center();
                $maccoPhotoWarp = $("<div id=‘maccoPhotoWarp‘>").append($addDom).appendTo(form);
                var $maccoPhotoImg;
                if (settings.src) {
                    if ($.type(settings.src) === "string") {
                        settings.src = [settings.src];
                    }
                    if ($.type(settings.src) === "array") {
                        total = settings.src.length;
                        $maccoPhotoImg = $("<img id=‘maccoPhotoImg‘>").appendTo($maccoPhotoWarp).one("load", function () {
                            var position = $maccoPhotoImg.center(true);
                            $maccoPhotoWarp.center().animate({
                                top: position.top,
                                left: position.left,
                                width: $maccoPhotoImg.width(),
                                height: $maccoPhotoImg.height()
                            }, settings.time);
                        }).attr({
                            src: settings.src[num]
                        });
                        if (settings.src.length > 1) {
                            var $maccoPhotoPrev = $("<a id=‘maccoPhotoPrev‘></a>").appendTo($maccoPhotoLayer);
                            var $maccoPhotoNext = $("<a id=‘maccoPhotoNext‘></a>").appendTo($maccoPhotoLayer);
                            var refresh = function (dom, num) {
                                var $temp = $("<img>").one("load", function () {
                                    $maccoPhotoWarp.css({
                                        width: "1px",
                                        height: "1px"
                                    }).center();
                                    console.log(settings.src[num]);
                                    $maccoPhotoImg.attr("src", settings.src[num]);
                                    var position = $maccoPhotoImg.center(true);
                                    $maccoPhotoWarp.animate({
                                        width: $maccoPhotoImg.width(),
                                        height: $maccoPhotoImg.height(),
                                        top: position.top,
                                        left: position.left
                                    }, settings.time);
                                }).attr("src", settings.src[num]);
                                settings.change.call(dom, num);
                            }
                            $maccoPhotoPrev.bind("click.photoLayer", function () {
                                num = num >= total - 1 ? 0 : ++num;
                                refresh(this, num);
                            })
                            $maccoPhotoNext.bind("click.photoLayer", function () {
                                num = num < total - 1 ? total : --num;
                                refresh(this, num);
                            })
                        }
                        settings.callback.call($maccoPhotoWarp);
                    }
                }
                $(window).bind("resize.photoLayer", function () {
                    $maccoPhotoWarp.center();
                });
                $maccoPhotoClose = $("<a id=‘maccoPhotoClose‘></a>").appendTo($maccoPhotoLayer).bind("click.photoLayer", function (e) {
                    $maccoPhotoWarp.add($maccoPhotoLayer).animate({
                        opacity: 0
                    }, settings.time, function () {
                        $maccoPhotoLayer.remove();
                        $maccoPhotoWarp.remove();
                        settings.closeback();
                    });
                    return false;
                });
                $maccoPhotoLayer.click(function (e) {
                    $maccoPhotoWarp.add($maccoPhotoLayer).animate({
                        opacity: 0
                    }, settings.time, function () {
                        $maccoPhotoLayer.remove();
                        $maccoPhotoWarp.remove();
                        settings.closeback();
                    });
                    return false;
                })
            }
        }
    }
    window.macco = $$ = macco;
})(jQuery);

// extend jQuery Object
(function ($) {
    $.fn.center = function (flag) {
        var $window = $(window);
        var wwidth = $window.width();
        var wheight = $window.height();
        var postion = {};
        this.each(function (index, value) {
            var $this = $(value);
            var width = $this.outerWidth();
            var height = $this.outerHeight();
            var top = (wheight - height) / 2;
            var left = (wwidth - width) / 2;
            if (flag) {
                postion.top = top;
                postion.left = left;
            } else {
                $this.css({
                    top: top,
                    left: left
                })
            }
        });
        if (flag) {
            return postion;
        } else {
            return this;
        }
    }
    $.fn.drag = function (options) {
        var settings = {
            zIndex: 999,
            before: $.noop,
            moving: $.noop,
            after: $.noop,
            out: false
        }
        options = options || {};
        $.extend(settings, options);
        $(this).each(function (index, value) {
            (function () {
                if ($(this).attr("unDrag") == "true")
                    return;
                var x = y = _x = _y = 0;
                var objx, objy, flag = false;
                var $this = $(this);
                $this.bind({
                    "mousedown.drag": function (event) {
                        settings.before.call($this);
                        x = event.pageX;
                        y = event.pageY;
                        objx = $this.offset().left;
                        objy = $this.offset().top;
                        $(document).bind("mousemove.drag", function (event) {
                            settings.moving.call($this);
                            _x = event.pageX;
                            _y = event.pageY;
                            var _top = objy + (_y - y);
                            var _left = objx + (_x - x);
                            if (!settings.out) {
                                var winh = $(window).height();
                                var wind = $(window).width();
                                if (_top + $this.height() > $(window).height() - 10) {
                                    _top = winh - $this.height() - 10;
                                } else if (_top < 10) {
                                    _top = 10;
                                }
                                if (_left + $this.width() > $(window).width() - 10) {
                                    _left = wind - $this.width() - 10;
                                } else if (_left < 10) {
                                    _left = 10;
                                }
                            }
                            $this.css({
                                "position": "absolute",
                                "zIndex": settings.zIndex
                            }).offset({
                                top: _top,
                                left: _left
                            });
                        });
                        event.stopPropagation();
                        return false;
                    },
                    "mouseup.drag": function (event) {
                        settings.after.call($this);
                        $(document).unbind("mousemove.drag");
                        event.stopPropagation();
                        return false;
                    },
                    "mouseover.drag": function () {
                    },
                    "mouseout.drag": function () {
                    }
                });
            }).call(value)
        });
        return this;
    }
    $.fn.undrag = function () {
        $(this).each(function (index, value) {
            (function () {
                $(this).unbind("mouseover.drag");
                $(this).unbind("mouseout.drag");
                $(this).unbind("mousedown.drag");
                $(this).unbind("mouseup.drag");
            }).call(value)
        });
        $(document).unbind("mousemove.drag");
        $(document).unbind("mouseup.drag");
        return this;
    }
    $.fn.layer = function (options) {
        var settings = {
            layer: {
                "width": 300,
                "height": 200,
                "position": "absolute"
            },
            data: [],
            position: "lc",
            html: "<p>123123123</p>",
            style: "outside",
            offset: {
                top: 0,
                left: 0,
                right: 0,
                bottom: 0
            }
        };
        // inside and outside
        $.extend(true, settings, options);
        this.each(function (index, value) {
            if (settings.style == "outside") {
                var $this = $(this);
                var width = $this.innerWidth();
                var height = $this.innerHeight();
                var position = $this.position();
                var top = position.top;
                var left = position.left;
                var a = width + settings.offset.left;
                macco.dir(position);
                var $maccoLayer = $("<div class=‘maccoLayer‘ position=‘" + settings.position + "‘>" + settings.html + "</div>")
                $maccoLayer.appendTo("body").css(settings.layer);
                var $maccoLayerPostion = $(‘<i class="maccoLayerPostion ‘ + settings.position + ‘">‘);
                var layerWidth = $maccoLayer.innerWidth();
                var layerHeight = $maccoLayer.innerHeight();
                switch (settings.position) {
                    case "rc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("top", layerHeight / 2 - 7);
                        $maccoLayer.css(rightCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                    case "lc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("top", layerHeight / 2 - 7);
                        $maccoLayer.css(leftCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                    case "tc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("left", layerWidth / 2 - 7);
                        $maccoLayer.css(topCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                    case "bc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("left", layerWidth / 2 - 7);
                        $maccoLayer.css(bottomCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                }

                function rightCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x - (bh - ah) / 2 + settings.offset.top,
                        left: y + 15 + aw + settings.offset.left
                    }
                    return position;
                }

                function leftCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x - (bh - ah) / 2 + settings.offset.top,
                        left: y - 15 - bw - settings.offset.left
                    }
                    return position;
                }

                function topCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x - 15 - bh - settings.offset.top,
                        left: y - (bw - aw) / 2 - settings.offset.left
                    }
                    return position;
                }

                function bottomCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x + 15 + ah + settings.offset.top,
                        left: y - (bw - aw) / 2 - settings.offset.left
                    }
                    return position;
                }

            } else if (settings.style == "inside") {
                var $this = $(this);
                var width = $this.innerWidth();
                var height = $this.innerHeight();
                var position = $this.position();
                var top = position.top;
                var left = position.left;
                var a = width + settings.offset.left;
                macco.dir(position);
                var $maccoLayer = $("<div class=‘maccoLayer‘ position=‘" + settings.position + "‘>" + settings.html + "</div>")
                $maccoLayer.appendTo("body").css(settings.layer);
                var $maccoLayerPostion = $(‘<i class="maccoLayerPostion ‘ + settings.position + ‘">‘);
                var layerWidth = $maccoLayer.innerWidth();
                var layerHeight = $maccoLayer.innerHeight();
                switch (settings.position) {
                    case "rc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("top", layerHeight / 2 - 7);
                        $maccoLayer.css(rightCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                    case "lc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("top", layerHeight / 2 - 7);
                        $maccoLayer.css(leftCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                    case "tc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("left", layerWidth / 2 - 7);
                        $maccoLayer.css(topCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                    case "bc":
                        $maccoLayerPostion.appendTo($maccoLayer).css("left", layerWidth / 2 - 7);
                        $maccoLayer.css(bottomCenter(top, left, width, height, layerWidth, layerHeight));
                        break;
                }

                function rightCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x - (bh - ah) / 2 + settings.offset.top,
                        left: y + 15 + aw + settings.offset.left
                    }
                    return position;
                }

                function leftCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x - (bh - ah) / 2 + settings.offset.top,
                        left: y - 15 - bw - settings.offset.left
                    }
                    return position;
                }

                function topCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x - 15 - bh - settings.offset.top,
                        left: y - (bw - aw) / 2 - settings.offset.left
                    }
                    return position;
                }

                function bottomCenter(x, y, aw, ah, bw, bh) {
                    var position = {
                        top: x + 15 + ah + settings.offset.top,
                        left: y - (bw - aw) / 2 - settings.offset.left
                    }
                    return position;
                }

            }
        })
    }
    var regex = {};
    var reg = {
        usn: /^[a-zA-Z0-9_-]{6,24}$/,
        psd: /^[a-zA-Z0-9_-]{6,32}$/,
        mail: /^([a-zA-Z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/,
        num: /^[0-9]+(.[0-9]+)?$/,
        url: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/,
        eng: /^[0-9a-z]+$/,
        chn: /^[\u2E80-\u9FFF]+$/,
        hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/,
        notnull: /\S/,
        all: /^[.]+$/
    };
    $.each(reg, function (key, value) {
        regex[key] = function (text) {
            return reg[key].test(text);
        }
    });
    $.regex = macco.regex = regex;
    $.fn.textbox = function (options) {
        var $this = $(this);
        $this.filter("input").each(function (index, value) {
            var $this = $(value);
            var settings = {
                hint: "",
                textbox: "all",
                error: $.noop,
                success: $.noop,
                custom: undefined,
                blur: $.noop,
                change: $.noop,
                focus: $.noop,
                max: 9999
            }
            $.extend(settings, options);
            settings.hint = $this.attr("hint") || settings.hint;
            settings.textbox = $this.attr("textbox") || settings.textbox;
            $this.bind("change.textbox", function () {
                var $this = $(this);
                var val = $this.val();
                macco.log("val", val);
                if (val.length > settings.max) {
                    settings.error.call($this, val, "beyond");
                    $this.val(val.limit(settings.max));
                    return;
                }
                settings.change.call(this, val);
            });
            $this.bind("focus.textbox", function () {
                var $this = $(this);
                var val = $this.val();
                if (settings.hint == val) {
                    $this.val("");
                }
                settings.focus.call(this, val);
            });
            $this.bind("blur.textbox", function (e, data) {
                var $this = $(this);
                var val = $this.val();
                if (settings.hint && val == "") {
                    $this.val(settings.hint);
                }
                if (data)
                    return;
                if (val != settings.hint || val.trim() == ‘‘) {
                    var ans = regex[settings.textbox](val);
                    macco.log("ans", ans);
                    macco.log("type", settings.textbox);
                    if (ans) {
                        if (settings.custom) {
                            var result = settings.custom.call($this, val);
                            if (result.trim() == ‘‘) {
                                $this.attr("textboxcheak", "true");
                                settings.success.call($this, val, settings.textbox, "success");
                            } else {
                                $this.attr("textboxcheak", "false");
                                settings.error.call($this, val, result);
                            }
                        } else {
                            $this.attr("textboxcheak", "true");
                            settings.success.call($this, val, settings.textbox, "success");
                        }
                    } else {
                        $this.attr("textboxcheak", "false");
                        settings.error.call($this, val, settings.textbox, "error");
                    }
                }
                settings.blur.call(this, val);
            });
            $this.triggerHandler("blur.textbox", true);
        })
    }
    return this;
})(jQuery);
// macco extend String/Array prototype
(function () {
    // macco ext string
    macco.extobj(String.prototype, {
        trim: function () {
            return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
        },
        padLeft: function (n, c) {
            var s = this;
            var x = n - s.length;
            if (x > 0) {
                c = c || " ";
                s = (new Array(Math.ceil(x / c.length) + 1)).join(c) + s;
                return s.substring(s.length - n, n);
            }
            return s;
        },
        padRight: function (n, c) {
            s = this;
            var x = n - s.length;
            if (x > 0) {
                c = c || " ";
                s = s + (new Array(Math.ceil(x / c.length))).join(c);
                return s.substring(0, n);
            }
            return s;
        },
        format: function () {
            var fmt = this;
            for (var i = 0, l = arguments.length; i < l; i++) {
                fmt = fmt.replace(new RegExp(‘\\{‘ + i + ‘\\}‘, "mg"), arguments[i]);
            }
            return fmt;
        },
        equals: function (str2, ignoreCase) {
            var str1 = this;
            if (str1 == null && str2 == null) {
                return true;
            } else if (str1 == null || str2 == null) {
                return false;
            }
            if (ignoreCase) {
                return str1.toLowerCase() == str2.toLowerCase();
            } else {
                return str1 == str2;
            }
        },
        encodeHtml: function () {
            var rtval = this.replace(/\>/g, "&gt;").replace(/\</g, "&lt;").replace(/\&/g, "&amp;").replace(/\‘/g, "&#039;").replace(/\"/g, "&quot;");
            return rtval;
        },
        hasXss: function () {
            var xssRe = /<|&lt|\\u0*3c|\\x0*3c|%3C|&#0*60|>|&gt|\\u0*3e|\\x0*3e|%3E|&#0*62/gi;
            return xssRe.test(this);
        },
        escape: function () {
            return !!(encodeURIComponent) ? encodeURIComponent(this) : escape(this);
        },
        unescape: function () {
            return !!(decodeURIComponent) ? decodeURIComponent(this) : unescape(this);
        },
        limit: function (maxlimit) {
            var size = 0;
            var i = 0;
            var len = this.length;
            for (i = 0; i < len; i++) {
                if (this.charCodeAt(i) > 255) {
                    size += 2;
                } else {
                    size++;
                }
                if (size > maxlimit) {
                    break;
                }
            }
            return this.substring(0, i);
        },
        size: function () {
            var size = 0;
            var i = 0;
            var len = this.length;
            for (i = 0; i < len; i++) {
                if (this.charCodeAt(i) > 255) {
                    size += 2;
                } else {
                    size++;
                }
            }
            return size;
        }
    })
    // macco ext array
    macco.extobj(Array.prototype, {
        foreach: function (proc) {
            for (var i = 0, l = this.length; i < l; i++) {
                // proc(this[i]);
                proc.call(this, this[i], i);
            }
        },
        push: function () {
            for (var i = 0, l = arguments.length; i < l; i++) {
                this[this.length] = arguments[i];
            }
            return this.length;
        },
        pop: function () {
            if (this.length > 0) {
                return this[--this.length];
            } else {
                return null;
            }
        },
        indexOf: function (elm, bgnIdx) {
            bgnIdx = bgnIdx || 0;
            if (bgnIdx < 0)
                bgnIdx = 0;
            for (var i = 0, l = this.length; i < l; i++) {
                if (this[i] === elm) {
                    return i;
                }
            }
            return -1;
        },
        contains: function (elm) {
            return (this.indexOf(elm) >= 0);
        },
        shift: function () {
            return this.splice(0, 1)[0];
        },
        last: function () {
            return (this.length > 0 ? this[this.length - 1] :
   void (0));
        },
        remove: function (obj) {
            for (var i = this.length - 1; i >= 0; i--) {
                if (this[i] === obj) {
                    this.splice(i, 1);
                }
            }
            return this;
        },
        map: function (fun, context) {
            var ret = [];
            for (var i = 0, l = this.length; i < l; i++) {
                ret.push(fun.call(context, this[i], i, this));
            }
            return ret;
        },
        splice: function (idx, num) {
            var delta;
            var addCount = arguments.length - 2;
            if (idx > this.length) {
                idx = this.length;
            }
            if (idx + num > this.length) {
                num = this.length - idx;
            }
            var deleted = [];
            for (var i = 0; i < num; ++i) {
                deleted.push(this[idx + i]);
            }
            if (addCount > num) {
                delta = addCount - num;
                for (i = this.length + delta - 1; i >= idx + delta; i--) {
                    this[i] = this[i - delta];
                }
            } else if (addCount < num) {
                delta = num - addCount;
                for (i = idx + addCount; i < this.length - delta; i++) {
                    this[i] = this[i + delta];
                }
                for (; i < this.length - 1; ++i) {
                    delete this[i];
                }
                this.length -= delta;
            }
            for (i = 0; i < addCount; ++i) {
                this[idx + i] = arguments[2 + i];
            }
            return deleted;
        },
        swap: function (i, j) {
            var temp = this[i];
            this[i] = this[j];
            this[j] = temp;
        },
        bubbleSort: function () {
            for (var i = this.length - 1; i > 0; --i) {
                for (var j = 0; j < i; ++j) {
                    if (this[j] > this[j + 1])
                        this.swap(j, j + 1);
                }
            }
        },
        selectionSort: function () {
            for (var i = 0; i < this.length; ++i) {
                var index = i;
                for (var j = i + 1; j < this.length; ++j) {
                    if (this[j] < this[index])
                        index = j;
                }
                this.swap(i, index);
            }
        },
        insertionSort: function () {
            for (var i = 1; i < this.length; ++i) {
                var j = i, value = this[i];
                while (j > 0 && this[j - 1] > value) {
                    this[j] = this[j - 1]; --j;
                }
                this[j] = value;
            }
        },
        shellSort: function () {
            for (var step = this.length >> 1; step > 0; step >>= 1) {
                for (var i = 0; i < step; ++i) {
                    for (var j = i + step; j < this.length; j += step) {
                        var k = j, value = this[j];
                        while (k >= step && this[k - step] > value) {
                            this[k] = this[k - step];
                            k -= step;
                        }
                        this[k] = value;
                    }
                }
            }
        },
        quickSort: function (s, e) {
            if (s == null)
                s = 0;
            if (e == null)
                e = this.length - 1;
            if (s >= e)
                return;
            this.swap((s + e) >> 1, e);
            var index = s - 1;
            for (var i = s; i <= e; ++i) {
                if (this[i] <= this[e])
                    this.swap(i, ++index);
            }
            this.quickSort(s, index - 1);
            this.quickSort(index + 1, e);
        },
        stackQuickSort: function () {
            var stack = [0, this.length - 1];
            while (stack.length > 0) {
                var e = stack.pop(), s = stack.pop();
                if (s >= e)
                    continue;
                this.swap((s + e) >> 1, e);
                var index = s - 1;
                for (var i = s; i <= e; ++i) {
                    if (this[i] <= this[e])
                        this.swap(i, ++index);
                }
                stack.push(s, index - 1, index + 1, e);
            }
        },
        mergeSort: function (s, e, b) {
            if (s == null)
                s = 0;
            if (e == null)
                e = this.length - 1;
            if (b == null)
                b = new Array(this.length);
            if (s >= e)
                return;
            var m = (s + e) >> 1;
            this.mergeSort(s, m, b);
            this.mergeSort(m + 1, e, b);
            for (var i = s, j = s, k = m + 1; i <= e; ++i) {
                b[i] = this[(k > e || j <= m && this[j] < this[k]) ? j++ : k++];
            }
            for (var i = s; i <= e; ++i)
                this[i] = b[i];
        },
        heapSort: function () {
            for (var i = 1; i < this.length; ++i) {
                for (var j = i, k = (j - 1) >> 1; k >= 0; j = k, k = (k - 1) >> 1) {
                    if (this[k] >= this[j])
                        break;
                    this.swap(j, k);
                }
            }
            for (var i = this.length - 1; i > 0; --i) {
                this.swap(0, i);
                for (var j = 0, k = (j + 1) << 1; k <= i; j = k, k = (k + 1) << 1) {
                    if (k == i || this[k] < this[k - 1])
                        --k;
                    if (this[k] <= this[j])
                        break;
                    this.swap(j, k);
                }
            }
        }
    });

})(jQuery)

 

 

 

2.macco.Alert.css

#maccoAlertSpan {
    display: block;
    position: fixed;
    line-height: 16px;
    top: 0;
    left: 0;
    color: gray;
    opacity: 0.1;
    padding: 7px;
    filter: alpha(opacity=1);
    overflow: hidden;
    z-index: 999;
}

#maccoAlert {
    background-color: #FFF;
    display: block;
    background-color: #FFF;
    color: gray;
    -moz-border-radius: 0 0 0 0;
    -webkit-border-radius: 0 0 0 0;
    border-radius:0 0 0 0;
}

    #maccoAlert .maccoAlertTitle {
        position: relative;
        display: block;
        text-align: left;
        text-indent: 1em;
        font-size: 14px;
        line-height: 30px;
        height: 50px;
    }

    #maccoAlert .maccoAlertContent {
        display: block;
        font-size: 14px;
        /*text-indent: 2em;*/
        line-height: 20px;
        padding: 6px 0px 35px 0px;
        overflow-x: hidden;
        overflow-y: auto;
        word-wrap: break-word;
        text-align: center;
    }

    #maccoAlert .maccoAlertButtons {
        position:relative;
        display: block;
        text-align: center;
        padding: 2px;
        padding-right: 10px;
         margin-top:-15px;
    }

    #maccoAlert .maccoAlertButton {
        color: #FFFFFF;
        border: 0px;
        margin-right: 5px;
        padding: 5px 20px;
        background-color: #33cc99;
        margin: 5px;
        min-height: 30px;
    }

    #maccoAlert .maccoAlertClose {
        display: block;
        position: absolute;
        top: 10px;
        right: 10px;
        width: 30px;
        height: 30px;
        background-position: center center;
        background-repeat: no-repeat;
        background-image: url("/Images/public/close.png");
    }

#maccoAlertLayer {
    display: block;
    background-image: url("/Images/public/outbg.png");
    position: fixed;
    height: 100%;
    width: 100%;
    top: 0;
    left: 0;
    overflow: hidden;
    z-index: 998;
}

 

.ssubdel {
    margin-right: 10px;
    margin: 0 auto;
}

.subconfirm {
    width: 50px;
    height: 30px;
    line-height: 30px;
    display: inline-block;
    color: #218e6d;
    font-size: 14px;
    font-weight: bold;
    margin-right: 10px;
    cursor: pointer;
}


#shade {
    /*
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    background: #000;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
    filter: alpha(opacity=50);
    opacity: .5;
    z-index: 111;*/
}

 

 

二.调用

   
    $(".InitialReviewPageUnpassA").click(function () {
        //$(this).closest("tr").remove();
        var obj = $(this).closest("table");
        macco.ui.alert({
            size: {
                width: 408,
                height: 240
            },
            title: "<font style=‘color:#FF8F19;font-family:‘Microsoft YaHei‘; font-weight:bold; font-size:16px;‘></font>",
            content: "<font style=‘ color: #fcac57;font-size: 20px;position: absolute;left: 15px;top: 26px;‘>请输入不通过原因</font><textarea style=‘overflow:hidden; width:360px;height:110px; border:1px solid #94C801‘ ></textarea>",
     
           
            button: [{
                text: "",
                cls: "unpassSure jtwoa",
                val: true,
                text: "确定"
            }, {
                text: "",
                cls: "UnpassCancel btwoa",
                val: false,
                text: "取消"
            }],
            callback: function (value) {
                if (value) {
                    var temlen = 1;
                    obj.find("tr").each(function () {
                        if (!$(this).hasClass("title")) {
                            var input = $(this).find(".tcc1 input").clone(true);

                            $(this).find(".tcc1").html(temlen++);
                            input.appendTo($(this).find(".tcc1"));
                        }
                        if ($(this).hasClass("rr2")) {
                            return false;
                        }
                    });
                }
            }
        });
    });

《JS弹出页面》

标签:style   http   color   os   io   ar   for   文件   div   

原文地址:http://www.cnblogs.com/beesky520/p/3954261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!