
WySharpSize = {
    Large: "Large",
    Middle: "Middle",
    Small: "Small"
};

$.extend({
    getJqObj: function (target) {
        ///<summary>可根据标签id、#id、HTMLElement或者JQuery对象，自动装配为JQuery对象</summary>
        ///<param name="args" type="Object">字符串、HTMLElement或JQuery对象</param>
        if (!target) {
            return null;
        }
        if (target instanceof jQuery) {
            return target;
        } /*else if (target instanceof HTMLElement) {
            return $(target);
        }
        else if (typeof target == "string")
        {
            if (target.indexOf("#") == 0) {
                return $(target);
            } else {
                return $("#" + target);
            }
        }*/
        return $(target);
    },

    pinBottom: function (args) {
        ///<summary>将源固定到目标下方</summary>
        ///<param name="args" type="object">参数对象</param>
        ///<param name="args.source" type="string">源JQuery选择器</param>
        ///<param name="args.target" type="string">目标JQuery选择器</param>
        ///<param name="args.setInterval" type="bool">是否循环设置</param>
        ///<param name="args.interval" type="int">循环间隔时长（毫秒）</param>
        ///<param name="args.intervalTimes" type="int">循环次数</param>
        ///<param name="args.stopFunc" type="function">停止方法</param>
        var defaultArgs = {
            setInterval: false,
            interval: 100,
            intervalTimes: 10
        };
        var finalArgs = $.extend(true, defaultArgs, args);

        var handle;
        var times = 1;
        var pinFunc = function () {
            try {
                if (finalArgs.setInterval && finalArgs.setInterval == true && finalArgs.stopFunc && finalArgs.stopFunc(finalArgs.source, finalArgs.target)){
                    window.clearInterval(handle);
                }
                if (finalArgs.setInterval && finalArgs.setInterval == true && finalArgs.intervalTimes && times > finalArgs.intervalTimes){
                    window.clearInterval(handle);
                }
                var targetJqObj = $.getJqObj(finalArgs.target);
                var targetPosition = targetJqObj.position();
                var targetHeight = targetJqObj.prop("clientHeight");
                var sourceJqObj = $.getJqObj(finalArgs.source);
                sourceJqObj.css({
                    "position": "absolute",
                    "top": targetPosition.top + targetHeight,
                    "left": targetPosition.left,
                });
                times += 1;
            } catch(e) {
                window.clearInterval(handle);
            }
        }

        if (finalArgs.setInterval && finalArgs.setInterval == true){
            handle = setInterval(pinFunc, finalArgs.interval);
        }else {
            pinFunc();
        }
    },
});

$.fn.extend({

    pinBottom: function (args) {
        ///<summary>将源固定到目标下方</summary>
        ///<param name="target" type="String">目标JQuery选择器</param>
        var source = this
        var finalArgs = $.extend(true, args, { source: source });
        $.pinBottom(finalArgs);
    },
});

