txlib.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  1. /** @namespace */
  2. var $tx = {};
  3. (function() {
  4. /**
  5. * @function
  6. */
  7. Object.extend = function(destination, source) {
  8. for (var property in source) {
  9. destination[property] = source[property];
  10. }
  11. return destination;
  12. };
  13. _WIN.Class = {
  14. create: function() {
  15. return function() {
  16. this.initialize.apply(this, arguments);
  17. };
  18. }
  19. };
  20. /**
  21. * @class
  22. */
  23. _WIN.$break = {};
  24. /**
  25. * 함수(=메소드) 소유자 객체로 미리 묶는 함수의 인스턴스를 반환. 반환된 함수는 원래의 것과 같은 인자를 가질 것이다.
  26. * @function
  27. */
  28. Function.prototype.bind = function() {
  29. var __method = this, args = $A(arguments), object = args.shift();
  30. return function() {
  31. return __method.apply(object, args.concat($A(arguments)));
  32. };
  33. };
  34. /**
  35. * 유하는 객체 함수(=메소드) 소유자 객체로 미리 묶는 함수의 인스턴스를 반환. 반환된 함수는 이것의 인자로 현재 이벤트 객체를 가질것이다.
  36. * @function
  37. */
  38. Function.prototype.bindAsEventListener = function() {
  39. var __method = this, args = $A(arguments), object = args.shift();
  40. return function(event) {
  41. return __method.apply(object, [event || _WIN.event].concat(args));
  42. };
  43. };
  44. var txlib = function(element) {
  45. var args = arguments;
  46. if (args.length > 1) {
  47. for (var i = 0, elements = [], length = args.length; i < length; i++)
  48. elements.push($tx(args[i]));
  49. return elements;
  50. }
  51. if (typeof element == 'string') {
  52. element = _DOC.getElementById(element);
  53. }
  54. return element;
  55. };
  56. $tx = txlib;
  57. var txua = navigator.userAgent.toLowerCase();
  58. var isExistAgentString = function(str){
  59. return txua.indexOf(str)!=-1;
  60. };
  61. var isExistAgentStringByRegx = function(regx){
  62. return regx.test(txua);
  63. };
  64. Object.extend($tx, /** @lends $tx */{
  65. /**
  66. * Chrome browser 이면 true
  67. * @field
  68. */
  69. chrome: isExistAgentString("chrome"),
  70. /**
  71. * safari browser 이면 true
  72. * @field
  73. */
  74. safari: isExistAgentString("safari") && isExistAgentString("chrome") == _FALSE,
  75. /**
  76. * Firefox browser 이면 true
  77. * @field
  78. */
  79. gecko: isExistAgentString("firefox"),
  80. /**
  81. * Firefox browser의 버전
  82. * @field
  83. */
  84. gecko_ver: isExistAgentString("firefox")?parseFloat(txua.replace(/.*firefox\/([\d\.]+).*/g,"$1")):0,
  85. /**
  86. * MS IE 이면 true
  87. * IE7 이하는 msie로 구분
  88. * IE8 이상은 trident로 구분
  89. * @field
  90. */
  91. msie: isExistAgentString("msie") || isExistAgentString("trident"),
  92. /**
  93. * MS IE browser 버전 a.match(/rv:(\d+)\.\d+/)
  94. * IE7 이하는 msie로 구분
  95. * IE8 이상은 trident & rv:x로 구분
  96. * @field
  97. */
  98. msie_ver: isExistAgentString("msie") || isExistAgentString("trident")?(function(){
  99. return isExistAgentString("msie") ? parseFloat(txua.split("msie")[1]) : parseFloat(txua.split("rv:")[1]);
  100. })():0,
  101. /**
  102. * MS IE document mode 버전
  103. * @field
  104. */
  105. msie_docmode: _DOC.documentMode || 0,
  106. /**
  107. * AppleWebKit browser 이면 true
  108. * @field
  109. */
  110. webkit: isExistAgentString("applewebkit"),
  111. /**
  112. * AppleWebKit 버전
  113. * @field
  114. */
  115. webkit_ver: isExistAgentString("applewebkit")?parseFloat(txua.replace(/.*safari\//g,"")):0,
  116. /**
  117. * Opera 이면 true
  118. * @field
  119. */
  120. opera: isExistAgentString("opera"),
  121. /**
  122. * Presto browser 이면 true
  123. * @field
  124. */
  125. presto: isExistAgentString("presto"),
  126. os_win: isExistAgentString("win"),
  127. os_win7: isExistAgentString('windows nt 6.1'),
  128. os_win8: isExistAgentString('windows nt 6.2'),
  129. os_win8_1: isExistAgentString('windows nt 6.3'),
  130. os_mac: isExistAgentString("mac"),
  131. /**
  132. * iPhone 이면 true
  133. * @field
  134. */
  135. iphone: isExistAgentString("iphone"),
  136. /**
  137. * iPod 이면 true
  138. * @field
  139. */
  140. ipod: isExistAgentString("ipod"),
  141. /**
  142. * iPad 이면 true
  143. * @field
  144. */
  145. ipad: isExistAgentString("ipad"),
  146. /**
  147. * iPhone, iPod Touch, iPad 이면 true (애플 모바일 OS)
  148. */
  149. ios: isExistAgentString("like mac os x") && isExistAgentString("mobile"),
  150. /**
  151. * iPhone, iPod Touch, iPad 의 iOS 버전
  152. */
  153. ios_ver: (isExistAgentString("like mac os x") && isExistAgentString("mobile")) ? parseFloat(txua.replace(/^.*os (\d+)([_\d]*) .*$/g, "$1.$2").replace(/_/g, "")) : 0,
  154. /**
  155. * Android 이면 true
  156. */
  157. android: isExistAgentString("android"),
  158. /**
  159. * Android OS 버전
  160. */
  161. android_ver: isExistAgentString("android") ? parseFloat(txua.replace(/.*android[\s]*([\d\.]+).*/g, "$1")) : 0,
  162. /**
  163. * BlackBerry 이면 true
  164. */
  165. blackberry: isExistAgentString("blackberry"),
  166. /**
  167. * Windows Phone OS 이면 true
  168. */
  169. winphone: isExistAgentString("windows phone os"),
  170. /**
  171. * Windows CE 이면 true
  172. */
  173. wince: isExistAgentString("windows ce")
  174. });
  175. Object.extend($tx, /** @lends $tx */{
  176. //msie11above: (isExistAgentString("trident") && isExistAgentStringByRegx(/rv:\d+\.\d+/)),//@Deprecated $tx.msie11above
  177. msie_std: ($tx.msie && !_DOC.selection),
  178. msie_nonstd: ($tx.msie && !!_DOC.selection),
  179. msie6: ($tx.msie && 6 <= $tx.msie_ver && $tx.msie_ver < 7),
  180. msie_quirks: (function(){
  181. try {
  182. return $tx.msie && _WIN.top.document.compatMode !== 'CSS1Compat'
  183. } catch(e) {
  184. try {
  185. return _DOC.compatMode !== 'CSS1Compat'
  186. } catch(e) {
  187. return _FALSE;
  188. }
  189. }
  190. })()
  191. });
  192. Object.extend($tx, /** @lends $tx */{
  193. extend: Object.extend,
  194. /**
  195. * browser의 이름 리턴
  196. * @function
  197. */
  198. browser: function() {
  199. if($tx.msie) {
  200. return 'msie';
  201. } else if($tx.gecko) {
  202. return 'firefox';
  203. } else if($tx.chrome) {
  204. return 'chrome';
  205. } else if($tx.webkit) {
  206. return 'safari';
  207. } else if($tx.opera) {
  208. return 'opera';
  209. } else {
  210. return "";
  211. }
  212. }()
  213. });
  214. /**
  215. * @function
  216. */
  217. _WIN.$must = function(id, className) {
  218. var _el = $tx(id);
  219. if (!_el) {
  220. throw new Error("[Exception] " + className + ": cannot find element: id='" + id + "'");
  221. }
  222. return _el;
  223. };
  224. //expose
  225. _WIN.txlib = txlib;
  226. })();
  227. (function() {
  228. /**
  229. * template
  230. * @deprecated
  231. (function() {
  232. window.Template = Class.create();
  233. Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\}|#%7B(.*?)%7D)/;
  234. Template.prototype = {
  235. initialize: function(template, pattern) {
  236. this.template = template.toString();
  237. this.pattern = pattern || Template.Pattern;
  238. },
  239. evaluate: function(object) {
  240. return this.template.gsub(this.pattern, function(match) {
  241. var before = match[1];
  242. if (before == '\\')
  243. return match[2];
  244. return before + String.interpret(object[match[3] || match[4]]);
  245. });
  246. }
  247. };
  248. })();
  249. */
  250. $tx.extend($tx, /** @lends $tx */{
  251. /**
  252. * 주어진 element와 관련된 CSS 클래스명을 표시하는 Element.ClassNames 객체를 반환
  253. * @function
  254. */
  255. classNames: function(el) {
  256. return el.className.split(' ');
  257. },
  258. /**
  259. * 요소가 class명중에 하나로 주어진 class명을 가진다면 true를 반환
  260. * @function
  261. */
  262. hasClassName: function(el, className) {
  263. if (className && el.className) {
  264. var classNames = el.className.split(/\s+/);
  265. return classNames.contains(className);
  266. }
  267. return _FALSE;
  268. },
  269. /**
  270. * 주어진 class명을 요소의 class명으로 추가
  271. * @function
  272. */
  273. addClassName: function(el, c) {
  274. if (!this.hasClassName(el, c)) {
  275. el.className += ' ' + c;
  276. }
  277. },
  278. /**
  279. * 요소의 class명으로 부터 주어진 class명을 제거
  280. * @function
  281. */
  282. removeClassName: function(el, className) {
  283. var classNames = el.className.split(/\s+/);
  284. el.className = classNames.without(className)
  285. .compact()
  286. .join(' ');
  287. },
  288. /**
  289. * 요소가 눈에 보이는지 표시하는 Boolean값을 반환
  290. * @function
  291. */
  292. visible: function(element) {
  293. //return $tx(element).style.display != 'none';
  294. return $tx.getStyle(element, "display" ) != 'none';
  295. },
  296. /**
  297. * 각각의 전달된 요소의 가시성(visibility)을 토글(toggle)한다.
  298. * @function
  299. */
  300. toggle: function(element) {
  301. element = $tx(element);
  302. $tx[$tx.visible(element) ? 'hide' : 'show'](element);
  303. return element;
  304. },
  305. /**
  306. * style.display를 'block'로 셋팅하여 각각의 요소를 보여준다.
  307. * @function
  308. */
  309. show: function(element) {
  310. $tx(element).style.display = 'block';
  311. return element;
  312. },
  313. /**
  314. * style.display를 'none'로 셋팅하여 각각의 요소를 숨긴다.
  315. * @function
  316. */
  317. hide: function(element) {
  318. $tx(element).style.display = 'none';
  319. return element;
  320. }
  321. });
  322. })();
  323. $tx.extend($tx, /** @lends $tx */{
  324. /**
  325. * 인자로 넘겨 받은 Element의 style 속성값을 리턴한다.
  326. * @function
  327. * @param {HTMLElement} element
  328. * @param {string} style property name
  329. */
  330. getStyle: function(element, style) {
  331. element = $tx(element);
  332. style = style == 'float' ? 'cssFloat' : style.camelize();
  333. var value = element.style[style];
  334. if (!value) {
  335. var css = _DOC.defaultView.getComputedStyle(element, _NULL);
  336. value = css ? css[style] : _NULL;
  337. }
  338. if (style == 'opacity')
  339. return value ? parseFloat(value) : 1.0;
  340. return value == 'auto' ? _NULL : value;
  341. },
  342. /**
  343. * 요소의 style 속성을 셋팅한다.
  344. * @function
  345. */
  346. setStyle: function(element, styles, camelized) {
  347. element = $tx(element);
  348. var elementStyle = element.style;
  349. for (var property in styles) {
  350. if (styles.hasOwnProperty(property)) {
  351. if (property === 'opacity') {
  352. $tx.setOpacity(element, styles[property]);
  353. } else {
  354. // TODO What the...
  355. elementStyle[(property === 'float' || property === 'cssFloat') ? (elementStyle.styleFloat === _UNDEFINED ? 'cssFloat' : 'styleFloat') : (camelized ? property : property.camelize())] = styles[property];
  356. }
  357. }
  358. }
  359. // TODO is it necessary?
  360. return element;
  361. },
  362. setStyleProperty: function(element, styles) {
  363. var isCamelizedPropertyName = _TRUE;
  364. this.setStyle(element, styles, isCamelizedPropertyName);
  365. },
  366. /**
  367. * 요소의 style속성 중 opacity 값을 리턴한다.
  368. * @function
  369. */
  370. getOpacity: function(element) {
  371. return $tx(element).getStyle('opacity');
  372. },
  373. /**
  374. * 요소의 opacity style 속성을 셋팅한다.
  375. * @function
  376. */
  377. setOpacity: function(element, value) {
  378. element = $tx(element);
  379. element.style.opacity = (value == 1 || value === '') ? '' : (value < 0.00001) ? 0 : value;
  380. return element;
  381. },
  382. applyCSSText: function(targetDocument, cssText) {
  383. var styleElement = targetDocument.createElement('style');
  384. styleElement.setAttribute("type", "text/css");
  385. if (styleElement.styleSheet) { // IE
  386. styleElement.styleSheet.cssText = cssText;
  387. } else { // the other
  388. styleElement.textContent = cssText;
  389. }
  390. targetDocument.getElementsByTagName('head')[0].appendChild(styleElement);
  391. }
  392. });
  393. (function() {
  394. if ($tx.msie_nonstd) {
  395. $tx.getStyle = function (element, style) {
  396. element = $tx(element);
  397. style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
  398. var value = element.style[style];
  399. if (!value && element.currentStyle)
  400. value = element.currentStyle[style];
  401. if (style == 'opacity') {
  402. if (value = ($tx.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/))
  403. if (value[1])
  404. return parseFloat(value[1]) / 100;
  405. return 1.0;
  406. }
  407. if (value == 'auto') {
  408. if ((style == 'width' || style == 'height') && ($tx.getStyle(element, 'display') != 'none')) {
  409. return element['offset' + style.capitalize()] + 'px';
  410. }
  411. return _NULL;
  412. }
  413. return value;
  414. };
  415. }
  416. if ($tx.msie_nonstd) {
  417. $tx.setOpacity = function (element, value) {
  418. element = $tx(element);
  419. var filter = $tx.getStyle(element, 'filter'), style = element.style;
  420. if (value == 1 || value === '') {
  421. style.filter = filter.replace(/alpha\([^\)]*\)/gi, '');
  422. return element;
  423. } else if (value < 0.00001)
  424. value = 0;
  425. style.filter = filter.replace(/alpha\([^\)]*\)/gi, '') +
  426. 'alpha(opacity=' +
  427. (value * 100) +
  428. ')';
  429. return element;
  430. };
  431. }
  432. if ($tx.gecko) {
  433. $tx.extend($tx, {
  434. setOpacity: function(element, value) {
  435. element = $tx(element);
  436. element.style.opacity = (value == 1) ? 0.999999 : (value === '') ? '' : (value < 0.00001) ? 0 : value;
  437. return element;
  438. }
  439. });
  440. }
  441. // json2.js helper functions
  442. $tx.JSONHelper = {
  443. /**
  444. * JSON.stringify 시에 문자열을 encodeURIComponent 처리 하여준다.
  445. * @example JSON.stringify(object, $tx.JSONHelper.encodeURIComponentReplacer);
  446. */
  447. encodeURIComponentReplacer: function (key, value) {
  448. if (typeof value === 'string') {
  449. if (!isStringifiedArray(value)) {
  450. return encodeURIComponent(value);
  451. }
  452. }
  453. return value;
  454. },
  455. /**
  456. * JSON.parse 시에 문자열을 decodeURIComponent 처리 하여준다.
  457. * @example JSON.parse(object, $tx.JSONHelper.decodeURIComponentReviver);
  458. */
  459. decodeURIComponentReviver: function (key, value) {
  460. if (typeof value === 'string') {
  461. if (!isStringifiedArray(value)) {
  462. return decodeURIComponent(value);
  463. } else {
  464. // "{ \"string\": \"[1,2,3]\" }" 의 경우 => { "string": [1, 2, 3] } 으로 파싱된다.
  465. // WHY???
  466. try {
  467. // "[말머리]" 와 같은 값은 파싱 중 오류가 발생한다. 이런 경우는 무시하고 value를 그대로 반환하도록 한다. #FTDUEDTR-1432
  468. return JSON.parse(value, arguments.callee);
  469. } catch(ignore) {}
  470. }
  471. }
  472. return value;
  473. }
  474. };
  475. // 이 문자열이 "[1, 3, 4]" 와 같이 배열을 Stringify 한 것인지 확인한다
  476. var isStringifiedArray = function (str) {
  477. if (str.charAt(0) == "[" && str.charAt(str.length - 1) == "]") {
  478. try{
  479. JSON.parse(str);
  480. return true;
  481. }catch (ignore) {}
  482. }
  483. return false;
  484. };
  485. })();
  486. //position
  487. (function() {
  488. $tx.extend($tx, /** @lends $tx */ {
  489. /**
  490. * 요소의 최상위 요소까지의 offset position 을 더한 값을 리턴한다.
  491. * @function
  492. */
  493. cumulativeOffset: function(element) {
  494. var valueT = 0, valueL = 0;
  495. do {
  496. valueT += element.offsetTop || 0;
  497. valueL += element.offsetLeft || 0;
  498. element = element.offsetParent;
  499. } while (element);
  500. return [valueL, valueT];
  501. },
  502. /**
  503. * 요소의 최상위 요소까지의 offset position 을 더한 값을 리턴한다.
  504. * 상위 요소가 body이거나 position이 relative 또는 absolute 인 경우 계산을 중지한다.
  505. * @function
  506. */
  507. positionedOffset: function(element) {
  508. var valueT = 0, valueL = 0;
  509. do {
  510. valueT += element.offsetTop || 0;
  511. valueL += element.offsetLeft || 0;
  512. element = element.offsetParent;
  513. if (element) {
  514. if (element.tagName == 'BODY')
  515. break;
  516. var p = $tx.getStyle(element, 'position');
  517. if (p == 'relative' || p == 'absolute')
  518. break;
  519. }
  520. } while (element);
  521. return [valueL, valueT];
  522. },
  523. /**
  524. * element의 면적(dimensions)을 반환. 반환된 값은 두개의 프라퍼티(height 와 width)를 가지는 객체이다.
  525. * @function
  526. */
  527. getDimensions: function(element) {
  528. var display = $tx.getStyle(element, 'display');
  529. if (display != 'none' && display != _NULL) // Safari bug
  530. return {width: element.offsetWidth, height: element.offsetHeight};
  531. // All *Width and *Height properties give 0 on elements with display none,
  532. // so enable the element temporarily
  533. var els = element.style;
  534. var originalVisibility = els.visibility;
  535. var originalPosition = els.position;
  536. var originalDisplay = els.display;
  537. els.visibility = 'hidden';
  538. els.position = 'absolute';
  539. els.display = 'block';
  540. var originalWidth = element.clientWidth;
  541. var originalHeight = element.clientHeight;
  542. els.display = originalDisplay;
  543. els.position = originalPosition;
  544. els.visibility = originalVisibility;
  545. return {width: originalWidth, height: originalHeight};
  546. },
  547. /**
  548. * 요소의 최상위 요소까지의 offset position 을 더한 값을 리턴한다.
  549. * 상위 요소가 body이거나 position이 relative 또는 absolute 인 경우 계산을 중지한다.
  550. * left, top, right, bottom 값을 리턴한다.
  551. * @function
  552. */
  553. getCoords : function(e, useOffset) {
  554. var uo = useOffset || false;
  555. var w = e.offsetWidth;
  556. var h = e.offsetHeight;
  557. var coords = { "left": 0, "top": 0, "right": 0, "bottom": 0 };
  558. var p;
  559. while(e){
  560. coords.left += e.offsetLeft || 0;
  561. coords.top += e.offsetTop || 0;
  562. e = e.offsetParent;
  563. if(uo){
  564. if(e){
  565. if(e.tagName == "BODY"){break;}
  566. p = $tx.getStyle(e, "position");
  567. if(p !== "static"){break;}
  568. }
  569. }
  570. }
  571. coords.right = coords.left + w;
  572. coords.bottom = coords.top + h;
  573. return coords;
  574. },
  575. getCoordsTarget: function(element){
  576. return this.getCoords(element, _TRUE);
  577. }
  578. });
  579. // Safari returns margins on body which is incorrect if the child is absolutely
  580. // positioned. For performance reasons, redefine Position.cumulativeOffset for
  581. // KHTML/WebKit only.
  582. if ($tx.webkit) {
  583. $tx.cumulativeOffset = function(element) {
  584. var valueT = 0, valueL = 0;
  585. do {
  586. valueT += element.offsetTop || 0;
  587. valueL += element.offsetLeft || 0;
  588. if (element.offsetParent == _DOC.body)
  589. if ($tx.getStyle(element, 'position') == 'absolute')
  590. break;
  591. element = element.offsetParent;
  592. } while (element);
  593. return [valueL, valueT];
  594. };
  595. }
  596. })();
  597. //events
  598. (function () /** @lends $tx */ {
  599. $tx.extend($tx, {
  600. /** @field backspace key */
  601. KEY_BACKSPACE: 8,
  602. /** @field tab key */
  603. KEY_TAB: 9,
  604. /** @field return key */
  605. KEY_RETURN: 13,
  606. /** @field esc key */
  607. KEY_ESC: 27,
  608. /** @field left key */
  609. KEY_LEFT: 37,
  610. /** @field up key */
  611. KEY_UP: 38,
  612. /** @field right key */
  613. KEY_RIGHT: 39,
  614. /** @field down key */
  615. KEY_DOWN: 40,
  616. /** @field delete key */
  617. KEY_DELETE: 46,
  618. /** @field home key */
  619. KEY_HOME: 36,
  620. /** @field end key */
  621. KEY_END: 35,
  622. /** @field pageup key */
  623. KEY_PAGEUP: 33,
  624. /** @field pagedown key */
  625. KEY_PAGEDOWN: 34,
  626. /**
  627. * 이벤트의 target 또는 srcElement 를 반환
  628. * @function
  629. */
  630. element: function(event) {
  631. return $tx(event.target || event.srcElement);
  632. },
  633. /**
  634. * 마우스 왼쪽 버튼을 클릭시 true값 반환
  635. * @function
  636. */
  637. isLeftClick: function(event) {
  638. return (((event.which) && (event.which == 1)) ||
  639. ((event.button) && (event.button == 1)));
  640. },
  641. /**
  642. * 페이지에서 마우스 포인터의 x측 좌표값 반환
  643. * @function
  644. */
  645. pointerX: function(event) {
  646. return event.pageX ||
  647. (event.clientX +
  648. (_DOC.documentElement.scrollLeft || _DOC.body.scrollLeft));
  649. },
  650. /**
  651. * 페이지에서 마우스 포인터의 y측 좌표값 반환
  652. * @function
  653. */
  654. pointerY: function(event) {
  655. return event.pageY ||
  656. (event.clientY +
  657. (_DOC.documentElement.scrollTop || _DOC.body.scrollTop));
  658. },
  659. /**
  660. * 이벤트의 디폴트 행위를 취소하고 위임을 연기하기 위해 이 함수를 사용
  661. * @function
  662. */
  663. stop: function(event) {
  664. if (event.preventDefault) {
  665. event.preventDefault();
  666. event.stopPropagation();
  667. } else {
  668. event.returnValue = _FALSE;
  669. event.cancelBubble = _TRUE;
  670. }
  671. },
  672. /**
  673. * 이벤트가 시작된 노드로부터 상위로 순회하며 주어진 태그이름을 갖는 첫번째 노드를 찾는다.
  674. * find the first node with the given tagName, starting from the
  675. * node the event was triggered on; traverses the DOM upwards
  676. * @function
  677. */
  678. findElement: function(event, tagName) {
  679. var element = $tx.element(event);
  680. while (element.parentNode &&
  681. (!element.tagName || !element.tagName.toUpperCase ||
  682. (element.tagName.toUpperCase() != tagName.toUpperCase())))
  683. element = element.parentNode;
  684. return element;
  685. },
  686. observers: _FALSE,
  687. _observeAndCache: function(element, name, observer, useCapture) {
  688. if (!this.observers)
  689. this.observers = [];
  690. if (element.addEventListener) {
  691. this.observers.push([element, name, observer, useCapture]);
  692. element.addEventListener(name, observer, useCapture);
  693. } else if (element.attachEvent) {
  694. this.observers.push([element, name, observer, useCapture]);
  695. element.attachEvent('on' + name, observer);
  696. }
  697. },
  698. simulateEvent: function(elem, eventName, event) {
  699. var observers = $tx.observers;
  700. if (!observers) {
  701. return;
  702. }
  703. for (var i = 0, length = observers.length; i < length; i++) {
  704. var observer = observers[i];
  705. if (observer && observer[1] === eventName && observer[0] === elem) {
  706. // if (observer && observer[1] === eventName && $tom.include(observer[0], elem)) {
  707. observer[2](event);
  708. }
  709. }
  710. },
  711. unloadCache: function() {
  712. if (!$tx.observers)
  713. return;
  714. for (var i = 0, length = $tx.observers.length; i < length; i++) {
  715. $tx.stopObserving.apply(this, $tx.observers[i]);
  716. $tx.observers[i][0] = _NULL;
  717. }
  718. $tx.observers = _FALSE;
  719. },
  720. /**
  721. * 이벤트를 위한 이벤트 핸들러 함수를 추가
  722. * @function
  723. * @param {Object} element 요소객체 또는 아이디
  724. * @param {String} name 이벤트 명
  725. * @param {Function} observer 이벤트를 다루는 함수
  726. * @param {Boolean} useCapture true라면, capture내 이벤트를 다루고 false라면 bubbling 내 이벤트를 다룬다.
  727. */
  728. observe: function(element, name, observer, useCapture) {
  729. element = $tx(element);
  730. useCapture = useCapture || _FALSE;
  731. if (name == 'keypress' /*&& ($tx.webkit || element.attachEvent)*/) {
  732. name = 'keydown';
  733. }
  734. $tx._observeAndCache(element, name, observer, useCapture);
  735. },
  736. /**
  737. * 이벤트로부터 이벤트 핸들러를 제거
  738. * @function
  739. * @param {Object} element 요소객체 또는 아이디
  740. * @param {String} name 이벤트 명
  741. * @param {Function} observer 이벤트를 다루는 함수
  742. * @param {Boolean} useCapture true라면, capture내 이벤트를 다루고 false라면 bubbling 내 이벤트를 다룬다.
  743. */
  744. stopObserving: function(element, name, observer, useCapture) {
  745. element = $tx(element);
  746. useCapture = useCapture || _FALSE;
  747. if (name == 'keypress' /*&&
  748. ($tx.webkit || element.attachEvent)*/)
  749. name = 'keydown';
  750. if (element.removeEventListener) {
  751. element.removeEventListener(name, observer, useCapture);
  752. } else if (element.detachEvent) {
  753. try {
  754. element.detachEvent('on' + name, observer);
  755. } catch (e) {
  756. }
  757. }
  758. }
  759. });
  760. // prevent memory leaks in IE
  761. if ($tx.msie) {
  762. $tx.observe(window, 'unload', $tx.unloadCache, _FALSE);
  763. }
  764. })();
  765. (function() {
  766. $tx.extend(Object, /** @lends Object */ {
  767. /**
  768. * object 를 복사
  769. * @function
  770. */
  771. clone: function(object) {
  772. return Object.extend({}, object);
  773. }
  774. });
  775. $tx.extend($tx, {
  776. isPrimitiveType: function(data) {
  777. var primitiveTypes = new $tx.Set("string", "number", "boolean", "date", "function");
  778. return primitiveTypes.contains(typeof data);
  779. },
  780. deepcopy: function(preset, service) {
  781. var _dest = preset;
  782. if(!service) {
  783. return _dest;
  784. }
  785. for(var _name in service) {
  786. switch(typeof(service[_name])) {
  787. case 'string':
  788. case 'number':
  789. case 'boolean':
  790. case 'date':
  791. case 'function':
  792. _dest[_name] = service[_name];
  793. break;
  794. default:
  795. if (service[_name]) {
  796. if (service[_name].constructor == Array) {
  797. _dest[_name] = [].concat(service[_name]);
  798. } else {
  799. _dest[_name] = _dest[_name] || {};
  800. this.deepcopy(_dest[_name], service[_name]);
  801. }
  802. } else {
  803. _dest[_name] = _NULL;
  804. }
  805. break;
  806. }
  807. }
  808. return _dest;
  809. }
  810. });
  811. })();
  812. (function () {
  813. $tx.extend(String, /** @lends String */{
  814. /**
  815. * value 를 문자열로 만들어 반환한다. value 가 null 이면 빈문자열을 반환한다.
  816. * @function
  817. */
  818. interpret: function(value) {
  819. return value == _NULL ? '' : String(value);
  820. },
  821. /**
  822. * @field
  823. */
  824. specialChar: {
  825. '\b': '\\b',
  826. '\t': '\\t',
  827. '\n': '\\n',
  828. '\f': '\\f',
  829. '\r': '\\r',
  830. '\\': '\\\\'
  831. }
  832. });
  833. $tx.extend(String.prototype, /** @lends String.prototype */{
  834. /**
  835. * 현재 문자열에서 패턴 문자열을 찾은 결과의 문자열을 반환하고 대체 문자열이나 패턴에 일치하는 문자열을 가진 배열을 전달하는 대체함수를 호출한 결과로 대체한다.
  836. * 대체물이 문자열일때, #{n}과 같은 특별한 템플릿 형태의 토큰을 포함할수 있다.
  837. * 여기서 n이라는 값은 정규표현식 그룹의 인덱스이다.
  838. * #{0}는 완전히 일치하면 대체될것이고 #{1}는 첫번째 그룹, #{2}는 두번째이다.
  839. * @function
  840. */
  841. gsub: function(pattern, replacement) {
  842. var result = '', source = this, match;
  843. replacement = arguments.callee.prepareReplacement(replacement);
  844. while (source.length > 0) {
  845. if (match = source.match(pattern)) {
  846. result += source.slice(0, match.index);
  847. result += String.interpret(replacement(match));
  848. source = source.slice(match.index + match[0].length);
  849. } else {
  850. result += source, source = '';
  851. }
  852. }
  853. return result;
  854. },
  855. /**
  856. * 문자열 앞,뒤의 공백을 제거
  857. * @function
  858. */
  859. strip: function() {
  860. return this.replace(/^\s+/, '').replace(/\s+$/, '');
  861. },
  862. /**
  863. * 문자열 중 태그 <tag> 를 삭제
  864. * @function
  865. */
  866. stripTags: function() {
  867. return this.replace(/<\/?[^>]+>/gi, '');
  868. },
  869. /**
  870. * url query string 을 json 으로 만들어 반환한다. separator 를 & 대신 다른 값을 사용할 수 있다.
  871. * @function
  872. */
  873. toQueryParams: function(separator) {
  874. var match = this.strip().match(/([^?#]*)(#.*)?$/);
  875. if (!match) return {};
  876. var _hash = {};
  877. var _lastkey = _NULL;
  878. match[1].split(separator || '&').each(function(pair) {
  879. var _key = _NULL, _value = _NULL;
  880. var _matches = pair.match(/([\w_]+)=(.*)/);
  881. if(_matches) {
  882. _lastkey = _key = decodeURIComponent(_matches[1]);
  883. if(_matches[2]) {
  884. _value = decodeURIComponent(_matches[2]);
  885. }
  886. } else if(_lastkey) {
  887. _key = _lastkey;
  888. _value = _hash[_key];
  889. _value += '&' + decodeURIComponent(pair);
  890. } else {
  891. return;
  892. }
  893. if (_key in _hash) {
  894. if (_hash[_key].constructor != Array)
  895. _hash[_key] = [_hash[_key]];
  896. _hash[_key].push(_value);
  897. } else {
  898. _hash[_key] = _value;
  899. }
  900. });
  901. return _hash;
  902. },
  903. /**
  904. * 문자열을 배열로 반환한다.
  905. * @function
  906. */
  907. toArray: function() {
  908. return this.split('');
  909. },
  910. /**
  911. * count 만큼 문자열을 반복하여 이어 붙인다.
  912. * @function
  913. */
  914. times: function(count) {
  915. var result = '';
  916. for (var i = 0; i < count; i++)
  917. result += this;
  918. return result;
  919. },
  920. /**
  921. * -(하이픈)으로 분리된 문자열을 camelCaseString으로 변환
  922. * @function
  923. */
  924. camelize: function() {
  925. var parts = this.split('-'), len = parts.length;
  926. if (len == 1)
  927. return parts[0];
  928. var camelized = this.charAt(0) == '-' ? parts[0].charAt(0).toUpperCase() + parts[0].substring(1) : parts[0];
  929. for (var i = 1; i < len; i++)
  930. camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
  931. return camelized;
  932. },
  933. /**
  934. * 첫번째 글자를 대문자로 변환
  935. * @function
  936. */
  937. capitalize: function() {
  938. return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
  939. },
  940. /**
  941. * 문자열이 주어진 패턴을 포함하면 true
  942. * @function
  943. */
  944. include: function(pattern) {
  945. return this.indexOf(pattern) > -1;
  946. },
  947. /**
  948. * 빈문자열이면 true
  949. * @function
  950. */
  951. empty: function() {
  952. return this == '';
  953. },
  954. /**
  955. * 공백문자열이면 true
  956. * @function
  957. */
  958. blank: function() {
  959. return /^\s*$/.test(this);
  960. }
  961. });
  962. String.prototype.gsub.prepareReplacement = function(replacement) {
  963. if (typeof replacement == 'function')
  964. return replacement;
  965. var template = new Template(replacement);
  966. return function(match) {
  967. return template.evaluate(match);
  968. };
  969. };
  970. //////
  971. $tx.extend(String.prototype, /** @lends String.prototype */{
  972. /**
  973. * 문자열 앞,뒤의 공백을 제거
  974. * @function
  975. */
  976. trim: function() {
  977. return this.replace(/(^\s*)|(\s*$)/g, "");
  978. },
  979. /**
  980. * 정규표현식에서 사용되는 메타문자를 이스케이프해서 반환한다.
  981. * @function
  982. */
  983. getRegExp: function() {
  984. return this.replace(/\\/g, "\\\\").replace(/\./g, "\\.").replace(/\//g, "\\/").replace(/\?/g, "\\?").replace(/\^/g, "\\^").replace(/\)/g, "\\)").replace(/\(/g, "\\(").replace(/\]/g, "\\]").replace(/\[/g, "\\[").replace(/\$/g, "\\$").replace(/\+/g, "\\+").replace(/\|/g, "\\|").replace(/&/g, "(&|&amp;)");
  985. },
  986. /**
  987. * 문자열을 정수형으로 반환한다. 숫자가 아닌 문자열은 0
  988. * @function
  989. */
  990. toNumber: function() {
  991. return (isNaN(this) ? 0 : parseInt(this, 10));
  992. },
  993. /**
  994. * 문자열을 부동소수점 형태로 반환한다. 숫자가 아닌 문자열은 0
  995. * @function
  996. */
  997. toFloat: function() {
  998. return (isNaN(this) ? 0 : parseFloat(this));
  999. },
  1000. /**
  1001. * 문자열의 길이를 반환
  1002. * @function
  1003. */
  1004. getRealLength: function() {
  1005. var str = this;
  1006. var idx = 0;
  1007. for (var i = 0; i < str.length; i++) {
  1008. idx += (escape(str.charAt(i)).charAt(1) == "u") ? 2 : 1;
  1009. }
  1010. return idx;
  1011. },
  1012. /**
  1013. * 문자열이 주어진 길이보다 길면 자르고 마지막에 ... 를 붙인다.
  1014. * @function
  1015. */
  1016. cutRealLength: function(length) {
  1017. var str = this;
  1018. var idx = 0;
  1019. for (var i = 0; i < str.length; i++) {
  1020. idx += (escape(str.charAt(i)).charAt(1) == "u") ? 2 : 1;
  1021. if (idx > length) {
  1022. return str.substring(0, i - 3).concat("...");
  1023. }
  1024. }
  1025. return str;
  1026. },
  1027. /**
  1028. * @deprecated
  1029. */
  1030. getCut: function(length) {
  1031. return this.cutRealLength(length);
  1032. },
  1033. /**
  1034. * 문자열에 px 가 있으면 잘라내고 반환한다.
  1035. * @function
  1036. */
  1037. parsePx: function() {
  1038. if (this == _NULL || this.length == 0)
  1039. return 0;
  1040. else if (this.indexOf("px") > -1)
  1041. return this.substring(0, this.indexOf("px")).toNumber();
  1042. else
  1043. return this.toNumber();
  1044. },
  1045. /**
  1046. * 문자열에 px 를 붙여서 반환한다.
  1047. * @function
  1048. */
  1049. toPx: function() {
  1050. if (this.indexOf("px") > -1) {
  1051. return this + "";
  1052. } else {
  1053. return this + "px";
  1054. }
  1055. },
  1056. /**
  1057. * 픽셀값으로 사용 가능한 문자열인지 boolean 으로 반환 ( 공백 허용안함 )
  1058. * @function
  1059. */
  1060. isPx: function(){
  1061. var str = this;
  1062. if ( str.trim() == "" ){
  1063. return false;
  1064. } else if( str.indexOf("px") != -1 ){
  1065. str = this.parsePx();
  1066. }
  1067. return !isNaN(str);
  1068. },
  1069. isPercent: function(){
  1070. var str = this.trim();
  1071. return parseInt(str, 10)+'%' === str;
  1072. },
  1073. /**
  1074. * 바이트를 계산하여 단위를(KB, MB) 붙여서 반환한다.
  1075. * @function
  1076. */
  1077. toByteUnit: function() {
  1078. return this.toNumber().toByteUnit();
  1079. },
  1080. /**
  1081. * 숫자로된 문자열을 천단위로 쉼표(,)를 붙인다.
  1082. * @function
  1083. */
  1084. toCurrency: function() {
  1085. var amount = this;
  1086. for (var i = 0; i < Math.floor((amount.length - (1 + i)) / 3); i++) {
  1087. amount = amount.substring(0, amount.length - (4 * i + 3)) + "," + amount.substring(amount.length - (4 * i + 3));
  1088. }
  1089. return amount;
  1090. },
  1091. /**
  1092. * source를 문자열 끝까지 찾아서 target으로 치환한다.
  1093. * @function
  1094. */
  1095. replaceAll: function(source, target) {
  1096. source = source.replace(new RegExp("(\\W)", "g"), "\\$1");
  1097. target = target.replace(new RegExp("\\$", "g"), "$$$$");
  1098. return this.replace(new RegExp(source, "gm"), target);
  1099. }
  1100. });
  1101. })();
  1102. (function() {
  1103. /**
  1104. * @name Number
  1105. * @class
  1106. */
  1107. $tx.extend(Number.prototype, /** @lends Number.prototype */{
  1108. /**
  1109. * 숫자로된 문자열이 주어진 길이보다 짧으면 앞부분에 0 으로 채워넣어서 반환한다.
  1110. * @function
  1111. * @param {Number} length 반환되는 문자열의 최소 길이
  1112. * @param {Number} radix 표기될 진수. optional. 기본 10진수
  1113. */
  1114. toPaddedString: function(length, radix) {
  1115. var string = this.toString(radix || 10);
  1116. return '0'.times(length - string.length) + string;
  1117. },
  1118. /**
  1119. *
  1120. * @function
  1121. */
  1122. toTime: function() {
  1123. return Math.floor(this / 60).toString().toPaddedString(2) + ":" + (this % 60).toString().toPaddedString(2);
  1124. },
  1125. /**
  1126. * 바이트를 계산하여 단위를(KB, MB) 붙여서 반환한다.
  1127. * @function
  1128. */
  1129. toByteUnit: function() {
  1130. var number;
  1131. var units = ['GB', 'MB', 'KB'];
  1132. if (this == 0) {
  1133. return "0" + units[2];
  1134. }
  1135. for (var i = 0; i < units.length; i++) {
  1136. number = this / Math.pow(1024, 3 - i);
  1137. if (number < 1) {
  1138. continue;
  1139. }
  1140. return (Math.round(number * 10) / 10) + units[i];
  1141. }
  1142. return "1" + units[2];
  1143. },
  1144. /**
  1145. * px를 붙인다.
  1146. * @function
  1147. */
  1148. toPx: function() {
  1149. return this.toString() + "px";
  1150. },
  1151. /**
  1152. * 그대로 반환한다.
  1153. * @function
  1154. */
  1155. parsePx: function() {
  1156. return this + 0;
  1157. },
  1158. /**
  1159. * 숫자형은 무조건 px로 사용 가능하다.
  1160. */
  1161. isPx: function(){
  1162. return _TRUE;
  1163. },
  1164. /**
  1165. * 문자열을 정수형으로 반환한다. 숫자가 아닌 문자열은 0
  1166. * @function
  1167. */
  1168. toNumber: function() {
  1169. return this + 0;
  1170. },
  1171. /**
  1172. * 천단위로 쉼표(,)를 붙인다.
  1173. * @function
  1174. */
  1175. toCurrency: function() {
  1176. return this.toString().toCurrency();
  1177. },
  1178. /**
  1179. * 정규표현식에서 사용되는 메타문자를 이스케이프해서 반환한다.
  1180. * @function
  1181. */
  1182. getRegExp: function() {
  1183. return this.toString().getRegExp();
  1184. }
  1185. });
  1186. })();
  1187. (function() {
  1188. $tx.extend(Array.prototype, /** @lends Array.prototype */{
  1189. each: function(iterator) {
  1190. if (_WIN['DEBUG']) {
  1191. for (var i = 0, length = this.length; i < length; i++) {
  1192. iterator(this[i]);
  1193. }
  1194. } else {
  1195. try {
  1196. for (var i = 0, length = this.length; i < length; i++) {
  1197. iterator(this[i]);
  1198. }
  1199. } catch (e) {
  1200. if (e != $break) {
  1201. throw e;
  1202. }
  1203. }
  1204. }
  1205. return this;
  1206. },
  1207. indexOf: function(value) {
  1208. for (var i = 0; i < this.length; i++) {
  1209. if (this[i] == value) {
  1210. return i;
  1211. }
  1212. }
  1213. return -1;
  1214. },
  1215. map: function(f) {
  1216. for (var b = [], i = 0, n = this.length; i < n; ++i) {
  1217. b[i] = f(this[i]);
  1218. }
  1219. return b;
  1220. },
  1221. /**
  1222. * @deprecated use contains()
  1223. */
  1224. include: function(object) {
  1225. return this.contains(object);
  1226. },
  1227. contains: function(item) {
  1228. return this.indexOf(item) >= 0;
  1229. },
  1230. /**
  1231. * 집합의 각각의 요소내 propertyName에 의해 명시된 프라퍼티에 값을 가져가고 Array객체로 결과를 반환한다.
  1232. * @function
  1233. */
  1234. pluck: function(property) {
  1235. var results = [];
  1236. this.each(function(value) {
  1237. results.push(value[property]);
  1238. });
  1239. return results;
  1240. },
  1241. /**
  1242. * 배열 내에서 조건을 만족하는 첫번째 요소를 리턴한다.
  1243. * @function
  1244. * @param {function} filterFn 조건 함수. 조건에 만족하는 경우 true 리턴, 아닌 경우 false를 리턴한다.
  1245. * @return {object}
  1246. */
  1247. find: function(filterFn) {
  1248. for (var i = 0, len = this.length; i < len; i++) {
  1249. var value = this[i];
  1250. if (filterFn(value, i)) {
  1251. return value;
  1252. }
  1253. }
  1254. return _NULL;
  1255. },
  1256. /**
  1257. * 배열 내에서 조건에 만족하는 요소들을 추출한다.
  1258. * @function
  1259. * @param {function} filterFn 조건 함수. 조건에 만족하는 경우 true 리턴, 아닌 경우 false를 리턴한다.
  1260. * @return {Array}
  1261. */
  1262. findAll: function(filterFn) {
  1263. var results = [];
  1264. for (var i = 0, len = this.length; i < len; i++) {
  1265. var value = this[i];
  1266. if (filterFn(value, i)) {
  1267. results.push(value);
  1268. }
  1269. }
  1270. return results;
  1271. },
  1272. /**
  1273. * iterator함수를 사용하여 집합의 모든 요소를 조합한다.
  1274. * 호출된 iterator는 accumulator인자에서 이전 반복의 결과를 전달한다.
  1275. * 첫번째 반복은 accumulator인자내 initialValue를 가진다. 마지막 결과는 마지막 반환값이다.
  1276. * @function
  1277. */
  1278. inject: function(array, iterator) {
  1279. for (var i = 0, len = this.length; i < len; i++) {
  1280. var value = this[i];
  1281. array = iterator(array, value, i);
  1282. }
  1283. return array;
  1284. },
  1285. /**
  1286. * 인자의 리스트에 포함된 요소를 제외한 배열을 반환. 이 메소드는 배열 자체를 변경하지는 않는다.
  1287. * @function
  1288. */
  1289. without: function() {
  1290. var values = $A(arguments);
  1291. return this.findAll(function(value) {
  1292. return !values.include(value);
  1293. });
  1294. },
  1295. /**
  1296. * 배열의 마지막 요소를 반환한다.
  1297. * @function
  1298. */
  1299. last: function() {
  1300. return this[this.length - 1];
  1301. },
  1302. /**
  1303. * 기복이 없고, 1차원의 배열을 반환한다. 이 함수는 배열이고 반환된 배열내 요소를 포함하는 배열의 각 요소를 찾음으로써 수행된다.
  1304. * @function
  1305. */
  1306. flatten: function() {
  1307. return this.inject([], function(array, value) {
  1308. return array.concat(value && value.constructor == Array ? value.flatten() : [value]);
  1309. });
  1310. },
  1311. /**
  1312. * 배열의 요소가 null 이나 빈문자열이면 제거한다.
  1313. * @function
  1314. */
  1315. compact: function() {
  1316. return this.findAll(function(value) {
  1317. return (value != _NULL) && (value != '');
  1318. });
  1319. },
  1320. /**
  1321. * 배열의 요소의 값 중 중복되는 값은 제거한다.
  1322. * @function
  1323. */
  1324. uniq: function(sorted) {
  1325. return this.inject([], function(array, value, index) {
  1326. if (0 == index || (sorted ? array.last() != value : !array.contains(value)))
  1327. array.push(value);
  1328. return array;
  1329. });
  1330. },
  1331. /**
  1332. * 배열의 특정요소값을 추출하여 json객체(map)을 만든다.
  1333. * @function
  1334. */
  1335. toMap: function(property) {
  1336. var results = {};
  1337. this.each(function(value) {
  1338. results[value[property]] = value;
  1339. });
  1340. return results;
  1341. }
  1342. });
  1343. /**
  1344. * @deprecated use Array.prototype.findAll
  1345. */
  1346. Array.prototype.select = Array.prototype.findAll;
  1347. /**
  1348. * @deprecated use Array.prototype.find
  1349. */
  1350. Array.prototype.detect = Array.prototype.find;
  1351. /**
  1352. * array like object(length와 index를 이용한 요소 접근이 가능)를 Array object로 변환한다.
  1353. * @example
  1354. * var arrayLikeObject = document.getElementsByTagName('img');
  1355. * var arrayObject = $A(arrayLikeObject);
  1356. */
  1357. _WIN.$A = function(arrayLikeObject) {
  1358. if (!arrayLikeObject) {
  1359. return [];
  1360. }
  1361. if (typeof arrayLikeObject.toArray === "function") {
  1362. return arrayLikeObject.toArray();
  1363. } else {
  1364. var array = [];
  1365. for (var i = 0, len = arrayLikeObject.length; i < len; i++) {
  1366. array.push(arrayLikeObject[i]);
  1367. }
  1368. return array;
  1369. }
  1370. };
  1371. $tx.Set = function (/* comma seperated elements */) {
  1372. var args = arguments;
  1373. for (var i = 0, len = args.length; i < len; i++) {
  1374. this[args[i]] = _TRUE;
  1375. }
  1376. };
  1377. $tx.Set.prototype.contains = function (element) {
  1378. return element in this;
  1379. };
  1380. $tx.objectToQueryString = function(obj) {
  1381. var queryString = [];
  1382. for (var key in obj) if (obj.hasOwnProperty(key)) {
  1383. var value = obj[key];
  1384. if (value === _NULL || value === _UNDEFINED) { // 다른 falsy value 들은 값으로 출력되어야 한다.
  1385. value = "";
  1386. }
  1387. queryString.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
  1388. }
  1389. return queryString.join("&");
  1390. };
  1391. })();
  1392. // crossbrowser
  1393. (function() {
  1394. if (typeof(HTMLElement) != _UNDEFINED+'') {
  1395. // HTMLElement.prototype.innerText;
  1396. var hElementProto = HTMLElement.prototype;
  1397. var hElementGrandProto = hElementProto.__proto__ = {
  1398. __proto__: hElementProto.__proto__
  1399. };
  1400. if (HTMLElement.prototype.__defineSetter__) {
  1401. hElementGrandProto.__defineSetter__("innerText", function(sText) {
  1402. this.textContent = sText;
  1403. });
  1404. }
  1405. if (HTMLElement.prototype.__defineGetter__) {
  1406. hElementGrandProto.__defineGetter__("innerText", function() {
  1407. return this.textContent;
  1408. });
  1409. }
  1410. }
  1411. if (typeof(XMLDocument) != _UNDEFINED+'') {
  1412. var XMLDoc = XMLDocument;
  1413. if (XMLDoc.prototype.__defineGetter__) {
  1414. XMLDoc.prototype.__defineGetter__("xml", function() {
  1415. return (new XMLSerializer()).serializeToString(this);
  1416. });
  1417. }
  1418. }
  1419. if (typeof(Node) != _UNDEFINED+'') {
  1420. if (Node.prototype && Node.prototype.__defineGetter__) {
  1421. Node.prototype.__defineGetter__("xml", function() {
  1422. return (new XMLSerializer()).serializeToString(this);
  1423. });
  1424. }
  1425. }
  1426. // Simple Implementation of
  1427. // setProperty() and selectNodes() and selectSingleNode()
  1428. // for FireFox [Mozilla]
  1429. if (typeof(_DOC.implementation) != _UNDEFINED+'') {
  1430. if (_DOC.implementation.hasFeature("XPath", "3.0")) {
  1431. if (typeof(XMLDoc) != _UNDEFINED+'') {
  1432. XMLDoc.prototype.selectNodes = function(cXPathString, xNode) {
  1433. if (!xNode) {
  1434. xNode = this;
  1435. }
  1436. var defaultNS = this.defaultNS;
  1437. var aItems = this.evaluate(cXPathString, xNode, {
  1438. normalResolver: this.createNSResolver(this.documentElement),
  1439. lookupNamespaceURI: function(prefix) {
  1440. switch (prefix) {
  1441. case "dflt":
  1442. return defaultNS;
  1443. default:
  1444. return this.normalResolver.lookupNamespaceURI(prefix);
  1445. }
  1446. }
  1447. }, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, _NULL);
  1448. var aResult = [];
  1449. for (var i = 0; i < aItems.snapshotLength; i++) {
  1450. aResult[i] = aItems.snapshotItem(i);
  1451. }
  1452. return aResult;
  1453. };
  1454. XMLDoc.prototype.setProperty = function(p, v) {
  1455. if (p == "SelectionNamespaces" && v.indexOf("xmlns:dflt") == 0) {
  1456. this.defaultNS = v.replace(/^.*=\'(.+)\'/, "$1");
  1457. }
  1458. };
  1459. XMLDoc.prototype.defaultNS;
  1460. // prototying the XMLDocument
  1461. XMLDoc.prototype.selectSingleNode = function(cXPathString, xNode) {
  1462. if (!xNode) {
  1463. xNode = this;
  1464. }
  1465. var xItems = this.selectNodes(cXPathString, xNode);
  1466. if (xItems.length > 0) {
  1467. return xItems[0];
  1468. } else {
  1469. return _NULL;
  1470. }
  1471. };
  1472. XMLDoc.prototype.createNode = function(nNodeType, sNodeName, sNameSpace) {
  1473. if (nNodeType == 1)
  1474. return this.createElementNS(sNameSpace, sNodeName);
  1475. else //Etc Not Use
  1476. return _NULL;
  1477. };
  1478. }
  1479. if (typeof(Element) != _UNDEFINED+'') {
  1480. Element.prototype.selectNodes = function(cXPathString) {
  1481. if (this.ownerDocument.selectNodes) {
  1482. return this.ownerDocument.selectNodes(cXPathString, this);
  1483. } else {
  1484. throw "For XML Elements Only";
  1485. }
  1486. };
  1487. // prototying the Element
  1488. Element.prototype.selectSingleNode = function(cXPathString) {
  1489. if (this.ownerDocument.selectSingleNode) {
  1490. return this.ownerDocument.selectSingleNode(cXPathString, this);
  1491. } else {
  1492. throw "For XML Elements Only";
  1493. }
  1494. };
  1495. Element.prototype.text;
  1496. var elementProto = Element.prototype;
  1497. var elementGrandProto = elementProto.__proto__ = {
  1498. __proto__: elementProto.__proto__
  1499. };
  1500. if (Element.prototype.__defineSetter__) {
  1501. elementGrandProto.__defineSetter__("text", function(text) {
  1502. this.textContent = text;
  1503. });
  1504. }
  1505. if (Element.prototype.__defineGetter__) {
  1506. elementGrandProto.__defineGetter__("text", function() {
  1507. return this.textContent;
  1508. });
  1509. }
  1510. if ( _WIN.origElement ) {
  1511. _WIN.origElement.prototype.selectNodes = Element.prototype.selectNodes;
  1512. _WIN.origElement.prototype.selectSingleNode = Element.prototype.selectSingleNode;
  1513. }
  1514. }
  1515. }
  1516. }
  1517. })();
  1518. _WIN.$tx = $tx;