zy_control.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. var $support = {
  2. transform3d : ('WebKitCSSMatrix' in window),
  3. touch : ('ontouchstart' in window)
  4. };
  5. var $E = {
  6. start : $support.touch ? 'touchstart' : 'mousedown',
  7. move : $support.touch ? 'touchmove' : 'mousemove',
  8. end : $support.touch ? 'touchend' : 'mouseup',
  9. cancel : $support.touch ? 'touchcancel' : '',
  10. transEnd : 'webkitTransitionEnd'
  11. };
  12. function setJson(str) {
  13. var ret = (typeof (str) == 'object') ? JSON.stringify(str) : JSON
  14. .parse(str);
  15. return ret;
  16. }
  17. function setHtml(id, html) {
  18. if ("string" == typeof (id)) {
  19. var ele = $$(id);
  20. if (ele != null) {
  21. ele.innerHTML = html == null ? "" : html;
  22. }
  23. } else if (id != null) {
  24. id.innerHTML = html == null ? "" : html;
  25. }
  26. }
  27. function getValue(id) {
  28. var e = $$(id);
  29. if (e)
  30. return e.value;
  31. }
  32. function setValue(id, vl) {
  33. var e = $$(id);
  34. if (e)
  35. e.value = vl;
  36. }
  37. function isDefine(para) {
  38. if (typeof para == 'undefined' || para == "" || para == null
  39. || para == undefined)
  40. return false;
  41. else
  42. return true;
  43. }
  44. function fucCheckLength(strTemp) { // 第一种计算字节
  45. var i, sum;
  46. sum = 0;
  47. for (i = 0; i < strTemp.length; i++) {
  48. if ((strTemp.charCodeAt(i) >= 0) && (strTemp.charCodeAt(i) <= 255))
  49. sum = sum + 1;
  50. else
  51. sum = sum + 2;
  52. }
  53. return sum;
  54. }
  55. function strLen(str) { // 第二种计算字节
  56. return str.replace(/[^\x00-\xff]/g, '__').length;
  57. }
  58. function loadBanner(e, url, json) {
  59. var img = new Image();
  60. img.src = url;
  61. img.onload = function() {
  62. var banner = $$(e);
  63. banner.innerHTML = '<img src="'
  64. + this.src
  65. + '" ontouchstart="zy_touch()" onclick="slideJump(\''
  66. + json.type
  67. + '\','
  68. + json.nid
  69. + ')" /><del ontouchstart="zy_touch()" onclick="hideBanner()"></del>';
  70. banner.style.height = this.height / (this.width / banner.offsetWidth)
  71. + 'px';
  72. banner.style.opacity = 1;
  73. }
  74. }
  75. function getBanner(id, fun) {
  76. AJAX.get(serverurl + 'advertising.php?id=' + id, function(json) {
  77. var src = json.img;
  78. zy_imgcache('banner', src, src, function(e, url) {
  79. loadBanner(e, url, json);
  80. }, function(e) {
  81. loadBanner(e, src, json);
  82. });
  83. if (fun)
  84. fun(1);
  85. }, function() {
  86. if (fun)
  87. fun(0);
  88. }, -10);
  89. }
  90. function hideBanner() {
  91. if (checkActive(event.currentTarget))
  92. return;
  93. $$('banner').style.height = '0';
  94. $$('banner').style.opacity = 0;
  95. }
  96. var rim = (2.5 + 3.125), // 顶部和底部的高度
  97. fontSize = 16, // 字体大小
  98. loadStatus = 0, // 加载状态,默认为可加载状态
  99. maxsize = 0; // 是否最大页
  100. function loadScroll(t) {
  101. if (loadStatus)
  102. return;
  103. var scrollTop = document.body.scrollTop
  104. || document.documentElement.scrollTop;
  105. var downHeight = parseInt(window.screen.availHeight,10) + parseInt(scrollTop,10), // 可见窗口高度+网页被卷去的高
  106. Height = parseInt(document.body.scrollHeight,10) - parseInt($$("more").offsetHeight * 3,10); // body总高度-加载更多的高度
  107. if (localStorage['device'] == 'ios')
  108. downHeight -= rim;
  109. if (downHeight > Height) {
  110. Load(1);
  111. return;
  112. }
  113. if (t == 'end') {
  114. window.setTimeout(function() {
  115. Scroll('end');
  116. }, 1000);
  117. }
  118. }
  119. function bodyTouch() {
  120. var s = window.getComputedStyle(document.body, null);
  121. fontSize = parseInt(s.fontSize,10);
  122. rim *= fontSize;
  123. document.body.addEventListener($E.move, function(event) {
  124. loadScroll('move');
  125. }, false);
  126. document.body.addEventListener($E.end, function(event) {
  127. loadScroll('end');
  128. }, false);
  129. }
  130. var isScroll = 0;
  131. function Scroll() { // 是否禁止拖滚动条
  132. if (isScroll)
  133. event.preventDefault();
  134. }
  135. var active = 0;
  136. function checkActive(t) {
  137. if (active)
  138. return 1;
  139. active = 1;
  140. if (arguments.length == 1) {
  141. t.className = 'active';
  142. }
  143. window.setTimeout(function() {
  144. t.className = '';
  145. active = 0;
  146. }, 1000);
  147. return 0;
  148. }
  149. function checkActiveNo(t) {
  150. if (active)
  151. return 1;
  152. active = 1;
  153. window.setTimeout(function() {
  154. active = 0;
  155. }, 300);
  156. return 0;
  157. }
  158. function base64_decode(data) {
  159. var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  160. var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = [];
  161. if (!data) {
  162. return data;
  163. }
  164. data += '';
  165. do { // unpack four hexets into three octets using index points in b64
  166. h1 = b64.indexOf(data.charAt(i++));
  167. h2 = b64.indexOf(data.charAt(i++));
  168. h3 = b64.indexOf(data.charAt(i++));
  169. h4 = b64.indexOf(data.charAt(i++));
  170. bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
  171. o1 = bits >> 16 & 0xff;
  172. o2 = bits >> 8 & 0xff;
  173. o3 = bits & 0xff;
  174. if (h3 == 64) {
  175. tmp_arr[ac++] = String.fromCharCode(o1);
  176. } else if (h4 == 64) {
  177. tmp_arr[ac++] = String.fromCharCode(o1, o2);
  178. } else {
  179. tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
  180. }
  181. } while (i < data.length);
  182. dec = tmp_arr.join('');
  183. return dec;
  184. }
  185. function urlParse(url) {
  186. var params = {};
  187. var loc = String(url);
  188. var pieces = loc.substr(loc.indexOf('#') + 1).split('&');
  189. params.keys = [];
  190. for ( var i = 0; i < pieces.length; i += 1) {
  191. var keyVal = pieces[i].split('=');
  192. params[keyVal[0]] = decodeURIComponent(keyVal[1]);
  193. params.keys.push(keyVal[0]);
  194. }
  195. return params;
  196. }
  197. function uescript(wn, scr) {
  198. uexWindow.evaluateScript(wn, '0', scr);
  199. }
  200. function ueppscript(wn, pn, scr) {
  201. uexWindow.evaluatePopoverScript(wn, pn, scr);
  202. }
  203. function openwin(winName, url, anim) {
  204. uexWindow.open(winName, "0", url, anim, "", "", "4", "275");
  205. }
  206. function closewin(anim) {
  207. var a = '-1';
  208. if (anim)
  209. a = anim;
  210. uexWindow.close(a);
  211. }
  212. function setstorage(objName, objValue) { // 设置字符串类型的本地缓存
  213. var sto = window.localStorage;
  214. if (sto)
  215. sto.setItem(objName, objValue);
  216. }
  217. function getstorage(objName) { // 读取字符串类型的本地缓存
  218. var ret = '';
  219. var sto = window.localStorage;
  220. if (sto)
  221. ret = sto.getItem(objName);
  222. return ret;
  223. }
  224. function clearstorage(objName) { // 清除本地缓存,如没指定名称则为清空所有缓存
  225. var sto = window.localStorage;
  226. if (sto) {
  227. if (objName)
  228. sto.removeItem(objName);
  229. else
  230. sto.clear();
  231. }
  232. }
  233. function setStorJson(objName, json) { // 设置Json类型的本地缓存
  234. if (json)
  235. setstorage(objName, JSON.stringify(json));
  236. }
  237. function getStorJson(objName) { // 读取Json类型的本地缓存
  238. var ret = {};
  239. var str = getstorage(objName);
  240. if (str)
  241. ret = JSON.parse(str);
  242. return ret;
  243. }
  244. window.AJAX = {
  245. callBack : {},
  246. index : 1,
  247. dataType : 'json',
  248. get : function(url, succCall, errCall, opId, dataType, timeout) {
  249. this.index++;
  250. var id = (opId || this.index);
  251. this.callBack[id] = [ succCall, errCall ];
  252. this.dataType = (dataType || this.dataType);
  253. uexXmlHttpMgr.open(id, 'get', url, (timeout || 8000));
  254. this._send(id);
  255. },
  256. post : function(url, data, succCall, errCall, opId, dataType, timeout) {
  257. this.index++;
  258. var id = (opId || this.index);
  259. this.callBack[id] = [ succCall, errCall ];
  260. this.dataType = (dataType || this.dataType);
  261. uexXmlHttpMgr.open(id, 'post', url, (timeout || 8000));
  262. var fileData = null;
  263. if (data.length == 2) {
  264. fileData = data[1]; // 二进制数据
  265. data = data[0]; // 文字数据
  266. }
  267. if (data) {
  268. for ( var k in data) {
  269. uexXmlHttpMgr.setPostData(id, 0, k, data[k]);
  270. }
  271. }
  272. if (fileData) {
  273. for ( var k in fileData) {
  274. uexXmlHttpMgr.setPostData(id, 1, k, fileData[k]);
  275. }
  276. }
  277. this._send(id);
  278. },
  279. _send : function(id) {
  280. uexXmlHttpMgr.onData = this.onData;
  281. uexXmlHttpMgr.send(id);
  282. },
  283. onData : function(inOpCode, inStatus, inResult) {
  284. var that = AJAX, callBack = that.callBack[inOpCode] || [];
  285. if (inStatus == -1) {
  286. callBack[1] && callBack[1]();
  287. delete that.callBack[inOpCode];
  288. uexXmlHttpMgr.close(inOpCode);
  289. } else if (inStatus == 1) {
  290. if (that.dataType == 'json')
  291. inResult = eval("(" + inResult + ")");
  292. // inResult= JSON.parse(inResult);
  293. // inResult= eval("("+inResult+")");
  294. callBack[0] && callBack[0](inResult);
  295. delete that.callBack[inOpCode];
  296. if (that.dataType != 'json')
  297. window.AJAX.dataType = 'json';
  298. uexXmlHttpMgr.close(inOpCode);
  299. }
  300. }
  301. };
  302. var em_focus = 1;
  303. function zy_Switch(t, i) {
  304. var Switch = $$('switch'), Em = Switch.getElementsByTagName('em');
  305. if (typeof (i) != 'undefined') {
  306. em_focus = i;
  307. }
  308. Switch.querySelector('.focus').className = '';
  309. if (em_focus == Em.length) {
  310. em_focus = 0;
  311. }
  312. Em[em_focus].className = 'focus';
  313. t.moveToPoint(em_focus);
  314. em_focus++;
  315. }
  316. function zy_slide() {
  317. var switchTime;
  318. $$('slider').slide = new zySlide('slider', 'H', function() {
  319. window.clearInterval(switchTime);
  320. zy_Switch(this, this.currentPoint);
  321. var t = this;
  322. switchTime = window.setInterval(function() {
  323. zy_Switch(t);
  324. }, 5000);
  325. }, false, function(e) {
  326. });
  327. switchTime = window.setInterval(function() {
  328. zy_Switch($$('slider').slide);
  329. }, 5000);
  330. }
  331. // 调用外部浏览器
  332. function loadLink(url) {
  333. var appInfo = '';
  334. var filter = '';
  335. var dataInfo = url;
  336. // var dataInfo = url.toLowerCase();//全部小写
  337. if (localStorage['device'] == 'android') {
  338. appInfo = 'android.intent.action.VIEW';
  339. filter = 'text/html';
  340. }
  341. uexWidget.loadApp(appInfo, filter, dataInfo);
  342. }
  343. function zy_selectmenu(sl) {
  344. if (sl) {
  345. var sp = sl.parentElement; // <span>
  346. if (sp) {
  347. var ch = sp.getElementsByTagName("div")[0];
  348. var t = sl.options[sl.selectedIndex].text;
  349. if (ch) {
  350. ch.innerHTML = t;
  351. }
  352. }
  353. }
  354. }
  355. function zy_for(e, cb) {
  356. var ch;
  357. if (e.currentTarget)
  358. ch = e.currentTarget.previousElementSibling;
  359. else
  360. ch = e.previousElementSibling;
  361. if (ch.nodeName == "INPUT") {
  362. if (ch.type == "checkbox") {
  363. ch.checked = !ch.checked;
  364. angular.element(ch).triggerHandler("click");
  365. }
  366. if (ch.type == "radio" && !ch.checked) {
  367. ch.checked = "checked";
  368. angular.element(ch).triggerHandler("click");
  369. }
  370. }
  371. if (cb)
  372. cb(e, ch.checked);
  373. }
  374. function zy_fold(e, col) {
  375. var a = e.currentTarget.nextElementSibling;
  376. if (a.nodeName == "DIV") {
  377. if (col)
  378. a.className = a.className.replace("col-c", "");
  379. else
  380. a.className += ' col-c';
  381. }
  382. }
  383. function zy_touch(c, f, lf) {
  384. var t = event.currentTarget;
  385. if (!t.zTouch) {
  386. t.zTouch = new zyClick(t, f, c, lf);
  387. t.zTouch._touchStart(event);
  388. }
  389. }
  390. function zy_Bounce() {
  391. var t = event.currentTarget;
  392. if (!t.zTouch) {
  393. t.zTouch = new zyBounce(t);
  394. t.zTouch._touchStart(event);
  395. }
  396. }
  397. function zy_parse() {
  398. var params = {};
  399. var loc = String(document.location);
  400. if (loc.indexOf("?") > 0)
  401. loc = loc.substr(loc.indexOf('?') + 1);
  402. else
  403. loc = uexWindow.getUrlQuery();
  404. var pieces = loc.split('&');
  405. params.keys = [];
  406. for ( var i = 0; i < pieces.length; i += 1) {
  407. var keyVal = pieces[i].split('=');
  408. params[keyVal[0]] = decodeURIComponent(keyVal[1]);
  409. params.keys.push(keyVal[0]);
  410. }
  411. return params;
  412. }
  413. function $$(id) {
  414. return document.getElementById(id);
  415. }
  416. function zy_con(id, url, x, y) {
  417. var s = window.getComputedStyle($$(id), null);
  418. uexWindow.openPopover(id, "0", url, "", parseInt(x,10), parseInt(y,10), parseInt(s.width,10),
  419. parseInt(s.height,10), parseInt(s.fontSize,10), "4");
  420. }
  421. function zy_resize(id, x, y) {
  422. var s = window.getComputedStyle($$(id), null);
  423. uexWindow.setPopoverFrame(id, parseInt(x,10), parseInt(y,10), parseInt(s.width,10), parseInt(s.height,10));
  424. }
  425. function zy_init() {
  426. // if(window.navigator.appVersion.indexOf("Android 4.2.1")!=-1){
  427. // angular.element(document.getElementsByTagName("body")).css("font-size","48px");
  428. // }
  429. if (window.navigator.platform == "Win32")
  430. document.body.style.fontSize = window.localStorage["defaultfontsize"];
  431. if (window.navigator.platform == "iPad"){
  432. document.body.style.fontSize = "24px";
  433. // document.body.style.fontSize = "12px";
  434. HT.$($$("footer"))?HT.$($$("footer")).attr({"style":"height:4em !important;"}):"";
  435. }
  436. }
  437. function zy_cc(t) {
  438. if (!t.cancelClick) {
  439. t.cancelClick = true;
  440. t.addEventListener("click", function() {
  441. event.stopPropagation();
  442. }, true);
  443. }
  444. }
  445. function removeNode(id) {
  446. var e = $$(id);
  447. if (e)
  448. e.parentElement.removeChild(e);
  449. }
  450. function Trim(str) {
  451. return str.replace(/(^\s*)|(\s*$)/g, "")
  452. }
  453. function LTrim(str) {
  454. return str.replace(/(^\s*)/g, "")
  455. }
  456. function RTrim(str) {
  457. return str.replace(/(\s*$)/g, "")
  458. }
  459. function AllTrim(str) {
  460. return str.replace(/\s*/g, '')
  461. }
  462. function substr(str, len) {
  463. if (!str || !len) {
  464. return '';
  465. }
  466. // 预期计数:中文2字节,英文1字节
  467. var a = 0;
  468. // 循环计数
  469. var i = 0;
  470. // 临时字串
  471. var temp = '';
  472. for (i = 0; i < str.length; i++) {
  473. if (str.charCodeAt(i) > 255) {
  474. // 按照预期计数增加2
  475. a += 2;
  476. } else {
  477. a++;
  478. }
  479. // 如果增加计数后长度大于限定长度,就直接返回临时字符串
  480. if (a > len) {
  481. return temp;
  482. }
  483. // 将当前内容加到临时字符串
  484. temp += str.charAt(i);
  485. }
  486. // 如果全部是单字节字符,就直接返回源字符串
  487. return str;
  488. }
  489. function Now() {
  490. var myDate = new Date()
  491. return myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-'
  492. + (myDate.getDate() < 10 ? '0' : '') + myDate.getDate() + ' '
  493. + (myDate.getHours() < 10 ? '0' : '') + myDate.getHours() + ':'
  494. + (myDate.getMinutes() < 10 ? '0' : '') + myDate.getMinutes() + ':'
  495. + (myDate.getSeconds() < 10 ? '0' : '') + myDate.getSeconds();
  496. }
  497. /**
  498. * 触发该元素下第一个子input的事件(单选、复选、toggle)
  499. *
  500. * @param e
  501. * @param cb
  502. */
  503. function zy_for_input(e, cb) {
  504. var ch = e.currentTarget ? (ch = angular.element(e.currentTarget).find(
  505. "input")[0]) : (e.previousElementSibling);
  506. if (ch && ch.nodeName == "INPUT") {
  507. var elm = angular.element(ch),
  508. controltype = elm.attr("controltype"),
  509. scope = elm.scope();
  510. if (ch.type == "checkbox") {
  511. ch.checked = !ch.checked;
  512. if(controltype && controltype== 'toggle'){//toggle
  513. var ngCheckedValue = elm.attr("ng-checked-value"),
  514. ngNocheckedValue = elm.attr("ng-nochecked-value"),
  515. ngChecked = elm.attr("ng-checked");
  516. noUpdateValue = elm.attr("no-update-value");
  517. if(noUpdateValue)
  518. return;
  519. if (ch.checked)
  520. val = ngCheckedValue?ngCheckedValue:1;
  521. else
  522. val = ngNocheckedValue?ngNocheckedValue:0;
  523. try{
  524. eval('(scope.' + ngChecked + '='+val +')');
  525. }catch(e){}
  526. scope.$digest();
  527. }else{
  528. var isParent = elm.attr("is-parent"),
  529. val = elm.attr("value"),
  530. ngModel = elm.attr("ng-model"),
  531. scopeVal = '',
  532. v = [];
  533. if(isParent){
  534. for(var i=0;i<isParent;i++){
  535. scope = scope.$parent;
  536. }
  537. }
  538. try{
  539. eval('(scopeVal = scope.' + ngModel + ')');
  540. }catch(e){}
  541. if (scopeVal)
  542. v = scopeVal.split(",");
  543. if (ch.checked)
  544. v.push(val);
  545. else
  546. v.remove(val);
  547. var s = '(scope.' + ngModel + '="' + v.join(',') + '")';
  548. try{
  549. eval(s);
  550. scope.valid({element:elm});
  551. }catch(e){}
  552. scope.$digest();
  553. }
  554. } else if(ch.type == "radio"){
  555. var isParent = elm.attr("is-parent"),
  556. val = elm.attr("value"),
  557. ngModel = elm.attr("ng-model");
  558. if(isParent){
  559. for(var i=0;i<isParent;i++){
  560. scope = scope.$parent;
  561. }
  562. }
  563. if (!ch.checked) {
  564. ch.checked = "checked";
  565. }else{
  566. val ='';
  567. }
  568. var s = '(scope.' + ngModel + '="' + val + '")';
  569. try{
  570. eval(s);
  571. scope.valid({element:elm});
  572. }catch(e){}
  573. scope.$digest();
  574. }
  575. }
  576. if (cb)
  577. cb(e, ch.checked);
  578. }