winlin.utility.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. // winlin.utility.js
  2. /**
  3. * common utilities
  4. * depends: jquery1.10
  5. * https://gitee.com/winlinvip/codes/rpn0c2ewbomj81augzk4y59
  6. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  7. * v 1.0.22
  8. */
  9. /**
  10. * padding the output.
  11. * padding(3, 5, '0') is 00003
  12. * padding(3, 5, 'x') is xxxx3
  13. * @see http://blog.csdn.net/win_lin/article/details/12065413
  14. */
  15. function padding(number, length, prefix) {
  16. if(String(number).length >= length){
  17. return String(number);
  18. }
  19. return padding(prefix+number, length, prefix);
  20. }
  21. /**
  22. * extends system array, to remove all specified elem.
  23. * @param arr the array to remove elem from.
  24. * @param elem the elem to remove.
  25. * @remark all elem will be removed.
  26. * for example,
  27. * arr = [10, 15, 20, 30, 20, 40]
  28. * system_array_remove(arr, 10) // arr=[15, 20, 30, 20, 40]
  29. * system_array_remove(arr, 20) // arr=[15, 30, 40]
  30. */
  31. function system_array_remove(arr, elem) {
  32. if (!arr) {
  33. return;
  34. }
  35. var removed = true;
  36. var i = 0;
  37. while (removed) {
  38. removed = false;
  39. for (; i < arr.length; i++) {
  40. if (elem == arr[i]) {
  41. arr.splice(i, 1);
  42. removed = true;
  43. break;
  44. }
  45. }
  46. }
  47. }
  48. /**
  49. * whether the array contains specified element.
  50. * @param arr the array to find.
  51. * @param elem_or_function the element value or compare function.
  52. * @returns true contains elem; otherwise false.
  53. * for example,
  54. * arr = [10, 15, 20, 30, 20, 40]
  55. * system_array_contains(arr, 10) // true
  56. * system_array_contains(arr, 11) // false
  57. * system_array_contains(arr, function(elem){return elem == 30;}); // true
  58. * system_array_contains(arr, function(elem){return elem == 60;}); // false
  59. */
  60. function system_array_contains(arr, elem_or_function) {
  61. return system_array_get(arr, elem_or_function) != null;
  62. }
  63. /**
  64. * get the specified element from array
  65. * @param arr the array to find.
  66. * @param elem_or_function the element value or compare function.
  67. * @returns the matched elem; otherwise null.
  68. * for example,
  69. * arr = [10, 15, 20, 30, 20, 40]
  70. * system_array_get(arr, 10) // 10
  71. * system_array_get(arr, 11) // null
  72. * system_array_get(arr, function(elem){return elem == 30;}); // 30
  73. * system_array_get(arr, function(elem){return elem == 60;}); // null
  74. */
  75. function system_array_get(arr, elem_or_function) {
  76. for (var i = 0; i < arr.length; i++) {
  77. if (typeof elem_or_function == "function") {
  78. if (elem_or_function(arr[i])) {
  79. return arr[i];
  80. }
  81. } else {
  82. if (elem_or_function == arr[i]) {
  83. return arr[i];
  84. }
  85. }
  86. }
  87. return null;
  88. }
  89. /**
  90. * to iterate on array.
  91. * @param arr the array to iterate on.
  92. * @param pfn the function to apply on it. return false to break loop.
  93. * for example,
  94. * arr = [10, 15, 20, 30, 20, 40]
  95. * system_array_foreach(arr, function(elem, index){
  96. * console.log('index=' + index + ',elem=' + elem);
  97. * });
  98. * @return true when iterate all elems.
  99. */
  100. function system_array_foreach(arr, pfn) {
  101. if (!pfn) {
  102. return false;
  103. }
  104. for (var i = 0; i < arr.length; i++) {
  105. if (!pfn(arr[i], i)) {
  106. return false;
  107. }
  108. }
  109. return true;
  110. }
  111. /**
  112. * whether the str starts with flag.
  113. */
  114. function system_string_startswith(str, flag) {
  115. if (typeof flag == "object" && flag.constructor == Array) {
  116. for (var i = 0; i < flag.length; i++) {
  117. if (system_string_startswith(str, flag[i])) {
  118. return true;
  119. }
  120. }
  121. }
  122. return str && flag && str.length >= flag.length && str.indexOf(flag) == 0;
  123. }
  124. /**
  125. * whether the str ends with flag.
  126. */
  127. function system_string_endswith(str, flag) {
  128. if (typeof flag == "object" && flag.constructor == Array) {
  129. for (var i = 0; i < flag.length; i++) {
  130. if (system_string_endswith(str, flag[i])) {
  131. return true;
  132. }
  133. }
  134. }
  135. return str && flag && str.length >= flag.length && str.indexOf(flag) == str.length - flag.length;
  136. }
  137. /**
  138. * trim the start and end of flag in str.
  139. * @param flag a string to trim.
  140. */
  141. function system_string_trim(str, flag) {
  142. if (!flag || !flag.length || typeof flag != "string") {
  143. return str;
  144. }
  145. while (system_string_startswith(str, flag)) {
  146. str = str.slice(flag.length);
  147. }
  148. while (system_string_endswith(str, flag)) {
  149. str = str.slice(0, str.length - flag.length);
  150. }
  151. return str;
  152. }
  153. /**
  154. * array sort asc, for example:
  155. * [a, b] in [10, 11, 9]
  156. * then sort to: [9, 10, 11]
  157. * Usage, for example:
  158. obj.data.data.sort(function(a, b){
  159. return array_sort_asc(a.metadata.meta_id, b.metadata.meta_id);
  160. });
  161. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  162. * @remark, if need desc, use -1*array_sort_asc(a,b)
  163. */
  164. function array_sort_asc(elem_a, elem_b) {
  165. if (elem_a > elem_b) {
  166. return 1;
  167. }
  168. return (elem_a < elem_b)? -1 : 0;
  169. }
  170. function array_sort_desc(elem_a, elem_b) {
  171. return -1 * array_sort_asc(elem_a, elem_b);
  172. }
  173. function system_array_sort_asc(elem_a, elem_b) {
  174. return array_sort_asc(elem_a, elem_b);
  175. }
  176. function system_array_sort_desc(elem_a, elem_b) {
  177. return -1 * array_sort_asc(elem_a, elem_b);
  178. }
  179. /**
  180. * parse the query string to object.
  181. * parse the url location object as: host(hostname:http_port), pathname(dir/filename)
  182. * for example, url http://192.168.1.168:1980/ui/players.html?vhost=player.vhost.com&app=test&stream=livestream
  183. * parsed to object:
  184. {
  185. host : "192.168.1.168:1980",
  186. hostname : "192.168.1.168",
  187. http_port : 1980,
  188. pathname : "/ui/players.html",
  189. dir : "/ui",
  190. filename : "/players.html",
  191. vhost : "player.vhost.com",
  192. app : "test",
  193. stream : "livestream"
  194. }
  195. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  196. */
  197. function parse_query_string(){
  198. var obj = {};
  199. // add the uri object.
  200. // parse the host(hostname:http_port), pathname(dir/filename)
  201. obj.host = window.location.host;
  202. obj.hostname = window.location.hostname;
  203. obj.http_port = (window.location.port == "")? 80:window.location.port;
  204. obj.pathname = window.location.pathname;
  205. if (obj.pathname.lastIndexOf("/") <= 0) {
  206. obj.dir = "/";
  207. obj.filename = "";
  208. } else {
  209. obj.dir = obj.pathname.slice(0, obj.pathname.lastIndexOf("/"));
  210. obj.filename = obj.pathname.slice(obj.pathname.lastIndexOf("/"));
  211. }
  212. // pure user query object.
  213. obj.user_query = {};
  214. // parse the query string.
  215. var query_string = String(window.location.search).replace(" ", "").split("?")[1];
  216. if(query_string === undefined){
  217. query_string = String(window.location.hash).replace(" ", "").split("#")[1];
  218. if(query_string === undefined){
  219. return obj;
  220. }
  221. }
  222. __fill_query(query_string, obj);
  223. return obj;
  224. }
  225. function __fill_query(query_string, obj) {
  226. // pure user query object.
  227. obj.user_query = {};
  228. if (query_string.length === 0) {
  229. return;
  230. }
  231. // split again for angularjs.
  232. if (query_string.indexOf("?") >= 0) {
  233. query_string = query_string.split("?")[1];
  234. }
  235. var queries = query_string.split("&");
  236. for (var i = 0; i < queries.length; i++) {
  237. var elem = queries[i];
  238. var query = elem.split("=");
  239. obj[query[0]] = query[1];
  240. obj.user_query[query[0]] = query[1];
  241. }
  242. // alias domain for vhost.
  243. if (obj.domain) {
  244. obj.vhost = obj.domain;
  245. }
  246. }
  247. /**
  248. * parse the rtmp url,
  249. * for example: rtmp://demo.srs.com:1935/live...vhost...players/livestream
  250. * @return object {server, port, vhost, app, stream}
  251. * for exmaple, rtmp_url is rtmp://demo.srs.com:1935/live...vhost...players/livestream
  252. * parsed to object:
  253. {
  254. server: "demo.srs.com",
  255. port: 1935,
  256. vhost: "players",
  257. app: "live",
  258. stream: "livestream"
  259. }
  260. */
  261. function parse_rtmp_url(rtmp_url) {
  262. // @see: http://stackoverflow.com/questions/10469575/how-to-use-location-object-to-parse-url-without-redirecting-the-page-in-javascri
  263. var a = document.createElement("a");
  264. a.href = rtmp_url.replace("rtmp://", "http://")
  265. .replace("webrtc://", "http://")
  266. .replace("rtc://", "http://");
  267. var vhost = a.hostname;
  268. var app = a.pathname.substring(1, a.pathname.lastIndexOf("/"));
  269. var stream = a.pathname.slice(a.pathname.lastIndexOf("/") + 1);
  270. // parse the vhost in the params of app, that srs supports.
  271. app = app.replace("...vhost...", "?vhost=");
  272. if (app.indexOf("?") >= 0) {
  273. var params = app.slice(app.indexOf("?"));
  274. app = app.slice(0, app.indexOf("?"));
  275. if (params.indexOf("vhost=") > 0) {
  276. vhost = params.slice(params.indexOf("vhost=") + "vhost=".length);
  277. if (vhost.indexOf("&") > 0) {
  278. vhost = vhost.slice(0, vhost.indexOf("&"));
  279. }
  280. }
  281. }
  282. // when vhost equals to server, and server is ip,
  283. // the vhost is __defaultVhost__
  284. if (a.hostname === vhost) {
  285. var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
  286. if (re.test(a.hostname)) {
  287. vhost = "__defaultVhost__";
  288. }
  289. }
  290. // parse the schema
  291. var schema = "rtmp";
  292. if (rtmp_url.indexOf("://") > 0) {
  293. schema = rtmp_url.slice(0, rtmp_url.indexOf("://"));
  294. }
  295. var port = a.port;
  296. if (!port) {
  297. if (schema === 'http') {
  298. port = 80;
  299. } else if (schema === 'https') {
  300. port = 443;
  301. } else if (schema === 'rtmp') {
  302. port = 1935;
  303. }
  304. }
  305. var ret = {
  306. url: rtmp_url,
  307. schema: schema,
  308. server: a.hostname, port: port,
  309. vhost: vhost, app: app, stream: stream
  310. };
  311. __fill_query(a.search, ret);
  312. // For webrtc API, we use 443 if page is https, or schema specified it.
  313. if (!ret.port) {
  314. if (schema === 'webrtc' || schema === 'rtc') {
  315. if (ret.user_query.schema === 'https') {
  316. ret.port = 443;
  317. } else if (window.location.href.indexOf('https://') === 0) {
  318. ret.port = 443;
  319. } else {
  320. ret.port = 80;
  321. }
  322. }
  323. }
  324. return ret;
  325. }
  326. /**
  327. * get the agent.
  328. * @return an object specifies some browser.
  329. * for example, get_browser_agents().MSIE
  330. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  331. */
  332. function get_browser_agents() {
  333. var agent = navigator.userAgent;
  334. /**
  335. WindowsPC platform, Win7:
  336. chrome 31.0.1650.63:
  337. Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
  338. (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
  339. firefox 23.0.1:
  340. Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101
  341. Firefox/23.0
  342. safari 5.1.7(7534.57.2):
  343. Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2
  344. (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
  345. opera 15.0.1147.153:
  346. Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36
  347. (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
  348. OPR/15.0.1147.153
  349. 360 6.2.1.272:
  350. Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64;
  351. Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729;
  352. .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C;
  353. .NET4.0E)
  354. IE 10.0.9200.16750(update: 10.0.12):
  355. Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64;
  356. Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729;
  357. .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C;
  358. .NET4.0E)
  359. */
  360. return {
  361. // platform
  362. Android: agent.indexOf("Android") != -1,
  363. Windows: agent.indexOf("Windows") != -1,
  364. iPhone: agent.indexOf("iPhone") != -1,
  365. // Windows Browsers
  366. Chrome: agent.indexOf("Chrome") != -1,
  367. Firefox: agent.indexOf("Firefox") != -1,
  368. QQBrowser: agent.indexOf("QQBrowser") != -1,
  369. MSIE: agent.indexOf("MSIE") != -1,
  370. // Android Browsers
  371. Opera: agent.indexOf("Presto") != -1,
  372. MQQBrowser: agent.indexOf("MQQBrowser") != -1
  373. };
  374. }
  375. /**
  376. * format relative seconds to HH:MM:SS,
  377. * for example, 210s formated to 00:03:30
  378. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  379. * @usage relative_seconds_to_HHMMSS(210)
  380. */
  381. function relative_seconds_to_HHMMSS(seconds){
  382. var date = new Date();
  383. date.setTime(Number(seconds) * 1000);
  384. var ret = padding(date.getUTCHours(), 2, '0')
  385. + ":" + padding(date.getUTCMinutes(), 2, '0')
  386. + ":" + padding(date.getUTCSeconds(), 2, '0');
  387. return ret;
  388. }
  389. /**
  390. * format absolute seconds to HH:MM:SS,
  391. * for example, 1389146480s (2014-01-08 10:01:20 GMT+0800) formated to 10:01:20
  392. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  393. * @usage absolute_seconds_to_HHMMSS(new Date().getTime() / 1000)
  394. */
  395. function absolute_seconds_to_HHMMSS(seconds){
  396. var date = new Date();
  397. date.setTime(Number(seconds) * 1000);
  398. var ret = padding(date.getHours(), 2, '0')
  399. + ":" + padding(date.getMinutes(), 2, '0')
  400. + ":" + padding(date.getSeconds(), 2, '0');
  401. return ret;
  402. }
  403. /**
  404. * format absolute seconds to YYYY-mm-dd,
  405. * for example, 1389146480s (2014-01-08 10:01:20 GMT+0800) formated to 2014-01-08
  406. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  407. * @usage absolute_seconds_to_YYYYmmdd(new Date().getTime() / 1000)
  408. */
  409. function absolute_seconds_to_YYYYmmdd(seconds) {
  410. var date = new Date();
  411. date.setTime(Number(seconds) * 1000);
  412. var ret = date.getFullYear()
  413. + "-" + padding(date.getMonth() + 1, 2, '0')
  414. + "-" + padding(date.getDate(), 2, '0');
  415. return ret;
  416. }
  417. /**
  418. * parse the date in str to Date object.
  419. * @param str the date in str, format as "YYYY-mm-dd", for example, 2014-12-11
  420. * @returns a date object.
  421. * @usage YYYYmmdd_parse("2014-12-11")
  422. */
  423. function YYYYmmdd_parse(str) {
  424. var date = new Date();
  425. date.setTime(Date.parse(str));
  426. return date;
  427. }
  428. /**
  429. * async refresh function call. to avoid multiple call.
  430. * @remark AsyncRefresh is for jquery to refresh the speicified pfn in a page;
  431. * if angularjs, use AsyncRefresh2 to change pfn, cancel previous request for angularjs use singleton object.
  432. * @param refresh_interval the default refresh interval ms.
  433. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  434. * the pfn can be implements as following:
  435. var async_refresh = new AsyncRefresh(pfn, 3000);
  436. function pfn() {
  437. if (!async_refresh.refresh_is_enabled()) {
  438. async_refresh.request(100);
  439. return;
  440. }
  441. $.ajax({
  442. type: 'GET', async: true, url: 'xxxxx',
  443. complete: function(){
  444. if (!async_refresh.refresh_is_enabled()) {
  445. async_refresh.request(0);
  446. } else {
  447. async_refresh.request(async_refresh.refresh_interval);
  448. }
  449. },
  450. success: function(res){
  451. // if donot allow refresh, directly return.
  452. if (!async_refresh.refresh_is_enabled()) {
  453. return;
  454. }
  455. // render the res.
  456. }
  457. });
  458. }
  459. */
  460. function AsyncRefresh(pfn, refresh_interval) {
  461. this.refresh_interval = refresh_interval;
  462. this.__handler = null;
  463. this.__pfn = pfn;
  464. this.__enabled = true;
  465. }
  466. /**
  467. * disable the refresher, the pfn must check the refresh state.
  468. */
  469. AsyncRefresh.prototype.refresh_disable = function() {
  470. this.__enabled = false;
  471. }
  472. AsyncRefresh.prototype.refresh_enable = function() {
  473. this.__enabled = true;
  474. }
  475. AsyncRefresh.prototype.refresh_is_enabled = function() {
  476. return this.__enabled;
  477. }
  478. /**
  479. * start new async request
  480. * @param timeout the timeout in ms.
  481. * user can use the refresh_interval of the AsyncRefresh object,
  482. * which initialized in constructor.
  483. */
  484. AsyncRefresh.prototype.request = function(timeout) {
  485. if (this.__handler) {
  486. clearTimeout(this.__handler);
  487. }
  488. this.__handler = setTimeout(this.__pfn, timeout);
  489. }
  490. /**
  491. * async refresh v2, support cancellable refresh, and change the refresh pfn.
  492. * @remakr for angularjs. if user only need jquery, maybe AsyncRefresh is better.
  493. * @see: http://blog.csdn.net/win_lin/article/details/17994347
  494. * Usage:
  495. bsmControllers.controller('CServers', ['$scope', 'MServer', function($scope, MServer){
  496. async_refresh2.refresh_change(function(){
  497. // 获取服务器列表
  498. MServer.servers_load({}, function(data){
  499. $scope.servers = data.data.servers;
  500. async_refresh2.request();
  501. });
  502. }, 3000);
  503. async_refresh2.request(0);
  504. }]);
  505. bsmControllers.controller('CStreams', ['$scope', 'MStream', function($scope, MStream){
  506. async_refresh2.refresh_change(function(){
  507. // 获取流列表
  508. MStream.streams_load({}, function(data){
  509. $scope.streams = data.data.streams;
  510. async_refresh2.request();
  511. });
  512. }, 3000);
  513. async_refresh2.request(0);
  514. }]);
  515. */
  516. function AsyncRefresh2() {
  517. /**
  518. * the function callback before call the pfn.
  519. * the protype is function():bool, which return true to invoke, false to abort the call.
  520. * null to ignore this callback.
  521. *
  522. * for example, user can abort the refresh by find the class popover:
  523. * async_refresh2.on_before_call_pfn = function() {
  524. * if ($(".popover").length > 0) {
  525. * async_refresh2.request();
  526. * return false;
  527. * }
  528. * return true;
  529. * };
  530. */
  531. this.on_before_call_pfn = null;
  532. // use a anonymous function to call, and check the enabled when actually invoke.
  533. this.__call = {
  534. pfn: null,
  535. timeout: 0,
  536. __enabled: false,
  537. __handler: null
  538. };
  539. }
  540. // singleton
  541. var async_refresh2 = new AsyncRefresh2();
  542. /**
  543. * initialize or refresh change. cancel previous request, setup new request.
  544. * @param pfn a function():void to request after timeout. null to disable refresher.
  545. * @param timeout the timeout in ms, to call pfn. null to disable refresher.
  546. */
  547. AsyncRefresh2.prototype.initialize = function(pfn, timeout) {
  548. this.refresh_change(pfn, timeout);
  549. }
  550. /**
  551. * stop refresh, the refresh pfn is set to null.
  552. */
  553. AsyncRefresh2.prototype.stop = function() {
  554. this.__call.__enabled = false;
  555. }
  556. /**
  557. * restart refresh, use previous config.
  558. */
  559. AsyncRefresh2.prototype.restart = function() {
  560. this.__call.__enabled = true;
  561. this.request(0);
  562. }
  563. /**
  564. * change refresh pfn, the old pfn will set to disabled.
  565. */
  566. AsyncRefresh2.prototype.refresh_change = function(pfn, timeout) {
  567. // cancel the previous call.
  568. if (this.__call.__handler) {
  569. clearTimeout(this.__handler);
  570. }
  571. this.__call.__enabled = false;
  572. // setup new call.
  573. this.__call = {
  574. pfn: pfn,
  575. timeout: timeout,
  576. __enabled: true,
  577. __handler: null
  578. };
  579. }
  580. /**
  581. * start new request, we never auto start the request,
  582. * user must start new request when previous completed.
  583. * @param timeout [optional] if not specified, use the timeout in initialize or refresh_change.
  584. */
  585. AsyncRefresh2.prototype.request = function(timeout) {
  586. var self = this;
  587. var this_call = this.__call;
  588. // clear previous timeout.
  589. if (this_call.__handler) {
  590. clearTimeout(this_call.__handler);
  591. }
  592. // override the timeout
  593. if (timeout == undefined) {
  594. timeout = this_call.timeout;
  595. }
  596. // if user disabled refresher.
  597. if (this_call.pfn == null || timeout == null) {
  598. return;
  599. }
  600. this_call.__handler = setTimeout(function(){
  601. // cancelled by refresh_change, ignore.
  602. if (!this_call.__enabled) {
  603. return;
  604. }
  605. // callback if the handler installled.
  606. if (self.on_before_call_pfn) {
  607. if (!self.on_before_call_pfn()) {
  608. return;
  609. }
  610. }
  611. // do the actual call.
  612. this_call.pfn();
  613. }, timeout);
  614. }