dever.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. /* ================================================================================
  2. * dever.js v1.0
  3. * http://git.shemic.com/dever/script
  4. * ================================================================================
  5. * Copyright 2017-2018 Dever(dever.cc)
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ================================================================================
  19. */
  20. //<filter><script src="../js/lib/jquery.min.js"></script><script src="../js/dever.js"></script></filter>
  21. $(function()
  22. {
  23. Dever.Init();
  24. });
  25. //公共类库
  26. var Dever =
  27. {
  28. Init : function()
  29. {
  30. this.Import();
  31. this.Page().Init();
  32. this.User().Init();
  33. this.Editor().Init();
  34. this.Change();
  35. this.Upload();
  36. this.LoadPage();
  37. this.Extend();
  38. //this.Target();
  39. //this.Pjax();
  40. }
  41. ,Pjax : function()
  42. {
  43. $(document).pjax('a', '.container');
  44. //$.pjax.reload('.container');
  45. }
  46. ,Page : function()
  47. {
  48. return _Dever_Page;
  49. }
  50. ,Share : function()
  51. {
  52. return _Dever_Share;
  53. }
  54. ,Template : function()
  55. {
  56. return _Dever_Template;
  57. }
  58. ,Editor : function()
  59. {
  60. return _Dever_Editor;
  61. }
  62. ,User : function()
  63. {
  64. return _Dever_User;
  65. }
  66. ,Modal : function()
  67. {
  68. return _Dever_Modal;
  69. }
  70. ,Proxy : function(uri)
  71. {
  72. return config.proxy + 'proxy_method=' + encodeURIComponent(uri);
  73. }
  74. ,Jump : function(url)
  75. {
  76. location.href = url;
  77. }
  78. ,BackRun : function(url)
  79. {
  80. $.post(url);
  81. }
  82. ,Reload : function(e)
  83. {
  84. e.attr('src', e.attr('src'));
  85. }
  86. ,Target : function()
  87. {
  88. var link = config.host;
  89. $("a").each(function() {
  90. if (!$(this).attr('onclick')) {
  91. var url = $(this).attr('href');
  92. if (url && url.indexOf(link) == -1) {
  93. //$(this).attr('target', '_blank');
  94. }
  95. }
  96. })
  97. }
  98. ,Import : function()
  99. {
  100. var self = this;
  101. var include = $("include");
  102. var count = include.length-1;
  103. if (include.length) {
  104. include.each(function(i){
  105. var dom = $(this);
  106. var system = dom.attr('system');
  107. var path = dom.attr('path');
  108. var name = dom.attr('file');
  109. var file = '';
  110. if(path) file = path;
  111. if(system) file = file + '/' + system;
  112. file += name + '.html';
  113. dom.load(file, function(){
  114. $("html").find("include").eq(i).get(0).outerHTML = dom.html();
  115. if (i == count) {
  116. self.Template().Init();
  117. }
  118. });
  119. })
  120. } else {
  121. self.Template().Init();
  122. }
  123. }
  124. ,LoadPage : function()
  125. {
  126. if ($('.dever-loadpage').length) {
  127. $('.dever-loadpage').each(function() {
  128. var url = $(this).attr('dever-url');
  129. var self = $(this);
  130. $.getJSON(Dever.CallUrl(url), function(t) {
  131. self.html(t.msg);
  132. _Dever_Page.Ajax(self);
  133. });
  134. });
  135. }
  136. }
  137. ,CallUrl : function(url)
  138. {
  139. if (url.indexOf('callback') == -1) {
  140. if (url.indexOf('=') != -1) {
  141. url += '&json=1&callback=?';
  142. } else {
  143. url += '?json=1&callback=?';
  144. }
  145. }
  146. return url;
  147. }
  148. ,Change : function()
  149. {
  150. if ($('.dever-change').length) {
  151. $('.dever-change').change(function() {
  152. Dever.Jump($(this).attr('dever-change')+$(this).val());
  153. });
  154. //$('.dever-change').val($('.dever-change').attr('dever-value'));
  155. }
  156. }
  157. ,Host : function(host, uri)
  158. {
  159. var result = '';
  160. uri = uri ? uri : '';
  161. result = config.host.replace('www', host);
  162. result = result.replace('main', host);
  163. result = result + config.type;
  164. result = result.replace('??', '?');
  165. if (config.proxy) {
  166. return this.Proxy(host + '/' + uri);
  167. }
  168. return result + uri;
  169. }
  170. // 输出数据,提示框
  171. ,Out : function(content, callback, ele, title)
  172. {
  173. if (content && content.indexOf('登录') != -1 && $("#login_url").length) {
  174. var href = $("#login_url").val();
  175. location.href = href;
  176. return;
  177. } else {
  178. alert(content);
  179. if (ele && callback) {
  180. ele.unbind('click').bind('click', callback);
  181. } else if (callback) {
  182. callback();
  183. }
  184. }
  185. }
  186. // 将数据解析,并进行下一步操作
  187. ,Msg : function(result, error_callback, success_callback)
  188. {
  189. if (result.status == 2) {
  190. if (error_callback) {
  191. return error_callback(result.msg);
  192. }
  193. this.Out(result.msg);
  194. } else {
  195. if (success_callback) {
  196. return success_callback(result.msg);
  197. }
  198. if (result.msg.indexOf('http://') != -1) {
  199. this.Jump(result.msg);
  200. } else if (parseInt(result.msg) > 0) {
  201. this.Out('操作成功', function() {
  202. location.reload();
  203. });
  204. } else {
  205. this.Out(result.msg);
  206. }
  207. }
  208. }
  209. ,Confirm : function(callback)
  210. {
  211. if (confirm('确定进行此项操作吗?')) {
  212. callback();
  213. }
  214. }
  215. //上传组件加载
  216. ,Upload : function()
  217. {
  218. if ($(".dever-upload-drag").length) {
  219. $(".dever-upload-drag").each(function() {
  220. var key = $(this).attr('key');
  221. if (config.proxy) {
  222. var url = Dever.Proxy('upload/save.drag') + '&key=' + key;
  223. } else {
  224. var url = config.upload + '.drag?key='+ key;
  225. }
  226. $(this).inlineattachment({
  227. uploadUrl: url,
  228. progressText: '![文件上传中...]()',
  229. urlText: "![文件描述]({filename})\n",
  230. errorText: '上传失败'
  231. });
  232. });
  233. }
  234. if ($(".dever-upload").length) {
  235. $(".dever-upload").each(function(i) {
  236. loadUpload(i,$(this),$(this).attr('key'),config.upload + '.start', config.assets + 'image/');//三个参数说明1:第几个上传框2:文件对象3:图片的基本配置标题
  237. })
  238. }
  239. }
  240. ,Load : function(filename,filetype)
  241. {
  242. if (filetype == "js") {
  243. var fileref = document.createElement('script');
  244. fileref.setAttribute("type","text/javascript");
  245. fileref.setAttribute("src",filename + '.' + filetype);
  246. } else if (filetype == "css") {
  247. var fileref = document.createElement('link');
  248. fileref.setAttribute("rel","stylesheet");
  249. fileref.setAttribute("type","text/css");
  250. fileref.setAttribute("href",filename + '.' + filetype);
  251. }
  252. if (typeof fileref != "undefined") {
  253. document.getElementsByTagName("head")[0].appendChild(fileref);
  254. }
  255. }
  256. ,Extend : function()
  257. {
  258. Array.prototype.indexIn = function(val) {
  259. for (var i = 0; i < this.length; i++) {
  260. if (this[i] == val) return i;
  261. }
  262. return -1;
  263. };
  264. Array.prototype.remove = function(val) {
  265. var index = this.indexIn(val);
  266. if (index > -1) {
  267. this.splice(index, 1);
  268. }
  269. };
  270. $("select option").each(function() {
  271. if ($(this).attr('select') && $(this).attr('select') == 'true') {
  272. $(this).attr('selected', 'true');
  273. } else {
  274. $(this).removeAttr('selected');
  275. }
  276. });
  277. }
  278. ,Ucfirst : function(str)
  279. {
  280. var str = str.toLowerCase();
  281. var strarr = str.split(' ');
  282. var result = '';
  283. for (var i in strarr){
  284. result += strarr[i].substring(0,1).toUpperCase()+strarr[i].substring(1)+' ';
  285. }
  286. return result;
  287. }
  288. };
  289. //瀑布流分页
  290. var _Dever_Page =
  291. {
  292. name : '',
  293. Init : function()
  294. {
  295. if ($(this.name).length) {
  296. var self = this;
  297. $(window).scroll(function() {
  298. if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
  299. self.Start(self.name);
  300. }
  301. });
  302. }
  303. }
  304. ,Start : function(page)
  305. {
  306. page = page ? page : this.name;
  307. if ($(page).length) {
  308. $(page).hide();
  309. var url = $(page).attr('link');
  310. if (url) {
  311. var key = $(page).attr('dever-list');
  312. $.get(url, function(t) {
  313. t = '<div>' + t + '</div>';
  314. var c = $(t).find(key).html();
  315. if (c) {
  316. $(key).append(c);
  317. var l = $(t).find(page).attr('link');
  318. $(page).attr('link', l);
  319. }
  320. });
  321. }
  322. }
  323. }
  324. ,Ajax : function(e)
  325. {
  326. var self = this;
  327. e.find('a').each(function() {
  328. var url = $(this).attr('href');
  329. $(this).attr('href', 'javascript:;');
  330. $(this).unbind('click').bind('click', function() {
  331. $.get(url.replace('callback', ''), function(t) {
  332. e.html(t);
  333. self.Ajax(e);
  334. });
  335. });
  336. });
  337. }
  338. }
  339. //模态框
  340. var _Dever_Modal =
  341. {
  342. state : false,
  343. html : '',
  344. box : '',
  345. title : '',
  346. content : '',
  347. yes : '',
  348. no : '',
  349. setting : '',
  350. confirm : '',
  351. Init : function()
  352. {
  353. this.state = false;
  354. if (this.html) {
  355. $('body').append(this.html);
  356. if(this.box) this.box = $(this.box);
  357. if(this.title) this.title = $(this.title);
  358. if(this.content) this.content = $(this.content);
  359. if(this.yes) this.yes = $(this.yes);
  360. if(this.no) this.no = $(this.no);
  361. if(this.setting) this.setting = $(this.setting);
  362. if(this.confirm) this.confirm = $(this.confirm);
  363. this.state = true;
  364. }
  365. }
  366. ,Alert : function(content, callback)
  367. {
  368. if (this.state == false) {
  369. alert(content);
  370. return;
  371. } else {
  372. if (this.setting.length && this.setting.html()) {
  373. this.confirm.hide();
  374. this.setting.show();
  375. } else {
  376. this.setting.hide();
  377. this.confirm.show();
  378. }
  379. this.title.html(content);
  380. this.box.show();
  381. if (callback) {
  382. this.Bind(callback);
  383. }
  384. }
  385. }
  386. ,Confirm : function(content, callback)
  387. {
  388. if (this.state == false) {
  389. alert(content);
  390. return;
  391. } else {
  392. this.confirm.show();
  393. this.setting.hide();
  394. this.title.html(content);
  395. this.box.show();
  396. if(callback)
  397. {
  398. this.Bind(callback);
  399. }
  400. }
  401. }
  402. ,Bind : function(callback)
  403. {
  404. if (this.yes.length && callback.yes) {
  405. this.yes.unbind('click').bind('click', callback.yes);
  406. }
  407. if (this.no.length) {
  408. if (callback.no) {
  409. this.no.unbind('click').bind('click', callback.no);
  410. } else {
  411. var self = this;
  412. this.no.unbind('click').bind('click', function()
  413. {
  414. self.Close();
  415. });
  416. }
  417. }
  418. }
  419. ,Close : function()
  420. {
  421. this.box.hide();
  422. }
  423. }
  424. //用户相关
  425. var _Dever_User =
  426. {
  427. config : [],
  428. uid : -1,
  429. name : '匿名用户',
  430. Init : function()
  431. {
  432. var self = this;
  433. if (this.config.click) {
  434. for (var i in this.config.click) {
  435. var e = self.config.click[i];
  436. var c = 1;
  437. if (e.indexOf('|') != -1) {
  438. var t = e.split('|');
  439. e = t[0];
  440. c = 2;
  441. }
  442. if ($(e).length) {
  443. $(e).attr('data-i', i);
  444. $(e).attr('data-c', c);
  445. $(e).unbind('click').bind('click', function() {
  446. if ($(this).attr('data-c') == 2) {
  447. var t1 = $(this);
  448. Dever.Confirm(function() {
  449. self.Save($(this).attr('data-i'), t1, config);
  450. });
  451. } else {
  452. self.Save($(this).attr('data-i'), $(this), config);
  453. }
  454. });
  455. }
  456. }
  457. }
  458. }
  459. //通用的保存数据功能
  460. ,Save : function(key, e, setting)
  461. {
  462. var self = this;
  463. var config = self.config[key];
  464. if (config.start) {
  465. config.start.call();
  466. }
  467. var send = {};
  468. var callback = function(msg,state) {
  469. if (config.status && $(config.status).length) {
  470. //$(config.status).html(msg).css('visibility','initial');
  471. state ? $(config.status).html(msg).hide() : $(config.status).html(msg).show();
  472. } else if(!state) {
  473. Dever.Out(msg);
  474. }
  475. }
  476. if (typeof(config.input) != 'undefined') {
  477. if (typeof(config.input) == 'string' && config.input == 'parent') {
  478. if (e.attr('dever-send')) {
  479. send[e.attr('dever-send')] = e.attr('dever-' + e.attr('dever-send'));
  480. }
  481. send.id = e.attr('dever-id');
  482. send.value = e.parent().find('input').val();
  483. if (!send.id || !send.value) {
  484. callback(config.error);
  485. return;
  486. }
  487. } else if (typeof(config.input) == 'string' && config.input == 'click') {
  488. if (e.attr('dever-send')) {
  489. var a = e.attr('dever-send').split('&');
  490. for (var i in a) {
  491. if (typeof(a[i]) == 'string') {
  492. var b = a[i].split('=');
  493. send[b[0]] = b[1];
  494. }
  495. }
  496. }
  497. } else if (typeof(config.input) == 'object') {
  498. for (var i in config.input) {
  499. var option = false;
  500. var input = config.input[i];
  501. if (input.indexOf('|') != -1) {
  502. var t = input.split('|');
  503. input = t[0];
  504. option = true;
  505. }
  506. var m = true;
  507. var el = $(input);
  508. //e.get(0).tagName == 'TEXTAREA'
  509. send[i] = el.val();
  510. if (option == false) {
  511. if (send[i] && el.attr('dever-match')) {
  512. var r = new RegExp(el.attr('dever-match'));
  513. m = r.test(send[i]);
  514. }
  515. if (send[i] && el.attr('dever-value')) {
  516. m = $(el.attr('dever-value')).val() == send[i];
  517. }
  518. if (!send[i] || m != true) {
  519. var error = el.attr('dever-error') ? el.attr('dever-error') : config.error;
  520. callback(error);
  521. return;
  522. }
  523. }
  524. }
  525. }
  526. }
  527. if (!send) {
  528. callback(config.error);
  529. return;
  530. }
  531. if (!config.url) {
  532. config.url = e.attr('dever-send');
  533. }
  534. callback(1,1);
  535. config.url = Dever.CallUrl(config.url);
  536. if (setting.proxy) {
  537. $.post(config.url, send, function(t) {
  538. t = eval('(' + t + ')');
  539. Dever.Msg(t, callback, (config.callback ? function(msg){config.callback(e,msg,t)} : false));
  540. });
  541. } else {
  542. $.getJSON(config.url, send, function(t) {
  543. Dever.Msg(t, callback, (config.callback ? function(msg){config.callback(e,msg,t)} : false));
  544. });
  545. }
  546. }
  547. };
  548. //编辑器相关
  549. var _Dever_Editor =
  550. {
  551. state : false,
  552. editors : [],
  553. Init : function()
  554. {
  555. if (typeof marked == 'function') {
  556. this.state = true;
  557. } else {
  558. this.state = false;
  559. }
  560. this.SetMark();
  561. var self = this;
  562. if ($('.dever-note').length) {
  563. $('.dever-note').each(function() {
  564. self.InitEditor($(this));
  565. })
  566. }
  567. }
  568. ,InitEditor : function(e)
  569. {
  570. var id = e.attr('id');
  571. var key = e.attr('key');
  572. if (config.uid && config.uid > 0) {
  573. var toolbar = [
  574. 'title'
  575. ,'bold'
  576. ,'italic'
  577. ,'underline'
  578. ,'strikethrough'
  579. ,'fontScale'
  580. ,'color'
  581. ,'ol'
  582. ,'ul'
  583. ,'blockquote'
  584. ,'code'
  585. ,'table'
  586. ,'link'
  587. ,'image'
  588. ,'hr'
  589. ,'indent'
  590. ,'outdent'
  591. ,'alignment'
  592. //,'emoji'
  593. ];
  594. } else {
  595. var toolbar = [
  596. 'title'
  597. ,'bold'
  598. ,'fontScale'
  599. ,'color'
  600. ,'ol'
  601. ,'ul'
  602. ,'blockquote'
  603. ,'indent'
  604. ,'outdent'
  605. ,'alignment'
  606. ];
  607. }
  608. if (typeof(this.editors[id]) == "undefined") {
  609. this.editors[id] = new Simditor({
  610. textarea: e,
  611. upload:
  612. {
  613. url: config.upload + '.simditor',
  614. params: {key:key},
  615. fileKey: 'file',
  616. connectionCount: 10,
  617. leaveConfirm: 'Uploading is in progress, are you sure to leave this page?'
  618. },
  619. toolbar : toolbar
  620. /*
  621. ,emoji:
  622. {
  623. imagePath: config.lib + 'simditor/plugins/emoji/images/emoji/'
  624. }
  625. */
  626. });
  627. }
  628. }
  629. ,SetMark : function()
  630. {
  631. return;
  632. }
  633. ,GetMark : function(content)
  634. {
  635. if (this.state == true) {
  636. return marked(content);
  637. }
  638. return content;
  639. }
  640. };
  641. //模板
  642. var _Dever_Template =
  643. {
  644. state : false,
  645. method : '',
  646. element : '',
  647. data : '',
  648. param : '',
  649. attr : '',
  650. Init : function()
  651. {
  652. if (this.Check()) {
  653. var url = config.proxyTemplateUrl;
  654. var send = {};
  655. var parsing = [];
  656. $("dever").each(function(){
  657. parsing.push($(this).html());
  658. $(this).remove();
  659. });
  660. send.url = location.href;
  661. send.parsing = parsing.join('');
  662. send.html = $("html").html();
  663. //$("html").html('dever template loading...');
  664. $.ajax({
  665. type: "POST",
  666. url: url,
  667. data: send,
  668. dataType: "json",
  669. success: function(result){
  670. $("html").html(result.data);
  671. }
  672. });
  673. }
  674. }
  675. ,Check : function()
  676. {
  677. if ($("dever").length) {
  678. this.state = true;
  679. } else {
  680. this.state = false;
  681. }
  682. return this.state;
  683. }
  684. }
  685. //分享 暂时只支持手机版微信分享 请同时安装wechat组件
  686. var _Dever_Share =
  687. {
  688. wechat : false,
  689. url : '',
  690. project : '',
  691. uid : '-1',
  692. param : {
  693. title : '',
  694. img : '',
  695. desc : '',
  696. url : '',
  697. timelineCallback: function() {},
  698. sendMessageCallback: function() {},
  699. shareQQCallback: function() {}
  700. },
  701. Init : function(uid, project, url, param, button)
  702. {
  703. var self = this;
  704. self.wechat = self.CheckWechat();
  705. self.project = project;
  706. self.url = url;
  707. self.uid = uid;
  708. //self.param = param;
  709. $.extend(true, self.param, param)
  710. if (button) {
  711. $(button).on('click', function() {
  712. if (self.wechat == 1) {
  713. self.WechatGuide();
  714. } else {
  715. self.WeiboShare($(this));
  716. }
  717. })
  718. }
  719. if (self.wechat == 1) {
  720. self.WechatInit();
  721. }
  722. self.Reflux();
  723. }
  724. ,CheckWechat : function()
  725. {
  726. var state = navigator.userAgent.toLowerCase().indexOf("micromessenger") > -1;
  727. if (state) {
  728. return 1;
  729. } else {
  730. return 2;
  731. }
  732. }
  733. ,WechatGuide : function()
  734. {
  735. var param = this.param;
  736. 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>';
  737. $('#weixin_guide').remove();
  738. $(tpl).attr('id', 'weixin_guide').appendTo($('body'));
  739. $('#weixin_guide img').css(weixinCfg.style || {})
  740. setTimeout(function() {
  741. $('#weixin_guide').click(function() {
  742. $(this).remove();
  743. })
  744. }, 300)
  745. }
  746. ,WechatInit: function()
  747. {
  748. var url = this.url + 'init?callback=?';
  749. var param = this.param;
  750. var project = this.project;
  751. $.ajax({
  752. type:'post',
  753. dataType:'jsonp',
  754. jsonp: 'jsonp_cb',
  755. url: url,
  756. data: {
  757. 'project' : project,
  758. 'url' : location.href.split('#')[0]
  759. },
  760. success:function(result) {
  761. var data = result.data;
  762. wx.config({
  763. //debug:true,
  764. appId: data.appId,
  765. timestamp: data.timestamp,
  766. nonceStr: data.nonceStr,
  767. signature: data.signature,
  768. jsApiList: [
  769. 'onMenuShareTimeline',
  770. 'onMenuShareAppMessage',
  771. 'onMenuShareQQ'
  772. ]
  773. });
  774. wx.ready(function() {
  775. wx.onMenuShareAppMessage({
  776. title: param.title,
  777. desc: param.desc,
  778. link: param.url,
  779. imgUrl: param.img,
  780. success: function(res) {
  781. param.sendMessageCallback('success', res)
  782. self.ShareLog(1, 1);
  783. },
  784. cancel: function(res) {
  785. param.sendMessageCallback('cancel', res)
  786. self.ShareLog(1, 2);
  787. },
  788. fail: function(res) {
  789. param.sendMessageCallback('fail', res)
  790. self.ShareLog(1, 3);
  791. }
  792. });
  793. wx.onMenuShareTimeline({
  794. title: param.title,
  795. link: param.url,
  796. imgUrl: param.img,
  797. success: function(res) {
  798. param.timelineCallback('success', res)
  799. self.ShareLog(2, 1);
  800. },
  801. cancel: function(res) {
  802. param.timelineCallback('cancel', res)
  803. self.ShareLog(2, 2);
  804. },
  805. fail: function(res) {
  806. param.timelineCallback('fail', res)
  807. self.ShareLog(2, 3);
  808. }
  809. });
  810. wx.onMenuShareQQ({
  811. title: param.title,
  812. link: param.url,
  813. imgUrl: param.img,
  814. success: function(res) {
  815. param.shareQQCallback('success', res)
  816. self.ShareLog(3, 1);
  817. },
  818. cancel: function(res) {
  819. param.shareQQCallback('cancel', res)
  820. self.ShareLog(3, 2);
  821. },
  822. fail: function(res) {
  823. param.shareQQCallback('fail', res)
  824. self.ShareLog(3, 3);
  825. }
  826. });
  827. });
  828. },
  829. async:'true',
  830. timeout: 3000
  831. });
  832. }
  833. ,Reflux: function() {
  834. var refer = document.referrer,
  835. url = encodeURIComponent(document.location.href),
  836. param = location.search.substr(1),
  837. ua = encodeURIComponent(navigator.userAgent),
  838. project = this.project,
  839. uid = this.uid,
  840. wechat = this.wechat;
  841. if (param.indexOf("tsina-") > -1 || param.indexOf("timeline") > -1 || param.indexOf("singlemessage") > -1 || param.indexOf("groupmessage") > -1) {
  842. $.getJSON(this.url + 'reflux?callback=?' + '&project='+project+'&url=' + url + '&ua=' + ua + '&param=' + encodeURIComponent(param) + '&uid=' + uid + '&type=' + wechat);
  843. }
  844. }
  845. ,ShareLog: function(actType, actResult) {
  846. var project = this.project;
  847. var uid = this.uid;
  848. var wechat = this.wechat;
  849. var ua = encodeURIComponent(ua);
  850. var url = encodeURIComponent(document.location.href);
  851. $.getJSON(this.url + 'collect?callback=?' + '&project='+project+'&url=' + url + '&actType=' + actType + '&actResult=' + actResult + '&ua=' + ua + '&uid=' + uid + '&type=' + wechat);
  852. }
  853. }