Browse Source

Merge branch 'BI4.1' of http://cloud.finedevelop.com:2015/scm/~windy/fineui

# Conflicts:
#	bi/core.js
#	dist/bundle.min.js
es6
windy 7 years ago
parent
commit
4bba2ff11b
  1. 2
      bi/base.js
  2. 2
      dist/base.js
  3. 168
      dist/bundle.js
  4. 88
      dist/bundle.min.js
  5. 166
      dist/core.js
  6. 2
      src/base/single/text.js
  7. 47
      src/core/alias.js
  8. 6
      src/core/func/dom.js
  9. 21
      src/core/func/function.js
  10. 92
      src/core/proto/date.js

2
bi/base.js

@ -587,7 +587,7 @@ BI.Text = BI.inherit(BI.Single, {
setText: function (text) { setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments); BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text; this.options.text = text;
this.text.element.html(BI.Func.formatSpecialCharInHtml(text)); this.text.element.html(BI.htmlEncode(text));
} }
}); });

2
dist/base.js vendored

@ -587,7 +587,7 @@ BI.Text = BI.inherit(BI.Single, {
setText: function (text) { setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments); BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text; this.options.text = text;
this.text.element.html(BI.Func.formatSpecialCharInHtml(text)); this.text.element.html(BI.htmlEncode(text));
} }
}); });

168
dist/bundle.js vendored

@ -17448,6 +17448,53 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return newText return newText
}; };
/**
* 将cjkEncode处理过的字符串转化为原始字符串
*
* @static
* @param text 需要做解码的字符串
* @return {String} 解码后的字符串
*/
BI.cjkDecode = function (text) {
if (text == null) {
return "";
}
//查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回.
if (!isNaN(text) || text.indexOf('[') == -1) {
return text;
}
var newText = "";
for (var i = 0; i < text.length; i++) {
var ch = text.charAt(i);
if (ch == '[') {
var rightIdx = text.indexOf(']', i + 1);
if (rightIdx > i + 1) {
var subText = text.substring(i + 1, rightIdx);
//james:主要是考虑[CDATA[]]这样的值的出现
if (subText.length > 0) {
ch = String.fromCharCode(eval("0x" + subText));
}
i = rightIdx;
}
}
newText += ch;
}
return newText;
};
//replace the html special tags
BI.htmlEncode = function (text) {
return (text == null) ? '' : String(text).replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};
//html decode
BI.htmlDecode = function (text) {
return (text == null) ? '' : String(text).replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ');
};
BI.cjkEncodeDO = function (o) { BI.cjkEncodeDO = function (o) {
if (BI.isPlainObject(o)) { if (BI.isPlainObject(o)) {
var result = {}; var result = {};
@ -19174,7 +19221,7 @@ BI.extend(jQuery.fn, {
*/ */
__textKeywordMarked__: function (text, keyword, py) { __textKeywordMarked__: function (text, keyword, py) {
if (!BI.isKey(keyword) || (text + "").length > 100) { if (!BI.isKey(keyword) || (text + "").length > 100) {
return this.html(BI.Func.formatSpecialCharInHtml(text)); return this.html(BI.htmlEncode(text));
} }
keyword = keyword + ""; keyword = keyword + "";
keyword = BI.toUpperCase(keyword); keyword = BI.toUpperCase(keyword);
@ -19197,7 +19244,7 @@ BI.extend(jQuery.fn, {
if (tidx >= 0) { if (tidx >= 0) {
this.append(textLeft.substr(0, tidx)); this.append(textLeft.substr(0, tidx));
this.append($("<span>").addClass("bi-keyword-red-mark") this.append($("<span>").addClass("bi-keyword-red-mark")
.html(BI.Func.formatSpecialCharInHtml(textLeft.substr(tidx, keyword.length)))); .html(BI.htmlEncode(textLeft.substr(tidx, keyword.length))));
textLeft = textLeft.substr(tidx + keyword.length); textLeft = textLeft.substr(tidx + keyword.length);
if (py != null) { if (py != null) {
@ -19206,7 +19253,7 @@ BI.extend(jQuery.fn, {
} else if (pidx != null && pidx >= 0 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length)) { } else if (pidx != null && pidx >= 0 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length)) {
this.append(textLeft.substr(0, pidx)); this.append(textLeft.substr(0, pidx));
this.append($("<span>").addClass("bi-keyword-red-mark") this.append($("<span>").addClass("bi-keyword-red-mark")
.html(BI.Func.formatSpecialCharInHtml(textLeft.substr(pidx, keyword.length)))); .html(BI.htmlEncode(textLeft.substr(pidx, keyword.length))));
if (py != null) { if (py != null) {
py = py.substr(pidx + keyword.length); py = py.substr(pidx + keyword.length);
} }
@ -19811,27 +19858,6 @@ BI.extend(BI.Func, {
matched: matched, matched: matched,
finded: finded finded: finded
} }
},
/**
* 将字符串中的尖括号等字符encode成html能解析的形式
* @param str
*/
formatSpecialCharInHtml: function (str) {
return (str + "").replaceAll("\\s|<=?|>=?", function (str) {
switch (str) {
case "<":
return "&lt;";
case "<=":
return "&le;";
case ">":
return "&gt;";
case ">=":
return "&ge;";
default:
return "&nbsp;";
}
});
} }
}); });
@ -20786,16 +20812,17 @@ Date.prototype.getDayOfYear = function () {
Date.prototype.getWeekNumber = function () { Date.prototype.getWeekNumber = function () {
var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
//周一是一周第一天 //周一是一周第一天
var week = d.getDay(); var week = d.getDay() === 0 ? 7 : d.getDay();
//var week = d.getDay();
if (this.getMonth() === 0 && this.getDate() <= week) { if (this.getMonth() === 0 && this.getDate() <= week) {
return 1; return 1;
} }
d.setDate(this.getDate() - week); d.setDate(this.getDate() - (week - 1));
var ms = d.valueOf(); // GMT var ms = d.valueOf(); // GMT
d.setMonth(0); d.setMonth(0);
d.setDate(1); d.setDate(1);
var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
if (d.getDay() > 0) { if (d.getDay() !== 1) {
offset++; offset++;
} }
return offset; return offset;
@ -20807,17 +20834,17 @@ Date.prototype.getQuarter = function () {
//离当前时间多少天的时间 //离当前时间多少天的时间
Date.prototype.getOffsetDate = function (offset) { Date.prototype.getOffsetDate = function (offset) {
return Date.getDate(this.getTime() + offset * 864e5); return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5);
}; };
Date.prototype.getAfterMulQuarter = function (n) { Date.prototype.getAfterMulQuarter = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() + n * 3); dt.setMonth(dt.getMonth() + n * 3);
return dt; return dt;
}; };
//获得n个季度前的日期 //获得n个季度前的日期
Date.prototype.getBeforeMulQuarter = function (n) { Date.prototype.getBeforeMulQuarter = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() - n * 3); dt.setMonth(dt.getMonth() - n * 3);
return dt; return dt;
}; };
@ -20849,49 +20876,19 @@ Date.prototype.getQuarterEndDate = function () {
return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth));
}; };
Date.prototype.getAfterMultiMonth = function (n) { Date.prototype.getAfterMultiMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() + n | 0); dt.setMonth(dt.getMonth() + n | 0);
return dt; return dt;
}; };
Date.prototype.getBeforeMultiMonth = function (n) { Date.prototype.getBeforeMultiMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() - n | 0); dt.setMonth(dt.getMonth() - n | 0);
return dt; return dt;
}; };
Date.prototype.getAfterMulQuarter = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() + n * 3);
return dt;
};
//获得n个季度前的日期
Date.prototype.getBeforeMulQuarter = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() - n * 3);
return dt;
};
//得到本季度的起始月份
Date.prototype.getQuarterStartMonth = function () {
var quarterStartMonth = 0;
var nowMonth = this.getMonth();
if (nowMonth < 3) {
quarterStartMonth = 0;
}
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
}
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
}
if (nowMonth > 8) {
quarterStartMonth = 9;
}
return quarterStartMonth;
};
//指定日期n个月之前或之后的日期 //指定日期n个月之前或之后的日期
Date.prototype.getOffsetMonth = function (n) { Date.prototype.getOffsetMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
var day = dt.getDate(); var day = dt.getDate();
var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays();
if (day > monthDay) { if (day > monthDay) {
@ -20905,42 +20902,12 @@ Date.prototype.getOffsetMonth = function (n) {
//获得本周的起始日期 //获得本周的起始日期
Date.prototype.getWeekStartDate = function () { Date.prototype.getWeekStartDate = function () {
var w = this.getDay(); var w = this.getDay();
return this.getOffsetDate(-w); return this.getOffsetDate(w === 0 ? -6 : 1 - w);
}; };
//得到本周的结束日期 //得到本周的结束日期
Date.prototype.getWeekEndDate = function () { Date.prototype.getWeekEndDate = function () {
var w = this.getDay(); var w = this.getDay();
var offset = (w === 0 ? 6 : 6 - w); return this.getOffsetDate(w === 0 ? 0 : 7 - w);
return this.getOffsetDate(offset);
};
//获得本季度的起始日期
Date.prototype.getQuarterStartDate = function () {
return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1);
};
//得到本季度的结束日期
Date.prototype.getQuarterEndDate = function () {
var quarterEndMonth = this.getQuarterStartMonth() + 2;
return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth));
};
Date.prototype.getAfterMultiMonth = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() + n | 0);
return dt;
};
Date.prototype.getBeforeMultiMonth = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() - n | 0);
return dt;
};
//获得当前时区对应指定时区的时间
Date.prototype.getTimeZoneTimeByTimezoneOffset = function (offset) {
var dt = Date.getDate(this.getTime());
var localTime = dt.getTime();
var localOffset = dt.getTimezoneOffset() * 60000; //获得当地时间偏移的毫秒数
var utc = localTime + localOffset; //utc即GMT时间标准时区
return Date.getDate(utc + offset);
}; };
/** Checks date and time equality */ /** Checks date and time equality */
@ -21245,6 +21212,15 @@ Date.getDate = function () {
return dt; return dt;
} }
}; };
Date.getTime = function () {
var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))();
if(BI.isNotNull(Date.timeZone)){
return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000;
}else{
return dt.getTime();
}
};
/* /*
* 给jQuery.Event对象添加的工具方法 * 给jQuery.Event对象添加的工具方法
*/ */
@ -26399,7 +26375,7 @@ BI.Text = BI.inherit(BI.Single, {
setText: function (text) { setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments); BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text; this.options.text = text;
this.text.element.html(BI.Func.formatSpecialCharInHtml(text)); this.text.element.html(BI.htmlEncode(text));
} }
}); });

88
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

166
dist/core.js vendored

@ -17448,6 +17448,53 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return newText return newText
}; };
/**
* 将cjkEncode处理过的字符串转化为原始字符串
*
* @static
* @param text 需要做解码的字符串
* @return {String} 解码后的字符串
*/
BI.cjkDecode = function (text) {
if (text == null) {
return "";
}
//查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回.
if (!isNaN(text) || text.indexOf('[') == -1) {
return text;
}
var newText = "";
for (var i = 0; i < text.length; i++) {
var ch = text.charAt(i);
if (ch == '[') {
var rightIdx = text.indexOf(']', i + 1);
if (rightIdx > i + 1) {
var subText = text.substring(i + 1, rightIdx);
//james:主要是考虑[CDATA[]]这样的值的出现
if (subText.length > 0) {
ch = String.fromCharCode(eval("0x" + subText));
}
i = rightIdx;
}
}
newText += ch;
}
return newText;
};
//replace the html special tags
BI.htmlEncode = function (text) {
return (text == null) ? '' : String(text).replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};
//html decode
BI.htmlDecode = function (text) {
return (text == null) ? '' : String(text).replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ');
};
BI.cjkEncodeDO = function (o) { BI.cjkEncodeDO = function (o) {
if (BI.isPlainObject(o)) { if (BI.isPlainObject(o)) {
var result = {}; var result = {};
@ -19174,7 +19221,7 @@ BI.extend(jQuery.fn, {
*/ */
__textKeywordMarked__: function (text, keyword, py) { __textKeywordMarked__: function (text, keyword, py) {
if (!BI.isKey(keyword) || (text + "").length > 100) { if (!BI.isKey(keyword) || (text + "").length > 100) {
return this.html(BI.Func.formatSpecialCharInHtml(text)); return this.html(BI.htmlEncode(text));
} }
keyword = keyword + ""; keyword = keyword + "";
keyword = BI.toUpperCase(keyword); keyword = BI.toUpperCase(keyword);
@ -19197,7 +19244,7 @@ BI.extend(jQuery.fn, {
if (tidx >= 0) { if (tidx >= 0) {
this.append(textLeft.substr(0, tidx)); this.append(textLeft.substr(0, tidx));
this.append($("<span>").addClass("bi-keyword-red-mark") this.append($("<span>").addClass("bi-keyword-red-mark")
.html(BI.Func.formatSpecialCharInHtml(textLeft.substr(tidx, keyword.length)))); .html(BI.htmlEncode(textLeft.substr(tidx, keyword.length))));
textLeft = textLeft.substr(tidx + keyword.length); textLeft = textLeft.substr(tidx + keyword.length);
if (py != null) { if (py != null) {
@ -19206,7 +19253,7 @@ BI.extend(jQuery.fn, {
} else if (pidx != null && pidx >= 0 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length)) { } else if (pidx != null && pidx >= 0 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length)) {
this.append(textLeft.substr(0, pidx)); this.append(textLeft.substr(0, pidx));
this.append($("<span>").addClass("bi-keyword-red-mark") this.append($("<span>").addClass("bi-keyword-red-mark")
.html(BI.Func.formatSpecialCharInHtml(textLeft.substr(pidx, keyword.length)))); .html(BI.htmlEncode(textLeft.substr(pidx, keyword.length))));
if (py != null) { if (py != null) {
py = py.substr(pidx + keyword.length); py = py.substr(pidx + keyword.length);
} }
@ -19811,27 +19858,6 @@ BI.extend(BI.Func, {
matched: matched, matched: matched,
finded: finded finded: finded
} }
},
/**
* 将字符串中的尖括号等字符encode成html能解析的形式
* @param str
*/
formatSpecialCharInHtml: function (str) {
return (str + "").replaceAll("\\s|<=?|>=?", function (str) {
switch (str) {
case "<":
return "&lt;";
case "<=":
return "&le;";
case ">":
return "&gt;";
case ">=":
return "&ge;";
default:
return "&nbsp;";
}
});
} }
}); });
@ -20786,16 +20812,17 @@ Date.prototype.getDayOfYear = function () {
Date.prototype.getWeekNumber = function () { Date.prototype.getWeekNumber = function () {
var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
//周一是一周第一天 //周一是一周第一天
var week = d.getDay(); var week = d.getDay() === 0 ? 7 : d.getDay();
//var week = d.getDay();
if (this.getMonth() === 0 && this.getDate() <= week) { if (this.getMonth() === 0 && this.getDate() <= week) {
return 1; return 1;
} }
d.setDate(this.getDate() - week); d.setDate(this.getDate() - (week - 1));
var ms = d.valueOf(); // GMT var ms = d.valueOf(); // GMT
d.setMonth(0); d.setMonth(0);
d.setDate(1); d.setDate(1);
var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
if (d.getDay() > 0) { if (d.getDay() !== 1) {
offset++; offset++;
} }
return offset; return offset;
@ -20807,17 +20834,17 @@ Date.prototype.getQuarter = function () {
//离当前时间多少天的时间 //离当前时间多少天的时间
Date.prototype.getOffsetDate = function (offset) { Date.prototype.getOffsetDate = function (offset) {
return Date.getDate(this.getTime() + offset * 864e5); return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5);
}; };
Date.prototype.getAfterMulQuarter = function (n) { Date.prototype.getAfterMulQuarter = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() + n * 3); dt.setMonth(dt.getMonth() + n * 3);
return dt; return dt;
}; };
//获得n个季度前的日期 //获得n个季度前的日期
Date.prototype.getBeforeMulQuarter = function (n) { Date.prototype.getBeforeMulQuarter = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() - n * 3); dt.setMonth(dt.getMonth() - n * 3);
return dt; return dt;
}; };
@ -20849,49 +20876,19 @@ Date.prototype.getQuarterEndDate = function () {
return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth));
}; };
Date.prototype.getAfterMultiMonth = function (n) { Date.prototype.getAfterMultiMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() + n | 0); dt.setMonth(dt.getMonth() + n | 0);
return dt; return dt;
}; };
Date.prototype.getBeforeMultiMonth = function (n) { Date.prototype.getBeforeMultiMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() - n | 0); dt.setMonth(dt.getMonth() - n | 0);
return dt; return dt;
}; };
Date.prototype.getAfterMulQuarter = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() + n * 3);
return dt;
};
//获得n个季度前的日期
Date.prototype.getBeforeMulQuarter = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() - n * 3);
return dt;
};
//得到本季度的起始月份
Date.prototype.getQuarterStartMonth = function () {
var quarterStartMonth = 0;
var nowMonth = this.getMonth();
if (nowMonth < 3) {
quarterStartMonth = 0;
}
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
}
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
}
if (nowMonth > 8) {
quarterStartMonth = 9;
}
return quarterStartMonth;
};
//指定日期n个月之前或之后的日期 //指定日期n个月之前或之后的日期
Date.prototype.getOffsetMonth = function (n) { Date.prototype.getOffsetMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
var day = dt.getDate(); var day = dt.getDate();
var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays();
if (day > monthDay) { if (day > monthDay) {
@ -20905,42 +20902,12 @@ Date.prototype.getOffsetMonth = function (n) {
//获得本周的起始日期 //获得本周的起始日期
Date.prototype.getWeekStartDate = function () { Date.prototype.getWeekStartDate = function () {
var w = this.getDay(); var w = this.getDay();
return this.getOffsetDate(-w); return this.getOffsetDate(w === 0 ? -6 : 1 - w);
}; };
//得到本周的结束日期 //得到本周的结束日期
Date.prototype.getWeekEndDate = function () { Date.prototype.getWeekEndDate = function () {
var w = this.getDay(); var w = this.getDay();
var offset = (w === 0 ? 6 : 6 - w); return this.getOffsetDate(w === 0 ? 0 : 7 - w);
return this.getOffsetDate(offset);
};
//获得本季度的起始日期
Date.prototype.getQuarterStartDate = function () {
return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1);
};
//得到本季度的结束日期
Date.prototype.getQuarterEndDate = function () {
var quarterEndMonth = this.getQuarterStartMonth() + 2;
return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth));
};
Date.prototype.getAfterMultiMonth = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() + n | 0);
return dt;
};
Date.prototype.getBeforeMultiMonth = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() - n | 0);
return dt;
};
//获得当前时区对应指定时区的时间
Date.prototype.getTimeZoneTimeByTimezoneOffset = function (offset) {
var dt = Date.getDate(this.getTime());
var localTime = dt.getTime();
var localOffset = dt.getTimezoneOffset() * 60000; //获得当地时间偏移的毫秒数
var utc = localTime + localOffset; //utc即GMT时间标准时区
return Date.getDate(utc + offset);
}; };
/** Checks date and time equality */ /** Checks date and time equality */
@ -21245,6 +21212,15 @@ Date.getDate = function () {
return dt; return dt;
} }
}; };
Date.getTime = function () {
var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))();
if(BI.isNotNull(Date.timeZone)){
return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000;
}else{
return dt.getTime();
}
};
/* /*
* 给jQuery.Event对象添加的工具方法 * 给jQuery.Event对象添加的工具方法
*/ */

2
src/base/single/text.js

@ -114,7 +114,7 @@ BI.Text = BI.inherit(BI.Single, {
setText: function (text) { setText: function (text) {
BI.Text.superclass.setText.apply(this, arguments); BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text; this.options.text = text;
this.text.element.html(BI.Func.formatSpecialCharInHtml(text)); this.text.element.html(BI.htmlEncode(text));
} }
}); });

47
src/core/alias.js

@ -251,6 +251,53 @@
return newText return newText
}; };
/**
* 将cjkEncode处理过的字符串转化为原始字符串
*
* @static
* @param text 需要做解码的字符串
* @return {String} 解码后的字符串
*/
BI.cjkDecode = function (text) {
if (text == null) {
return "";
}
//查找没有 "[", 直接返回. kunsnat:数字的时候, 不支持indexOf方法, 也是直接返回.
if (!isNaN(text) || text.indexOf('[') == -1) {
return text;
}
var newText = "";
for (var i = 0; i < text.length; i++) {
var ch = text.charAt(i);
if (ch == '[') {
var rightIdx = text.indexOf(']', i + 1);
if (rightIdx > i + 1) {
var subText = text.substring(i + 1, rightIdx);
//james:主要是考虑[CDATA[]]这样的值的出现
if (subText.length > 0) {
ch = String.fromCharCode(eval("0x" + subText));
}
i = rightIdx;
}
}
newText += ch;
}
return newText;
};
//replace the html special tags
BI.htmlEncode = function (text) {
return (text == null) ? '' : String(text).replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};
//html decode
BI.htmlDecode = function (text) {
return (text == null) ? '' : String(text).replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ');
};
BI.cjkEncodeDO = function (o) { BI.cjkEncodeDO = function (o) {
if (BI.isPlainObject(o)) { if (BI.isPlainObject(o)) {
var result = {}; var result = {};

6
src/core/func/dom.js

@ -20,7 +20,7 @@ BI.extend(jQuery.fn, {
*/ */
__textKeywordMarked__: function (text, keyword, py) { __textKeywordMarked__: function (text, keyword, py) {
if (!BI.isKey(keyword) || (text + "").length > 100) { if (!BI.isKey(keyword) || (text + "").length > 100) {
return this.html(BI.Func.formatSpecialCharInHtml(text)); return this.html(BI.htmlEncode(text));
} }
keyword = keyword + ""; keyword = keyword + "";
keyword = BI.toUpperCase(keyword); keyword = BI.toUpperCase(keyword);
@ -43,7 +43,7 @@ BI.extend(jQuery.fn, {
if (tidx >= 0) { if (tidx >= 0) {
this.append(textLeft.substr(0, tidx)); this.append(textLeft.substr(0, tidx));
this.append($("<span>").addClass("bi-keyword-red-mark") this.append($("<span>").addClass("bi-keyword-red-mark")
.html(BI.Func.formatSpecialCharInHtml(textLeft.substr(tidx, keyword.length)))); .html(BI.htmlEncode(textLeft.substr(tidx, keyword.length))));
textLeft = textLeft.substr(tidx + keyword.length); textLeft = textLeft.substr(tidx + keyword.length);
if (py != null) { if (py != null) {
@ -52,7 +52,7 @@ BI.extend(jQuery.fn, {
} else if (pidx != null && pidx >= 0 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length)) { } else if (pidx != null && pidx >= 0 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length)) {
this.append(textLeft.substr(0, pidx)); this.append(textLeft.substr(0, pidx));
this.append($("<span>").addClass("bi-keyword-red-mark") this.append($("<span>").addClass("bi-keyword-red-mark")
.html(BI.Func.formatSpecialCharInHtml(textLeft.substr(pidx, keyword.length)))); .html(BI.htmlEncode(textLeft.substr(pidx, keyword.length))));
if (py != null) { if (py != null) {
py = py.substr(pidx + keyword.length); py = py.substr(pidx + keyword.length);
} }

21
src/core/func/function.js

@ -68,27 +68,6 @@ BI.extend(BI.Func, {
matched: matched, matched: matched,
finded: finded finded: finded
} }
},
/**
* 将字符串中的尖括号等字符encode成html能解析的形式
* @param str
*/
formatSpecialCharInHtml: function (str) {
return (str + "").replaceAll("\\s|<=?|>=?", function (str) {
switch (str) {
case "<":
return "&lt;";
case "<=":
return "&le;";
case ">":
return "&gt;";
case ">=":
return "&ge;";
default:
return "&nbsp;";
}
});
} }
}); });

92
src/core/proto/date.js

@ -109,16 +109,17 @@ Date.prototype.getDayOfYear = function () {
Date.prototype.getWeekNumber = function () { Date.prototype.getWeekNumber = function () {
var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); var d = Date.getDate(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
//周一是一周第一天 //周一是一周第一天
var week = d.getDay(); var week = d.getDay() === 0 ? 7 : d.getDay();
//var week = d.getDay();
if (this.getMonth() === 0 && this.getDate() <= week) { if (this.getMonth() === 0 && this.getDate() <= week) {
return 1; return 1;
} }
d.setDate(this.getDate() - week); d.setDate(this.getDate() - (week - 1));
var ms = d.valueOf(); // GMT var ms = d.valueOf(); // GMT
d.setMonth(0); d.setMonth(0);
d.setDate(1); d.setDate(1);
var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1; var offset = Math.floor((ms - d.valueOf()) / (7 * 864e5)) + 1;
if (d.getDay() > 0) { if (d.getDay() !== 1) {
offset++; offset++;
} }
return offset; return offset;
@ -130,17 +131,17 @@ Date.prototype.getQuarter = function () {
//离当前时间多少天的时间 //离当前时间多少天的时间
Date.prototype.getOffsetDate = function (offset) { Date.prototype.getOffsetDate = function (offset) {
return Date.getDate(this.getTime() + offset * 864e5); return Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5);
}; };
Date.prototype.getAfterMulQuarter = function (n) { Date.prototype.getAfterMulQuarter = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() + n * 3); dt.setMonth(dt.getMonth() + n * 3);
return dt; return dt;
}; };
//获得n个季度前的日期 //获得n个季度前的日期
Date.prototype.getBeforeMulQuarter = function (n) { Date.prototype.getBeforeMulQuarter = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() - n * 3); dt.setMonth(dt.getMonth() - n * 3);
return dt; return dt;
}; };
@ -172,49 +173,19 @@ Date.prototype.getQuarterEndDate = function () {
return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth));
}; };
Date.prototype.getAfterMultiMonth = function (n) { Date.prototype.getAfterMultiMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() + n | 0); dt.setMonth(dt.getMonth() + n | 0);
return dt; return dt;
}; };
Date.prototype.getBeforeMultiMonth = function (n) { Date.prototype.getBeforeMultiMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
dt.setMonth(dt.getMonth() - n | 0); dt.setMonth(dt.getMonth() - n | 0);
return dt; return dt;
}; };
Date.prototype.getAfterMulQuarter = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() + n * 3);
return dt;
};
//获得n个季度前的日期
Date.prototype.getBeforeMulQuarter = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() - n * 3);
return dt;
};
//得到本季度的起始月份
Date.prototype.getQuarterStartMonth = function () {
var quarterStartMonth = 0;
var nowMonth = this.getMonth();
if (nowMonth < 3) {
quarterStartMonth = 0;
}
if (2 < nowMonth && nowMonth < 6) {
quarterStartMonth = 3;
}
if (5 < nowMonth && nowMonth < 9) {
quarterStartMonth = 6;
}
if (nowMonth > 8) {
quarterStartMonth = 9;
}
return quarterStartMonth;
};
//指定日期n个月之前或之后的日期 //指定日期n个月之前或之后的日期
Date.prototype.getOffsetMonth = function (n) { Date.prototype.getOffsetMonth = function (n) {
var dt = Date.getDate(this.getTime()); var dt = Date.getDate(Date.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()));
var day = dt.getDate(); var day = dt.getDate();
var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays(); var monthDay = Date.getDate(dt.getFullYear(), dt.getMonth() + parseInt(n), 1).getMonthDays();
if (day > monthDay) { if (day > monthDay) {
@ -228,42 +199,12 @@ Date.prototype.getOffsetMonth = function (n) {
//获得本周的起始日期 //获得本周的起始日期
Date.prototype.getWeekStartDate = function () { Date.prototype.getWeekStartDate = function () {
var w = this.getDay(); var w = this.getDay();
return this.getOffsetDate(-w); return this.getOffsetDate(w === 0 ? -6 : 1 - w);
}; };
//得到本周的结束日期 //得到本周的结束日期
Date.prototype.getWeekEndDate = function () { Date.prototype.getWeekEndDate = function () {
var w = this.getDay(); var w = this.getDay();
var offset = (w === 0 ? 6 : 6 - w); return this.getOffsetDate(w === 0 ? 0 : 7 - w);
return this.getOffsetDate(offset);
};
//获得本季度的起始日期
Date.prototype.getQuarterStartDate = function () {
return Date.getDate(this.getFullYear(), this.getQuarterStartMonth(), 1);
};
//得到本季度的结束日期
Date.prototype.getQuarterEndDate = function () {
var quarterEndMonth = this.getQuarterStartMonth() + 2;
return Date.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth));
};
Date.prototype.getAfterMultiMonth = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() + n | 0);
return dt;
};
Date.prototype.getBeforeMultiMonth = function (n) {
var dt = Date.getDate(this.getTime());
dt.setMonth(dt.getMonth() - n | 0);
return dt;
};
//获得当前时区对应指定时区的时间
Date.prototype.getTimeZoneTimeByTimezoneOffset = function (offset) {
var dt = Date.getDate(this.getTime());
var localTime = dt.getTime();
var localOffset = dt.getTimezoneOffset() * 60000; //获得当地时间偏移的毫秒数
var utc = localTime + localOffset; //utc即GMT时间标准时区
return Date.getDate(utc + offset);
}; };
/** Checks date and time equality */ /** Checks date and time equality */
@ -568,3 +509,12 @@ Date.getDate = function () {
return dt; return dt;
} }
}; };
Date.getTime = function () {
var dt = Function.prototype.bind.apply(Date.getDate, BI.concat([null], [].slice.apply(arguments)))();
if(BI.isNotNull(Date.timeZone)){
return dt.getTime() - Date.timeZone - dt.getTimezoneOffset() * 60000;
}else{
return dt.getTime();
}
};

Loading…
Cancel
Save