123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- $(function()
- {
- Maze.Init();
- });
- //公共类库
- var Maze =
- {
- Init : function()
- {
- this.Page().Init();
- this.User().Init();
- //this.Modal().Init();
- this.Change();
- }
- ,Page : function()
- {
- return _Maze_Page;
- }
- ,User : function()
- {
- return _Maze_User;
- }
-
- ,Modal : function()
- {
- return _Maze_Modal;
- }
- ,Jump : function(url)
- {
- location.href = url;
- }
-
- ,BackRun : function(url)
- {
- $.post(url);
- }
- ,Change : function()
- {
- if($('.maze-change').length)
- {
- $('.maze-change').change(function()
- {
- Maze.Jump($(this).attr('maze-change')+$(this).val());
- });
- //$('.maze-change').val($('.maze-change').attr('maze-value'));
- }
- }
- ,Host : function(host)
- {
- var result = '';
-
- result = config.host.replace('www', host);
- result = result.replace('main', host);
- result = result + config.type;
-
- result = result.replace('??', '?');
- return result;
- }
- // 输出数据,提示框
- ,Out : function(content, callback, ele, title)
- {
- if(content && content.indexOf('登录') != -1 && $("#login_url").length)
- {
- var href = $("#login_url").val();
- location.href = href;
- return;
- }
- else
- {
- alert(content);
- if(ele && callback)
- {
- ele.unbind('click').bind('click', callback);
- }
- else if(callback)
- {
- callback();
- }
- }
- }
- // 将数据解析,并进行下一步操作
- ,Msg : function(result, error_callback, success_callback)
- {
- if(result.status == 2)
- {
- if(error_callback)
- {
- return error_callback(result.msg);
- }
- this.Out(result.msg);
- }
- else
- {
- if(success_callback)
- {
- return success_callback(result.msg);
- }
- if(result.msg.indexOf('http://') != -1)
- {
- this.Jump(result.msg);
- }
- else if(parseInt(result.msg) > 0)
- {
- this.Out('操作成功', function()
- {
- location.reload();
- });
- }
- else
- {
- this.Out(result.msg);
- }
- }
- }
- ,Confirm : function(callback)
- {
- if(confirm('确定进行此项操作吗?'))
- {
- callback();
- }
- }
- //上传组件加载
- ,Upload : function()
- {
- if($(".image_upload").length)
- {
- $(".image_upload").each(function(i)
- {
- loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.assets + 'image/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
- })
- }
- }
- ,Load : function(filename,filetype)
- {
- if(filetype == "js")
- {
- var fileref = document.createElement('script');
- fileref.setAttribute("type","text/javascript");
- fileref.setAttribute("src",filename + '.' + filetype);
- }
- else if(filetype == "css")
- {
- var fileref = document.createElement('link');
- fileref.setAttribute("rel","stylesheet");
- fileref.setAttribute("type","text/css");
- fileref.setAttribute("href",filename + '.' + filetype);
- }
- if(typeof fileref != "undefined")
- {
- document.getElementsByTagName("head")[0].appendChild(fileref);
- }
- }
- };
- //瀑布流分页
- var _Maze_Page =
- {
- name : '',
- Init : function()
- {
- if($(this.name).length)
- {
- var self = this;
- $(window).scroll(function()
- {
- if($(window).scrollTop() >= $(document).height() - $(window).height())
- {
- self.Start(self.name);
- }
- });
- }
- }
- ,Start : function(page)
- {
- page = page ? page : this.name;
- if($(page).length)
- {
- $(page).hide();
- var url = $(page).attr('link');
- if(url)
- {
- var key = $(page).attr('data-list');
- $.get(url, function(t)
- {
- t = '<div>' + t + '</div>';
- var c = $(t).find(key).html();
- if(c)
- {
- $(key).append(c);
- var l = $(t).find(page).attr('link');
- $(page).attr('link', l);
- }
- });
- }
- }
- }
- }
- //模态框
- var _Maze_Modal =
- {
- state : false,
- html : '',
- box : '',
- title : '',
- content : '',
- yes : '',
- no : '',
- setting : '',
- confirm : '',
-
- Init : function()
- {
- this.state = false;
- if(this.html)
- {
- $('body').append(this.html);
- if(this.box) this.box = $(this.box);
- if(this.title) this.title = $(this.title);
- if(this.content) this.content = $(this.content);
- if(this.yes) this.yes = $(this.yes);
- if(this.no) this.no = $(this.no);
- if(this.setting) this.setting = $(this.setting);
- if(this.confirm) this.confirm = $(this.confirm);
- this.state = true;
- }
- }
-
- ,Alert : function(content, callback, body)
- {
- if(this.state == false)
- {
- alert(content);
- return;
- }
- else
- {
- if(this.setting.length && this.setting.html())
- {
- this.confirm.hide();
- this.setting.show();
- }
- else
- {
- this.setting.hide();
- this.confirm.show();
- }
- this.title.html(content);
- if(body)
- {
- this.content.html(body).show();
- }
- else
- {
- this.content.html('').hide();
- }
- this.box.show();
- if(callback)
- {
- this.Bind(callback);
- }
- }
- }
-
- ,Confirm : function(content, callback, body)
- {
- if(this.state == false)
- {
- alert(content);
- return;
- }
- else
- {
- this.confirm.show();
- this.setting.hide();
-
- this.title.html(content);
- if(body)
- {
- this.content.html(body).show();
- }
- else
- {
- this.content.html('').hide();
- }
- this.box.show();
- if(callback)
- {
- this.Bind(callback);
- }
- }
- }
-
- ,Bind : function(callback)
- {
- if(this.yes.length && callback.yes)
- {
- this.yes.unbind('click').bind('click', callback.yes);
- }
-
- if(this.no.length)
- {
- if(callback.no)
- {
- this.no.unbind('click').bind('click', callback.no);
- }
- else
- {
- var self = this;
- this.no.unbind('click').bind('click', function()
- {
- self.Close();
- });
- }
- }
- }
-
- ,Close : function()
- {
- this.box.hide();
- }
- }
- //用户相关
- var _Maze_User =
- {
- config : [],
- uid : -1,
- name : '匿名用户',
- Init : function()
- {
- var self = this;
- if(this.config.click)
- {
- for(var i in this.config.click)
- {
- var e = this.config.click[i];
- var c = false;
- if(e.indexOf('|') != -1)
- {
- var t = e.split('|');
- e = t[0];
- c = true;
- }
- if($(e).length)
- {
- var index = i;
- var con = c;
- $(e).unbind('click').bind('click', function()
- {
- if(con == true)
- {
- var t1 = $(this);
- Maze.Confirm(function()
- {
- self.Save(index, t1);
- });
- }
- else
- {
- self.Save(index, $(this));
- }
- });
- }
- }
- }
- }
- //通用的保存数据功能
- ,Save : function(key, e)
- {
- var self = this;
- var config = self.config[key];
- var send = {};
- var callback = function(msg)
- {
- if(config.status && $(config.status).length)
- {
- $(config.status).html(msg).css('visibility','initial');
- }
- else
- {
- Maze.Out(msg);
- }
- }
- if(typeof(config.input) != 'undefined')
- {
- if(typeof(config.input) == 'string' && config.input == 'parent')
- {
- if(e.attr('data-send'))
- {
- send[e.attr('data-send')] = e.attr('data-' + e.attr('data-send'));
- }
- send.id = e.attr('data-id');
- send.value = e.parent().find('input').val();
- if(!send.id || !send.value)
- {
- callback(config.error);
- return;
- }
- }
- else if(typeof(config.input) == 'object')
- {
- for(var i in config.input)
- {
- send[i] = $(config.input[i]).val();
- if(!send[i])
- {
- callback(config.error);
- return;
- }
- }
- }
- }
- if(!send)
- {
- callback(config.error);
- return;
- }
- $.getJSON(config.url + '?callback=?', send, function(t)
- {
- Maze.Msg(t, callback);
- });
- }
- };
|