tvSysBtnBind.v2.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. try{
  2. (function(arr) {
  3. //当前元素删除
  4. arr.forEach(function(item) {
  5. if (item.hasOwnProperty('remove')) {
  6. return
  7. }
  8. Object.defineProperty(item, 'remove', {
  9. configurable: true,
  10. enumerable: true,
  11. writable: true,
  12. value: function remove() {
  13. this.parentNode.removeChild(this)
  14. }
  15. })
  16. })
  17. })([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
  18. if (!("classList" in document.documentElement)) {
  19. // classList 兼容
  20. Object.defineProperty(HTMLElement.prototype, 'classList', {
  21. get: function() {
  22. var self = this;
  23. function update(fn) {
  24. return function(value) {
  25. var classes = self.className.split(/\s+/g),
  26. index = classes.indexOf(value);
  27. fn(classes, index, value);
  28. self.className = classes.join(" ")
  29. }
  30. }
  31. return {
  32. add: update(function(classes, index, value) {
  33. if (!~index) classes.push(value)
  34. }),
  35. remove: update(function(classes, index) {
  36. if (~index) classes.splice(index, 1)
  37. }),
  38. toggle: update(function(classes, index, value) {
  39. if (~index) classes.splice(index, 1);
  40. else classes.push(value)
  41. }),
  42. contains: function(value) {
  43. return !!~self.className.split(/\s+/g).indexOf(value)
  44. },
  45. item: function(i) {
  46. return self.className.split(/\s+/g)[i] || null
  47. }
  48. }
  49. }
  50. })
  51. }
  52. function fireKeyEvent(el, evtType, keyCode) {
  53. //创建事件
  54. var doc = el.ownerDocument,
  55. win = doc.defaultView || doc.parentWindow,
  56. evtObj;
  57. if (doc.createEvent) {
  58. if (win.KeyEvent) {
  59. evtObj = doc.createEvent('KeyEvents');
  60. evtObj.initKeyEvent(evtType, true, true, win, false, false, false, false, keyCode, 0)
  61. } else {
  62. evtObj = doc.createEvent('UIEvents');
  63. Object.defineProperty(evtObj, 'keyCode', {
  64. get: function() {
  65. return this.keyCodeVal
  66. }
  67. });
  68. Object.defineProperty(evtObj, 'which', {
  69. get: function() {
  70. return this.keyCodeVal
  71. }
  72. });
  73. evtObj.initUIEvent(evtType, true, true, win, 1);
  74. evtObj.keyCodeVal = keyCode;
  75. if (evtObj.keyCode !== keyCode) {
  76. // console.log("keyCode " + evtObj.keyCode + " 和 (" + evtObj.which + ") 不匹配")
  77. }
  78. }
  79. el.dispatchEvent(evtObj)
  80. } else if (doc.createEventObject) {
  81. evtObj = doc.createEventObject();
  82. evtObj.keyCode = keyCode;
  83. el.fireEvent('on' + evtType, evtObj)
  84. }
  85. }
  86. }catch(e){
  87. //版本很低
  88. }
  89. function addClass(ele, cls) {
  90. if(ele.classList){
  91. ele.classList.add(cls);
  92. }else{
  93. if (!this.hasClass(ele, cls)) ele.className += " " + cls;
  94. }
  95. }
  96. function arrIndexOf(arr, v) {
  97. for (var i = 0; i < arr.length; i++) {
  98. if (arr[i] == v) {
  99. return i;
  100. }
  101. }
  102. return -1;
  103. }
  104. //删除指定dom元素的样式
  105. function removeClass(ele, cls) {
  106. if(ele.classList){
  107. ele.classList.remove(cls);
  108. }else{
  109. if (ele.className != '' && hasClass(ele, cls)) {
  110. var arrClassName = ele.className.split(' ');
  111. var classIndex = arrIndexOf(arrClassName, cls);
  112. if (classIndex!==-1) {
  113. arrClassName.splice(classIndex, 1);
  114. ele.className = arrClassName.join(' ');
  115. }
  116. }
  117. }
  118. }
  119. //如果存在(不存在),就删除(添加)一个样式
  120. function toggleClass(ele,cls){
  121. if(hasClass(ele,cls)){
  122. removeClass(ele, cls);
  123. }else{
  124. addClass(ele, cls);
  125. }
  126. }
  127. function hasClass(element, cls) {
  128. return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
  129. }
  130. // function hasClass(tagStr,classStr){
  131. // if(tagStr.classList){
  132. // return tagStr.classList.contains(classStr);
  133. // } else{
  134. // var arr=tagStr.className.split(/\s+/ ); //这个正则表达式是因为class可以有多个,判断是否包含
  135. // for (var i=0;i<arr.length;i++){
  136. // if (arr[i]==classStr){
  137. // return true ;
  138. // }
  139. // }
  140. // return false
  141. // }
  142. // }
  143. function getClassNames(classStr,target, tagName) {
  144. /* classStr 样式名(必须) 目标元素 标签类型 */
  145. target= target?target:document;
  146. tagName = tagName?tagName:"*";
  147. if (document.getElementsByClassName) {
  148. return target.getElementsByClassName(classStr)
  149. } else {
  150. var nodes = target.getElementsByTagName(tagName),
  151. ret = [];
  152. for (i = 0; i < nodes.length; i++) {
  153. if (hasClass(nodes[i], classStr)) {
  154. ret.push(nodes[i])
  155. }
  156. }
  157. return ret;
  158. }
  159. }
  160. function getElementLeft(ele) {
  161. var actualLeft = ele.offsetLeft;
  162. var current = ele.offsetParent;
  163. // 如果当前元素不是根元素
  164. while (current !== null) {
  165. actualLeft += current.offsetLeft;
  166. current = current.offsetParent;
  167. }
  168. return actualLeft;
  169. }
  170. function getElementTop(ele) {
  171. var actualTop = ele.offsetTop;
  172. var current = ele.offsetParent;
  173. while (current !== null) {
  174. actualTop += current.offsetTop;
  175. current = current.offsetParent;
  176. }
  177. return actualTop;
  178. }
  179. function getBoundingClientRect(ele) {
  180. // 该方法是计算当前元素距离当前视口的距离,所以需要得到页面的滚动距离
  181. var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  182. var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
  183. // 如果浏览器支持该方法
  184. if (ele.getBoundingClientRect) {
  185. if (typeof arguments.callee.offset !== 'number') {
  186. //不同浏览器中,元素的默认位置不同。为了统一起见,需要新创建一个元素
  187. var temp = document.createElement('div');
  188. temp.style.cssText = "position:absolute;top:0;left:0";
  189. document.body.appendChild(temp);
  190. arguments.callee.offset = -temp.getBoundingClientRect().top - scrollTop;
  191. document.body.removeChild(temp);
  192. temp = null;
  193. }
  194. var rect = ele.getBoundingClientRect();
  195. var offset = arguments.callee.offset;
  196. return {
  197. left: rect.left + offset,
  198. right: rect.right + offset,
  199. top: rect.top + offset,
  200. bottom: rect.bottom + offset,
  201. width:(rect.right + offset)-(rect.left + offset),
  202. height:(rect.bottom + offset)-(rect.top + offset)
  203. }
  204. } else {
  205. //当前浏览器不支持该方法
  206. var actualLeft = getElementLeft(ele);
  207. var actualTop = getElementTop(ele);
  208. var offsetWidth=ele.offsetWidth;
  209. var offsetHeight=ele.offsetHeight;
  210. return {
  211. left: actualLeft - scrollLeft,
  212. right: actualLeft + offsetWidth - scrollLeft,
  213. top: actualTop - scrollTop,
  214. bottom: actualTop + offsetHeight - scrollTop,
  215. width:(actualLeft + offsetWidth- scrollLeft) -(actualLeft - scrollLeft),
  216. height:(actualTop + offsetHeight - scrollTop)-(actualTop - scrollTop)
  217. }
  218. }
  219. }
  220. (function(window) {
  221. var tvSysBtnBind = function(init) {
  222. var _this = this,
  223. _self = self;
  224. var id = init.id ? init.id : null,
  225. keyRemoveDefault = typeof init.keyRemoveDefault == "undefined" ? false : init.keyRemoveDefault,
  226. currentIndex = init.currentIndex ? parseInt(init.currentIndex) : 0,
  227. btnLeft = init.btnLeft ? init.btnLeft : 37,
  228. btnUp = init.btnUp ? init.btnUp : 38,
  229. btnRight = init.btnRight ? init.btnRight : 39,
  230. btnDown = init.btnDown ? init.btnDown : 40,
  231. btnEnter = init.btnEnter ? init.btnEnter : 13,
  232. history = typeof init.history == "undefined" ? true : init.history,
  233. isFloatLast = typeof init.isFloatLast == "undefined" ? false : init.isFloatLast,
  234. isCentered = typeof init.isCentered == "undefined" ? true : init.isCentered,
  235. currentClass = init.currentClass ? init.currentClass : "current",
  236. effect = init.effect ? init.effect : "slide1",
  237. element = new Array(),
  238. rules = init.rules,
  239. direction = "y";
  240. _this.className = init.className ? init.className : "hotbutton";
  241. this.event = {};
  242. var _tempElem;
  243. this.currentIndex = parseInt(currentIndex);
  244. this.defaultIndex = parseInt(currentIndex);
  245. this.currentClass = currentClass;
  246. this.historyFocus = {};
  247. if (!window.focusobj) window.focusobj = document.createElement("span");
  248. (typeof init.onLoad) == "function" ? init.onLoad : init.onLoad = function() {};
  249. (typeof init.onBack) == "function" ? init.onLoad : init.onBack = function() {};
  250. this.onLoad = function() {
  251. focusobj.innerHTML = '<div class="cssbk"><b class="lt"></b><b class="t"></b><b class="rt"></b><b class="r"></b><b class="rb"></b><b class="b"></b><b class="lb"></b> <b class="l"></b></div>';
  252. addClass(focusobj,"focusobj");
  253. addClass(focusobj,"current");
  254. focusobj.style.display = "none";
  255. _this.target = init.id ? document.getElementById(init.id) : document.body;
  256. _this.defaultTarget = _this.target;
  257. _this.currentId = init.id ? init.id : "Jdoc";
  258. _this.reLoad();
  259. _this.sourceClassName = _this.className;
  260. _this.sourceLength = element.length;
  261. _this.prev = element[currentIndex];
  262. _this.prevIndex = currentIndex;
  263. _this.current = element[currentIndex];
  264. _this.currentIndex = currentIndex;
  265. _this.target.appendChild(focusobj);
  266. init.onLoad.call(_this);
  267. }
  268. self.getCurRule=function(){
  269. var obj = {};
  270. if (rules) {
  271. obj = rules["#" + _this.currentId + ">." + _this.className];
  272. if (typeof obj == "undefined") obj = rules[_this.className]
  273. }
  274. return obj
  275. }
  276. this.reSetClass = function(item, index, curClass) {
  277. var obj =_self.getCurRule();
  278. if(typeof obj["history"]=="undefined") obj["history"]=history; //默认历史记录开关
  279. if (obj["history"]) _this.historyFocus[_this.currentId+_this.className] = _this.currentIndex; //当前历史开关
  280. //index = index ? index : 0;
  281. _this.prevCurrentClass = _this.currentClass;
  282. if (curClass) {
  283. _this.currentClass = curClass
  284. }
  285. var arr = item.split(">");
  286. for (var i = 0; i < arr.length; i++) {
  287. if (arr[i] == "") arr.splice(i)
  288. }
  289. for (var i = 0; i < arr.length; i++) {
  290. if (arr[i].indexOf("#") != -1) {
  291. _this.currentId=arr[i].replace("#", "");
  292. if (document.getElementById( _this.currentId)) _this.target = document.getElementById( _this.currentId);
  293. }
  294. if (arr[i].indexOf(".") != -1) {
  295. item = arr[i].replace(".", "")
  296. }
  297. if (arr[i].indexOf(".") == -1 && arr[i].indexOf("#") == -1) {
  298. item = arr[i]
  299. }
  300. }
  301. if (getClassNames(item,_this.target).length > 0) {
  302. _self.newItem(item, index)
  303. } else {
  304. _this.target = _this.defaultTarget;
  305. if (getClassNames(item,_this.target).length > 0) _self.newItem(item, index)
  306. }
  307. }
  308. self.newItem = function(item, index) {
  309. if (_this.prev) removeClass(_this.prev,_this.currentClass);
  310. //_this.target=document.getElementById(_this.currentId);
  311. if(typeof _this.historyFocus[_this.currentId+item]=="undefined")
  312. _this.historyFocus[_this.currentId+item]=0;
  313. _this.className = item;
  314. _this.prevIndex = _this.currentIndex = typeof index!="undefined" ?index: _this.historyFocus[_this.currentId+item];
  315. _this.reLoad();
  316. }
  317. self.readFn = function() {
  318. if ((typeof init.onEnterPress) == "function") {
  319. init.onEnterPress
  320. } else {
  321. init.onEnterPress = function() {}
  322. }
  323. if ((typeof init.onPress) == "function") {
  324. init.onPress
  325. } else {
  326. init.onPress = function() {}
  327. }
  328. }
  329. this.reLoad = function() {
  330. self.readFn();
  331. element =getClassNames(_this.className,_this.target);
  332. this.hotbtn = element;
  333. if (element.length <= 0) return false;
  334. if (_this.currentIndex || _this.currentIndex == 0) {
  335. _this.currentIndex = parseInt(_this.currentIndex)
  336. } else {
  337. _this.currentIndex = parseInt(init.currentIndex)
  338. }
  339. if (isload >= 2 && _this.sourceClass == _this.className && _this.sourceLength != element.length && !isSet) {
  340. if (hasClass(_this.prev,_this.className) && _this.sourceLength > element.length) {
  341. _this.currentIndex = _this.currentIndex - (_this.sourceLength - element.length);
  342. _this.prevIndex = _this.prevIndex - (_this.sourceLength - element.length);
  343. _this.sourceLength = element.length
  344. } else if (hasClass(_this.prev,_this.className) && _this.sourceLength < element.length) {
  345. _this.currentIndex = _this.currentIndex + (element.length - _this.sourceLength);
  346. _this.prevIndex = _this.prevIndex + (element.length - _this.sourceLength);
  347. _this.sourceLength = element.length
  348. }
  349. }
  350. isSet = false;
  351. _this.current = element[_this.currentIndex];
  352. _this.currentIndex = _this.currentIndex;
  353. _self.classDo(_this.currentIndex);
  354. for (var i = 0; i < this.hotbtn.length; i++) {
  355. this.hotbtn[i].setAttribute("data-id", i)
  356. }
  357. }
  358. function keydefault(e) {
  359. try {
  360. if (keyRemoveDefault) window.event ? window.event.returnValue = false : e.preventDefault()
  361. } catch (e) {}
  362. }
  363. var isSet = false;
  364. this.setCurrentIndex = function(index) {
  365. isSet = true;
  366. index = parseInt(index);
  367. _this.currentIndex = index;
  368. _this.current = element[index]
  369. }
  370. var maxTop = 0;
  371. this.viewScrollY = function(y,view) {
  372. var obj = self.getCurRule();
  373. // var view = _this.current.parentNode.parentNode;
  374. var sumtop = obj["directionY"] ? parseInt(obj["directionY"]) : 0;
  375. var top = sumtop + y + view.clientHeight / 2 - Math.ceil(_this.current.clientHeight / 2);
  376. if (top > 0) top = 0;
  377. obj["directionY"]=top;
  378. view.children[0].style.top = top + "px"
  379. }
  380. var maxLeft = 0;
  381. this.viewScrollX = function(x,view) {
  382. var obj = self.getCurRule();
  383. // var view = _this.current.parentNode.parentNode;
  384. var sumleft = obj["directionX"] ? parseInt(obj["directionX"]) : 0;
  385. var left = sumleft + x + view.clientWidth / 2 - Math.ceil(_this.current.clientWidth / 2);
  386. if (isCentered) {
  387. if (left > 0) left = 0;
  388. if (obj["maxLeft"]==undefined||obj["maxLeft"]==null) {
  389. maxLeft = getBoundingClientRect(_this.hotbtn[_this.hotbtn.length - 1]).right - getBoundingClientRect(view).right;
  390. obj["maxLeft"]=maxLeft;
  391. }
  392. if (left < sumleft && left < -maxLeft) {
  393. left = -maxLeft
  394. }
  395. // if(maxLeft<view.clientWidth)
  396. // left=0;
  397. }
  398. obj["directionX"]=left;
  399. view.children[0].style.left = left + "px"
  400. }
  401. this.onPress = function(e) {
  402. init.onPress.call(_this)
  403. }
  404. this.onEnterPress = function() {
  405. init.onEnterPress.call(_this)
  406. }
  407. this.onBack = function() {
  408. init.onBack.call(_this)
  409. }
  410. self.getScrollTop = function() {
  411. var scrollTop = 0;
  412. if (document.documentElement && document.documentElement.scrollTop) {
  413. scrollTop = document.documentElement.scrollTop
  414. } else if (document.body) {
  415. scrollTop = document.body.scrollTop
  416. }
  417. return scrollTop
  418. }
  419. this.scroll = function() {
  420. var obj = self.getCurRule();
  421. if (getBoundingClientRect(_this.current).bottom > document.body.clientHeight || getBoundingClientRect(_this.current).top < 0) {
  422. var y = getBoundingClientRect(_this.current).top - (document.body.clientHeight / 2 - _this.current.clientHeight / 2);
  423. window.scrollTo(0, y)
  424. }
  425. var view = _this.current.parentNode.parentNode;
  426. if(obj["directionParent"])view=obj["directionParent"];
  427. // var direction = view.getAttribute("data-scroll-direction");
  428. // if (!direction) {
  429. // view = _this.current.parentNode.parentNode.parentNode;
  430. // direction = view.getAttribute("data-scroll-direction");
  431. // }
  432. if (obj == undefined || !obj["direction"] )return;
  433. view.style.position = "relative";
  434. view.children[0].style.position = "absolute";
  435. var sumleft = obj["directionX"] ? parseInt(obj["directionX"]) : 0;
  436. if (obj["direction"] == "x") {
  437. view.children[0].style.width = _this.hotbtn.length * _this.current.clientWidth * 2 + "px";
  438. var scroll_left = getBoundingClientRect(view).left - getBoundingClientRect(_this.current).left;
  439. if( _this.hotbtn.length * _this.current.clientWidth>view.clientWidth)
  440. _this.viewScrollX(scroll_left,view);
  441. }
  442. var sumleft = obj["directionY"] ? parseInt(obj["directionY"]) : 0;
  443. if (obj["direction"] == "y") {
  444. var scroll_top = getBoundingClientRect(view).top - getBoundingClientRect(_this.current).top;
  445. _this.viewScrollY(scroll_top,view)
  446. }
  447. }
  448. var isload = 0;
  449. self.classDo = function(index) {
  450. isload = isload + 1;
  451. if (isload == 2) {
  452. _this.sourceLength = element.length
  453. }
  454. if (_this.prevCurrentClass) {
  455. var ele = getClassNames(_this.prevCurrentClass,_this.target) ;
  456. for (var i = 0; i < ele.length; i++) {
  457. if (hasClass(ele[i],_this.prevCurrentClass)) {
  458. removeClass(ele[i],_this.prevCurrentClass);
  459. }
  460. }
  461. }
  462. if (element[index]) addClass(element[index],_this.currentClass);
  463. else return;
  464. for (var i = 0; i < element.length; i++) {
  465. if (i != index && hasClass(element[i],_this.currentClass)) {
  466. removeClass(element[i],_this.currentClass);
  467. }
  468. }
  469. _this.scroll();
  470. var effect = element[index].getAttribute("data-effect");
  471. if (effect) {
  472. focusobj.setAttribute("style", " position: fixed; z-index: 19;width:" + (getBoundingClientRect(element[index]).width) + "px ;height:" + (getBoundingClientRect(element[index]).height) + "px; left:" + getBoundingClientRect(element[index]).left + "px;top:" + getBoundingClientRect(element[index]).top + "px;");
  473. focusobj.setAttribute("class", "focusobj current " + effect);
  474. focusobj.style.display = "list-item"
  475. } else {
  476. focusobj.setAttribute("style", "");
  477. focusobj.style.display = "none"
  478. }
  479. }
  480. self.EventUtil = {
  481. add: function(obj, callback) {
  482. if (typeof(obj.onkeypress) == "null") {
  483. obj.onkeypress = function(e) {
  484. callback && callback(e)
  485. }
  486. } else {
  487. obj.onkeydown = function(e) {
  488. callback && callback(e)
  489. }
  490. }
  491. }
  492. }
  493. try{
  494. Webview.requestFocus();
  495. Webview.setKeyEventHandler(function (action, keyCode, keyName, metaState){
  496. var e = this;
  497. e.keyCode = keyName;
  498. _self.onPressdo(e);
  499. // _this.makepress(keyName)
  500. })
  501. }catch(err){
  502. self.EventUtil.add(document, function (e) {
  503. _self.onPressdo(e);
  504. });
  505. }
  506. // EventUtil.add(document, function(e) {
  507. // _self.onPressdo(e)
  508. // });
  509. self.overIndex = function() {
  510. if (_this.currentIndex >= element.length - 1) {
  511. _this.currentIndex = element.length - 1
  512. }
  513. if (_this.currentIndex < 0) {
  514. _this.currentIndex = 0
  515. }
  516. }
  517. self.isNumber = function(val) {
  518. var regPos = /^\d+(\.\d+)?$/;
  519. var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
  520. if (regPos.test(val) || regNeg.test(val)) {
  521. return true
  522. } else {
  523. return false
  524. }
  525. }
  526. self.ruleFn = function(index, direction) {
  527. var obj = {};
  528. if (rules) {
  529. obj =_self.getCurRule();
  530. }
  531. if (obj && typeof obj == "object" && typeof obj["line"] != "undefined") {
  532. var line = obj["line"]
  533. } else {
  534. var line = _this.hotbtn.length
  535. }
  536. line = parseInt(line);
  537. if (obj && typeof obj == "object" && typeof obj[_this.currentIndex] != "undefined" && typeof obj[_this.currentIndex][index] != "undefined") {
  538. var objRules = obj[_this.currentIndex];
  539. if (self.isNumber(objRules[index])) {
  540. _this.currentIndex = parseInt(_this.currentIndex) + parseInt(objRules[index])
  541. } else if (Array.isArray(objRules[index])) {
  542. _this.reSetClass(objRules[index][0], objRules[index][1])
  543. } else if (typeof obj["line"] != "undefined") {
  544. _this.currentIndex = _this.currentIndex + line
  545. }
  546. } else {
  547. var jump = element[_this.currentIndex].getAttribute("data-" + direction);
  548. jump = parseInt(jump);
  549. if (direction == "up") {
  550. if (_this.currentIndex > line - 1) _this.currentIndex = jump ? _this.currentIndex - jump : _this.currentIndex - line;
  551. else if (obj && typeof obj["up"] == "object") _this.reSetClass(obj[direction][0], obj["up"][1], obj["up"][2], obj["up"][3]);
  552. else if (obj && typeof obj["up"] == "function") obj["up"].call(_this)
  553. } else if (direction == "left") {
  554. if ((_this.currentIndex) % line != 0) _this.currentIndex = jump ? _this.currentIndex - jump : _this.currentIndex - 1;
  555. else if (obj && typeof obj["left"] == "object") _this.reSetClass(obj["left"][0], obj["left"][1], obj["left"][2], obj["left"][3]);
  556. else if (obj && typeof obj["left"] == "function") obj["left"].call(_this)
  557. } else if (direction == "right") {
  558. if ((_this.currentIndex + 1) % line != 0) _this.currentIndex = jump ? _this.currentIndex + jump : _this.currentIndex + 1;
  559. else if (obj && typeof obj["right"] == "object") _this.reSetClass(obj["right"][0], obj["right"][1], obj["right"][2], obj["right"][3]);
  560. else if (obj && typeof obj["right"] == "function") obj["right"].call(_this)
  561. } else if (direction == "down") {
  562. if (_this.hotbtn.length - line > _this.currentIndex) _this.currentIndex = jump ? _this.currentIndex + jump : _this.currentIndex + line;
  563. else if (obj && typeof obj["down"] == "object") _this.reSetClass(obj["down"][0], obj["down"][1], obj["down"][2], obj["down"][3]);
  564. else if (obj && typeof obj["down"] == "function") obj["down"].call(_this);
  565. else if (_this.currentIndex + line > _this.hotbtn.length - 1 && _this.currentIndex + line <= (line - _this.hotbtn.length % line) + _this.hotbtn.length - 1 && _this.hotbtn.length % line != 0 && isFloatLast) {
  566. _this.currentIndex = _this.currentIndex + line;
  567. self.overIndex()
  568. }
  569. }
  570. }
  571. }
  572. self.rule = function() {
  573. self.overIndex();
  574. if (_this.event.keyCode == btnLeft || _this.event.keyCode == "LEFT") {
  575. self.ruleFn(0, "left")
  576. } else if (_this.event.keyCode == btnRight || _this.event.keyCode == "RIGHT") {
  577. self.ruleFn(2, "right")
  578. } else if (_this.event.keyCode == btnUp || _this.event.keyCode == "UP") {
  579. self.ruleFn(1, "up")
  580. } else if (_this.event.keyCode == btnDown || _this.event.keyCode == "DOWN") {
  581. self.ruleFn(3, "down")
  582. }
  583. self.overIndex()
  584. }
  585. this.back=function(){
  586. _this.event.keyCode=8;
  587. self.onPressdo(_this.event);
  588. }
  589. // this.makepress=function(k){
  590. // if(k==""){
  591. // _this.event.keyCode=btnLeft;
  592. // }else if(k=="RIGHT"){
  593. // _this.event.keyCode=btnRight;
  594. // }else if(k=="UP"){
  595. // _this.event.keyCode=btnUp;
  596. // }else if(k=="DOWN"){
  597. // _this.event.keyCode=btnDown;
  598. // }else if(k=="ENTER"){
  599. // _this.event.keyCode=btnEnter;
  600. // }
  601. // self.onPressdo(_this.event);
  602. // }
  603. self.onPressdo = function(e) {
  604. _this.event = e;
  605. _this.currentIndex = _this.currentIndex >= element.length - 1 ? element.length - 1 : _this.currentIndex;
  606. _this.prev = element[_this.currentIndex];
  607. _this.prevIndex = _this.currentIndex;
  608. self.rule();
  609. _this.current = element[_this.currentIndex];
  610. _this.currentIndex = _this.currentIndex;
  611. _this.className = _this.className;
  612. //$.tips(e.keyCode)
  613. if (e.keyCode == 8 || e.keyCode == 27 || e.keyCode == "BACK") {
  614. if (rules["#" + _this.currentId + ">." +_this.className] && (typeof rules["#" + _this.currentId + ">." +_this.className]["onBack"]) == "function") rules["#" + _this.currentId + ">." +_this.className]["onBack"].call(_this);
  615. else if (rules[_this.className] && (typeof rules[_this.className]["onBack"]) == "function") rules[_this.className]["onBack"].call(_this);
  616. else _this.onBack.call(_this)
  617. }
  618. if (rules && rules["#" + _this.currentId + ">." + _this.className] && (typeof rules["#" + _this.currentId + ">." + _this.className]["onPress"]) == "function")
  619. init.rules["#" + _this.currentId + ">." + _this.className]["onPress"].call(_this);
  620. else if (rules && rules[_this.className] && (typeof rules[_this.className]["onPress"]) == "function")
  621. init.rules[_this.className]["onPress"].call(_this);
  622. else _this.onPress.call(_this);
  623. if (e.keyCode == btnEnter || e.keyCode == "ENTER") {
  624. if (rules["#" + _this.currentId + ">." +_this.className] && (typeof rules["#" + _this.currentId + ">." +_this.className]["onEnterPress"]) == "function") rules["#" + _this.currentId + ">." +_this.className]["onEnterPress"].call(_this);
  625. else if (rules[_this.className] && (typeof rules[_this.className]["onEnterPress"]) == "function") rules[_this.className]["onEnterPress"].call(_this);
  626. else _this.onEnterPress.call(_this)
  627. }
  628. _self.classDo(_this.currentIndex);
  629. keydefault(e)
  630. }
  631. this.onLoad();
  632. }
  633. window.tvSysBtnBind = tvSysBtnBind
  634. })(window)