`

js tools

阅读更多

 

// temp Id generator

SEQUENCE = {

value : -1,

next : function() {

this.value = ++this.value;

return this.value;

};

 

 

//reset form element

function clearForm(formName) {

    var formObj = document.forms[formName];

    var formEl = formObj.elements;

    for (var i=0; i<formEl.length; i++)

    {

        var element = formEl[i];

        if (element.type == 'submit') { continue; }

        if (element.type == 'reset') { continue; }

        if (element.type == 'button') { continue; }

        if (element.type == 'hidden') { continue; }

        if (element.type == 'text') { element.value = ''; }

        if (element.type == 'textarea') { element.value = ''; }

        if (element.type == 'checkbox') { element.checked = false; }

        if (element.type == 'radio') { element.checked = false; }

        if (element.type == 'select-multiple') { element.selectedIndex = -1; }

        if (element.type == 'select-one') { element.selectedIndex = -1; }

    }

}

 

//define stringBuffer object in present project

function StringBuffer() {

this.__strings__ = new Array;

}

 

StringBuffer.prototype.append = function(str) {

this.__strings__.push(str);

return this;

};

 

StringBuffer.prototype.toString = function() {

return this.__strings__.join("");

};

 

//extend one method,'startWith' for original string object

if(!String.prototype.startWith){

String.prototype.startWith = function(param){

if(!param){

return false;

}else{

if(String(this).substring(0,String(param).length)==param){

return true;

}else{

return false;

}

}

};

}

 

/**

 * 

 * @param divId  one container

 * @param info operation result message to show in the up DIV, such as: "Add Successfully!"

 * @param isSuccess one sign whether operate successfully.Just two values:true or false.true means success.

 * @returns undefined

 */

function showOperationResultInfo(divId,info,isSuccess){

$("#"+divId).removeAttr("style");

if(isSuccess){

$("#"+divId).attr("style","color:green");

}else{

$("#"+divId).attr("style","color:red");

}

$("#"+divId).empty();

$("#"+divId).html(info);

}

 

//refresh current page after ajax request

function deleteItemById(link){

$.ajax({

url :link,

cache:false,

context:document.body,

success:function(data){

if(!data.startWith("error")){

location.href="http://<%=request.getServerName()%>:<%=request.getServerPort()%><%=request.getContextPath() %>/demoWebSite/generateReport.action";

}else{

showOperationResultInfo("errorInfo",Messages.deleteFailureMess+",cause:"+data,false);

return false;

}

}

});

}

 

//obtain java version in the local PC by the plugin 'deployJava.js'

<script src="${contextPath}/js/plugins/deployJava.js"></script>

<script type="text/javascript">

var versions = deployJava.getJREs();

var reg = /1.6.|1.7.|1.8.|1.9./;

var result =  reg.exec(versions);

if(null == result){

$("#appletUploadControl").innerHTML = "Your java version is: <b>" + versions + "</b>, please install java1.6 or upper version<br/>" + "You could download latest JDK from here:" + "<a href='http://www.oracle.com/technetwork/java/javase/downloads/index.html', target='_blank'>oracle-java</a>";

}

</script>



/*
DESC:extend one method,'Format' from original Date object
for example: 
1. new Date().Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 ;
2. new Date().Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 ;
3. $("#createDateHtmlId").val(new Date().Format("MM/dd/yyyy")) .
*/
Date.prototype.Format = function(fmt) {
var o = {
"M+" : this.getMonth() + 1,
"d+" : this.getDate(), 
"h+" : this.getHours(),
"m+" : this.getMinutes(), 
"s+" : this.getSeconds(), 
"q+" : Math.floor((this.getMonth() + 3) / 3), 
"S" : this.getMilliseconds()
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
.substr(4 - RegExp.$1.length));
for ( var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
: (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};


<script type="text/javascript" src="${contextPath}/js/json.js"></script>
var project = {
value:"",
newProject:function(){
var one={
"id":"",
"project":"",
"projectCode":""
};
return one;
},
toJson:function(data){
return JSON.stringify(data);//the 'stringify' method from the plugin 'json.js'
},
};
//Construct one new instance
var item = project.newProject();
item.id=100;
item.project="demo";
item.projectCode="DE";

//Serialize object to character.After that,you can pass 'project.value' character as parameters for ajax request
project.value = project.toJson(item);


//transfer rgb to hexadecimal,such as (code section): var colorValue = rgb2hex($(this).parents("tr").css("color"));//"#ff6633"
function rgb2hex(rgb) {
if (!rgb) {
        return '#FFFFFF'; //default color
    }
    var hex_rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); 
    function hex(x) {return ("0" + parseInt(x).toString(16)).slice(-2);}
    if (hex_rgb) {
        return "#" + hex(hex_rgb[1]) + hex(hex_rgb[2]) + hex(hex_rgb[3]);
    } else {
        return rgb; //ie8 returns background-color in hex format then it will make compatible, you can improve it checking if format is in hexadecimal
    }
}

//the use of ajax request to download file : <a href="javascript:void(0)"  onclick="return downloadFile(URL.generateReportReq);"></a>
function downloadFile(link){
var flagObj=false;
$.ajax({
url :link,
context:document.body,
success:function(data){
if(!data.startWith("error")){
flagObj = true;
} else{
alert(Messages.downloadFileMess);
flagObj =  false;
}
return;
}
});
return flagObj;
}
分享到:
评论

相关推荐

    JavaScript Tools Guide CC.pdf

    《JavaScript Tools Guide CC》是Adobe Systems Incorporated为Photoshop创作的一份官方JavaScript脚本开发指南,适用于Windows和Macintosh操作系统。这份文档详细介绍了如何在Photoshop中利用JavaScript进行扩展...

    JavaScript Tools Guide CS6.pdf

    ### JavaScript Tools Guide for Adobe Creative Suite 6 #### 概述 《JavaScript Tools Guide CS6.pdf》是一份由Adobe Systems Incorporated发布的官方文档,旨在为使用Adobe Creative Suite 6(简称CS6)的用户...

    JavaScript Tools Guide CC

    1. 文档标题与描述:文档标题为“JavaScript Tools Guide CC”,描述中指出这是“Adobe®CreativeCloud®JavaScript Tools Guide”的开发说明。文档是为Windows和Macintosh操作系统编写的,由Adobe Systems ...

    html to js tools

    HTML到JavaScript工具是一种技术,它允许开发者将HTML代码转换成JavaScript字符串,以便在运行时动态地插入或操作DOM。这种转换对于创建可复用的组件、优化页面加载速度以及实现某些高级交互功能非常有用。以下是对...

    json解析js Tools

    json解析js Tools json解析js Tools json解析js Tools json解析js Tools

    JavaScript Tools Guide CS3

    ### JavaScript Tools Guide CS3 关键知识点解析 #### 一、引言 《JavaScript Tools Guide CS3》是一份针对Adobe Creative Suite 3 (CS3) 的专业文档,详细介绍了如何使用JavaScript进行扩展编程。Adobe CS3是一款...

    JavaScriptTools

    JavaScriptTools 是一个与JavaScript相关的工具集合,它特别强调了对代码的不同颜色标记功能,这通常意味着它可能包含了一些代码编辑器或语法高亮插件。HTML标签表明这个工具集可能与前端开发紧密关联,因为HTML是...

    PS插件开发 illustrator插件开发 JavaScript Tools Guide CC.pdf

    JavaScript Tools Guide for Adobe Creative Cloud是Adobe Systems Incorporated发布的一份指南,专注于如何利用JavaScript进行插件开发,涵盖了Photoshop(PS)、Illustrator、After Effects(AE)以及InDesign(ID...

    Node.js Tools for Visual Studio(NTVS)

    NTVS supports the following: node projects Intellisense Debugging local &amp; remote with support for Linux and MacOS Profiling node REPL with multi line editing Integrated npm GUI ...

    Node.js Tools 1.2 (ntvs 1.2 for vs 2015)

    **Node.js Tools 1.2 for Visual Studio 2015** 是一款强大的开发工具,专为使用Node.js开发JavaScript应用程序的Visual Studio 2015用户设计。它提供了丰富的集成开发环境(IDE)功能,使得JavaScript开发在VS 2015...

    [JavaScript][PDF][英文版]Oh My JS

    12. Useful Node.js Tools, Tutorials And Resources(有用的Node.js工具、教程和资源):介绍Node.js开发者应该掌握的一些工具、教程和资源,因为Node.js是一个基于Chrome V8引擎的JavaScript运行环境,它让...

    JavascriptTools

    各种原生javascript工具函数,方便日常web开发

    js-tools:js常用工具

    在JavaScript工具集"js-tools"中,我们通常会看到以下几类知识点: 1. **代码压缩与优化**:为了减少网页加载时间,JS代码通常需要进行压缩,如使用UglifyJS或Terser将源代码转换为最小化的生产版本。同时,Webpack...

    jquery.tools.min.js 最新的1.2.7版本

    jquery.tools.min.js 最新的1.2.7版本 jquery.min.js是压缩版的jquery库,是由完整版的jQuery库经过压缩得来,压缩后功能与未压缩的完全一样,只是将其中的空白字符、注释、空行等与逻辑无关的内容删除,并进行一些...

    jquery.tools.js下载

    jquery.tools.js jquery.tools.js

    geotools汉语版资料

    《GeoTools汉语版资料》是一份详实的资源集合,主要针对使用GeoTools进行地理信息系统(GIS)开发的用户。GeoTools是一个开放源代码的Java库,它实现了OGC(Open Geospatial Consortium)标准,提供了对地理空间数据...

    JSTool:个人开发中总结和积累的js工具(JS tools that are summarized and accumulated in personal development)

    个人开发中总结和积累的js工具(JS tools that are summarized and accumulated in personal development) 文件名 说明 md5.js MD5加密算法 Base64.js Base64对称加密算法 timeage.js 将时间格式为相对时间,如 1小时...

    tools(1).js

    tools(1).js

    用于 or-tools 车辆路线问题的 Node.js 绑定_C++_代码_下载

    在使用这个 Node.js 绑定时,开发者需要注意的是,由于是跨语言交互,性能可能会受到一定影响,但相比于纯 JavaScript 的解决方案,C++ 的高效执行仍然能带来显著的优化效果。此外,理解 `or-tools` 的基本概念和 ...

Global site tag (gtag.js) - Google Analytics