(function ($) {
$.fn.outerHTML = function (s) {
return (s)
? this.before(s).remove()
: $("<div>").append(this.eq(0).clone()).html();
};
$.Gmfp = {};
/**
* 發送get請求
* strUrl, oParams, funCallback
*/
$.Gmfp.AjaxGet = function (strUrl, oParams, funCallback) {
$.get(strUrl, oParams, funCallback);
};
/**
* 發送post請求
* strUrl, oParams, funSuccessCallback, funErrorCallback
*/
$.Gmfp.AjaxPost = function (strUrl, oParams, funSuccessCallback, funErrorCallback) {
var strJsonParams = $.toJSON(oParams);
$.ajax({
type: "POST",url: strUrl,
data: strJsonParams,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: funSuccessCallback,
error: funErrorCallback
});
};
/**
* 生成隨機的guid
*/
$.Gmfp.NewGuid = function () {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
guid += "-";
}
return guid;
};
/**
* HtmlEncode
*/
$.Gmfp.HtmlEncode = function (text) {
return text.replace(/&/g, '&').replace(/\ "/g, '"').replace(/</g, '<').replace(/>/g, '>');
};
/**
* HtmlDecode
*/
$.Gmfp.HtmlDecode = function (text) {
return text.replace(/&/g, '&').replace(/"/g, '\" ').replace(/</g, '<').replace(/>/g, '>');
};
/**
* 注意,以后JS代碼中如果遇到回調,可以在對象中通過oTag傳遞數據對象!!!!
* 給JQuery對象設置oTag屬性
* oItem, oTag
* oItem是Element對象
*/
$.Gmfp.SetData = function (oItem, oTag) {
$(oItem).data("oTag", oTag);
};
/**
* 從JQuery對象中獲取oTag屬性
* oItem, oTag
* oItem是Element對象
*/
$.Gmfp.GetData = function (oItem) {
return $(oItem).data("oTag");
};
/**
* 播放FLASH
* strDivid, url
*/
$.Gmfp.Flash = function (strDivid, url) {
$('#' + strDivid).flash({ src: url, width: 1, height: 1 });
};
/**
* 停止FLASH
* strDivid, url
*/
$.Gmfp.FlashStop = function (strDivid) {
$('#' + strDivid).html('');
};
/**
* 顯示消息框
* strMsg,
* strType: "success","notice","warning","error"
*/
$.Gmfp.ShowMsg = function (strMsg, strType, iStayTime) {
$().toastmessage('showToast', {
text: strMsg,
stayTime: iStayTime || 3000,
//fixed: false,
//modal: false,
//sticky: true,
position: 'top-center',
type: strType
});
};
/**
* 顯示不關閉的消息框,返回提示框句柄
* strMsg,
* strType: "success","notice","warning","error"
*/
$.Gmfp.ShowStickyMsg = function (strMsg, strType) {
return $().toastmessage('showToast', {
text: strMsg,
//stayTime: iStayTime || 3000,
//fixed: false,
//modal: false,
sticky: true,
position: 'top-center',
type: strType
});
};
/**
* 關閉消息彈出框
* strMsg
*/
$.Gmfp.CloseStickyMsg = function (toastItemInner, localSettings) {
$().toastmessage('removeToast', toastItemInner, localSettings);
};
/**
* 改變消息彈出框文字信息
* strMsg
*/
$.Gmfp.ChangeStickyMsg = function (toastItemInner, text) {
$().toastmessage('changeToast', toastItemInner, text);
};
/**
* 顯示消息彈出框
* strMsg
*/
$.Gmfp.ShowMsgDialog = function (strMsg) {
var options = {
title: "提示",
show: true,
unloadOnHide: true,
modal: true,
closeable: true
};
var oTextArea = $("<textarea>").css({
width: "400px",
height: "300px"
}).html(strMsg);
var oBody = $("<div>").css("display", "inline").append(oTextArea);
new Boxy(oBody, options, true);
};
/**
* 時間控件
*/
$.Gmfp.Date = function (strId, strDateFormat, bClear, strMinDate, strMaxDate, Changing) {
if (strDateFormat == undefined) {
strDateFormat = "yyyy-MM-dd";
}
if (bClear == undefined) {
bClear = true;
}
if (strMinDate == undefined) {
strMinDate = "1900-01-01";
}
if (strMaxDate == undefined) {
strMaxDate = "2099-12-31";
}
if (Changing == undefined) {
Changing = function () { };
}
if (typeof (strId) == 'string') {
strId = $("#" + strId);
}
strId.attr("class", "Wdate").focus(function () {
WdatePicker({ dateFmt: strDateFormat, isShowClear: bClear, minDate: strMinDate,
maxDate: strMaxDate, readOnly: true, onpicked: Changing
});
});
};
/**
* 注冊回車事件
* oJqEle, JQ對象
* oCallback: 回調方法
*/
$.Gmfp.Regist13Key = function (oJqEle, oCallback) {
oJqEle.keydown(function (e) {
if (e.keyCode == 13) {
if (oCallback != undefined) {
oCallback();
}
}
});
};
/**
* 加載SELECT
*/
$.Gmfp.InitSelect = function (oSelect, arrOption, strKeyField, strValueField) {
//復制一個select元素(因為IE創建SELECT的BUG所以要這么做,我也不想的...)
var oSel = $(oSelect.outerHTML());
for (var i = 0; i < arrOption.length; i++) {
var option = arrOption[i];
if (typeof (option) != "object") {
option = $.Gmfp.HtmlEncode(option);
$("<option>").attr('value', option).html(option).appendTo(oSel);
}
else {
option[strValueField] = $.Gmfp.HtmlEncode(option[strValueField]);
$("<option>").attr('value', option[strKeyField]).html(option[strValueField]).appendTo(oSel);
}
}
oSelect.after(oSel);
oSelect.remove();
};
/**
* 上傳功能, AjaxUpload
strSrcId: 觸發上傳的控件的(Jquery對象)
strAction: 接收文件的后台接口
onComplete: 完成上傳后的回調方法 function (file, response) {}
onSubmit: 開始上傳的回調方法,返回false可以取消上傳 function (file, ext) {}
*/
$.Gmfp.AjaxUpload = function (oJqSrc, strAction, onComplete, onSubmit) {
new AjaxUpload(oJqSrc, {
action: strAction,
name: 'uploadfile',
onSubmit: onSubmit == undefined ? function () { } : onSubmit,
onComplete: onComplete == undefined ? function () { } : onComplete
});
};
/**
* 確認框
strMsg: 提示信息
oCallback: 確認后的回調方法
*/
$.Gmfp.Confirm = function (strMsg, oCallback) {
Boxy.confirm(strMsg, oCallback, {
title: "提示信息"
});
};
/**
* 確認框
strMsg: 提示信息
oCallback: 確認后的回調方法
*/
$.Gmfp.FishConfirm = function (strMsg, oCallback) {
var box = Boxy.fishmadeinchina(strMsg, oCallback, {
title: "提示信息"
});
return box;
};
/**
* 打開新頁面
url 新頁面地址
*/
$.Gmfp.OpenNewPage = function (url, param, strNewOpen) {
if (param != undefined && typeof (param) == "object") {
param = $.param(param);
url = url + "?" + param;
}
var _target = "_blant";
if (strNewOpen != undefined) {
_target = "_parent";
}
if ($.browser.webkit) {
window.location = url;
}
else {
var oA = document.createElement('a');
oA.href = url;
oA.target = _target;
oA.style.display = 'none';
document.body.appendChild(oA);
oA.click();
document.body.removeChild(oA);
}
};
/**
* 獲取Url里面的get提交參數
*/
$.Gmfp.GetUrlParams = function () {
var strRawUrl = decodeURI(window.location);
var regex = /^[^&]+?[?]([\s\S]*)$/g;
var matches = regex.exec(strRawUrl);
if (matches.length >= 2) {
var strParams = matches[1];
regex = /([^&=]+)=([^&=]*)/g;
var resObj = {};
while (matches = regex.exec(strParams)) {
resObj[matches[1]] = matches[2];
}
return resObj;
}
else {
return {};
}
}
/**
* 為oText設置默認Text和顏色
*/
$.Gmfp.ToSearchText = function (oText, strDefaultText, strDefaultColor) {
//onfocus="if(this._d == undefined || this._d == true){ this.style.color='#000';value=''; this._d = false;}"
//onblur="if(value==''){this.style.color='@color';value='@defaultText';this._d = true;}"
oText.focus(function () {
if (this._d == undefined || this._d == true) {
this.style.color = '#000';
this.value = '';
this._d = false;
}
});
var onblur = function () {
if (this.value == '') {
this.style.color = strDefaultColor;
this.value = strDefaultText;
this._d = true;
}
};
oText.blur(onblur);
//onblur.call(oText.get(0));
var _text = oText.get(0);
if (_text.value == '' || _text.value == strDefaultText) {
_text.style.color = strDefaultColor;
_text.value = strDefaultText;
_text._d = true;
}
}
/**
* 導航欄
*/
$.Gmfp.NavMenu = function (oNavMenu, Current) {
// oNavMenu.each(function (i, item) {
// $(item).mouseover(function () {
// $(this).find("ul").css("display", "block");
// });
// $(item).mouseout(function () {
// $(this).find("ul").css("display", "none");
// })
// });
$.each(oNavMenu, function (i, item) {
$(item).mouseover(function () {
$(this).find("ul").css("display", "block");
});
$(item).mouseout(function () {
$(this).find("ul").css("display", "none");
});
//設置當前頁
var current = $(item).find("a[current]").first();
var reg = new RegExp(Current);
if (reg.test(current.attr("current"))) {
current.attr("id", "current");
}
});
}
//回到頂部
$.Gmfp.Top = function (oTopBtn) {
var _this = this;
window.onscroll = function () { _this.GetScrollTop() > 0 ? oTopBtn.fadeIn("normal") : oTopBtn.fadeOut("normal"); }
oTopBtn.click(function () {
var scrollMove = function () {
_this.SetScrollTop(_this.GetScrollTop() / 1.1);
if (_this.GetScrollTop() < 1) window.clearInterval(goTop);
}
var goTop = setInterval(scrollMove, 10);
});
}
//獲取滾動條的值
$.Gmfp.GetScrollTop = function () {
return document.body.scrollTop || document.documentElement.scrollTop;
}
//設置滾動條的值
$.Gmfp.SetScrollTop = function (value) {
if (document.body.scrollTop) {
document.body.scrollTop = value;
}
else {
document.documentElement.scrollTop = value;
}
}
//格式化字符串
$.Gmfp.Format = function (source, params) {
if (arguments.length == 1)
return function () {
var args = $.makeArray(arguments);
args.unshift(source);
return $.format.apply(this, args);
};
if (arguments.length > 2 && params.constructor != Array) {
params = $.makeArray(arguments).slice(1);
}
if (params.constructor != Array) {
params = [params];
}
$.each(params, function (i, n) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
});
return source;
}
//son對象轉字符串形式
$.Gmfp.json2str = function (o) {
var arr = [];
var fmt = function (s) {
if (typeof s == 'object' && s != null) return json2str(s);
return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
}
for (var i in o) {
arr.push("'" + i + "':" + fmt(o[i]));
}
return '{' + arr.join(',') + '}';
}
})(jQuery);