Discuz!论坛用户登录模块的javascript处理过程的代码分析
时间:2010-07-08
来源:互联网
本帖最后由 寂寞流星 于 2010-7-8 09:56 编辑
先看看弹出这个窗口是怎么实现的,
复制代码
这段代码在header.htm文件中,一个表示登录,一个表示注册的链接
点登录弹出第一张图片显示的窗口,点击时会执行一个叫
floatwin(’open_login’, this.href, 600, 400);函数,这个函数在common.js文件中,看看这个函数的执行过程:
复制代码
先看看弹出这个窗口是怎么实现的,
- <!--{else}-->
- <a href="$regname" onclick="floatwin('open_register', this.href, 600, 400, '600,0');return false;" class="noborder">$reglinkname</a>
- <a href="logging.php?action=login" onclick="floatwin('open_login', this.href, 600, 400);return false;">{lang login}</a>
- <!--{/if}-->
这段代码在header.htm文件中,一个表示登录,一个表示注册的链接
点登录弹出第一张图片显示的窗口,点击时会执行一个叫
floatwin(’open_login’, this.href, 600, 400);函数,这个函数在common.js文件中,看看这个函数的执行过程:
- var cssloaded= new Array();
- function loadcss(cssname) {
- if(!cssloaded[cssname]) {//如果不存在
- css = document.createElement('link');//创建link标签
- css.type = 'text/css';//设置link的type
- css.rel = 'stylesheet';
- css.href = 'forumdata/cache/style_' + STYLEID + '_' + cssname + '.css?' + VERHASH;
- var headNode = document.getElementsByTagName("head")[0];//获取html head标签
- headNode.appendChild(css);//添加到head标签间
- cssloaded[cssname] = 1;
- }
- }
-
- function floatwin_wrapkeyhandle(e) {
- e = is_ie ? event : e;
- if(e.keyCode == 9) {//Tab键
- doane(e);
- } else if(e.keyCode == 27) {//退格键
- for(i = floatwins.length - 1;i >= 0; i--) {
- floatwin('close_' + floatwins[i]);
- }
- }
- }
-
- //FloatWin
- var hiddenobj = new Array();
- var floatwinhandle = new Array();
- var floatscripthandle = new Array();
- var floattabs = new Array();
- var floatwins = new Array();
- var InFloat = '';
- var floatwinreset = 0;
- var floatwinopened = 0;
- floatwin('open_login', this.href, 600, 400);
- function floatwin(action, script, w, h, scrollpos) {
- var floatonly = !floatonly ? 0 : 1;
- var actione = action.split('_');//以'_'将字符串分隔成数组
- action = actione[0];//action='open'
- if((!allowfloatwin || allowfloatwin == 0) && action == 'open' && in_array(actione[1], ['register','login','newthread','reply','edit']) && w >= 600) {
- //如果action='open',窗口宽度小于等于600,则设置location.href;
- location.href = script;
- return;
- }
- var handlekey = actione[1];//=login
- var layerid = 'floatwin_' + handlekey;//='floatwin_login'
- if(is_ie) {//获取动画对象
- var objs = $('wrap').getElementsByTagName("OBJECT");
- } else {
- var objs = $('wrap').getElementsByTagName("EMBED");
- }
- if(action == 'open') {
- loadcss('float');//将弹出层的css,插入到模板中
- //floatwinhandle['login_0'] = 'floatwin_login';
- floatwinhandle[handlekey + '_0'] = layerid;
- if(!floatwinopened) {
- $('wrap').onkeydown = floatwin_wrapkeyhandle;//对键盘换键的不同操作
- for(i = 0;i < objs.length; i ++) {
- if(objs[i].style.visibility != 'hidden') {
- objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
- objs[i].style.visibility = 'hidden';
- }
- }
- }
- scrollpos = !scrollpos ? '' : 'floatwin_scroll(\'' + scrollpos + '\');';
- var clientWidth = document.body.clientWidth;//对象可见的宽度
- var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
- var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
- //sciprt= logging.php?action=login;
- if(script && script != -1) {
- if(script.lastIndexOf('/') != -1) {
- script = script.substr(script.lastIndexOf('/') + 1);
- }
- var scriptfile = script.split('?');//scriptfile[0] = logging.php;
- scriptfile = scriptfile[0]; //scriptfile[1] = action=login;
- if(floatwinreset || floatscripthandle[scriptfile] && floatscripthandle[scriptfile][0] != script) {
- if(!isUndefined(floatscripthandle[scriptfile])) {
- $('append_parent').removeChild($(floatscripthandle[scriptfile][1]));
- $('append_parent').removeChild($(floatscripthandle[scriptfile][1] + '_mask'));
- }
- floatwinreset = 0;
- }
- //floatscripthandle[logging.php] = [logging.php?action=login, floatwin_login];
- floatscripthandle[scriptfile] = [script, layerid];
- }
- if(!$(layerid)) {
- floattabs[layerid] = new Array();
- div = document.createElement('div');//创建div标签
- div.className = 'floatwin';//设置创建div的css,id,宽,高
- div.id = layerid;
- div.style.width = w + 'px';
- div.style.height = h + 'px';
- //div.style.left = floatwinhandle['login_1'] = ((clientWidth - 600) / 2) + 'px';
- div.style.left = floatwinhandle[handlekey + '_1'] = ((clientWidth - w) / 2) + 'px';
- div.style.position = 'absolute';
- div.style.zIndex = '999';
- div.onkeydown = floatwin_keyhandle;
- $('append_parent').appendChild(div);//将创建的div标签插入到append_parent标签中
- $(layerid).style.display = '';
- $(layerid).style.top = floatwinhandle[handlekey + '_2'] = ((clientHeight - h) / 2 + scrollTop) + 'px';
- $(layerid).innerHTML = '<div><h3 class="float_ctrl"><em><img src="' + IMGDIR + '/loading.gif"> 加载中...</em><span><a href="javascript:;" class="float_close" onclick="floatwinreset = 1;floatwin(\'close_' + handlekey + '\');">&nbsp</a></span></h3></div>';
- //插入html
- divmask = document.createElement('div');//创建div标签
- divmask.className = 'floatwinmask';//设置css,id,width,height,left,top,position
- divmask.id = layerid + '_mask';
- divmask.style.width = (parseInt($(layerid).style.width) + 14) + 'px';
- divmask.style.height = (parseInt($(layerid).style.height) + 14) + 'px';
- divmask.style.left = (parseInt($(layerid).style.left) - 6) + 'px';
- divmask.style.top = (parseInt($(layerid).style.top) - 6) + 'px';
- divmask.style.position = 'absolute';
- divmask.style.zIndex = '998';
- divmask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=90,finishOpacity=100,style=0)';
- divmask.style.opacity = 0.9;
- $('append_parent').appendChild(divmask);//将创建的div标签插入到append_parent标签中
- if(script && script != -1) {
- //如果存在?,则后面加&,否则加?
- //script = logging.php?action=login&infloat=yes&handlekey=login';
- script += (script.search(/\?/) > 0 ? '&' : '?') + 'infloat=yes&handlekey=' + handlekey;
- try {//执行ajax,通过ajax获取login.htm模板
- ajaxget(script, layerid, '', '', '', scrollpos);
- } catch(e) {
- setTimeout("ajaxget('" + script + "', '" + layerid + "', '', '', '', '" + scrollpos + "')", 1000);
- }
- } else if(script == -1) {
- $(layerid).innerHTML = '<div><h3 class="float_ctrl"><em id="' + layerid + '_title"></em><span><a href="javascript:;" class="float_close" onclick="floatwinreset = 1;floatwin(\'close_' + handlekey + '\');">&nbsp</a></span></h3></div><div id="' + layerid + '_content"></div>';
- $(layerid).style.zIndex = '1099';
- $(layerid + '_mask').style.zIndex = '1098';
- }
- } else {
- $(layerid).style.width = w + 'px';
- $(layerid).style.height = h + 'px';
- $(layerid).style.display = '';
- $(layerid).style.top = floatwinhandle[handlekey + '_2'] = ((clientHeight - h) / 2 + scrollTop) + 'px';
- $(layerid + '_mask').style.width = (parseInt($(layerid).style.width) + 14) + 'px';
- $(layerid + '_mask').style.height = (parseInt($(layerid).style.height) + 14) + 'px';
- $(layerid + '_mask').style.display = '';
- $(layerid + '_mask').style.top = (parseInt($(layerid).style.top) - 6) + 'px';
- }
- floatwins[floatwinopened] = handlekey;
- floatwinopened++;
- }
- }
作者: 寂寞流星 发布时间: 2010-07-08
不错,学习一下- -楼主也开始发技术贴了么
作者: Vassago 发布时间: 2010-07-08
哥是技术人呀。
作者: 寂寞流星 发布时间: 2010-07-08
学习下 牛人啊
作者: 暖暖 发布时间: 2010-09-07
查看一下
作者: zjf1990 发布时间: 2013-04-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28