本文共 36675 字,大约阅读时间需要 122 分钟。
1.holiday_common.js
(function($){ var Calendar = { options :{ buttonImagePath : "" }, initCommonCalendarPicker : function(){ $(".commonDatePiker").each(function(){ $(this).datepicker({ showOn: "button", buttonImage: Calendar.options.buttonImagePath, buttonImageOnly:true, buttonText:"", holidayInfo: HolidayCalendar.monthChange, onClose: HolidayCalendar.pickerClose, leftDistance: 20, dateFormat: $(this).attr("title").substring(2) || 'yy/mm/dd' }); $(this).formtips({ tippedClass: 'tipped' }); }); }, monthChange : function(yearAndMonth){ if(typeof holidayList == "undefined"){ return ""; } var _array = yearAndMonth.split("_"); var obj; var year = _array[0]; var month = _array[1]; for (var key in holidayList) { if (key == year) { obj = holidayList[key][month - 1]; break; } } return Calendar.getResultHtml(obj); }, pickerClose : function(){ $(this).formtips({ tippedClass: 'tipped' }); }, getResultHtml: function(obj){ if (null != obj && obj.length > 0) { var info = "<span style=\"color: red;\">"; for (var i = 0; i < obj.length; i++) { var dt = new Date(obj[i].milliseconds); info += dt.getDate() + "日 " + obj[i].note + "<br/>"; } info += "</span>"; $("#holiday_info").remove(); var resultHtml = "<div id=\"holiday_info\">" + info + "</div>"; return resultHtml; } else { $("#holiday_info").remove(); return ""; } }, pickerDisable : function(target){ var $pic = $(target); $pic.datepicker( "disable" ); }, pickerEnable : function(target){ var $pic = $(target); $pic.datepicker( "enable" ); $pic.removeClass("tipped"); }, pickerAbleChange : function(target){ var $pic = $(target); if($pic.datepicker( "isDisabled" )){ Calendar.pickerEnable(target); }else{ Calendar.pickerDisable(target); } }, pickerSetDate : function(target,date){ var $pic = $(target); $pic.datepicker( "setDate" , date ) } }; window.HolidayCalendar = Calendar; })(jQuery); ####################################2.destination.js
var Destination = {
ajaxSearch : function(url) {
var customerCd = $("#customerCd").val();
if (customerCd == null || customerCd == "") {
$("#destination").empty().append("<option value=''></option>"); } else { $.ajax( { type : "post", url : url, data : "customerCd=" + customerCd, dataType : "json", success : function(obj) {$("#destination").empty().append("<option value=''></option>");
if (null != obj) { var html; for ( var i = 0; i < obj.length; i++) { html += "<option value=" + obj[i].shipmentCd+ ">" + obj[i].shipmentName + "</option> "; } $("#destination").append(html); } } }); } } };#########################################
3.fixture.js
/**
* 備品分類サブウィンドウ */var Fixture = {
largeSelectChange: function(dom){ if(dom.value == ""){ $("#midiumFixture").empty().append("<option value=''></option>"); $("#smallFixture").empty().append("<option value=''></option>"); return ; } $.ajax({ type: "post", url: $("#largeFixtureSelectChangeUrl").val(), data: "largeFixtureGroupCd=" + dom.value, dataType: "json", success: function(obj){ Fixture.callBack(obj, "midiumFixture"); $("#midiumFixture").trigger("onchange"); } }); },midiumSelectChange: function(dom){
if(dom.value == ""){ $("#smallFixture").empty().append("<option value=''></option>"); //$("#smallProduct").children().not("#default").remove(); return ; } $.ajax({ type: "post", url: $("#midiumFixtureSelectChangeUrl").val(), data: "midiumFixtureGroupCd=" + dom.value, dataType: "json", success: function(obj){ Fixture.callBack(obj, "smallFixture"); } }); },callBack: function(obj, id){
$("#" + id).empty().append("<option value=''></option>"); var html; for (var i = 0; i < obj.length; i++) { html += "<option value=" + obj[i].fixtureGroupCd + ">" + obj[i].fixtureGroupName + "</option> "; } $("#" + id).append(html); } };###############################################
4.jquey.input.js
/**
* 入力制限 * * @date 2010-04-06 * @author zhangxiong */ (function( $ ) {if ( typeof Keyboard == "undefined" ) {
throw 'Keyboard loading failed, Please to included Keyboard.js file'; }/**
* IME Mode */ $.fn.addIME = function() { $.each(this, function( i, n ) { Keyboard.IME( $( n ).get( 0 ), Keyboard.IME_INACTIVE ); });return this;
};/**
* 半角数字のみを入力する */ $.fn.number = function() { return $( this ).bind("keypress", function( e ) { return Keyboard.fn.onlyNum.call( $kb( e ), false ); // return Keyboard(e).onlyNum(false); }).addIME(); };/**
* 半角数字のみを入力する(ハイフン含ませる) */ $.fn.hypheNumber = function() { return $( this ).bind("keypress", function( e ) { return Keyboard.fn.onlyNum.call( $kb( e ), false, true ); }).addIME(); }; /** * 半角小数のみを入力する */ $.fn.decimal = function() { return $( this ).bind("keypress", function( e ) { return Keyboard.fn.onlyNum.call( $kb( e ), true ); }).addIME(); }; /** * 半角小数のみを入力する(ハイフン含ませる) */ $.fn.hypheDecimal = function() { return $( this ).bind("keypress", function( e ) { return Keyboard.fn.onlyNum.call( $kb( e ), true, true ); }).addIME(); };/**
* 半角英数字のみを入力する * */ $.fn.alphanumeric = function() { return $( this ).bind("keypress", function( e ) { return Keyboard.fn.alphanumeric.call( $kb( e ) ); }).addIME(); };/**
* メールのみを入力する * */ $.fn.email = function() { return $( this ).bind("keypress", function( e ) { return Keyboard.fn.isEmail.call( $kb( e ) ); }).addIME(); };})( window[ 'jQuery' ] );
##################################################
5.keyboard.js
/**
* Keyboard Helper * * @date 2010-04-06 * @author zhangxiong * * @param {Object} event window event */ (function( window ) {var KeyCode = {
KEY_TAB : 0, // Tab KEY_BACKSPACE : 8, // BackspceKEY_LOW_A : 97, // a
KEY_UPP_A : 65, // A KEY_LOW_V : 118, // v KEY_UPP_V : 86, // V KEY_LOW_C : 99, // c KEY_UPP_C : 67, // C KEY_LOW_Z : 122, // z KEY_UPP_Z : 90, // ZKEY_POINT : 46, // .
KEY_AT : 64, // @ KEY_UNDER_LINE : 95, // _ KEY_HYPHEN : 45, // -KEY_ZERO : 48, // 0
KEY_NINE : 57 // 9},
Keyboard = function( event ) {
return new Keyboard.fn.init( event ); };Keyboard.fn = Keyboard.prototype = {
init : function( event ) {
this.e = event;// E.which
this.__EWhich__ = this.e.which;return this;
},// Shift Tab
isShiftTab : function() { return this.isShift() && this.__EWhich__ == KeyCode.KEY_TAB; },// Tab
isTab : function() { return this.__EWhich__ == KeyCode.KEY_TAB; },// Ctrl + C
isCtrlC : function() { return this.isCtrl() && ( this.__EWhich__ == KeyCode.KEY_LOW_C || this.__EWhich__ == KeyCode.KEY_UPP_C ); },// Ctrl + V
isCtrlV : function() { return this.isCtrl() && ( this.__EWhich__ == KeyCode.KEY_LOW_V || this.__EWhich__ == KeyCode.KEY_UPP_V ); },// Ctrl
isCtrl : function() { return this.e.ctrlKey == true; },// Shift
isShift : function() { return this.e.shiftKey == true; },// Shift + Ctrl
isCtrlShift : function() { return this.isCtrl() && this.isShift(); },// Backspace
isBackspace : function() { return this.__EWhich__ == KeyCode.KEY_BACKSPACE; },// [0-9]
isNumber : function() { return this.__EWhich__ >= KeyCode.KEY_ZERO && this.__EWhich__ <= KeyCode.KEY_NINE; },// .
isPoint : function() { return this.__EWhich__ == KeyCode.KEY_POINT; },// -
isHyphe : function() { return this.__EWhich__ == KeyCode.KEY_HYPHEN; }, // Email isEmail : function() { return this.isAlpha() || this.onlyNum( true ) || this.isShift() && this.__EWhich__ == KeyCode.KEY_AT || this.__EWhich__ == KeyCode.KEY_UNDER_LINE; },// [a-zA-Z]
isAlpha : function() { return ( this.__EWhich__ >= KeyCode.KEY_LOW_A && this.__EWhich__ <= KeyCode.KEY_LOW_Z ) || ( this.__EWhich__ >= KeyCode.KEY_UPP_A && this.__EWhich__ <= KeyCode.KEY_UPP_Z ); },/*
* 半角数字(ポイントを含まれる)のみ * * @param {Boolean} point trueの場合は「.」を許可する。 */ onlyNum : function( point, hyphen ) { var p = point ? this.isPoint() : false, h = hyphen ? this.isHyphe() : false;return h || p || ( this.isShiftTab() || this.isTab() || this.isCtrlC() || this.isCtrlV() ||
( ( this.isNumber() && !this.isCtrlShift() ) || this.isBackspace() || this.isTab() ) );},
// 半角英数字
alphanumeric : function() { return this.isAlpha() || this.onlyNum(); } };// bind JSON
Keyboard.KeyCode = Keyboard.fn.KeyCode = KeyCode;// Give this init function prototype for later instantiation
Keyboard.fn.init.prototype = Keyboard.fn;/*
* Is to Activing IME Mode * * @param {DOM Object} o HTML Document Object,Don't jQuery Object @param * {Boolean} isInActive true = active, false = inactive */ Keyboard.IME = function( o, isInActive ) { if ( o && !isInActive ) { jQuery.browser.msie ? jQuery( o ).attr( "style", "ime-mode:disabled" ) : o.style.imeMode = "disabled"; } };Keyboard.IME_ACTIVE = true;
Keyboard.IME_INACTIVE = false;window.Keyboard = window.$kb = Keyboard;
})( window );####################################
6.member.js
/**
*会員選択サブウィンドウ */var Member = {};
Member.Search = {
windowOpen : function(fun){
callbackFunction = fun; var url = $("#memberWinUrl").val(); jQuery.facebox({ ajax: url}); }};
/** * 選択 */ Member.SearchHandle = { search : function(url){ $.ajax({ type: "post", url: url, data: $('#member_search_form').formSerialize(), dataType: "html", success: function(html){ $("#member_search_result").empty().append(html); } }); }, radioOnclick : function(dom){ if($(dom).prop("checked")){ $("#currentSelectMemberId").val($(dom).val()); } }, choose : function(){ var index = $(":radio:checked").val(); if(typeof index == "undefined"){ alert("please select one!"); return; } var jsonVal = { id: $("#"+index+"_id").val(), joinStudioName: $("#"+index+"_joinStudioName").val(), mainStudioName: $("#"+index+"_mainStudioName").val(), fullNameKanji: $("#"+index+"_fullNameKanji").val(), fullNameKana: $("#"+index+"_fullNameKana").val() }; callbackFunction(jsonVal); jQuery(document).trigger('close.facebox') }, callbackFunction : function(){} };
/**
* demo, user write owner js like this... */ TestMemberSearch = { f1 : function(){ Member.Search.windowOpen(this.f2); }, f2 : function(jsonVal){ $("#id").val(jsonVal.id); $("#fullNameKanji").val(jsonVal.fullNameKanji); } };###############################
7.page.js
var page = {
search: function(formId, pageNo){
var formObj = $("#" + formId); $("#" + formId + "__pageNo").val(pageNo); if (formId == "systemSearchForm") { $("#parentCd").val($("#realParentCd").val()); } $.ajax({ type: "post", url: $("#" + formId).attr("action"), data: $("#" + formId).formSerialize(), dataType: "html", success: function(html){ $("#member_search_result").empty().append(html); } }); }, jumpPageSearch: function(formId, searchButton){ var pageNo = $(searchButton).prev("input").val(); this.pageSearch(formId, pageNo); } }#################################
8.number.format.js
var NumberFormat = {addCommas : function(nStr) {
nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; }, removeCommas : function(nStr){ var reg = /,/g; return nStr.replace(reg,""); }, removeZero : function (nStr){ var reg = new RegExp("^[0]+"); return nStr.replace(reg,""); } };#########################
9.Number.js
/**
* fix javascript Decimal Precision */ (function() {Number.prototype.add = function( arg1 ) {
var r1, r2, m;try {
r1 = arg1.toString().split( "." )[1].length; } catch ( e ) { r1 = 0; } try { r2 = this.toString().split( "." )[1].length; } catch ( e ) { r2 = 0; }m = Math.pow( 10, Math.max( r1, r2 ) );
return (arg1 * m + this * m) / m; };Number.prototype.sub = function( arg ) {
return this.add( -arg ); };Number.prototype.multiply = function( arg1) {
var m = 0, s1 = arg1.toString(), s2 = this.toString();try {
m += s1.split( "." )[1].length; } catch ( e ) { } try { m += s2.split( "." )[1].length; } catch ( e ) { }return Number( s1.replace( ".", "" ) ) * Number( s2.replace( ".", "" ) ) / Math.pow( 10, m );
};Number.prototype.divide = function( arg1 ) {
var t1 = 0, t2 = 0, r1, r2; try { t1 = this.toString().split( "." )[1].length; } catch ( e ) { } try { t2 = arg1.toString().split( "." )[1].length; } catch ( e ) { } with ( Math ) { r1 = Number( this.toString().replace( ".", "" ) ); r2 = Number( arg1.toString().replace( ".", "" ) ); return (r1 / r2) * pow( 10, t2 - t1 ); } };})();
############################
10.product.js
/**
* 商品選択サブウィンドウ */var Product = {
largeProductGroupCd : -1,
idSuffix : "", produceChangeCallBackFun : null, currentSelectProductCds : null,windowOpen : function(modleType, supplier_cd, customer_cd, callbackFn) {
SearchHandle.callbackFn = callbackFn;
var url = $("#openWinUrl").val();
jQuery.facebox( {
ajax : url + "?supplierCd=" + supplier_cd + "&customerCd=" + customer_cd + "&modleType=" + modleType }); },/**
* 棚卸対象区分の選択 * * @param dom * 画面元素 */ stockTakingDivChange : function(dom) {if ($(dom).val() < 1) {
$("#largeProduct").empty().append("<option value=''></option>"); $("#midiumProduct").empty().append("<option value=''></option>"); $("#smallProduct").empty().append("<option value=''></option>"); return; }// layoutに埋め込む
var url = $("#ajax_stockTakingDiv_change").val();// 棚卸区分をセットする
this.largeProductGroupCd = $(dom).val();$.ajax( {
type : "post", url : url, data : "stockTakingDiv=" + dom.value, dataType : "json", success : function(obj) { Product.callBack(obj, "largeProduct"); $("#largeProduct").trigger("onchange"); } }); },largeSelectChange : function(dom, stockTakingDiv) {
idSuffix = Product.getIdSuffix($(dom).attr("id"));if ($(dom).val() == "") {
$("#midiumProduct"+idSuffix).empty().append("<option value=''></option>"); $("#smallProduct"+idSuffix).empty().append("<option value=''></option>"); return; }var _data = "largeProductGroupCd=" + dom.value;
if (this.largeProductGroupCd > 0) {
// call from 実棚入力画面 _data += "&stockTakingDiv=" + this.largeProductGroupCd; }$.ajax( {
type : "post", url : $("#largeSelectChangeUrl").val(), data : _data, dataType : "json", success : function(obj) { Product.callBack(obj, "midiumProduct"+idSuffix); $("#midiumProduct"+idSuffix).trigger("onchange"); } }); },midiumSelectChange : function(dom) {
idSuffix = Product.getIdSuffix($(dom).attr("id"));if ($(dom).val() == "") {
$("#smallProduct"+idSuffix).empty().append("<option value=''></option>"); // $("#smallProduct").children().not("#default").remove(); return; } var _data = "midiumProductGroupCd=" + dom.value;if (this.largeProductGroupCd > 0) {
// call from 実棚入力画面 _data += "&stockTakingDiv=" + this.largeProductGroupCd; }$.ajax( {
type : "post", url : $("#midiumSelectChangeUrl").val(), data : _data, dataType : "json", success : function(obj) { Product.callBack(obj, "smallProduct"+idSuffix); } }); },callBack : function(obj, id) {
$("#" + id).empty().append("<option value=''></option>");
var html;
for ( var i = 0; i < obj.length; i++) { html += "<option value=" + obj[i].productGroupCd + ">" + obj[i].productGroupName + "</option> "; } $("#" + id).append(html); }, getIdSuffix : function(targetId){ var array = targetId.split("\_"); if(array.length != 2){ return ""; } return "_"+array[1]; }};
/**
* 商品選択サブウィンドウ */ var SearchHandle = { /** * @param {Object} * url */ search : function(url) { $.ajax( { type : "post", url : url, data : $('#product_search_form').formSerialize(), dataType : "html", success : function(html) { $("#search_result").empty().append(html); $("#search_params_keep").val( $("#product_search_form").formSerialize()); } }); },choose : function() {
var index = $("#search_result :radio:checked").val();
if (typeof index == "undefined") {
alert("please select one!"); return; }; if (Product.currentSelectProductCds != null && Product.currentSelectProductCds.length > 0) { //明細行に同じ商品が選択されています。 var selectProductCd = $("#" + index + "_productCd").val(); var hasRepeatCd = false; var currentSelectProductCds = Product.currentSelectProductCds; for (var i = 0; i < currentSelectProductCds.length; i++) { if (currentSelectProductCds[i] == selectProductCd) { hasRepeatCd = true; break; } } if (hasRepeatCd) { var msg = "明細行に同じ商品が選択されています。"; alert("明細行に同じ商品が選択されています。"); return; } }$(".chooseButton").addClass("productChooseButton");
// pack info to json obj
var jsonObj = { productCd : $("#" + index + "_productCd").val(), productDisplayName : $("#" + index + "_productDisplayName").val(), price : $("#" + index + "_priceStr").val(), taxDiv : $("#" + index + "_taxDiv").val(), taxDivDisplayName : $("#" + index + "_taxDivDisplayName").val(), activeStockQty : $("#" + index + "_activeStockQty").val(), wholesale : $("#" + index + "_wholesale").val() };SearchHandle.callbackFn(jsonObj);
jQuery(document).trigger('close.facebox');
}, callbackFn : function() { } };/**
* demo, user write owner js like this... */ var Test = {f1 : function(modleType, supplier_cd, customer_cd) {
Product.windowOpen(modleType, supplier_cd, customer_cd, this.f2); },f2 : function(jsonObj) {
$("#productCd").val(jsonObj.productCd); $("#productDisplayName").val(jsonObj.productDisplayName); $("#priceStr").val(jsonObj.price); $("#activeStockQty").val(jsonObj.activeStockQty); $("#wholesale").val(jsonObj.wholesale); } };var porductChangeTest = {
f1 : function(dom){ Product.largeSelectChange(dom); var html = "<input type=\"hidden\" value=\""+$(dom).children("option:selected").text()+"\" name=\""+$(dom).attr("name")+"\">"; $(dom).next("span").empty().append(html); }, f2 : function(dom){ Product.midiumSelectChange(dom) var html = "<input type=\"hidden\" value=\""+$(dom).children("option:selected").text()+"\" name=\""+$(dom).attr("name")+"\">"; $(dom).next("span").empty().append(html); }, f3 : function(dom){ var html = "<input type=\"hidden\" value=\""+$(dom).children("option:selected").text()+"\" name=\""+$(dom).attr("name")+"\">"; $(dom).next("span").empty().append(html); } }#############################################
11.ajax.sort.js
(function($){ var Sort = { sort: function(formId){ $('table').find('th.toggle > a').bind({ click: function(){ var // 順番に指定される列 sortColumn = $(this).attr("id").toLowerCase(), // 現在の順番列 $colEle = $("#sortColumn"), currSortCol = $colEle.val(), // 昇順か降順に判断する $directEle = $("#sortDirection"), currSortDirect = $directEle.val().toLowerCase(); if (sortColumn == currSortCol) { currSortDirect = currSortDirect == "desc" ? "asc" : "desc"; } else { currSortDirect = "desc"; } // 表示順を設定する $colEle.val(sortColumn); $directEle.val(currSortDirect); // 表示順を更新するので、ページング最初に戻る。 $('input[id$="__pageNo"]').val(''); Sort.ajaxSearch($("#"+formId).attr("action"),$("#"+formId).formSerialize()); } }); }, ajaxSearch : function(url,params){ $.ajax({ type: "post", url: url, data: params+"&"+$("#search_params_keep").val(), dataType: "html", success: function(html){ $("#search_result").html(html); } }); } }; window.AjaxSort = Sort; })(jQuery);
#####################
12.sort.js
var Sort = {
/**
* 順番に設定する * * @param {String} フォームID(必須) * @param {String} テーブルID(optional) * */ sort : function(formId, tableId) {var
queryStr = tableId ? 'table#' + tableId : 'table', querySortColumn = tableId ? '#' + formId + ' > .sortColumn' : '#sortColumn', querySortDirection = tableId ? '#' + formId + ' > .sortDirection' : '#sortDirection'; $( queryStr ).find('th.toggle > a').bind( { click : function() { var // 順番に指定される列 sortColumn = $(this).attr("id").toLowerCase(),// 現在の順番列
$colEle = $(querySortColumn), currSortCol = $colEle.val(),// 昇順か降順に判断する
$directEle = $(querySortDirection), currSortDirect = $directEle.val().toLowerCase();if (sortColumn == currSortCol) {
currSortDirect = currSortDirect == "desc" ? "asc" : "desc"; } else { currSortDirect = "desc"; }// 表示順を設定する
$colEle.val(sortColumn); $directEle.val(currSortDirect);// 表示順を更新するので、ページング最初に戻る。
$('input[id$="__pageNo"]').val(''); $('#' + formId).submit(); } }); }};
########################
13.zipmast.js
var zipMaster = { ajaxInsert : function(val){ var zipCd = $("#zipCd").val(); if(zipCd==null || zipCd == ""){ alert("郵便番号は必ず入力してください。"); }else{ $.ajax({ type: "post", url: val, data: "zipCd="+zipCd, dataType: "json", success: function(obj){ $("#largestAreaCd option[selected='selected']").removeAttr("selected"); if(obj == null){ $("#defaultOption").attr("selected", "selected"); $("#metropolitanAreaName").val(""); }else{ var _value = $("#largestArea_" + obj.largestAreaCd).val(); if((typeof _value) == "undefined"){ $("#defaultOption").attr("selected", "selected"); }else{ $("#largestArea_" + obj.largestAreaCd).attr("selected", "selected"); } $("#metropolitanAreaName").val(obj.metropolitanAreaName); } } }); } } };
######################
14.form.js
var commonForm = {
Submit : function(formId, url) { jQuery("#" + formId).attr("action", url); jQuery("#" + formId).submit(); },backSubmit : function(formId, url) {
$("#nextFlg").val("back"); commonForm.Submit(formId, url); } };########################
15.selector.js
var Selector = {
selectAll : function() {
$("table:visible tr:visible input.ck").prop("checked", "checked"); }, unselectAll : function() { $("input.ck").removeProp("checked"); }, delSelected : function() { var $selectedBox = $('table:visible tr:visible').find("input.ck:checked"); if($selectedBox.size()==0) return false; $selectedBox.each(function(){ $(this).parents('tr').remove(); });$("table:visible tr:visible td.lineNo").each(function(i){
$(this).text(i+1); (i+1)%2 == 0 ? $(this).parents('tr').addClass("evenLine") : $(this).parents('tr').removeClass("evenLine"); $(this).parents('tr').find('input').each(function(){ var inputName = $(this).attr('name'); if(inputName != null){ var index1 = inputName.indexOf('['); var index2 = inputName.indexOf(']'); if(index1!=-1&&index2!=-1){ var part1 = inputName.substring(0,index1+1); var part2 = inputName.substring(index2); $(this).attr('name',part1+i+part2); } } }); $(this).parents('tr').find('select').each(function(){ var inputName = $(this).attr('name'); if(inputName != null){ var index1 = inputName.indexOf('['); var index2 = inputName.indexOf(']'); if(index1!=-1&&index2!=-1){ var part1 = inputName.substring(0,index1+1); var part2 = inputName.substring(index2); $(this).attr('name',part1+i+part2); } } }); }); } };##############################
15.jquery.blockUI.js
/*!
* jQuery blockUI plugin * Version 2.38 (29-MAR-2011) * @requires jQuery v1.2.3 or later * * Examples at: * Copyright (c) 2007-2010 M. Alsup * Dual licensed under the MIT and GPL licenses: * * * * Thanks to Amir-Hossein Sobhi for some excellent contributions! */;(function($) {
if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
alert('blockUI requires jQuery v1.2.3 or later! You are using v' + $.fn.jquery); return; }$.fn._fadeIn = $.fn.fadeIn;
var noOp = function() {};
// this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle
// retarded userAgent strings on Vista) var mode = document.documentMode || 0; var setExpr = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8); var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent) && !mode;// global $ methods for blocking/unblocking the entire page
$.blockUI = function(opts) { install(window, opts); }; $.unblockUI = function(opts) { remove(window, opts); };// convenience method for quick growl-like notifications ()
$.growlUI = function(title, message, timeout, onClose) { var $m = $('<div class="growlUI"></div>'); if (title) $m.append('<h1>'+title+'</h1>'); if (message) $m.append('<h2>'+message+'</h2>'); if (timeout == undefined) timeout = 3000; $.blockUI({ message: $m, fadeIn: 700, fadeOut: 1000, centerY: false, timeout: timeout, showOverlay: false, onUnblock: onClose, css: $.blockUI.defaults.growlCSS }); };// plugin method for blocking element content
$.fn.block = function(opts) { return this.unblock({ fadeOut: 0 }).each(function() { if ($.css(this,'position') == 'static') this.style.position = 'relative'; if ($.browser.msie) this.style.zoom = 1; // force 'hasLayout' install(this, opts); }); };// plugin method for unblocking element content
$.fn.unblock = function(opts) { return this.each(function() { remove(this, opts); }); };$.blockUI.version = 2.38; // 2nd generation blocking at no extra cost!
// override these in your code to change the default behavior and style
$.blockUI.defaults = { // message displayed when blocking (use null for no message) message: '<h1>Please wait...</h1>',title: null, // title string; only used when theme == true
draggable: true, // only used when theme == true (requires jquery-ui.js to be loaded) theme: false, // set to true to use with jQuery UI themes // styles for the message when blocking; if you wish to disable // these and use an external stylesheet then do this in your code: // $.blockUI.defaults.css = {}; css: { padding: 0, margin: 0, width: '30%', top: '40%', left: '35%', textAlign: 'center', color: '#000', border: '3px solid #aaa', backgroundColor:'#fff', cursor: 'wait' }, // minimal style set used when themes are used themedCSS: { width: '30%', top: '40%', left: '35%' },// styles for the overlay
overlayCSS: { backgroundColor: '#000', opacity: 0.6, cursor: 'wait' },// styles applied when using $.growlUI
growlCSS: { width: '350px', top: '10px', left: '', right: '10px', border: 'none', padding: '5px', opacity: 0.6, cursor: 'default', color: '#fff', backgroundColor: '#000', '-webkit-border-radius': '10px', '-moz-border-radius': '10px', 'border-radius': '10px' }, // IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w // (hat tip to Jorge H. N. de Vasconcelos) iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',// force usage of iframe in non-IE browsers (handy for blocking applets)
forceIframe: false,// z-index for the blocking overlay
baseZ: 1000,// set these to true to have the message automatically centered
centerX: true, // <-- only effects element blocking (page block controlled via css above) centerY: true,// allow body element to be stetched in ie6; this makes blocking look better
// on "short" pages. disable if you wish to prevent changes to the body height allowBodyStretch: true,// enable if you want key and mouse events to be disabled for content that is blocked
bindEvents: true,// be default blockUI will supress tab navigation from leaving blocking content
// (if bindEvents is true) constrainTabKey: true,// fadeIn time in millis; set to 0 to disable fadeIn on block
fadeIn: 200,// fadeOut time in millis; set to 0 to disable fadeOut on unblock
fadeOut: 400,// time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
timeout: 0,// disable if you don't want to show the overlay
showOverlay: true,// if true, focus will be placed in the first available input field when
// page blocking focusInput: true,// suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
applyPlatformOpacityRules: true, // callback method invoked when fadeIn has completed and blocking message is visible onBlock: null,// callback method invoked when unblocking has completed; the callback is
// passed the element that has been unblocked (which is the window object for page // blocks) and the options that were passed to the unblock call: // onUnblock(element, options) onUnblock: null,// don't ask; if you really must know:
quirksmodeOffsetHack: 4,// class name of the message block
blockMsgClass: 'blockMsg' };// private data and functions follow...
var pageBlock = null;
var pageBlockEls = [];function install(el, opts) {
var full = (el == window); var msg = opts && opts.message !== undefined ? opts.message : undefined; opts = $.extend({}, $.blockUI.defaults, opts || {}); opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {}); var css = $.extend({}, $.blockUI.defaults.css, opts.css || {}); var themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {}); msg = msg === undefined ? opts.message : msg;// remove the current block (if there is one)
if (full && pageBlock) remove(window, {fadeOut:0});// if an existing element is being used as the blocking content then we capture
// its current place in the DOM (and current display style) so we can restore // it when we unblock if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) { var node = msg.jquery ? msg[0] : msg; var data = {}; $(el).data('blockUI.history', data); data.el = node; data.parent = node.parentNode; data.display = node.style.display; data.position = node.style.position; if (data.parent) data.parent.removeChild(node); }var z = opts.baseZ;
// blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
// layer1 is the iframe layer which is used to supress bleed through of underlying content // layer2 is the overlay layer which has opacity and a wait cursor (by default) // layer3 is the message content that is displayed while blockingvar lyr1 = ($.browser.msie || opts.forceIframe)
? $('<iframe class="blockUI" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+opts.iframeSrc+'"></iframe>') : $('<div class="blockUI" style="display:none"></div>'); var lyr2 = opts.theme ? $('<div class="blockUI blockOverlay ui-widget-overlay" style="z-index:'+ (z++) +';display:none"></div>') : $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');var lyr3, s;
if (opts.theme && full) { s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+z+';display:none;position:fixed">' + '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>' + '<div class="ui-widget-content ui-dialog-content"></div>' + '</div>'; } else if (opts.theme) { s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement ui-dialog ui-widget ui-corner-all" style="z-index:'+z+';display:none;position:absolute">' + '<div class="ui-widget-header ui-dialog-titlebar ui-corner-all blockTitle">'+(opts.title || ' ')+'</div>' + '<div class="ui-widget-content ui-dialog-content"></div>' + '</div>'; } else if (full) { s = '<div class="blockUI ' + opts.blockMsgClass + ' blockPage" style="z-index:'+z+';display:none;position:fixed"></div>'; } else { s = '<div class="blockUI ' + opts.blockMsgClass + ' blockElement" style="z-index:'+z+';display:none;position:absolute"></div>'; } lyr3 = $(s);// if we have a message, style it
if (msg) { if (opts.theme) { lyr3.css(themedCSS); lyr3.addClass('ui-widget-content'); } else lyr3.css(css); }// style the overlay
if (!opts.theme && (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform)))) lyr2.css(opts.overlayCSS); lyr2.css('position', full ? 'fixed' : 'absolute');// make iframe layer transparent in IE
if ($.browser.msie || opts.forceIframe) lyr1.css('opacity',0.0);//$([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el); $.each(layers, function() { this.appendTo($par); }); if (opts.theme && opts.draggable && $.fn.draggable) { lyr3.draggable({ handle: '.ui-dialog-titlebar', cancel: 'li' }); }// ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
var expr = setExpr && (!$.boxModel || $('object,embed', full ? null : el).length > 0); if (ie6 || expr) { // give body 100% height if (full && opts.allowBodyStretch && $.boxModel) $('html,body').css('height','100%');// fix ie6 issue when blocked element has a border width
if ((ie6 || !$.boxModel) && !full) { var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth'); var fixT = t ? '(0 - '+t+')' : 0; var fixL = l ? '(0 - '+l+')' : 0; }// simulate fixed position
$.each([lyr1,lyr2,lyr3], function(i,o) { var s = o[0].style; s.position = 'absolute'; if (i < 2) { full ? s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"') : s.setExpression('height','this.parentNode.offsetHeight + "px"'); full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"') : s.setExpression('width','this.parentNode.offsetWidth + "px"'); if (fixL) s.setExpression('left', fixL); if (fixT) s.setExpression('top', fixT); } else if (opts.centerY) { if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"'); s.marginTop = 0; } else if (!opts.centerY && full) { var top = (opts.css && opts.css.top) ? parseInt(opts.css.top) : 0; var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"'; s.setExpression('top',expression); } }); }// show the message
if (msg) { if (opts.theme) lyr3.find('.ui-widget-content').append(msg); else lyr3.append(msg); if (msg.jquery || msg.nodeType) $(msg).show(); }if (($.browser.msie || opts.forceIframe) && opts.showOverlay)
lyr1.show(); // opacity is zero if (opts.fadeIn) { var cb = opts.onBlock ? opts.onBlock : noOp; var cb1 = (opts.showOverlay && !msg) ? cb : noOp; var cb2 = msg ? cb : noOp; if (opts.showOverlay) lyr2._fadeIn(opts.fadeIn, cb1); if (msg) lyr3._fadeIn(opts.fadeIn, cb2); } else { if (opts.showOverlay) lyr2.show(); if (msg) lyr3.show(); if (opts.onBlock) opts.onBlock(); }// bind key and mouse events
bind(1, el, opts);if (full) {
pageBlock = lyr3[0]; pageBlockEls = $(':input:enabled:visible',pageBlock); if (opts.focusInput) setTimeout(focus, 20); } else center(lyr3[0], opts.centerX, opts.centerY);if (opts.timeout) {
// auto-unblock var to = setTimeout(function() { full ? $.unblockUI(opts) : $(el).unblock(opts); }, opts.timeout); $(el).data('blockUI.timeout', to); } };// remove the block
function remove(el, opts) { var full = (el == window); var $el = $(el); var data = $el.data('blockUI.history'); var to = $el.data('blockUI.timeout'); if (to) { clearTimeout(to); $el.removeData('blockUI.timeout'); } opts = $.extend({}, $.blockUI.defaults, opts || {}); bind(0, el, opts); // unbind events var els; if (full) // crazy selector to handle odd field errors in ie6/7 els = $('body').children().filter('.blockUI').add('body > .blockUI'); else els = $('.blockUI', el);if (full)
pageBlock = pageBlockEls = null;if (opts.fadeOut) {
els.fadeOut(opts.fadeOut); setTimeout(function() { reset(els,data,opts,el); }, opts.fadeOut); } else reset(els, data, opts, el); };// move blocking element back into the DOM where it started
function reset(els,data,opts,el) { els.each(function(i,o) { // remove via DOM calls so we don't lose event handlers if (this.parentNode) this.parentNode.removeChild(this); });if (data && data.el) {
data.el.style.display = data.display; data.el.style.position = data.position; if (data.parent) data.parent.appendChild(data.el); $(el).removeData('blockUI.history'); }if (typeof opts.onUnblock == 'function')
opts.onUnblock(el,opts); };// bind/unbind the handler
function bind(b, el, opts) { var full = el == window, $el = $(el);// don't bother unbinding if there is nothing to unbind
if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked'))) return; if (!full) $el.data('blockUI.isBlocked', b);// don't bind events when overlay is not in use or if bindEvents is false
if (!opts.bindEvents || (b && !opts.showOverlay)) return;// bind anchors and inputs for mouse and key events
var events = 'mousedown mouseup keydown keypress'; b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);// former impl...
// var $e = $('a,:input'); // b ? $e.bind(events, opts, handler) : $e.unbind(events, handler); };// event handler to suppress keyboard/mouse events when blocking
function handler(e) { // allow tab navigation (conditionally) if (e.keyCode && e.keyCode == 9) { if (pageBlock && e.data.constrainTabKey) { var els = pageBlockEls; var fwd = !e.shiftKey && e.target === els[els.length-1]; var back = e.shiftKey && e.target === els[0]; if (fwd || back) { setTimeout(function(){focus(back)},10); return false; } } } var opts = e.data; // allow events within the message content if ($(e.target).parents('div.' + opts.blockMsgClass).length > 0) return true;// allow events for content that is not being blocked
return $(e.target).parents().children().filter('div.blockUI').length == 0; };function focus(back) {
if (!pageBlockEls) return; var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0]; if (e) e.focus(); };function center(el, x, y) {
var p = el.parentNode, s = el.style; var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth'); var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth'); if (x) s.left = l > 0 ? (l+'px') : '0'; if (y) s.top = t > 0 ? (t+'px') : '0'; };function sz(el, p) {
return parseInt($.css(el,p))||0; };})(jQuery);
转载地址:http://ajebi.baihongyu.com/