dever 5 years ago
commit
b6c994feb7

+ 14 - 0
LICENSE

@@ -0,0 +1,14 @@
+Apache License
+Copyright 2016-2017 Dever(dever.cc)
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.

+ 3 - 0
README.md

@@ -0,0 +1,3 @@
+# script
+
+dever javascript lib

+ 30 - 0
assets/html/demo.html

@@ -0,0 +1,30 @@
+<html lang="zh-CN">
+<head>
+	<title>test share</title>
+	<script src="../js/lib/jquery.min.js" ></script>
+	<script src="../js/share/weixin.js" ></script>
+	<script src="../js/dever.js" ></script>
+</head>
+
+<body>
+<a>分享</a>
+
+</body>
+
+<script>
+$(function()
+{
+	var uid = -1;
+	var project = 7;
+	var url = 'http://192.168.33.10/wechat/share/?api.';
+	var param = {
+		title : '大家好',
+        img : 'https://www.baidu.com/img/superlogo_c4d7df0a003d3db9b65e9ef0fe6da1ec.png?where=super',
+        desc : '大家好',
+        url : location.href,
+	};
+	var button = false;
+	Dever.Share().Init(uid, project, url, param, button);
+})
+</script>
+</html>

BIN
assets/img/background.png


BIN
assets/img/weixin-guide.png


+ 110 - 0
assets/js/config.dever.js

@@ -0,0 +1,110 @@
+//demo
+
+//定义瀑布流
+Dever.Page().name = '#page';
+
+//定义用户相关的一些信息
+Dever.User().config = 
+{
+	//初始化,绑定click
+	'click' : 
+	{
+		//登录
+		0 : '#login'
+		//注册
+		,1 : '#reg'
+		//发表主题
+		,2 : '#dever_create_post'
+		//发表评论
+		,3 : '#dever_create_comment'
+		//用户点赞
+		,4 : '.dever_up'
+	}
+
+	//登录信息
+	,0 :
+	{
+		'input' :
+		{
+			'email' : '#email'
+			,'password' : '#password'
+			,'refer' : '#refer'
+		}
+		//错误提示的div
+		,'status' : '.alert'
+		//错误提示
+		,'error' : '您的邮箱或密码错误'
+		//登录要提交的url
+		,'url' : Dever.Host('passport', 'login.action')
+	}
+
+	//注册信息
+	,1 :
+	{
+		'input' :
+		{
+			'email' : '#email'
+			,'username' : '#username'
+			,'password' : '#password'
+			,'cpassword' : '#cpassword'
+			,'refer' : '#refer'
+		}
+		//错误提示的div
+		,'status' : '.alert'
+		//错误提示
+		,'error' : '您填写的信息有误'
+		//登录要提交的url
+		,'url' : Dever.Host('passport', 'reg.action')
+	}
+	
+	//发表信息
+	,2 :
+	{
+		'input' :
+		{
+			'cate' : '#cate'
+			,'name' : '#dever_post_title'
+			,'content' : '#dever_post_content'
+			,'refer' : '#refer|'//增加|为选填
+		}
+		//错误提示的div
+		,'status' : '#dever_alert'
+		//错误提示
+		,'error' : '您填写的信息有误'
+	}
+
+	//发表信息
+	,3 :
+	{
+		'input' :
+		{
+			'content' : '#dever_comment_content'
+		}
+		//错误提示的div
+		,'status' : '#dever_alert'
+		//错误提示
+		,'error' : '您填写的信息有误'
+		//发表成功后,调用的callback
+		,'callback' : function(e, msg)
+		{
+			$("#dever_comment_content").val('');
+			Dever.LoadPage();
+		}
+	}
+	
+	//点赞
+	,4 :
+	{
+		'input' : 'click'
+		//错误提示
+		,'error' : '您填写的信息有误'
+		,'url' : Dever.Host('forum', 'vote.save')
+		//发表成功后,调用的callback
+		,'callback' : function(e, msg, t)
+		{
+			var num = parseInt(e.find('span').html());
+			e.find('span').html((t.msg == 1 ? num+1 : num-1));
+		}
+	}
+
+};

+ 944 - 0
assets/js/dever.js

@@ -0,0 +1,944 @@
+/* ================================================================================
+ * dever.js v1.0
+ * http://git.shemic.com/dever/script
+ * ================================================================================
+ * Copyright 2017-2018 Dever(dever.cc)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+
+ //<filter><script src="../js/lib/jquery.min.js"></script><script src="../js/dever.js"></script></filter>
+
+$(function()
+{
+    Dever.Init();
+});
+
+//公共类库
+var Dever = 
+{
+    Init : function()
+    {
+        this.Import();
+        this.Page().Init();
+        this.User().Init();
+        this.Editor().Init();
+        this.Change();
+        this.Upload();
+        this.LoadPage();
+        this.Extend();
+        //this.Target();
+        //this.Pjax();
+    }
+    
+    ,Pjax : function()
+    {
+		$(document).pjax('a', '.container');
+		//$.pjax.reload('.container');
+	}
+
+    ,Page : function()
+    {
+        return _Dever_Page;
+    }
+
+    ,Share : function()
+    {
+        return _Dever_Share;
+    }
+
+    ,Template : function()
+    {
+        return _Dever_Template;
+    }
+    
+    ,Editor : function()
+    {
+        return _Dever_Editor;
+    }
+
+    ,User : function()
+    {
+        return _Dever_User;
+    }
+    
+    ,Modal : function()
+    {
+        return _Dever_Modal;
+    }
+    
+    ,Proxy : function(uri)
+    {
+        return config.proxy + 'proxy_method=' + encodeURIComponent(uri);
+    }
+
+    ,Jump : function(url)
+    {
+        location.href = url;
+    }
+    
+    ,BackRun : function(url)
+    {
+        $.post(url);
+    }
+
+    ,Reload : function(e)
+    {
+        e.attr('src', e.attr('src'));
+    }
+    
+    ,Target : function()
+    {
+		var link = config.host;
+		$("a").each(function() {
+			if (!$(this).attr('onclick')) {
+				var url = $(this).attr('href');
+				
+				if (url && url.indexOf(link) == -1) {
+					//$(this).attr('target', '_blank');
+				}
+			}
+		})
+	}
+    
+    ,Import : function()
+	{
+        var self = this;
+        var include = $("include");
+        var count = include.length-1;
+        if (include.length) {
+            include.each(function(i){
+                var dom = $(this);
+                var system  = dom.attr('system');
+                var path    = dom.attr('path');
+                var name    = dom.attr('file');
+
+                var file = '';
+                if(path) file = path;
+                if(system) file = file + '/' + system;
+                
+                file += name + '.html';
+                dom.load(file, function(){
+                    $("html").find("include").eq(i).get(0).outerHTML = dom.html();
+
+                    if (i == count) {
+                        self.Template().Init();
+                    }
+                });
+            })
+        } else {
+            self.Template().Init();
+        }
+	}
+    
+    ,LoadPage : function()
+    {
+		if ($('.dever-loadpage').length) {
+            $('.dever-loadpage').each(function() {
+				var url = $(this).attr('dever-url');
+				var self = $(this);
+                $.getJSON(Dever.CallUrl(url), function(t) {
+					self.html(t.msg);
+					_Dever_Page.Ajax(self);
+				});
+            });
+        }
+    }
+    
+    ,CallUrl : function(url)
+    {
+		if (url.indexOf('callback') == -1) {
+			if (url.indexOf('=') != -1) {
+				url += '&json=1&callback=?';
+			} else {
+				url += '?json=1&callback=?';
+			}
+		}
+		
+		return url;
+	}
+
+    ,Change : function()
+    {
+        if ($('.dever-change').length) {
+            $('.dever-change').change(function() {
+                Dever.Jump($(this).attr('dever-change')+$(this).val());
+            });
+
+            //$('.dever-change').val($('.dever-change').attr('dever-value'));
+        }
+    }
+
+    ,Host : function(host, uri)
+    {
+        var result = '';
+        
+        uri = uri ? uri : '';
+    
+        result = config.host.replace('www', host);
+        result = result.replace('main', host);
+
+        result = result + config.type;
+        
+        result = result.replace('??', '?');
+        
+        if (config.proxy) {
+			return this.Proxy(host + '/' + uri);
+		}
+
+        return result + uri;
+    }
+
+    // 输出数据,提示框
+    ,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 ($(".dever-upload-drag").length) {
+            $(".dever-upload-drag").each(function() {
+                var key = $(this).attr('key');
+                
+                if (config.proxy) {
+					var url = Dever.Proxy('upload/save.drag') + '&key=' + key;
+				} else {
+					var url = config.upload + '.drag?key='+ key;
+				}
+                $(this).inlineattachment({
+                    uploadUrl: url,
+                    progressText: '![文件上传中...]()',
+                    urlText: "![文件描述]({filename})\n",
+                    errorText: '上传失败'
+                });
+            });
+        }
+
+        if ($(".dever-upload").length) {
+            $(".dever-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);
+        }
+    }
+    
+    ,Extend : function()
+	{
+		Array.prototype.indexIn = function(val) {
+			for (var i = 0; i < this.length; i++) {
+				if (this[i] == val) return i;
+			}
+			return -1;
+		};
+		Array.prototype.remove = function(val) {
+			var index = this.indexIn(val);
+			if (index > -1) {
+				this.splice(index, 1);
+			}
+		};
+
+        $("select option").each(function() {
+            if ($(this).attr('select') && $(this).attr('select') == 'true') {
+                $(this).attr('selected', 'true');
+            } else {
+                $(this).removeAttr('selected');
+            }
+        });
+	}
+
+    ,Ucfirst : function(str)
+    {
+        var str = str.toLowerCase();
+        var strarr = str.split(' ');
+        var result = '';
+        for (var i in strarr){
+            result += strarr[i].substring(0,1).toUpperCase()+strarr[i].substring(1)+' ';
+        }
+        return result;
+    }
+};
+
+//瀑布流分页
+var _Dever_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('dever-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);
+                    }
+                });
+            }
+        }
+    }
+    
+    ,Ajax : function(e)
+    {
+		var self = this;
+		e.find('a').each(function() {
+			var url = $(this).attr('href');
+			
+			$(this).attr('href', 'javascript:;');
+			
+			$(this).unbind('click').bind('click', function() {
+				$.get(url.replace('callback', ''), function(t) {
+					e.html(t);
+					self.Ajax(e);
+				});
+			});
+		});
+	}
+}
+
+//模态框
+var _Dever_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)
+    {
+        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);
+            this.box.show();
+            if (callback) {
+                this.Bind(callback);
+            }
+        }
+    }
+    
+    ,Confirm : function(content, callback)
+    {
+        if (this.state == false) {
+            alert(content);
+            return;
+        } else {
+            this.confirm.show();
+            this.setting.hide();
+            
+            this.title.html(content);
+            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 _Dever_User = 
+{
+    config : [],
+    uid : -1,
+    name : '匿名用户',
+
+    Init : function()
+    {
+        var self = this;
+        if (this.config.click) {
+            for (var i in this.config.click) {
+                var e = self.config.click[i];
+                var c = 1;
+                if (e.indexOf('|') != -1) {
+                    var t = e.split('|');
+                    e = t[0];
+                    c = 2;
+                }
+                if ($(e).length) {
+                    $(e).attr('data-i', i);
+                    $(e).attr('data-c', c);
+                    
+                    $(e).unbind('click').bind('click', function() {
+                        if ($(this).attr('data-c') == 2) {
+                            var t1 = $(this);
+                            Dever.Confirm(function() {
+                                self.Save($(this).attr('data-i'), t1, config);
+                            });
+                        } else {
+                            self.Save($(this).attr('data-i'), $(this), config);
+                        }
+                    });
+                }
+            }
+        }
+    }
+
+    //通用的保存数据功能
+    ,Save : function(key, e, setting)
+    {
+        var self = this;
+        var config = self.config[key];
+        if (config.start) {
+            config.start.call();
+        }
+        var send = {};
+        var callback = function(msg,state) {
+            if (config.status && $(config.status).length) {
+                //$(config.status).html(msg).css('visibility','initial');
+                state ? $(config.status).html(msg).hide() : $(config.status).html(msg).show();
+            } else if(!state) {
+                Dever.Out(msg);
+            }
+        }
+
+        if (typeof(config.input) != 'undefined') {
+            if (typeof(config.input) == 'string' && config.input == 'parent') {
+                if (e.attr('dever-send')) {
+                    send[e.attr('dever-send')] = e.attr('dever-' + e.attr('dever-send'));
+                }
+                send.id = e.attr('dever-id');
+                send.value = e.parent().find('input').val();
+
+                if (!send.id || !send.value) {
+                    callback(config.error);
+                    return;
+                }
+            } else if (typeof(config.input) == 'string' && config.input == 'click') {
+                if (e.attr('dever-send')) {
+					var a = e.attr('dever-send').split('&');
+					for (var i in a) {
+						if (typeof(a[i]) == 'string') {
+							var b = a[i].split('=');
+							send[b[0]] = b[1];
+						}
+					}
+                }
+            } else if (typeof(config.input) == 'object') {
+                for (var i in config.input) {
+                    var option = false;
+                    var input = config.input[i];
+                    if (input.indexOf('|') != -1) {
+                        var t = input.split('|');
+                        input = t[0];
+                        option = true;
+                    }
+                    var m = true;
+                    var el = $(input);
+                    //e.get(0).tagName == 'TEXTAREA'
+                    send[i] = el.val();
+
+                    if (option == false) {
+                        if (send[i] && el.attr('dever-match')) {
+                            var r = new RegExp(el.attr('dever-match'));
+                            m = r.test(send[i]);
+                        }
+
+                        if (send[i] && el.attr('dever-value')) {
+                            m = $(el.attr('dever-value')).val() == send[i];
+                        }
+
+                        if (!send[i] || m != true) {
+                            var error = el.attr('dever-error') ? el.attr('dever-error') : config.error;
+                            callback(error);
+                            return;
+                        }
+                    }
+                }
+            }
+        }
+
+        if (!send) {
+            callback(config.error);
+            return;
+        }
+        
+        if (!config.url) {
+			config.url = e.attr('dever-send');
+		}
+		
+		callback(1,1);
+		
+		config.url = Dever.CallUrl(config.url);
+
+		if (setting.proxy) {
+			$.post(config.url, send, function(t) {
+				t = eval('(' + t + ')');
+				Dever.Msg(t, callback, (config.callback ? function(msg){config.callback(e,msg,t)} : false));
+			});
+		} else {
+			$.getJSON(config.url, send, function(t) {
+				Dever.Msg(t, callback, (config.callback ? function(msg){config.callback(e,msg,t)} : false));
+			});
+		}
+    }
+};
+
+//编辑器相关
+var _Dever_Editor = 
+{
+	state : false,
+    editors : [],
+    Init : function()
+    {
+		if (typeof marked == 'function') {
+			this.state = true;
+		} else {
+			this.state = false;
+		}
+		this.SetMark();
+        var self = this;
+		
+		if ($('.dever-note').length) {
+			$('.dever-note').each(function() {
+				self.InitEditor($(this));
+			})
+        }
+	}
+
+    ,InitEditor : function(e)
+    {
+        var id = e.attr('id');
+        var key = e.attr('key');
+        if (config.uid && config.uid > 0) {
+            var toolbar = [
+              'title'
+              ,'bold'
+              ,'italic'
+              ,'underline'
+              ,'strikethrough'
+              ,'fontScale'
+              ,'color'
+              ,'ol'
+              ,'ul'
+              ,'blockquote'
+              ,'code'
+              ,'table'
+              ,'link'
+              ,'image'
+              ,'hr'
+              ,'indent'
+              ,'outdent'
+              ,'alignment'
+              //,'emoji'
+            ];
+        } else {
+            var toolbar = [
+              'title'
+              ,'bold'
+              ,'fontScale'
+              ,'color'
+              ,'ol'
+              ,'ul'
+              ,'blockquote'
+              ,'indent'
+              ,'outdent'
+              ,'alignment'
+            ];
+        }
+        
+        if (typeof(this.editors[id]) == "undefined")  {
+            this.editors[id] = new Simditor({
+                textarea: e,
+                upload:
+                {
+                    url: config.upload + '.simditor',
+                    params: {key:key},
+                    fileKey: 'file',
+                    connectionCount: 10,
+                    leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
+                },
+                toolbar : toolbar
+                /*
+                ,emoji: 
+                {
+                    imagePath: config.lib + 'simditor/plugins/emoji/images/emoji/'
+                }
+                */
+            });
+        }
+    }
+	
+	,SetMark : function()
+	{
+        return;
+	}
+	
+	,GetMark : function(content)
+	{
+		if (this.state == true) {
+			return marked(content);
+		}
+		
+		return content;
+	}
+};
+
+//模板
+var _Dever_Template = 
+{
+    state : false,
+    method : '',
+    element : '',
+    data : '',
+    param : '',
+    attr : '',
+    Init : function()
+    {
+        if (this.Check()) {
+            var url = config.proxyTemplateUrl;
+            var send = {};
+            var parsing = [];
+            $("dever").each(function(){
+                parsing.push($(this).html());
+                $(this).remove();
+            });
+            send.url = location.href;
+            send.parsing = parsing.join('');
+            send.html = $("html").html();
+            //$("html").html('dever template loading...');
+            $.ajax({
+                type: "POST",
+                url: url,
+                data: send,
+                dataType: "json",
+                success: function(result){
+                    $("html").html(result.data);
+                }
+            });
+        }
+    }
+
+    ,Check : function()
+    {
+        if ($("dever").length) {
+            this.state = true;
+        } else {
+            this.state = false;
+        }
+        return this.state;
+    }
+}
+
+//分享 暂时只支持手机版微信分享 请同时安装wechat组件
+var _Dever_Share = 
+{
+    wechat : false,
+    url : '',
+    project : '',
+    uid : '-1',
+    param : {
+        title : '',
+        img : '',
+        desc : '',
+        url : '',
+        timelineCallback: function() {},
+        sendMessageCallback: function() {},
+        shareQQCallback: function() {}
+    },
+    Init : function(uid, project, url, param, button)
+    {
+        var self = this;
+        self.wechat = self.CheckWechat();
+        self.project = project;
+        self.url = url;
+        self.uid = uid;
+        //self.param = param;
+        $.extend(true, self.param, param)
+
+        if (button) {
+            $(button).on('click', function() {
+                if (self.wechat == 1) {
+                    self.WechatGuide();
+                } else {
+                    self.WeiboShare($(this));
+                }
+            })
+        }
+        if (self.wechat == 1) {
+            self.WechatInit();
+        }
+        self.Reflux();
+    }
+
+    ,CheckWechat : function()
+    {
+        var state = navigator.userAgent.toLowerCase().indexOf("micromessenger") > -1;
+        if (state) {
+            return 1;
+        } else {
+            return 2;
+        }
+    }
+
+    ,WechatGuide : function()
+    {
+        var param = this.param;
+        var tpl = '<div id="weixin_guide" style="position: fixed;background:url(../img/background.png) repeat;left:0;top:0;right:0;bottom:0;z-index:1000;"><img src="../img/weixin-guide.png" style="position: absolute;z-index:100;" width="295" height="273"/></div>';
+        $('#weixin_guide').remove();
+        $(tpl).attr('id', 'weixin_guide').appendTo($('body'));
+
+        $('#weixin_guide img').css(weixinCfg.style || {})
+        setTimeout(function() {
+            $('#weixin_guide').click(function() {
+                $(this).remove();
+            })
+        }, 300)
+    }
+
+    ,WechatInit: function()
+    {
+        var url = this.url + 'init?callback=?';
+        var param = this.param;
+        var project = this.project;
+        $.ajax({
+            type:'post',
+            dataType:'jsonp',
+            jsonp: 'jsonp_cb',
+            url: url,
+            data: {
+                'project' : project,
+                'url' : location.href.split('#')[0]
+            },
+            success:function(result) {
+                var data = result.data;
+                wx.config({
+                    //debug:true,
+                    appId: data.appId,
+                    timestamp: data.timestamp,
+                    nonceStr: data.nonceStr,
+                    signature: data.signature,
+                    jsApiList: [
+                        'onMenuShareTimeline',
+                        'onMenuShareAppMessage',
+                        'onMenuShareQQ'
+                    ]
+                });
+
+                wx.ready(function() {
+                    wx.onMenuShareAppMessage({
+                        title: param.title,
+                        desc: param.desc,
+                        link: param.url,
+                        imgUrl: param.img,
+                        success: function(res) {
+                            param.sendMessageCallback('success', res)
+                            self.ShareLog(1, 1);
+                        },
+                        cancel: function(res) {
+                            param.sendMessageCallback('cancel', res)
+                            self.ShareLog(1, 2);
+                        },
+                        fail: function(res) {
+                            param.sendMessageCallback('fail', res)
+                            self.ShareLog(1, 3);
+                        }
+                    });
+                    wx.onMenuShareTimeline({
+                        title: param.title,
+                        link: param.url,
+                        imgUrl: param.img,
+                        success: function(res) {
+                            param.timelineCallback('success', res)
+                            self.ShareLog(2, 1);
+                        },
+                        cancel: function(res) {
+                            param.timelineCallback('cancel', res)
+                            self.ShareLog(2, 2);
+                        },
+                        fail: function(res) {
+                            param.timelineCallback('fail', res)
+                            self.ShareLog(2, 3);
+                        }
+                    });
+                    wx.onMenuShareQQ({
+                        title: param.title,
+                        link: param.url,
+                        imgUrl: param.img,
+                        success: function(res) {
+                            param.shareQQCallback('success', res)
+                            self.ShareLog(3, 1);
+                        },
+                        cancel: function(res) {
+                            param.shareQQCallback('cancel', res)
+                            self.ShareLog(3, 2);
+                        },
+                        fail: function(res) {
+                            param.shareQQCallback('fail', res)
+                            self.ShareLog(3, 3);
+                        }
+                    });
+                });
+            },
+            async:'true',
+            timeout: 3000            
+        });
+    }
+
+    ,Reflux: function() {
+        var refer = document.referrer,
+            url = encodeURIComponent(document.location.href),
+            param = location.search.substr(1),
+            ua = encodeURIComponent(navigator.userAgent),
+            project = this.project,
+            uid = this.uid,
+            wechat = this.wechat;
+
+        if (param.indexOf("tsina-") > -1 || param.indexOf("timeline") > -1 || param.indexOf("singlemessage") > -1 || param.indexOf("groupmessage") > -1) {
+            $.getJSON(this.url + 'reflux?callback=?' + '&project='+project+'&url=' + url + '&ua=' + ua + '&param=' + encodeURIComponent(param) + '&uid=' + uid + '&type=' + wechat);
+        }
+    }
+
+    ,ShareLog: function(actType, actResult) {
+        var project = this.project;
+        var uid = this.uid;
+        var wechat = this.wechat;
+        var ua = encodeURIComponent(ua);
+        var url = encodeURIComponent(document.location.href);
+        $.getJSON(this.url + 'collect?callback=?' + '&project='+project+'&url=' + url + '&actType=' + actType + '&actResult=' + actResult + '&ua=' + ua + '&uid=' + uid + '&type=' + wechat);
+    }
+}

File diff suppressed because it is too large
+ 3 - 0
assets/js/lib/jquery.min.js


+ 461 - 0
assets/js/share/weixin.js

@@ -0,0 +1,461 @@
+! function(a, b) {
+    // "function" == typeof define && (define.amd || define.cmd) ? define(function() {
+    //     return b(a)
+    // }) : b(a, !0)
+    b(a, !0);
+    
+}(this, function(a, b) {
+    function c(b, c, d) {
+        a.WeixinJSBridge ? WeixinJSBridge.invoke(b, e(c), function(a) {
+            i(b, a, d)
+        }) : l(b, d)
+    }
+
+    function d(b, c, d) {
+        a.WeixinJSBridge ? WeixinJSBridge.on(b, function(a) {
+            d && d.trigger && d.trigger(a), i(b, a, c)
+        }) : d ? l(b, d) : l(b, c)
+    }
+
+    function e(a) {
+        return a = a || {}, a.appId = B.appId, a.verifyAppId = B.appId, a.verifySignType = "sha1", a.verifyTimestamp = B.timestamp + "", a.verifyNonceStr = B.nonceStr, a.verifySignature = B.signature, a
+    }
+
+    function f(a, b) {
+        return {
+            scope: b,
+            signType: "sha1",
+            timeStamp: a.timestamp + "",
+            nonceStr: a.nonceStr,
+            addrSign: a.addrSign
+        }
+    }
+
+    function g(a) {
+        return {
+            timeStamp: a.timestamp + "",
+            nonceStr: a.nonceStr,
+            "package": a.package,
+            paySign: a.paySign,
+            signType: "SHA1"
+        }
+    }
+
+    function i(a, b, c) {
+        var d, e, f;
+        switch (delete b.err_code, delete b.err_desc, delete b.err_detail, d = b.errMsg, d || (d = b.err_msg, delete b.err_msg, d = j(a, d, c), b.errMsg = d), c = c || {}, c._complete && (c._complete(b), delete c._complete), d = b.errMsg || "", B.debug && !c.isInnerInvoke && alert(JSON.stringify(b)), e = d.indexOf(":"), f = d.substring(e + 1)) {
+            case "ok":
+                c.success && c.success(b);
+                break;
+            case "cancel":
+                c.cancel && c.cancel(b);
+                break;
+            default:
+                c.fail && c.fail(b)
+        }
+        c.complete && c.complete(b)
+    }
+
+    function j(a, b) {
+        var d, e, f, g;
+        if (b) {
+            switch (d = b.indexOf(":"), a) {
+                case q.config:
+                    e = "config";
+                    break;
+                case q.openProductSpecificView:
+                    e = "openProductSpecificView";
+                    break;
+                default:
+                    e = b.substring(0, d), e = e.replace(/_/g, " "), e = e.replace(/\b\w+\b/g, function(a) {
+                        return a.substring(0, 1).toUpperCase() + a.substring(1)
+                    }), e = e.substring(0, 1).toLowerCase() + e.substring(1), e = e.replace(/ /g, ""), -1 != e.indexOf("Wcpay") && (e = e.replace("Wcpay", "WCPay")), f = r[e], f && (e = f)
+            }
+            g = b.substring(d + 1), "confirm" == g && (g = "ok"), -1 != g.indexOf("failed_") && (g = g.substring(7)), -1 != g.indexOf("fail_") && (g = g.substring(5)), g = g.replace(/_/g, " "), g = g.toLowerCase(), ("access denied" == g || "no permission to execute" == g) && (g = "permission denied"), "config" == e && "function not exist" == g && (g = "ok"), b = e + ":" + g
+        }
+        return b
+    }
+
+    function k(a) {
+        var b, c, d, e;
+        if (a) {
+            for (b = 0, c = a.length; c > b; ++b) d = a[b], e = q[d], e && (a[b] = e);
+            return a
+        }
+    }
+
+    function l(a, b) {
+        if (B.debug && !b.isInnerInvoke) {
+            var c = r[a];
+            c && (a = c), b && b._complete && delete b._complete, console.log('"' + a + '",', b || "")
+        }
+    }
+
+    function m() {
+        if (!("6.0.2" > y)) {
+            var b = new Image;
+            A.appId = B.appId, A.initTime = z.initEndTime - z.initStartTime, A.preVerifyTime = z.preVerifyEndTime - z.preVerifyStartTime, E.getNetworkType({
+                isInnerInvoke: !0,
+                success: function(a) {
+                    A.networkType = a.networkType;
+                    var c = "https://open.weixin.qq.com/sdk/report?v=" + A.version + "&o=" + A.isPreVerifyOk + "&s=" + A.systemType + "&c=" + A.clientVersion + "&a=" + A.appId + "&n=" + A.networkType + "&i=" + A.initTime + "&p=" + A.preVerifyTime + "&u=" + A.url;
+                    b.src = c
+                }
+            })
+        }
+    }
+
+    function n() {
+        return (new Date).getTime()
+    }
+
+    function o(b) {
+        v && (a.WeixinJSBridge ? b() : s.addEventListener && s.addEventListener("WeixinJSBridgeReady", b, !1))
+    }
+
+    function p() {
+        E.invoke || (E.invoke = function(b, c, d) {
+            a.WeixinJSBridge && WeixinJSBridge.invoke(b, e(c), d)
+        }, E.on = function(b, c) {
+            a.WeixinJSBridge && WeixinJSBridge.on(b, c)
+        })
+    }
+    var q, r, s, t, u, v, w, x, y, z, A, B, C, D, E;
+    if (!a.jWeixin) return q = {
+        config: "preVerifyJSAPI",
+        onMenuShareTimeline: "menu:share:timeline",
+        onMenuShareAppMessage: "menu:share:appmessage",
+        onMenuShareQQ: "menu:share:qq",
+        onMenuShareWeibo: "menu:share:weiboApp",
+        previewImage: "imagePreview",
+        getLocation: "geoLocation",
+        openProductSpecificView: "openProductViewWithPid",
+        addCard: "batchAddCard",
+        openCard: "batchViewCard",
+        chooseWXPay: "getBrandWCPayRequest"
+    }, r = function() {
+        var b, a = {};
+        for (b in q) a[q[b]] = b;
+        return a
+    }(), s = a.document, t = s.title, u = navigator.userAgent.toLowerCase(), v = -1 != u.indexOf("micromessenger"), w = -1 != u.indexOf("android"), x = -1 != u.indexOf("iphone") || -1 != u.indexOf("ipad"), y = function() {
+        var a = u.match(/micromessenger\/(\d+\.\d+\.\d+)/) || u.match(/micromessenger\/(\d+\.\d+)/);
+        return a ? a[1] : ""
+    }(), z = {
+        initStartTime: n(),
+        initEndTime: 0,
+        preVerifyStartTime: 0,
+        preVerifyEndTime: 0
+    }, A = {
+        version: 1,
+        appId: "",
+        initTime: 0,
+        preVerifyTime: 0,
+        networkType: "",
+        isPreVerifyOk: 1,
+        systemType: x ? 1 : w ? 2 : -1,
+        clientVersion: y,
+        url: encodeURIComponent(location.href)
+    }, B = {}, C = {
+        _completes: []
+    }, D = {
+        state: 0,
+        res: {}
+    }, o(function() {
+        z.initEndTime = n()
+    }), E = {
+        config: function(a) {
+            B = a, l("config", a), o(function() {
+                c(q.config, {
+                    verifyJsApiList: k(B.jsApiList)
+                }, function() {
+                    C._complete = function(a) {
+                        z.preVerifyEndTime = n(), D.state = 1, D.res = a
+                    }, C.success = function() {
+                        A.isPreVerifyOk = 0
+                    }, C.fail = function(a) {
+                        C._fail ? C._fail(a) : D.state = -1
+                    };
+                    var a = C._completes;
+                    return a.push(function() {
+                        B.debug || m()
+                    }), C.complete = function(b) {
+                        for (var c = 0, d = a.length; d > c; ++c) a[c](b);
+                        C._completes = []
+                    }, C
+                }()), z.preVerifyStartTime = n()
+            }), B.beta && p()
+        },
+        ready: function(a) {
+            0 != D.state ? a() : (C._completes.push(a), !v && B.debug && a())
+        },
+        error: function(a) {
+            "6.0.2" > y || (-1 == D.state ? a(D.res) : C._fail = a)
+        },
+        checkJsApi: function(a) {
+            var b = function(a) {
+                var c, d, b = a.checkResult;
+                for (c in b) d = r[c], d && (b[d] = b[c], delete b[c]);
+                return a
+            };
+            c("checkJsApi", {
+                jsApiList: k(a.jsApiList)
+            }, function() {
+                return a._complete = function(a) {
+                    if (w) {
+                        var c = a.checkResult;
+                        c && (a.checkResult = JSON.parse(c))
+                    }
+                    a = b(a)
+                }, a
+            }())
+        },
+        onMenuShareTimeline: function(a) {
+            d(q.onMenuShareTimeline, {
+                complete: function() {
+                    c("shareTimeline", {
+                        title: a.title || t,
+                        desc: a.title || t,
+                        img_url: a.imgUrl,
+                        link: a.link || location.href
+                    }, a)
+                }
+            }, a)
+        },
+        onMenuShareAppMessage: function(a) {
+            d(q.onMenuShareAppMessage, {
+                complete: function() {
+                    c("sendAppMessage", {
+                        title: a.title || t,
+                        desc: a.desc || "",
+                        link: a.link || location.href,
+                        img_url: a.imgUrl,
+                        type: a.type || "link",
+                        data_url: a.dataUrl || ""
+                    }, a)
+                }
+            }, a)
+        },
+        onMenuShareQQ: function(a) {
+            d(q.onMenuShareQQ, {
+                complete: function() {
+                    c("shareQQ", {
+                        title: a.title || t,
+                        desc: a.desc || "",
+                        img_url: a.imgUrl,
+                        link: a.link || location.href
+                    }, a)
+                }
+            }, a)
+        },
+        onMenuShareWeibo: function(a) {
+            d(q.onMenuShareWeibo, {
+                complete: function() {
+                    c("shareWeiboApp", {
+                        title: a.title || t,
+                        desc: a.desc || "",
+                        img_url: a.imgUrl,
+                        link: a.link || location.href
+                    }, a)
+                }
+            }, a)
+        },
+        startRecord: function(a) {
+            c("startRecord", {}, a)
+        },
+        stopRecord: function(a) {
+            c("stopRecord", {}, a)
+        },
+        onVoiceRecordEnd: function(a) {
+            d("onVoiceRecordEnd", a)
+        },
+        playVoice: function(a) {
+            c("playVoice", {
+                localId: a.localId
+            }, a)
+        },
+        pauseVoice: function(a) {
+            c("pauseVoice", {
+                localId: a.localId
+            }, a)
+        },
+        stopVoice: function(a) {
+            c("stopVoice", {
+                localId: a.localId
+            }, a)
+        },
+        onVoicePlayEnd: function(a) {
+            d("onVoicePlayEnd", a)
+        },
+        uploadVoice: function(a) {
+            c("uploadVoice", {
+                localId: a.localId,
+                isShowProgressTips: a.isShowProgressTips || 1
+            }, a)
+        },
+        downloadVoice: function(a) {
+            c("downloadVoice", {
+                serverId: a.serverId,
+                isShowProgressTips: a.isShowProgressTips || 1
+            }, a)
+        },
+        translateVoice: function(a) {
+            c("translateVoice", {
+                localId: a.localId,
+                isShowProgressTips: a.isShowProgressTips || 1
+            }, a)
+        },
+        chooseImage: function(a) {
+            c("chooseImage", {
+                scene: "1|2"
+            }, function() {
+                return a._complete = function(a) {
+                    if (w) {
+                        var b = a.localIds;
+                        b && (a.localIds = JSON.parse(b))
+                    }
+                }, a
+            }())
+        },
+        previewImage: function(a) {
+            c(q.previewImage, {
+                current: a.current,
+                urls: a.urls
+            }, a)
+        },
+        uploadImage: function(a) {
+            c("uploadImage", {
+                localId: a.localId,
+                isShowProgressTips: a.isShowProgressTips || 1
+            }, a)
+        },
+        downloadImage: function(a) {
+            c("downloadImage", {
+                serverId: a.serverId,
+                isShowProgressTips: a.isShowProgressTips || 1
+            }, a)
+        },
+        getNetworkType: function(a) {
+            var b = function(a) {
+                var c, d, e, b = a.errMsg;
+                if (a.errMsg = "getNetworkType:ok", c = a.subtype, delete a.subtype, c) a.networkType = c;
+                else switch (d = b.indexOf(":"), e = b.substring(d + 1)) {
+                    case "fail":
+                    case "permission denied":
+                    case "localparameters":
+                        a.errMsg = "getNetworkType:fail";
+                        break;
+                    default:
+                        a.networkType = e
+                }
+                return a
+            };
+            c("getNetworkType", {}, function() {
+                return a._complete = function(a) {
+                    a = b(a)
+                }, a
+            }())
+        },
+        openLocation: function(a) {
+            c("openLocation", {
+                latitude: a.latitude,
+                longitude: a.longitude,
+                name: a.name || "",
+                address: a.address || "",
+                scale: a.scale || 28,
+                infoUrl: a.infoUrl || ""
+            }, a)
+        },
+        getLocation: function(a) {
+            c(q.getLocation, f(a, "jsapi_location"), a)
+        },
+        hideOptionMenu: function(a) {
+            c("hideOptionMenu", {}, a)
+        },
+        showOptionMenu: function(a) {
+            c("showOptionMenu", {}, a)
+        },
+        closeWindow: function(a) {
+            c("closeWindow", {
+                immediate_close: a && a.immediateClose || 0
+            }, a)
+        },
+        hideMenuItems: function(a) {
+            c("hideMenuItems", {
+                menuList: a.menuList
+            }, a)
+        },
+        showMenuItems: function(a) {
+            c("showMenuItems", {
+                menuList: a.menuList
+            }, a)
+        },
+        hideAllNonBaseMenuItem: function(a) {
+            c("hideAllNonBaseMenuItem", {}, a)
+        },
+        showAllNonBaseMenuItem: function(a) {
+            c("showAllNonBaseMenuItem", {}, a)
+        },
+        scanQRCode: function(a) {
+            c("scanQRCode", {
+                desc: a.desc,
+                needResult: a.needResult || 0,
+                scanType: a.scanType || ["qrCode", "barCode"]
+            }, a)
+        },
+        openProductSpecificView: function(a) {
+            c(q.openProductSpecificView, {
+                pid: a.productId,
+                view_type: a.viewType || 0
+            }, a)
+        },
+        addCard: function(a) {
+            var e, f, g, h, b = a.cardList,
+                d = [];
+            for (e = 0, f = b.length; f > e; ++e) g = b[e], h = {
+                card_id: g.cardId,
+                card_ext: g.cardExt
+            }, d.push(h);
+            c(q.addCard, {
+                card_list: d
+            }, function() {
+                return a._complete = function(a) {
+                    var c, d, e, b = a.card_list;
+                    if (b) {
+                        for (b = JSON.parse(b), c = 0, d = b.length; d > c; ++c) e = b[c], e.cardId = e.card_id, e.cardExt = e.card_ext, e.isSuccess = e.is_succ ? !0 : !1, delete e.card_id, delete e.card_ext, delete e.is_succ;
+                        a.cardList = b, delete a.card_list
+                    }
+                }, a
+            }())
+        },
+        chooseCard: function(a) {
+            c("chooseCard", {
+                app_id: B.appId,
+                location_id: a.shopId || "",
+                sign_type: "SHA1",
+                card_id: a.cardId || "",
+                card_type: a.cardType || "",
+                card_sign: a.cardSign,
+                time_stamp: a.timestamp + "",
+                nonce_str: a.nonceStr
+            }, function() {
+                return a._complete = function(a) {
+                    a.cardList = a.choose_card_info, delete a.choose_card_info
+                }, a
+            }())
+        },
+        openCard: function(a) {
+            var e, f, g, h, b = a.cardList,
+                d = [];
+            for (e = 0, f = b.length; f > e; ++e) g = b[e], h = {
+                card_id: g.cardId,
+                code: g.code
+            }, d.push(h);
+            c(q.openCard, {
+                card_list: d
+            }, a)
+        },
+        chooseWXPay: function(a) {
+            c(q.chooseWXPay, g(a), a)
+        }
+    }, b && (a.wx = a.jWeixin = E), E
+});

+ 3 - 0
assets/js/template/template.dever.js

@@ -0,0 +1,3 @@
+// 待续...
+var config = {};
+config.proxyTemplateUrl = 'http://192.168.15.10/dever/package/ai/?src/proxy.template?';

Some files were not shown because too many files changed in this diff