/**
* Created by Jiangtao on 2015/5/12.
* Name Jihe
*/
(function () {
function gather (msg) {
Adaptation parameters
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,
Screen fit
Windowresize:function () {
var that=this;
That.getresize ();
$ (window). Resize (function () {
That.getresize ();
})
},
Screen self-adapting
Getresize:function () {
var docwidth = document.documentElement.clientWidth;
var html = document.queryselector (' html ');
Html.style.fontSize = (DOCWIDTH/20) + "px";
},
Modal frame self-adapting
Maskingresize:function (e) {
$ (E). Height ($ (window). Height ());
$ (E). Width ($ (window). width ());
$ (window). Resize (function () {
$ (E). Height ($ (window). Height ());
$ (E). Width ($ (window). width ());
})
},
Image upload
Uploadimg:function (back, settime) {
This.settime = settime;
var = 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)
})
},
Generate Base64 encoding
Base64:function (Success, before, Erro) {
var file = This.imgfile;
var = 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: ' image upload failed '});
},function (Ajax) {
Before ({Blob:results.blob,ajax:ajax})
});
});
};
},
Ajax uploading images;
Sendreq:function (base64, Success, Erro,before) {
var = 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);
},
Open upload wait animation
Openuploadanimation:function () {
$ ('. Loadmb '). Removeclass (' none ');
SetTimeout (function () {
$ ('. Loadmb '). Removeclass (' hidden ');
},100);
},
Turn off upload wait animation
Offuploadanimation:function () {
$ ('. Loadmb '). addclass (' hidden ');
SetTimeout (function () {
$ ('. Loadmb '). addclass (' none ');
},500);
},
Create picture frame
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 "> ' +
' </div><div class= ' button top changeimg > Replace current picture </div></div> ');
var index=$ ('. bianji>.tphp '). length;
return index;
},
Modify Picture Frame
Changecontainerimg:function (e,r) {
R.find (' img '). attr (' src ', e);
},
Create a text box
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= "Please enter text ..." ></textarea></div> ";
Control.append (Fontbox);
Back ();
},500);
},
URL encryption
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, ' + ');
},
Jump Login
Locationwechatlogin:function () {
var u = window.location.href;
var encodeurl = THIS.URLEOCDE (u);
if (!this.wechatappid) {
Alert (' Wechatappid not present ')
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;
},
Get URL address after parameter
Geturlarguments:function (str) {
var urlarguments = Location.search.split ("?") [1];//acquisition?] The latter part
if (urlarguments! = undefined) {
var arguments = Urlarguments.split (' & ');//Will? The following parameters are divided into arrays by &
for (var i = 0; i < arguments.length; i++) {
var key = arguments[i].split (' = ') [0],
val = arguments[i].split (' = ') [1];
if (key = = str) {
return Val;
}
}
}
},
Determine if code exists
Iscode:function () {
if (this.geturlarguments (' Code ')) {
return true;
} else {
return false;
}
},
Get UserID by code
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)
}
}
}
})
}
},
Determine if a userid exists on the page
Isuserid:function (e) {
return $ (E). text ();
},
Determine if the file is a picture
Isimage:function (ImageFile) {
var fileType = Imagefile.type;
if (FileType && filetype.split ('/') [0] = = ' image ') {
return true;
} else {
return false;
}
},
Prompt box
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)
},
Non-null judgment
Isblank:function (f) {
The matching space assignment is empty;
var Val, l;
if (f.value! = undefined) {
val = F.value.replace (/\s/g, "");
} else {
The alert (' Kongstring () method must have the value parameter! ‘)
return false;
}
determine the input length;
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 + ' can't exceed ' + F.len + ' characters!) ‘);
return False
}
} else {
This.messagebox (' Please fill out ' +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 (' Picture upload failed! ‘)
}else{
Back.success (Data.data);
}
}
})
Back.before (Sendajax);
},
Share the share parameter as an object
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
});
Share to Friends
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);
}
})()
JS Object-oriented plug-in writing, or very well understood