js 面向对象插件写法,还是很好理解的

/**
* Created by jiangtao on 2015/5/12.
* name jihe
*/
(function () {
function gather(msg) {
//适应参数
if (msg) {
if (msg.imgFile != undefined) {
this.imgFile = msg.imgFile;
};
if (msg.wechatAppid != undefined) {
this.wechatAppid = msg.wechatAppid;
};
};
this.sendEventUrl='/x1371/wechat/event/publish';
this.uploadUrl='/x1371/upload/array/second';
this.setTime = null;
this.index = 0;
this.ajax= null;
this.debug=true;
};
gather.prototype = {
constructor: gather,
//屏幕适应
windowResize:function(){
var that=this;
that.getResize();
$(window).resize(function(){
that.getResize();
})
},
//屏幕自适应
getResize:function(){
var docWidth = document.documentElement.clientWidth;
var html = document.querySelector('html');
html.style.fontSize = (docWidth / 20) + "px";
},
//模态框自适应
maskingResize:function(e){
$(e).height($(window).height());
$(e).width($(window).width());
$(window).resize(function(){
$(e).height($(window).height());
$(e).width($(window).width());
})
},
//图片上传
uploadImg: function (back, setTime) {
this.setTime = setTime;
var that = this;
back.success.callback = back.success;
back.before.callback = back.before;
back.erro.callback = back.erro;
that.base64(function (imgUrl) {
back.success(imgUrl);
}, function (data) {
back.before(data);
}, function (erro) {
back.erro(erro)
})
},
//生成base64编码
base64: function (success, before, erro) {
var file = this.imgFile;
var that = this;
success.callback = success;
before.callback = before;
erro.callback = erro;
for (var i = 0; i < file.length; i++) {
lrz(file[i], {width: 400}, function (results) {
var imgSize=results.imgSize;
that.sendreq(results.base64, function (e) {
success({imgUrl:e[0],imgSize:imgSize});
}, function () {
erro({errMsg:'图片上传失败'});
},function(ajax){
before({blob:results.blob,ajax:ajax})
});
});
};
},
//ajax上传图片;
sendreq: function (base64, success, erro,before) {
var that = this;
var data = JSON.stringify({base64: [base64]});
success.callback = success;
erro.callback = erro;
before.callback=before;
var sendAjax = $.ajax({
contentType: 'application/json;charset=utf-8',
dataType: 'json',
type: 'post',
url: that.uploadUrl,
data: data,
success: function (data) {
if (data.code != 0) {
erro(data.msg);
} else {
success(data.data);
}
},
error:function(data,err){
erro(err);
}
})
before(sendAjax);
this.pauseUplodImg(that.setTime,sendAjax);
},
//打开上传等待动画
openUploadAnimation:function(){
$('.loadmb').removeClass('none');
setTimeout(function(){
$('.loadmb').removeClass('hidden');
},100);
},
//关闭上传等待动画
offUploadAnimation:function(){
$('.loadmb').addClass('hidden');
setTimeout(function(){
$('.loadmb').addClass('none');
},500);
},
//创建图片框
createImgContainer:function(imgUrl){
$('.twhp').height($('.twhp').height() + 10.125 * parseFloat($('html').css('font-size')));
$(".bianji").append('<div class="tphp"><div class="delete">'+
'</div><div class="crtp"><img src="'+imgUrl+'" width="100%" height="auto" />'+
'</div><div class="button top changeImg">更换当前图片</div></div>');
var index=$('.bianji>.tphp').length;
return index;
},
//修改图片框
changeContainerImg:function(e,r){
r.find('img').attr('src',e);
},
//创建文本框
createfontContainer:function(control,back){
back.callback=back;
$('.tjdl').addClass('active');
$('.twhp').height($('.twhp').height() + 7 * parseFloat($('html').css('font-size')));
setTimeout(function(){
$('.tjdl').removeClass('active');
var fontBox='<div class="wzhp"><div class="delete"></div><textarea class="textCon1" rows="4" placeholder="请输入文字..."></textarea></div>';
control.append(fontBox);
back();
},500);
},
//url加密
urlEocde: function (str) {
str = (str + '').toString();
return encodeURIComponent(str).
replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
},
//跳转微信登录
locationWechatLogin: function () {
var u = window.location.href;
var encodeUrl = this.urlEocde(u);
if(!this.wechatAppid){
alert('wechatAppid不存在')
return false;
}
var wechatUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
this.wechatAppid + '&' + 'redirect_uri=' + encodeUrl + '&response_type=code&' +
'scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect';
location.href = wechatUrl;
},
//获取url地址后面参数
getUrlArguments: function (str) {
var urlArguments = location.search.split("?")[1];//获取?后面的部分
if (urlArguments != undefined) {
var arguments = urlArguments.split('&');//将?后的参数由&分割为数组
for (var i = 0; i < arguments.length; i++) {
var key = arguments[i].split('=')[0],
val = arguments[i].split('=')[1];
if (key == str) {
return val;
}
}
}
},
//判断code是否存在
isCode: function () {
if (this.getUrlArguments('code')) {
return true;
} else {
return false;
}
},
//通过code获取userid
getUser: function (code, url, back) {
var that=this;
if(back.success!=undefined){
back.success.callback = back.success;
}if(back.erro!=undefined){
back.erro.callback=back.erro;
}
if (code) {
$.ajax({
type: 'get',
url: url + '?code=' + code,
success: function (data) {
if(data.code!=0){
if(back.erro!=undefined){
back.erro(data.msg)
}
}else{
if(back.success!=undefined){
back.success(data.data.userId)
}
}
}
})
}
},
//判断页面上是否存在userid
isUserId:function(e){
return $(e).text();
},
//判断文件是否为图片
isImage: function (imageFile) {
var fileType = imageFile.type;
if (fileType && fileType.split('/')[0] == 'image') {
return true;
} else {
return false;
}
},
//提示框
messageBox: function (text) {
//alert(text)
setTimeout(function () {
$('.wsrwc').removeClass('none');
$(".wsrnrerro").text(text);
$('.fb').removeClass('active');
setTimeout(function () {
$('.wsrwc').removeClass('hidden');
}, 200)
}, 500);
},
closeMessageBox:function(){
$('.enter').addClass('active');
setTimeout(function(){
$('.enter').parent().parent().parent().addClass('hidden');
setTimeout(function(){
$(".wsrnrerro").text('');
$('.enter').parent().parent().parent().addClass('none');
$('.enter').removeClass('active');
},200);
},200)
},
//非空判断
isBlank: function (f) {
//匹配空格赋值为空;
var val, l;
if (f.value != undefined) {
val = f.value.replace(/\s/g, "");
} else {
alert('kongString()方法必须有value参数!')
return false;
}
//判断输入长度;
if (f.len != undefined) {
l = eval('/^(?!.{' + f.len + '}|\s*$)/g');
}
if (l) {
if (val) {
if (l.test(f.value)) {
return true;
} else {
this.messageBox(f.name + '不能超过' + f.len + '个字!');
return false
}
} else {
this.messageBox('请填写'+f.name+'!');
return false;
}
} else {
if (val) {
return true;
} else {
return false;
}
}
},
createEvent: function (data,back) {
var url=this.sendEventUrl;
back.before.callback=back.before;
back.success.callback=back.success;
back.erro.callback=back.erro;
var sendAjax= $.ajax({
contentType:'application/json;charset=utf-8',
dataType:'json',
type:'post',
url:url,
data:JSON.stringify(data),
success:function(data){
if(data.code!=0){
back.erro('图片上传失败!')
}else{
back.success(data.data);
}
}
})
back.before(sendAjax);
},
//微信分享share参数为一个对象
wechatShare: function (share) {
var shareTitle = share.title;
var shareContent = share.content;
var shareLink = share.linkUrl;
var shareImgUrl = share.imgUrl;
wx.ready(function () {
wx.onMenuShareTimeline({
title: shareTitle,
desc: shareContent,
link: shareLink,
imgUrl: shareImgUrl
});
//分享给朋友
wx.onMenuShareAppMessage({
title: shareTitle,
desc: shareContent,
link: shareLink,
imgUrl: shareImgUrl
});
})
},
pauseUplodImg: function (time,e) {
setTimeout(function () {
if (e && e.readystate != 4) {
e.abort();
}
}, time * 1000)
},
uploadEsc:function(e){
if (e && e.readystate != 4) {
e.abort();
}
}
};
window.gather = function (msg) {
return new gather(msg);
}
})()

转载于:https://www.cnblogs.com/ghost12/p/4531194.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/375937.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

操作系统上机题目(多进程2)

1、主进程创建2个子进程&#xff0c;主进程通过两个管道分别与两个子进程连接2、第一个子进程计算从1加到50的和&#xff0c;并将结果通过管道送给父进程3、第一个子进程计算从50加到100的和&#xff0c;并将结果通过管道送给父进程4、父进程读取两个子进程的结果&#xff0c;将…

JavaScript 的简介

JavaScript 是一种基于对象和事件驱动的脚本语言。JavaScript和HTML一起实现网页与客户端的交互&#xff0c;从而可以开发客户端的应用程序。JavaScript是通过潜入在标准的HTML文件中实现的&#xff0c;可以直接控制浏览器窗口个元素以及页面内容。JavaScript一个重要的功能就是…

c语言大乐透编译,Excel大乐透摇号vba代码分享,说不定就中百万了呢

大家好我是Excel从零到一&#xff0c;今天闲来无聊做了一套大乐透摇号程序的vba代码分享给大家来看下效果Excel大乐透摇号vba代码分享&#xff0c;说不定就中百万了呢Sub 摇号()Dim i, a, test, s(1 To 35) As IntegerFor i 1 To 5line1: test Application.WorksheetFunction…

操作系统上机题目(多线程1)

主线程创建10个子线程 第0个子线程计算从01加到10的和 - 第1个子线程计算从11加到20的和 … 第9个子线程计算从91加到100的和 2. 主线程归并10个子线程的计算结果&#xff0c;最终结果为5050 本题必须使用线程参数来完成 #include<stdio.h> #include<unistd.h> #i…

纸上谈兵: 堆 (heap)

纸上谈兵: 堆 (heap) 作者&#xff1a;Vamei 出处&#xff1a;http://www.cnblogs.com/vamei 欢迎转载&#xff0c;也请保留这段声明。谢谢&#xff01; 堆(heap)又被为优先队列(priority queue)。尽管名为优先队列&#xff0c;但堆并不是队列。回忆一下&#xff0c;在队列中&a…

C语言 取模运算 保证正数,c语言的取模运算

我们对C的%运算知多少呢&#xff1f;当是正整数时&#xff0c;可能大家都知道。例如&#xff1a;5%3等于2, 3%5等于3。当存在负数时呢&#xff1f;先看看例子&#xff1a;例一&#xff1a;int main(){int x;x -6%5; printf("%2d/n",x);x 6%-5; printf("%2d/n&…

操作系统上机题目(多线程2)

主线程创建4个子线程T1、T2、T3、T4&#xff0c;主线程在4个子线程退出后&#xff0c;才退出线程T1、T2、T3、T4的运行时代码如下&#xff1a; #include <unistd.h> // sleep函数声明在该头文件中void *T1_entry(void *arg) {sleep(2); // 睡眠2秒&#xff0c;不准删除…

图形GUI名称

15句柄图形(Handle Graphics)15.1图形窗的产生和控制(Figure window creation and control)clf 清除当前图close 关闭图形figure 打开或创建图形窗口gcf 获得当前图的柄openfig 打开图形refresh 刷新图形shg 显示图形窗15.2轴的产生和控制(Axis creation and control)axes 在任…

c语言编程非线性方程求解,c语言计算机编程三种方法求解非线性方程.doc

c语言计算机编程三种方法求解非线性方程.doc本 科 专 业 学 年 论 文题 目非线性方程求解比较姓 名 何 娟 专 业 计算机科学技术系 班 级 08 级本科(2)班 指 导 老 师 刘 晓 娜 完成日期 2010 年 11 月 21 日计算机学年专业论文 非线性方程求解- 1 -题 目非线性方程求解比较摘 …

最近用到这个强大的工具 PhysicsEditor (转)

今天收到PhysicsEditor作者发过来的license key&#xff0c;所以顺便把PhysicsEditor也尝试了一下。主要是尝试将PhysicsEditor与cocos2dx&#xff0c;box2d结合开发的一些步骤。之前大概网络检索了一下&#xff0c;知道PhysicsEditor的功能其实很简单。一句话就是给图片的边缘…

浅谈块级元素和内联元素的嵌套规则

1. 替换和不可替换元素 从元素本身的特点来讲&#xff0c;可以分为替换和不可替换元素。 a) 替换元素 替换元素就是浏览器根据元素的标签和属性&#xff0c;来决定元素的具体显示内容。 例如浏览器会根据<img>标签的src属性的值来读取图片信息并显示出来&#xff0c;而如…

如何更新Chrome

在浏览器的地址栏中输入chrome://help即可进行自动更新&#xff0c;如下图&#xff1a;

c语言用指针实现打开和关闭文件,我用rewind函数没把指针直到开始,关闭文件然后打开就行。帮忙看看...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼高手啊&#xff0c;我试了&#xff0c;结果是回到文件头了&#xff0c;把123覆盖了&#xff0c;为ABC 但我这个程序就能直接不关闭文件而用rewind函数到开头&#xff0c;你帮忙看看&#xff0c; //二进制文件的输入输出--数据块的读…

最佳适应算法模拟内存分配

最佳适应算法 从全部空闲区中找出能满足作业要求的&#xff0c;且大小最小的空闲分区&#xff0c;这种方法能使碎片尽量小。 问题描述 Given five memory partitions of 100 KB, 500 KB, 200 KB, 300 KB, and 600 KB (in order), how would each of the first-fit, best-fit…

单片机c语言 i%3c%3c1,单片机C语言作业及上机习题及答案

《单片机C语言作业及上机习题及答案》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《单片机C语言作业及上机习题及答案(37页珍藏版)》请在人人文库网上搜索。1、第一次课熟悉winTC编译环境、熟悉C语言程序结构1.使用C 语言编译环境&#xff0c;输入下面的源程序。将你…

基于顺序搜索的动态分区分配算法模拟内存动态分配--最佳适应算法(best fit,BF)

BF算法、男朋友算法&#xff0c;哈哈 要实现动态分区分配&#xff0c;需要考虑三个方面的问题。分别是数据结构、分区分配算法、分区的分配与回收操作。 首数据结构 这里我们使用的是空闲分区链&#xff0c;采用双向链表表示空闲分区。 具体实现如下&#xff1a; typedef …

我也要谈谈大型网站架构之系列(4)——分布式中的异步通信

我们知道在面向对象编程中&#xff0c;总会想着各种办法来实现代码的解耦&#xff0c;从而让项目中的各种人员面对自己熟悉的业务进行开发&#xff0c; 做到术业有专攻&#xff0c;比如大家非常熟悉的三层架构&#xff0c;MVC&#xff0c;MVP以及MVVM模式&#xff0c;让前端设计…

node模块函数图解

已截图方式记录模块信息&#xff1a; HTTP模块&#xff1a; 对于网络返回处理状态封装了很多种&#xff0c;我已截图展现 以上状态也是在http协议中包含的状态。 http函数&#xff1a; path模块&#xff1a; 转载于:https://www.cnblogs.com/kuailingmin/p/4547538.html

android 心跳效果动画,Android实现心跳的效果

最近再做一个教育类的项目。在做一些学习工具的时候&#xff0c;美工提出了一些要求&#xff0c;大致如下&#xff1a;其实实现过程也不难&#xff0c;大致就是对一个视图控件添加一个圆形的背景&#xff0c;然后该视图进行动画处理&#xff0c;膨胀的同时&#xff0c;透明度增…

Oracle超出最大连接数问题及解决

用过Oracle的应该都熟悉如何查看和设置Oracle数据库的最大连接数。这里就再啰嗦一遍。 查看当前的连接数&#xff0c;可以用select count(*) from v$process;设置的最大连接数&#xff08;默认值为150&#xff09;select value from v$parameter where name ‘processes’;修改…