tui-code-snippet.js 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988
  1. /*!
  2. * tui-code-snippet.js
  3. * @version 1.2.5
  4. * @author FE Development Lab
  5. * @license MIT
  6. */
  7. (function webpackUniversalModuleDefinition(root, factory) {
  8. if(typeof exports === 'object' && typeof module === 'object')
  9. module.exports = factory();
  10. else if(typeof define === 'function' && define.amd)
  11. define([], factory);
  12. else if(typeof exports === 'object')
  13. exports["util"] = factory();
  14. else
  15. root["tui"] = root["tui"] || {}, root["tui"]["util"] = factory();
  16. })(this, function() {
  17. return /******/ (function(modules) { // webpackBootstrap
  18. /******/ // The module cache
  19. /******/ var installedModules = {};
  20. /******/ // The require function
  21. /******/ function __webpack_require__(moduleId) {
  22. /******/ // Check if module is in cache
  23. /******/ if(installedModules[moduleId])
  24. /******/ return installedModules[moduleId].exports;
  25. /******/ // Create a new module (and put it into the cache)
  26. /******/ var module = installedModules[moduleId] = {
  27. /******/ exports: {},
  28. /******/ id: moduleId,
  29. /******/ loaded: false
  30. /******/ };
  31. /******/ // Execute the module function
  32. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  33. /******/ // Flag the module as loaded
  34. /******/ module.loaded = true;
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/ // expose the modules object (__webpack_modules__)
  39. /******/ __webpack_require__.m = modules;
  40. /******/ // expose the module cache
  41. /******/ __webpack_require__.c = installedModules;
  42. /******/ // __webpack_public_path__
  43. /******/ __webpack_require__.p = "";
  44. /******/ // Load entry module and return exports
  45. /******/ return __webpack_require__(0);
  46. /******/ })
  47. /************************************************************************/
  48. /******/ ([
  49. /* 0 */
  50. /***/ (function(module, exports, __webpack_require__) {
  51. 'use strict';
  52. /**
  53. * @fileoverview
  54. * @author NHN Ent.
  55. * FE Development Lab <dl_javascript@nhnent.com>
  56. * @namespace tui.util
  57. */
  58. var util = {};
  59. var object = __webpack_require__(1);
  60. var extend = object.extend;
  61. extend(util, object);
  62. extend(util, __webpack_require__(3));
  63. extend(util, __webpack_require__(2));
  64. extend(util, __webpack_require__(4));
  65. extend(util, __webpack_require__(5));
  66. extend(util, __webpack_require__(6));
  67. extend(util, __webpack_require__(7));
  68. extend(util, __webpack_require__(8));
  69. util.browser = __webpack_require__(9);
  70. util.popup = __webpack_require__(10);
  71. util.formatDate = __webpack_require__(11);
  72. util.defineClass = __webpack_require__(12);
  73. util.defineModule = __webpack_require__(13);
  74. util.defineNamespace = __webpack_require__(14);
  75. util.CustomEvents = __webpack_require__(15);
  76. util.Enum = __webpack_require__(16);
  77. util.ExMap = __webpack_require__(17);
  78. util.HashMap = __webpack_require__(19);
  79. util.Map = __webpack_require__(18);
  80. module.exports = util;
  81. /***/ }),
  82. /* 1 */
  83. /***/ (function(module, exports, __webpack_require__) {
  84. /**
  85. * @fileoverview This module has some functions for handling a plain object, json.
  86. * @author NHN Ent.
  87. * FE Development Lab <dl_javascript@nhnent.com>
  88. * @dependency type.js, collection.js, array.js
  89. */
  90. 'use strict';
  91. var type = __webpack_require__(2);
  92. var array = __webpack_require__(3);
  93. /**
  94. * The last id of stamp
  95. * @type {number}
  96. * @private
  97. */
  98. var lastId = 0;
  99. /**
  100. * Extend the target object from other objects.
  101. * @param {object} target - Object that will be extended
  102. * @param {...object} objects - Objects as sources
  103. * @returns {object} Extended object
  104. * @memberof tui.util
  105. */
  106. function extend(target, objects) { // eslint-disable-line no-unused-vars
  107. var hasOwnProp = Object.prototype.hasOwnProperty;
  108. var source, prop, i, len;
  109. for (i = 1, len = arguments.length; i < len; i += 1) {
  110. source = arguments[i];
  111. for (prop in source) {
  112. if (hasOwnProp.call(source, prop)) {
  113. target[prop] = source[prop];
  114. }
  115. }
  116. }
  117. return target;
  118. }
  119. /**
  120. * Assign a unique id to an object
  121. * @param {object} obj - Object that will be assigned id.
  122. * @returns {number} Stamped id
  123. * @memberof tui.util
  124. */
  125. function stamp(obj) {
  126. if (!obj.__fe_id) {
  127. lastId += 1;
  128. obj.__fe_id = lastId; // eslint-disable-line camelcase
  129. }
  130. return obj.__fe_id;
  131. }
  132. /**
  133. * Verify whether an object has a stamped id or not.
  134. * @param {object} obj - adjusted object
  135. * @returns {boolean}
  136. * @memberof tui.util
  137. */
  138. function hasStamp(obj) {
  139. return type.isExisty(pick(obj, '__fe_id'));
  140. }
  141. /**
  142. * Reset the last id of stamp
  143. * @private
  144. */
  145. function resetLastId() {
  146. lastId = 0;
  147. }
  148. /**
  149. * Return a key-list(array) of a given object
  150. * @param {object} obj - Object from which a key-list will be extracted
  151. * @returns {Array} A key-list(array)
  152. * @memberof tui.util
  153. */
  154. function keys(obj) {
  155. var keyArray = [];
  156. var key;
  157. for (key in obj) {
  158. if (obj.hasOwnProperty(key)) {
  159. keyArray.push(key);
  160. }
  161. }
  162. return keyArray;
  163. }
  164. /**
  165. * Return the equality for multiple objects(jsonObjects).<br>
  166. * See {@link http://stackoverflow.com/questions/1068834/object-comparison-in-javascript}
  167. * @param {...object} object - Multiple objects for comparing.
  168. * @returns {boolean} Equality
  169. * @example
  170. *
  171. * var jsonObj1 = {name:'milk', price: 1000};
  172. * var jsonObj2 = {name:'milk', price: 1000};
  173. * var jsonObj3 = {name:'milk', price: 1000};
  174. *
  175. * tui.util.compareJSON(jsonObj1, jsonObj2, jsonObj3); // true
  176. *
  177. *
  178. * var jsonObj4 = {name:'milk', price: 1000};
  179. * var jsonObj5 = {name:'beer', price: 3000};
  180. *
  181. * tui.util.compareJSON(jsonObj4, jsonObj5); // false
  182. * @memberof tui.util
  183. */
  184. function compareJSON(object) {
  185. var argsLen = arguments.length;
  186. var i = 1;
  187. if (argsLen < 1) {
  188. return true;
  189. }
  190. for (; i < argsLen; i += 1) {
  191. if (!isSameObject(object, arguments[i])) {
  192. return false;
  193. }
  194. }
  195. return true;
  196. }
  197. /**
  198. * @param {*} x - object to compare
  199. * @param {*} y - object to compare
  200. * @returns {boolean} - whether object x and y is same or not
  201. * @private
  202. */
  203. function isSameObject(x, y) { // eslint-disable-line complexity
  204. var leftChain = [];
  205. var rightChain = [];
  206. var p;
  207. // remember that NaN === NaN returns false
  208. // and isNaN(undefined) returns true
  209. if (isNaN(x) &&
  210. isNaN(y) &&
  211. type.isNumber(x) &&
  212. type.isNumber(y)) {
  213. return true;
  214. }
  215. // Compare primitives and functions.
  216. // Check if both arguments link to the same object.
  217. // Especially useful on step when comparing prototypes
  218. if (x === y) {
  219. return true;
  220. }
  221. // Works in case when functions are created in constructor.
  222. // Comparing dates is a common scenario. Another built-ins?
  223. // We can even handle functions passed across iframes
  224. if ((type.isFunction(x) && type.isFunction(y)) ||
  225. (x instanceof Date && y instanceof Date) ||
  226. (x instanceof RegExp && y instanceof RegExp) ||
  227. (x instanceof String && y instanceof String) ||
  228. (x instanceof Number && y instanceof Number)) {
  229. return x.toString() === y.toString();
  230. }
  231. // At last checking prototypes as good a we can
  232. if (!(x instanceof Object && y instanceof Object)) {
  233. return false;
  234. }
  235. if (x.isPrototypeOf(y) ||
  236. y.isPrototypeOf(x) ||
  237. x.constructor !== y.constructor ||
  238. x.prototype !== y.prototype) {
  239. return false;
  240. }
  241. // check for infinitive linking loops
  242. if (array.inArray(x, leftChain) > -1 ||
  243. array.inArray(y, rightChain) > -1) {
  244. return false;
  245. }
  246. // Quick checking of one object beeing a subset of another.
  247. for (p in y) {
  248. if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
  249. return false;
  250. } else if (typeof y[p] !== typeof x[p]) {
  251. return false;
  252. }
  253. }
  254. //This for loop executes comparing with hasOwnProperty() and typeof for each property in 'x' object,
  255. //and verifying equality for x[property] and y[property].
  256. for (p in x) {
  257. if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
  258. return false;
  259. } else if (typeof y[p] !== typeof x[p]) {
  260. return false;
  261. }
  262. if (typeof (x[p]) === 'object' || typeof (x[p]) === 'function') {
  263. leftChain.push(x);
  264. rightChain.push(y);
  265. if (!isSameObject(x[p], y[p])) {
  266. return false;
  267. }
  268. leftChain.pop();
  269. rightChain.pop();
  270. } else if (x[p] !== y[p]) {
  271. return false;
  272. }
  273. }
  274. return true;
  275. }
  276. /* eslint-enable complexity */
  277. /**
  278. * Retrieve a nested item from the given object/array
  279. * @param {object|Array} obj - Object for retrieving
  280. * @param {...string|number} paths - Paths of property
  281. * @returns {*} Value
  282. * @memberof tui.util
  283. * @example
  284. * var obj = {
  285. * 'key1': 1,
  286. * 'nested' : {
  287. * 'key1': 11,
  288. * 'nested': {
  289. * 'key1': 21
  290. * }
  291. * }
  292. * };
  293. * tui.util.pick(obj, 'nested', 'nested', 'key1'); // 21
  294. * tui.util.pick(obj, 'nested', 'nested', 'key2'); // undefined
  295. *
  296. * var arr = ['a', 'b', 'c'];
  297. * tui.util.pick(arr, 1); // 'b'
  298. */
  299. function pick(obj, paths) { // eslint-disable-line no-unused-vars
  300. var args = arguments;
  301. var target = args[0];
  302. var length = args.length;
  303. var i;
  304. try {
  305. for (i = 1; i < length; i += 1) {
  306. target = target[args[i]];
  307. }
  308. return target;
  309. } catch (e) {
  310. return; // eslint-disable-line consistent-return
  311. }
  312. }
  313. module.exports = {
  314. extend: extend,
  315. stamp: stamp,
  316. hasStamp: hasStamp,
  317. resetLastId: resetLastId,
  318. keys: Object.prototype.keys || keys,
  319. compareJSON: compareJSON,
  320. pick: pick
  321. };
  322. /***/ }),
  323. /* 2 */
  324. /***/ (function(module, exports) {
  325. /**
  326. * @fileoverview This module provides some functions to check the type of variable
  327. * @author NHN Ent.
  328. * FE Development Lab <dl_javascript@nhnent.com>
  329. * @dependency collection.js
  330. */
  331. 'use strict';
  332. var toString = Object.prototype.toString;
  333. /**
  334. * Check whether the given variable is existing or not.<br>
  335. * If the given variable is not null and not undefined, returns true.
  336. * @param {*} param - Target for checking
  337. * @returns {boolean} Is existy?
  338. * @memberof tui.util
  339. * @example
  340. * tui.util.isExisty(''); //true
  341. * tui.util.isExisty(0); //true
  342. * tui.util.isExisty([]); //true
  343. * tui.util.isExisty({}); //true
  344. * tui.util.isExisty(null); //false
  345. * tui.util.isExisty(undefined); //false
  346. */
  347. function isExisty(param) {
  348. return !isUndefined(param) && !isNull(param);
  349. }
  350. /**
  351. * Check whether the given variable is undefined or not.<br>
  352. * If the given variable is undefined, returns true.
  353. * @param {*} obj - Target for checking
  354. * @returns {boolean} Is undefined?
  355. * @memberof tui.util
  356. */
  357. function isUndefined(obj) {
  358. return obj === undefined; // eslint-disable-line no-undefined
  359. }
  360. /**
  361. * Check whether the given variable is null or not.<br>
  362. * If the given variable(arguments[0]) is null, returns true.
  363. * @param {*} obj - Target for checking
  364. * @returns {boolean} Is null?
  365. * @memberof tui.util
  366. */
  367. function isNull(obj) {
  368. return obj === null;
  369. }
  370. /**
  371. * Check whether the given variable is truthy or not.<br>
  372. * If the given variable is not null or not undefined or not false, returns true.<br>
  373. * (It regards 0 as true)
  374. * @param {*} obj - Target for checking
  375. * @returns {boolean} Is truthy?
  376. * @memberof tui.util
  377. */
  378. function isTruthy(obj) {
  379. return isExisty(obj) && obj !== false;
  380. }
  381. /**
  382. * Check whether the given variable is falsy or not.<br>
  383. * If the given variable is null or undefined or false, returns true.
  384. * @param {*} obj - Target for checking
  385. * @returns {boolean} Is falsy?
  386. * @memberof tui.util
  387. */
  388. function isFalsy(obj) {
  389. return !isTruthy(obj);
  390. }
  391. /**
  392. * Check whether the given variable is an arguments object or not.<br>
  393. * If the given variable is an arguments object, return true.
  394. * @param {*} obj - Target for checking
  395. * @returns {boolean} Is arguments?
  396. * @memberof tui.util
  397. */
  398. function isArguments(obj) {
  399. var result = isExisty(obj) &&
  400. ((toString.call(obj) === '[object Arguments]') || !!obj.callee);
  401. return result;
  402. }
  403. /**
  404. * Check whether the given variable is an instance of Array or not.<br>
  405. * If the given variable is an instance of Array, return true.
  406. * @param {*} obj - Target for checking
  407. * @returns {boolean} Is array instance?
  408. * @memberof tui.util
  409. */
  410. function isArray(obj) {
  411. return obj instanceof Array;
  412. }
  413. /**
  414. * Check whether the given variable is an object or not.<br>
  415. * If the given variable is an object, return true.
  416. * @param {*} obj - Target for checking
  417. * @returns {boolean} Is object?
  418. * @memberof tui.util
  419. */
  420. function isObject(obj) {
  421. return obj === Object(obj);
  422. }
  423. /**
  424. * Check whether the given variable is a function or not.<br>
  425. * If the given variable is a function, return true.
  426. * @param {*} obj - Target for checking
  427. * @returns {boolean} Is function?
  428. * @memberof tui.util
  429. */
  430. function isFunction(obj) {
  431. return obj instanceof Function;
  432. }
  433. /**
  434. * Check whether the given variable is a number or not.<br>
  435. * If the given variable is a number, return true.
  436. * @param {*} obj - Target for checking
  437. * @returns {boolean} Is number?
  438. * @memberof tui.util
  439. */
  440. function isNumber(obj) {
  441. return typeof obj === 'number' || obj instanceof Number;
  442. }
  443. /**
  444. * Check whether the given variable is a string or not.<br>
  445. * If the given variable is a string, return true.
  446. * @param {*} obj - Target for checking
  447. * @returns {boolean} Is string?
  448. * @memberof tui.util
  449. */
  450. function isString(obj) {
  451. return typeof obj === 'string' || obj instanceof String;
  452. }
  453. /**
  454. * Check whether the given variable is a boolean or not.<br>
  455. * If the given variable is a boolean, return true.
  456. * @param {*} obj - Target for checking
  457. * @returns {boolean} Is boolean?
  458. * @memberof tui.util
  459. */
  460. function isBoolean(obj) {
  461. return typeof obj === 'boolean' || obj instanceof Boolean;
  462. }
  463. /**
  464. * Check whether the given variable is an instance of Array or not.<br>
  465. * If the given variable is an instance of Array, return true.<br>
  466. * (It is used for multiple frame environments)
  467. * @param {*} obj - Target for checking
  468. * @returns {boolean} Is an instance of array?
  469. * @memberof tui.util
  470. */
  471. function isArraySafe(obj) {
  472. return toString.call(obj) === '[object Array]';
  473. }
  474. /**
  475. * Check whether the given variable is a function or not.<br>
  476. * If the given variable is a function, return true.<br>
  477. * (It is used for multiple frame environments)
  478. * @param {*} obj - Target for checking
  479. * @returns {boolean} Is a function?
  480. * @memberof tui.util
  481. */
  482. function isFunctionSafe(obj) {
  483. return toString.call(obj) === '[object Function]';
  484. }
  485. /**
  486. * Check whether the given variable is a number or not.<br>
  487. * If the given variable is a number, return true.<br>
  488. * (It is used for multiple frame environments)
  489. * @param {*} obj - Target for checking
  490. * @returns {boolean} Is a number?
  491. * @memberof tui.util
  492. */
  493. function isNumberSafe(obj) {
  494. return toString.call(obj) === '[object Number]';
  495. }
  496. /**
  497. * Check whether the given variable is a string or not.<br>
  498. * If the given variable is a string, return true.<br>
  499. * (It is used for multiple frame environments)
  500. * @param {*} obj - Target for checking
  501. * @returns {boolean} Is a string?
  502. * @memberof tui.util
  503. */
  504. function isStringSafe(obj) {
  505. return toString.call(obj) === '[object String]';
  506. }
  507. /**
  508. * Check whether the given variable is a boolean or not.<br>
  509. * If the given variable is a boolean, return true.<br>
  510. * (It is used for multiple frame environments)
  511. * @param {*} obj - Target for checking
  512. * @returns {boolean} Is a boolean?
  513. * @memberof tui.util
  514. */
  515. function isBooleanSafe(obj) {
  516. return toString.call(obj) === '[object Boolean]';
  517. }
  518. /**
  519. * Check whether the given variable is a instance of HTMLNode or not.<br>
  520. * If the given variables is a instance of HTMLNode, return true.
  521. * @param {*} html - Target for checking
  522. * @returns {boolean} Is HTMLNode ?
  523. * @memberof tui.util
  524. */
  525. function isHTMLNode(html) {
  526. if (typeof HTMLElement === 'object') {
  527. return (html && (html instanceof HTMLElement || !!html.nodeType));
  528. }
  529. return !!(html && html.nodeType);
  530. }
  531. /**
  532. * Check whether the given variable is a HTML tag or not.<br>
  533. * If the given variables is a HTML tag, return true.
  534. * @param {*} html - Target for checking
  535. * @returns {Boolean} Is HTML tag?
  536. * @memberof tui.util
  537. */
  538. function isHTMLTag(html) {
  539. if (typeof HTMLElement === 'object') {
  540. return (html && (html instanceof HTMLElement));
  541. }
  542. return !!(html && html.nodeType && html.nodeType === 1);
  543. }
  544. /**
  545. * Check whether the given variable is empty(null, undefined, or empty array, empty object) or not.<br>
  546. * If the given variables is empty, return true.
  547. * @param {*} obj - Target for checking
  548. * @returns {boolean} Is empty?
  549. * @memberof tui.util
  550. */
  551. function isEmpty(obj) {
  552. if (!isExisty(obj) || _isEmptyString(obj)) {
  553. return true;
  554. }
  555. if (isArray(obj) || isArguments(obj)) {
  556. return obj.length === 0;
  557. }
  558. if (isObject(obj) && !isFunction(obj)) {
  559. return !_hasOwnProperty(obj);
  560. }
  561. return true;
  562. }
  563. /**
  564. * Check whether given argument is empty string
  565. * @param {*} obj - Target for checking
  566. * @returns {boolean} whether given argument is empty string
  567. * @memberof tui.util
  568. * @private
  569. */
  570. function _isEmptyString(obj) {
  571. return isString(obj) && obj === '';
  572. }
  573. /**
  574. * Check whether given argument has own property
  575. * @param {Object} obj - Target for checking
  576. * @returns {boolean} - whether given argument has own property
  577. * @memberof tui.util
  578. * @private
  579. */
  580. function _hasOwnProperty(obj) {
  581. var key;
  582. for (key in obj) {
  583. if (obj.hasOwnProperty(key)) {
  584. return true;
  585. }
  586. }
  587. return false;
  588. }
  589. /**
  590. * Check whether the given variable is not empty
  591. * (not null, not undefined, or not empty array, not empty object) or not.<br>
  592. * If the given variables is not empty, return true.
  593. * @param {*} obj - Target for checking
  594. * @returns {boolean} Is not empty?
  595. * @memberof tui.util
  596. */
  597. function isNotEmpty(obj) {
  598. return !isEmpty(obj);
  599. }
  600. /**
  601. * Check whether the given variable is an instance of Date or not.<br>
  602. * If the given variables is an instance of Date, return true.
  603. * @param {*} obj - Target for checking
  604. * @returns {boolean} Is an instance of Date?
  605. * @memberof tui.util
  606. */
  607. function isDate(obj) {
  608. return obj instanceof Date;
  609. }
  610. /**
  611. * Check whether the given variable is an instance of Date or not.<br>
  612. * If the given variables is an instance of Date, return true.<br>
  613. * (It is used for multiple frame environments)
  614. * @param {*} obj - Target for checking
  615. * @returns {boolean} Is an instance of Date?
  616. * @memberof tui.util
  617. */
  618. function isDateSafe(obj) {
  619. return toString.call(obj) === '[object Date]';
  620. }
  621. module.exports = {
  622. isExisty: isExisty,
  623. isUndefined: isUndefined,
  624. isNull: isNull,
  625. isTruthy: isTruthy,
  626. isFalsy: isFalsy,
  627. isArguments: isArguments,
  628. isArray: isArray,
  629. isArraySafe: isArraySafe,
  630. isObject: isObject,
  631. isFunction: isFunction,
  632. isFunctionSafe: isFunctionSafe,
  633. isNumber: isNumber,
  634. isNumberSafe: isNumberSafe,
  635. isDate: isDate,
  636. isDateSafe: isDateSafe,
  637. isString: isString,
  638. isStringSafe: isStringSafe,
  639. isBoolean: isBoolean,
  640. isBooleanSafe: isBooleanSafe,
  641. isHTMLNode: isHTMLNode,
  642. isHTMLTag: isHTMLTag,
  643. isEmpty: isEmpty,
  644. isNotEmpty: isNotEmpty
  645. };
  646. /***/ }),
  647. /* 3 */
  648. /***/ (function(module, exports, __webpack_require__) {
  649. /**
  650. * @fileoverview This module has some functions for handling array.
  651. * @author NHN Ent.
  652. * FE Development Lab <dl_javascript@nhnent.com>
  653. */
  654. 'use strict';
  655. var collection = __webpack_require__(4);
  656. var type = __webpack_require__(2);
  657. var aps = Array.prototype.slice;
  658. var util;
  659. /**
  660. * Generate an integer Array containing an arithmetic progression.
  661. * @param {number} start - start index
  662. * @param {number} stop - stop index
  663. * @param {number} step - next visit index = current index + step
  664. * @returns {Array}
  665. * @memberof tui.util
  666. * @example
  667. *
  668. * var arr = tui.util.range(5);
  669. * console.log(arr); // [0,1,2,3,4]
  670. *
  671. * arr = tui.util.range(1, 5);
  672. * console.log(arr); // [1,2,3,4]
  673. *
  674. * arr = tui.util.range(2, 10, 2);
  675. * console.log(arr); // [2,4,6,8]
  676. *
  677. * arr = tui.util.range(10, 2, -2);
  678. * console.log(arr); // [10,8,6,4]
  679. */
  680. var range = function(start, stop, step) {
  681. var arr = [];
  682. var flag;
  683. if (type.isUndefined(stop)) {
  684. stop = start || 0;
  685. start = 0;
  686. }
  687. step = step || 1;
  688. flag = step < 0 ? -1 : 1;
  689. stop *= flag;
  690. for (; start * flag < stop; start += step) {
  691. arr.push(start);
  692. }
  693. return arr;
  694. };
  695. /* eslint-disable valid-jsdoc */
  696. /**
  697. * Zip together multiple lists into a single array
  698. * @param {...Array}
  699. * @returns {Array}
  700. * @memberof tui.util
  701. * @example
  702. *
  703. * var result = tui.util.zip([1, 2, 3], ['a', 'b','c'], [true, false, true]);
  704. *
  705. * console.log(result[0]); // [1, 'a', true]
  706. * console.log(result[1]); // [2, 'b', false]
  707. * console.log(result[2]); // [3, 'c', true]
  708. */
  709. /* eslint-enable valid-jsdoc */
  710. var zip = function() {
  711. var arr2d = aps.call(arguments);
  712. var result = [];
  713. collection.forEach(arr2d, function(arr) {
  714. collection.forEach(arr, function(value, index) {
  715. if (!result[index]) {
  716. result[index] = [];
  717. }
  718. result[index].push(value);
  719. });
  720. });
  721. return result;
  722. };
  723. /**
  724. * Returns the first index at which a given element can be found in the array
  725. * from start index(default 0), or -1 if it is not present.<br>
  726. * It compares searchElement to elements of the Array using strict equality
  727. * (the same method used by the ===, or triple-equals, operator).
  728. * @param {*} searchElement Element to locate in the array
  729. * @param {Array} array Array that will be traversed.
  730. * @param {number} startIndex Start index in array for searching (default 0)
  731. * @returns {number} the First index at which a given element, or -1 if it is not present
  732. * @memberof tui.util
  733. * @example
  734. *
  735. * var arr = ['one', 'two', 'three', 'four'];
  736. * var idx1;
  737. * var idx2;
  738. *
  739. * idx1 = tui.util.inArray('one', arr, 3);
  740. * alert(idx1); // -1
  741. *
  742. * idx2 = tui.util.inArray('one', arr);
  743. * alert(idx2); // 0
  744. */
  745. var inArray = function(searchElement, array, startIndex) {
  746. var i;
  747. var length;
  748. startIndex = startIndex || 0;
  749. if (!type.isArray(array)) {
  750. return -1;
  751. }
  752. if (Array.prototype.indexOf) {
  753. return Array.prototype.indexOf.call(array, searchElement, startIndex);
  754. }
  755. length = array.length;
  756. for (i = startIndex; startIndex >= 0 && i < length; i += 1) {
  757. if (array[i] === searchElement) {
  758. return i;
  759. }
  760. }
  761. return -1;
  762. };
  763. util = {
  764. inArray: inArray,
  765. range: range,
  766. zip: zip
  767. };
  768. module.exports = util;
  769. /***/ }),
  770. /* 4 */
  771. /***/ (function(module, exports, __webpack_require__) {
  772. /**
  773. * @fileoverview This module has some functions for handling object as collection.
  774. * @author NHN Ent.
  775. * FE Development Lab <dl_javascript@nhnent.com>
  776. * @dependency type.js, object.js
  777. */
  778. 'use strict';
  779. var type = __webpack_require__(2);
  780. var object = __webpack_require__(1);
  781. /**
  782. * Execute the provided callback once for each element present
  783. * in the array(or Array-like object) in ascending order.<br>
  784. * If the callback function returns false, the loop will be stopped.<br>
  785. * Callback function(iteratee) is invoked with three arguments:
  786. * - The value of the element
  787. * - The index of the element
  788. * - The array(or Array-like object) being traversed
  789. * @param {Array} arr The array(or Array-like object) that will be traversed
  790. * @param {function} iteratee Callback function
  791. * @param {Object} [context] Context(this) of callback function
  792. * @memberof tui.util
  793. * @example
  794. * var sum = 0;
  795. *
  796. * tui.util.forEachArray([1,2,3], function(value){
  797. * sum += value;
  798. * });
  799. * alert(sum); // 6
  800. */
  801. function forEachArray(arr, iteratee, context) {
  802. var index = 0;
  803. var len = arr.length;
  804. context = context || null;
  805. for (; index < len; index += 1) {
  806. if (iteratee.call(context, arr[index], index, arr) === false) {
  807. break;
  808. }
  809. }
  810. }
  811. /**
  812. * Execute the provided callback once for each property of object which actually exist.<br>
  813. * If the callback function returns false, the loop will be stopped.<br>
  814. * Callback function(iteratee) is invoked with three arguments:
  815. * - The value of the property
  816. * - The name of the property
  817. * - The object being traversed
  818. * @param {Object} obj The object that will be traversed
  819. * @param {function} iteratee Callback function
  820. * @param {Object} [context] Context(this) of callback function
  821. * @memberof tui.util
  822. * @example
  823. * var sum = 0;
  824. *
  825. * tui.util.forEachOwnProperties({a:1,b:2,c:3}, function(value){
  826. * sum += value;
  827. * });
  828. * alert(sum); // 6
  829. **/
  830. function forEachOwnProperties(obj, iteratee, context) {
  831. var key;
  832. context = context || null;
  833. for (key in obj) {
  834. if (obj.hasOwnProperty(key)) {
  835. if (iteratee.call(context, obj[key], key, obj) === false) {
  836. break;
  837. }
  838. }
  839. }
  840. }
  841. /**
  842. * Execute the provided callback once for each property of object(or element of array) which actually exist.<br>
  843. * If the object is Array-like object(ex-arguments object), It needs to transform to Array.(see 'ex2' of example).<br>
  844. * If the callback function returns false, the loop will be stopped.<br>
  845. * Callback function(iteratee) is invoked with three arguments:
  846. * - The value of the property(or The value of the element)
  847. * - The name of the property(or The index of the element)
  848. * - The object being traversed
  849. * @param {Object} obj The object that will be traversed
  850. * @param {function} iteratee Callback function
  851. * @param {Object} [context] Context(this) of callback function
  852. * @memberof tui.util
  853. * @example
  854. * //ex1
  855. * var sum = 0;
  856. *
  857. * tui.util.forEach([1,2,3], function(value){
  858. * sum += value;
  859. * });
  860. * alert(sum); // 6
  861. *
  862. * //ex2 - In case of Array-like object
  863. * function sum(){
  864. * var factors = Array.prototype.slice.call(arguments);
  865. * forEach(factors, function(value){
  866. * //......
  867. * });
  868. * }
  869. */
  870. function forEach(obj, iteratee, context) {
  871. if (type.isArray(obj)) {
  872. forEachArray(obj, iteratee, context);
  873. } else {
  874. forEachOwnProperties(obj, iteratee, context);
  875. }
  876. }
  877. /**
  878. * Execute the provided callback function once for each element in an array, in order,
  879. * and constructs a new array from the results.<br>
  880. * If the object is Array-like object(ex-arguments object),
  881. * It needs to transform to Array.(see 'ex2' of forEach example)<br>
  882. * Callback function(iteratee) is invoked with three arguments:
  883. * - The value of the property(or The value of the element)
  884. * - The name of the property(or The index of the element)
  885. * - The object being traversed
  886. * @param {Object} obj The object that will be traversed
  887. * @param {function} iteratee Callback function
  888. * @param {Object} [context] Context(this) of callback function
  889. * @returns {Array} A new array composed of returned values from callback function
  890. * @memberof tui.util
  891. * @example
  892. * var result = tui.util.map([0,1,2,3], function(value) {
  893. * return value + 1;
  894. * });
  895. *
  896. * alert(result); // 1,2,3,4
  897. */
  898. function map(obj, iteratee, context) {
  899. var resultArray = [];
  900. context = context || null;
  901. forEach(obj, function() {
  902. resultArray.push(iteratee.apply(context, arguments));
  903. });
  904. return resultArray;
  905. }
  906. /**
  907. * Execute the callback function once for each element present in the array(or Array-like object or plain object).<br>
  908. * If the object is Array-like object(ex-arguments object),
  909. * It needs to transform to Array.(see 'ex2' of forEach example)<br>
  910. * Callback function(iteratee) is invoked with four arguments:
  911. * - The previousValue
  912. * - The currentValue
  913. * - The index
  914. * - The object being traversed
  915. * @param {Object} obj The object that will be traversed
  916. * @param {function} iteratee Callback function
  917. * @param {Object} [context] Context(this) of callback function
  918. * @returns {*} The result value
  919. * @memberof tui.util
  920. * @example
  921. * var result = tui.util.reduce([0,1,2,3], function(stored, value) {
  922. * return stored + value;
  923. * });
  924. *
  925. * alert(result); // 6
  926. */
  927. function reduce(obj, iteratee, context) {
  928. var index = 0;
  929. var keys, length, store;
  930. context = context || null;
  931. if (!type.isArray(obj)) {
  932. keys = object.keys(obj);
  933. length = keys.length;
  934. store = obj[keys[index += 1]];
  935. } else {
  936. length = obj.length;
  937. store = obj[index];
  938. }
  939. index += 1;
  940. for (; index < length; index += 1) {
  941. store = iteratee.call(context, store, obj[keys ? keys[index] : index]);
  942. }
  943. return store;
  944. }
  945. /**
  946. * Transform the Array-like object to Array.<br>
  947. * In low IE (below 8), Array.prototype.slice.call is not perfect. So, try-catch statement is used.
  948. * @param {*} arrayLike Array-like object
  949. * @returns {Array} Array
  950. * @memberof tui.util
  951. * @example
  952. * var arrayLike = {
  953. * 0: 'one',
  954. * 1: 'two',
  955. * 2: 'three',
  956. * 3: 'four',
  957. * length: 4
  958. * };
  959. * var result = tui.util.toArray(arrayLike);
  960. *
  961. * alert(result instanceof Array); // true
  962. * alert(result); // one,two,three,four
  963. */
  964. function toArray(arrayLike) {
  965. var arr;
  966. try {
  967. arr = Array.prototype.slice.call(arrayLike);
  968. } catch (e) {
  969. arr = [];
  970. forEachArray(arrayLike, function(value) {
  971. arr.push(value);
  972. });
  973. }
  974. return arr;
  975. }
  976. /**
  977. * Create a new array or plain object with all elements(or properties)
  978. * that pass the test implemented by the provided function.<br>
  979. * Callback function(iteratee) is invoked with three arguments:
  980. * - The value of the property(or The value of the element)
  981. * - The name of the property(or The index of the element)
  982. * - The object being traversed
  983. * @param {Object} obj Object(plain object or Array) that will be traversed
  984. * @param {function} iteratee Callback function
  985. * @param {Object} [context] Context(this) of callback function
  986. * @returns {Object} plain object or Array
  987. * @memberof tui.util
  988. * @example
  989. * var result1 = tui.util.filter([0,1,2,3], function(value) {
  990. * return (value % 2 === 0);
  991. * });
  992. * alert(result1); // 0,2
  993. *
  994. * var result2 = tui.util.filter({a : 1, b: 2, c: 3}, function(value) {
  995. * return (value % 2 !== 0);
  996. * });
  997. * alert(result2.a); // 1
  998. * alert(result2.b); // undefined
  999. * alert(result2.c); // 3
  1000. */
  1001. function filter(obj, iteratee, context) {
  1002. var result, add;
  1003. context = context || null;
  1004. if (!type.isObject(obj) || !type.isFunction(iteratee)) {
  1005. throw new Error('wrong parameter');
  1006. }
  1007. if (type.isArray(obj)) {
  1008. result = [];
  1009. add = function(subResult, args) {
  1010. subResult.push(args[0]);
  1011. };
  1012. } else {
  1013. result = {};
  1014. add = function(subResult, args) {
  1015. subResult[args[1]] = args[0];
  1016. };
  1017. }
  1018. forEach(obj, function() {
  1019. if (iteratee.apply(context, arguments)) {
  1020. add(result, arguments);
  1021. }
  1022. }, context);
  1023. return result;
  1024. }
  1025. /**
  1026. * fetching a property
  1027. * @param {Array} arr target collection
  1028. * @param {String|Number} property property name
  1029. * @returns {Array}
  1030. * @memberof tui.util
  1031. * @example
  1032. * var objArr = [
  1033. * {'abc': 1, 'def': 2, 'ghi': 3},
  1034. * {'abc': 4, 'def': 5, 'ghi': 6},
  1035. * {'abc': 7, 'def': 8, 'ghi': 9}
  1036. * ];
  1037. * var arr2d = [
  1038. * [1, 2, 3],
  1039. * [4, 5, 6],
  1040. * [7, 8, 9]
  1041. * ];
  1042. * var result;
  1043. *
  1044. * result = tui.util.pluck(objArr, 'abc');
  1045. * console.log(result) // [1, 4, 7]
  1046. *
  1047. * result = tui.util.pluck(arr2d, 2);
  1048. * console.log(result) // [3, 6, 9]
  1049. */
  1050. function pluck(arr, property) {
  1051. var result = map(arr, function(item) {
  1052. return item[property];
  1053. });
  1054. return result;
  1055. }
  1056. module.exports = {
  1057. forEachOwnProperties: forEachOwnProperties,
  1058. forEachArray: forEachArray,
  1059. forEach: forEach,
  1060. toArray: toArray,
  1061. map: map,
  1062. reduce: reduce,
  1063. filter: filter,
  1064. pluck: pluck
  1065. };
  1066. /***/ }),
  1067. /* 5 */
  1068. /***/ (function(module, exports) {
  1069. /**
  1070. * @fileoverview This module provides a bind() function for context binding.
  1071. * @author NHN Ent.
  1072. * FE Development Lab <dl_javascript@nhnent.com>
  1073. */
  1074. 'use strict';
  1075. /**
  1076. * Create a new function that, when called, has its this keyword set to the provided value.
  1077. * @param {function} fn A original function before binding
  1078. * @param {*} obj context of function in arguments[0]
  1079. * @returns {function()} A new bound function with context that is in arguments[1]
  1080. * @memberof tui.util
  1081. */
  1082. function bind(fn, obj) {
  1083. var slice = Array.prototype.slice;
  1084. var args;
  1085. if (fn.bind) {
  1086. return fn.bind.apply(fn, slice.call(arguments, 1));
  1087. }
  1088. /* istanbul ignore next */
  1089. args = slice.call(arguments, 2);
  1090. /* istanbul ignore next */
  1091. return function() {
  1092. /* istanbul ignore next */
  1093. return fn.apply(obj, args.length ? args.concat(slice.call(arguments)) : arguments);
  1094. };
  1095. }
  1096. module.exports = {
  1097. bind: bind
  1098. };
  1099. /***/ }),
  1100. /* 6 */
  1101. /***/ (function(module, exports) {
  1102. /**
  1103. * @fileoverview This module provides some simple function for inheritance.
  1104. * @author NHN Ent.
  1105. * FE Development Lab <dl_javascript@nhnent.com>
  1106. */
  1107. 'use strict';
  1108. /**
  1109. * Create a new object with the specified prototype object and properties.
  1110. * @param {Object} obj This object will be a prototype of the newly-created object.
  1111. * @returns {Object}
  1112. * @memberof tui.util
  1113. */
  1114. function createObject(obj) {
  1115. function F() {} // eslint-disable-line require-jsdoc
  1116. F.prototype = obj;
  1117. return new F();
  1118. }
  1119. /**
  1120. * Provide a simple inheritance in prototype-oriented.<br>
  1121. * Caution :
  1122. * Don't overwrite the prototype of child constructor.
  1123. *
  1124. * @param {function} subType Child constructor
  1125. * @param {function} superType Parent constructor
  1126. * @memberof tui.util
  1127. * @example
  1128. * // Parent constructor
  1129. * function Animal(leg) {
  1130. * this.leg = leg;
  1131. * }
  1132. *
  1133. * Animal.prototype.growl = function() {
  1134. * // ...
  1135. * };
  1136. *
  1137. * // Child constructor
  1138. * function Person(name) {
  1139. * this.name = name;
  1140. * }
  1141. *
  1142. * // Inheritance
  1143. * core.inherit(Person, Animal);
  1144. *
  1145. * // After this inheritance, please use only the extending of property.
  1146. * // Do not overwrite prototype.
  1147. * Person.prototype.walk = function(direction) {
  1148. * // ...
  1149. * };
  1150. */
  1151. function inherit(subType, superType) {
  1152. var prototype = createObject(superType.prototype);
  1153. prototype.constructor = subType;
  1154. subType.prototype = prototype;
  1155. }
  1156. module.exports = {
  1157. createObject: createObject,
  1158. inherit: inherit
  1159. };
  1160. /***/ }),
  1161. /* 7 */
  1162. /***/ (function(module, exports, __webpack_require__) {
  1163. /**
  1164. * @fileoverview This module has some functions for handling the string.
  1165. * @author NHN Ent.
  1166. * FE Development Lab <dl_javascript@nhnent.com>
  1167. */
  1168. 'use strict';
  1169. var collection = __webpack_require__(4);
  1170. var object = __webpack_require__(1);
  1171. /**
  1172. * Transform the given HTML Entity string into plain string
  1173. * @param {String} htmlEntity - HTML Entity type string
  1174. * @returns {String} Plain string
  1175. * @memberof tui.util
  1176. * @example
  1177. * var htmlEntityString = "A &#39;quote&#39; is &lt;b&gt;bold&lt;/b&gt;"
  1178. * var result = decodeHTMLEntity(htmlEntityString); //"A 'quote' is <b>bold</b>"
  1179. */
  1180. function decodeHTMLEntity(htmlEntity) {
  1181. var entities = {
  1182. '&quot;': '"',
  1183. '&amp;': '&',
  1184. '&lt;': '<',
  1185. '&gt;': '>',
  1186. '&#39;': '\'',
  1187. '&nbsp;': ' '
  1188. };
  1189. return htmlEntity.replace(/&amp;|&lt;|&gt;|&quot;|&#39;|&nbsp;/g, function(m0) {
  1190. return entities[m0] ? entities[m0] : m0;
  1191. });
  1192. }
  1193. /**
  1194. * Transform the given string into HTML Entity string
  1195. * @param {String} html - String for encoding
  1196. * @returns {String} HTML Entity
  1197. * @memberof tui.util
  1198. * @example
  1199. * var htmlEntityString = "<script> alert('test');</script><a href='test'>";
  1200. * var result = encodeHTMLEntity(htmlEntityString);
  1201. * //"&lt;script&gt; alert(&#39;test&#39;);&lt;/script&gt;&lt;a href=&#39;test&#39;&gt;"
  1202. */
  1203. function encodeHTMLEntity(html) {
  1204. var entities = {'"': 'quot', '&': 'amp', '<': 'lt', '>': 'gt', '\'': '#39'};
  1205. return html.replace(/[<>&"']/g, function(m0) {
  1206. return entities[m0] ? '&' + entities[m0] + ';' : m0;
  1207. });
  1208. }
  1209. /**
  1210. * Return whether the string capable to transform into plain string is in the given string or not.
  1211. * @param {String} string - test string
  1212. * @memberof tui.util
  1213. * @returns {boolean}
  1214. */
  1215. function hasEncodableString(string) {
  1216. return (/[<>&"']/).test(string);
  1217. }
  1218. /**
  1219. * Return duplicate charters
  1220. * @param {string} operandStr1 The operand string
  1221. * @param {string} operandStr2 The operand string
  1222. * @private
  1223. * @memberof tui.util
  1224. * @returns {string}
  1225. * @example
  1226. * tui.util.getDuplicatedChar('fe dev', 'nhn entertainment');
  1227. * => 'e'
  1228. * tui.util.getDuplicatedChar('fdsa', 'asdf');
  1229. * => 'asdf'
  1230. */
  1231. function getDuplicatedChar(operandStr1, operandStr2) {
  1232. var i = 0;
  1233. var len = operandStr1.length;
  1234. var pool = {};
  1235. var dupl, key;
  1236. for (; i < len; i += 1) {
  1237. key = operandStr1.charAt(i);
  1238. pool[key] = 1;
  1239. }
  1240. for (i = 0, len = operandStr2.length; i < len; i += 1) {
  1241. key = operandStr2.charAt(i);
  1242. if (pool[key]) {
  1243. pool[key] += 1;
  1244. }
  1245. }
  1246. pool = collection.filter(pool, function(item) {
  1247. return item > 1;
  1248. });
  1249. pool = object.keys(pool).sort();
  1250. dupl = pool.join('');
  1251. return dupl;
  1252. }
  1253. module.exports = {
  1254. decodeHTMLEntity: decodeHTMLEntity,
  1255. encodeHTMLEntity: encodeHTMLEntity,
  1256. hasEncodableString: hasEncodableString,
  1257. getDuplicatedChar: getDuplicatedChar
  1258. };
  1259. /***/ }),
  1260. /* 8 */
  1261. /***/ (function(module, exports) {
  1262. /**
  1263. * @fileoverview collections of some technic methods.
  1264. * @author NHN Ent. FE Development Lab <e0242.nhnent.com>
  1265. */
  1266. 'use strict';
  1267. var tricks = {};
  1268. var aps = Array.prototype.slice;
  1269. /**
  1270. * Creates a debounced function that delays invoking fn until after delay milliseconds has elapsed
  1271. * since the last time the debouced function was invoked.
  1272. * @param {function} fn The function to debounce.
  1273. * @param {number} [delay=0] The number of milliseconds to delay
  1274. * @memberof tui.util
  1275. * @returns {function} debounced function.
  1276. * @example
  1277. *
  1278. * function someMethodToInvokeDebounced() {}
  1279. *
  1280. * var debounced = tui.util.debounce(someMethodToInvokeDebounced, 300);
  1281. *
  1282. * // invoke repeatedly
  1283. * debounced();
  1284. * debounced();
  1285. * debounced();
  1286. * debounced();
  1287. * debounced();
  1288. * debounced(); // last invoke of debounced()
  1289. *
  1290. * // invoke someMethodToInvokeDebounced() after 300 milliseconds.
  1291. */
  1292. function debounce(fn, delay) {
  1293. var timer, args;
  1294. /* istanbul ignore next */
  1295. delay = delay || 0;
  1296. function debounced() { // eslint-disable-line require-jsdoc
  1297. args = aps.call(arguments);
  1298. window.clearTimeout(timer);
  1299. timer = window.setTimeout(function() {
  1300. fn.apply(null, args);
  1301. }, delay);
  1302. }
  1303. return debounced;
  1304. }
  1305. /**
  1306. * return timestamp
  1307. * @memberof tui.util
  1308. * @returns {number} The number of milliseconds from Jan. 1970 00:00:00 (GMT)
  1309. */
  1310. function timestamp() {
  1311. return Number(new Date());
  1312. }
  1313. /**
  1314. * Creates a throttled function that only invokes fn at most once per every interval milliseconds.
  1315. *
  1316. * You can use this throttle short time repeatedly invoking functions. (e.g MouseMove, Resize ...)
  1317. *
  1318. * if you need reuse throttled method. you must remove slugs (e.g. flag variable) related with throttling.
  1319. * @param {function} fn function to throttle
  1320. * @param {number} [interval=0] the number of milliseconds to throttle invocations to.
  1321. * @memberof tui.util
  1322. * @returns {function} throttled function
  1323. * @example
  1324. *
  1325. * function someMethodToInvokeThrottled() {}
  1326. *
  1327. * var throttled = tui.util.throttle(someMethodToInvokeThrottled, 300);
  1328. *
  1329. * // invoke repeatedly
  1330. * throttled(); // invoke (leading)
  1331. * throttled();
  1332. * throttled(); // invoke (near 300 milliseconds)
  1333. * throttled();
  1334. * throttled();
  1335. * throttled(); // invoke (near 600 milliseconds)
  1336. * // ...
  1337. * // invoke (trailing)
  1338. *
  1339. * // if you need reuse throttled method. then invoke reset()
  1340. * throttled.reset();
  1341. */
  1342. function throttle(fn, interval) {
  1343. var base;
  1344. var isLeading = true;
  1345. var tick = function(_args) {
  1346. fn.apply(null, _args);
  1347. base = null;
  1348. };
  1349. var debounced, stamp, args;
  1350. /* istanbul ignore next */
  1351. interval = interval || 0;
  1352. debounced = tricks.debounce(tick, interval);
  1353. function throttled() { // eslint-disable-line require-jsdoc
  1354. args = aps.call(arguments);
  1355. if (isLeading) {
  1356. tick(args);
  1357. isLeading = false;
  1358. return;
  1359. }
  1360. stamp = tricks.timestamp();
  1361. base = base || stamp;
  1362. // pass array directly because `debounce()`, `tick()` are already use
  1363. // `apply()` method to invoke developer's `fn` handler.
  1364. //
  1365. // also, this `debounced` line invoked every time for implements
  1366. // `trailing` features.
  1367. debounced(args);
  1368. if ((stamp - base) >= interval) {
  1369. tick(args);
  1370. }
  1371. }
  1372. function reset() { // eslint-disable-line require-jsdoc
  1373. isLeading = true;
  1374. base = null;
  1375. }
  1376. throttled.reset = reset;
  1377. return throttled;
  1378. }
  1379. tricks.timestamp = timestamp;
  1380. tricks.debounce = debounce;
  1381. tricks.throttle = throttle;
  1382. module.exports = tricks;
  1383. /***/ }),
  1384. /* 9 */
  1385. /***/ (function(module, exports) {
  1386. /**
  1387. * @fileoverview This module detects the kind of well-known browser and version.
  1388. * @author NHN Ent.
  1389. * FE Development Lab <dl_javascript@nhnent.com>
  1390. */
  1391. 'use strict';
  1392. /**
  1393. * This object has an information that indicate the kind of browser.<br>
  1394. * The list below is a detectable browser list.
  1395. * - ie8 ~ ie11
  1396. * - chrome
  1397. * - firefox
  1398. * - safari
  1399. * - edge
  1400. * @memberof tui.util
  1401. * @example
  1402. * tui.util.browser.chrome === true; // chrome
  1403. * tui.util.browser.firefox === true; // firefox
  1404. * tui.util.browser.safari === true; // safari
  1405. * tui.util.browser.msie === true; // IE
  1406. * tui.util.browser.edge === true; // edge
  1407. * tui.util.browser.others === true; // other browser
  1408. * tui.util.browser.version; // browser version
  1409. */
  1410. var browser = {
  1411. chrome: false,
  1412. firefox: false,
  1413. safari: false,
  1414. msie: false,
  1415. edge: false,
  1416. others: false,
  1417. version: 0
  1418. };
  1419. var nav = window.navigator;
  1420. var appName = nav.appName.replace(/\s/g, '_');
  1421. var userAgent = nav.userAgent;
  1422. var rIE = /MSIE\s([0-9]+[.0-9]*)/;
  1423. var rIE11 = /Trident.*rv:11\./;
  1424. var rEdge = /Edge\/(\d+)\./;
  1425. var versionRegex = {
  1426. firefox: /Firefox\/(\d+)\./,
  1427. chrome: /Chrome\/(\d+)\./,
  1428. safari: /Version\/([\d\.]+).*Safari\/(\d+)/
  1429. };
  1430. var key, tmp;
  1431. var detector = {
  1432. Microsoft_Internet_Explorer: function() { // eslint-disable-line camelcase
  1433. var detectedVersion = userAgent.match(rIE);
  1434. if (detectedVersion) { // ie8 ~ ie10
  1435. browser.msie = true;
  1436. browser.version = parseFloat(detectedVersion[1]);
  1437. } else { // no version information
  1438. browser.others = true;
  1439. }
  1440. },
  1441. Netscape: function() { // eslint-disable-line complexity
  1442. var detected = false;
  1443. if (rIE11.exec(userAgent)) {
  1444. browser.msie = true;
  1445. browser.version = 11;
  1446. detected = true;
  1447. } else if (rEdge.exec(userAgent)) {
  1448. browser.edge = true;
  1449. browser.version = userAgent.match(rEdge)[1];
  1450. detected = true;
  1451. } else {
  1452. for (key in versionRegex) {
  1453. if (versionRegex.hasOwnProperty(key)) {
  1454. tmp = userAgent.match(versionRegex[key]);
  1455. if (tmp && tmp.length > 1) { // eslint-disable-line max-depth
  1456. browser[key] = detected = true;
  1457. browser.version = parseFloat(tmp[1] || 0);
  1458. break;
  1459. }
  1460. }
  1461. }
  1462. }
  1463. if (!detected) {
  1464. browser.others = true;
  1465. }
  1466. }
  1467. };
  1468. var fn = detector[appName];
  1469. if (fn) {
  1470. detector[appName]();
  1471. }
  1472. module.exports = browser;
  1473. /***/ }),
  1474. /* 10 */
  1475. /***/ (function(module, exports, __webpack_require__) {
  1476. /**
  1477. * @fileoverview This module has some methods for handling popup-window
  1478. * @author NHN Ent.
  1479. * FE Development Lab <dl_javascript@nhnent.com>
  1480. * @dependency browser.js, type.js, object.js, collection.js, func.js
  1481. */
  1482. 'use strict';
  1483. var collection = __webpack_require__(4);
  1484. var type = __webpack_require__(2);
  1485. var func = __webpack_require__(5);
  1486. var browser = __webpack_require__(9);
  1487. var object = __webpack_require__(1);
  1488. var popupId = 0;
  1489. /**
  1490. * Popup management class
  1491. * @constructor
  1492. * @memberof tui.util
  1493. */
  1494. function Popup() {
  1495. /**
  1496. * Caching the window-contexts of opened popups
  1497. * @type {Object}
  1498. */
  1499. this.openedPopup = {};
  1500. /**
  1501. * In IE7, an error occurs when the closeWithParent property attaches to window object.<br>
  1502. * So, It is for saving the value of closeWithParent instead of attaching to window object.
  1503. * @type {Object}
  1504. */
  1505. this.closeWithParentPopup = {};
  1506. /**
  1507. * Post data bridge for IE11 popup
  1508. * @type {string}
  1509. */
  1510. this.postBridgeUrl = '';
  1511. }
  1512. /**********
  1513. * public methods
  1514. **********/
  1515. /**
  1516. * Returns a popup-list administered by current window.
  1517. * @param {string} [key] The key of popup.
  1518. * @returns {Object} popup window list object
  1519. */
  1520. Popup.prototype.getPopupList = function(key) {
  1521. var target;
  1522. if (type.isExisty(key)) {
  1523. target = this.openedPopup[key];
  1524. } else {
  1525. target = this.openedPopup;
  1526. }
  1527. return target;
  1528. };
  1529. /**
  1530. * Open popup
  1531. * Caution:
  1532. * In IE11, when transfer data to popup by POST, must set the postBridgeUrl.
  1533. *
  1534. * @param {string} url - popup url
  1535. * @param {Object} options - popup options
  1536. * @param {string} [options.popupName] - Key of popup window.<br>
  1537. * If the key is set, when you try to open by this key, the popup of this key is focused.<br>
  1538. * Or else a new popup window having this key is opened.
  1539. *
  1540. * @param {string} [options.popupOptionStr=""] - Option string of popup window<br>
  1541. * It is same with the third parameter of window.open() method.<br>
  1542. * See {@link http://www.w3schools.com/jsref/met_win_open.asp}
  1543. *
  1544. * @param {boolean} [options.closeWithParent=true] - Is closed when parent window closed?
  1545. *
  1546. * @param {boolean} [options.useReload=false] - This property indicates whether reload the popup or not.<br>
  1547. * If true, the popup will be reloaded when you try to re-open the popup that has been opened.<br>
  1548. * When transmit the POST-data, some browsers alert a message for confirming whether retransmit or not.
  1549. *
  1550. * @param {string} [options.postBridgeUrl='']
  1551. * Use this url to avoid a certain bug occuring when transmitting POST data to the popup in IE11.<br>
  1552. * This specific buggy situation is known to happen because IE11 tries to open the requested url<br>
  1553. * not in a new popup window as intended, but in a new tab.<br>
  1554. * See {@link http://wiki.nhnent.com/pages/viewpage.action?pageId=240562844}
  1555. *
  1556. * @param {string} [options.method=get]
  1557. * The method of transmission when the form-data is transmitted to popup-window.
  1558. *
  1559. * @param {Object} [options.param=null]
  1560. * Using as parameters for transmission when the form-data is transmitted to popup-window.
  1561. */
  1562. Popup.prototype.openPopup = function(url, options) { // eslint-disable-line complexity
  1563. var popup, formElement, useIEPostBridge;
  1564. options = object.extend({
  1565. popupName: 'popup_' + popupId + '_' + Number(new Date()),
  1566. popupOptionStr: '',
  1567. useReload: true,
  1568. closeWithParent: true,
  1569. method: 'get',
  1570. param: {}
  1571. }, options || {});
  1572. options.method = options.method.toUpperCase();
  1573. this.postBridgeUrl = options.postBridgeUrl || this.postBridgeUrl;
  1574. useIEPostBridge = options.method === 'POST' && options.param &&
  1575. browser.msie && browser.version === 11;
  1576. if (!type.isExisty(url)) {
  1577. throw new Error('Popup#open() need popup url.');
  1578. }
  1579. popupId += 1;
  1580. /*
  1581. * In form-data transmission
  1582. * 1. Create a form before opening a popup.
  1583. * 2. Transmit the form-data.
  1584. * 3. Remove the form after transmission.
  1585. */
  1586. if (options.param) {
  1587. if (options.method === 'GET') {
  1588. url = url + (/\?/.test(url) ? '&' : '?') + this._parameterize(options.param);
  1589. } else if (options.method === 'POST') {
  1590. if (!useIEPostBridge) {
  1591. formElement = this.createForm(url, options.param, options.method, options.popupName);
  1592. url = 'about:blank';
  1593. }
  1594. }
  1595. }
  1596. popup = this.openedPopup[options.popupName];
  1597. if (!type.isExisty(popup)) {
  1598. this.openedPopup[options.popupName] = popup = this._open(useIEPostBridge, options.param,
  1599. url, options.popupName, options.popupOptionStr);
  1600. } else if (popup.closed) {
  1601. this.openedPopup[options.popupName] = popup = this._open(useIEPostBridge, options.param,
  1602. url, options.popupName, options.popupOptionStr);
  1603. } else {
  1604. if (options.useReload) {
  1605. popup.location.replace(url);
  1606. }
  1607. popup.focus();
  1608. }
  1609. this.closeWithParentPopup[options.popupName] = options.closeWithParent;
  1610. if (!popup || popup.closed || type.isUndefined(popup.closed)) {
  1611. alert('please enable popup windows for this website');
  1612. }
  1613. if (options.param && options.method === 'POST' && !useIEPostBridge) {
  1614. if (popup) {
  1615. formElement.submit();
  1616. }
  1617. if (formElement.parentNode) {
  1618. formElement.parentNode.removeChild(formElement);
  1619. }
  1620. }
  1621. window.onunload = func.bind(this.closeAllPopup, this);
  1622. };
  1623. /**
  1624. * Close the popup
  1625. * @param {boolean} [skipBeforeUnload] - If true, the 'window.onunload' will be null and skip unload event.
  1626. * @param {Window} [popup] - Window-context of popup for closing. If omit this, current window-context will be closed.
  1627. */
  1628. Popup.prototype.close = function(skipBeforeUnload, popup) {
  1629. var target = popup || window;
  1630. skipBeforeUnload = type.isExisty(skipBeforeUnload) ? skipBeforeUnload : false;
  1631. if (skipBeforeUnload) {
  1632. window.onunload = null;
  1633. }
  1634. if (!target.closed) {
  1635. target.opener = window.location.href;
  1636. target.close();
  1637. }
  1638. };
  1639. /**
  1640. * Close all the popups in current window.
  1641. * @param {boolean} closeWithParent - If true, popups having the closeWithParentPopup property as true will be closed.
  1642. */
  1643. Popup.prototype.closeAllPopup = function(closeWithParent) {
  1644. var hasArg = type.isExisty(closeWithParent);
  1645. collection.forEachOwnProperties(this.openedPopup, function(popup, key) {
  1646. if ((hasArg && this.closeWithParentPopup[key]) || !hasArg) {
  1647. this.close(false, popup);
  1648. }
  1649. }, this);
  1650. };
  1651. /**
  1652. * Activate(or focus) the popup of the given name.
  1653. * @param {string} popupName - Name of popup for activation
  1654. */
  1655. Popup.prototype.focus = function(popupName) {
  1656. this.getPopupList(popupName).focus();
  1657. };
  1658. /**
  1659. * Return an object made of parsing the query string.
  1660. * @returns {Object} An object having some information of the query string.
  1661. * @private
  1662. */
  1663. Popup.prototype.parseQuery = function() {
  1664. var param = {};
  1665. var search, pair;
  1666. search = window.location.search.substr(1);
  1667. collection.forEachArray(search.split('&'), function(part) {
  1668. pair = part.split('=');
  1669. param[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  1670. });
  1671. return param;
  1672. };
  1673. /**
  1674. * Create a hidden form from the given arguments and return this form.
  1675. * @param {string} action - URL for form transmission
  1676. * @param {Object} [data] - Data for form transmission
  1677. * @param {string} [method] - Method of transmission
  1678. * @param {string} [target] - Target of transmission
  1679. * @param {HTMLElement} [container] - Container element of form.
  1680. * @returns {HTMLElement} Form element
  1681. */
  1682. Popup.prototype.createForm = function(action, data, method, target, container) {
  1683. var form = document.createElement('form'),
  1684. input;
  1685. container = container || document.body;
  1686. form.method = method || 'POST';
  1687. form.action = action || '';
  1688. form.target = target || '';
  1689. form.style.display = 'none';
  1690. collection.forEachOwnProperties(data, function(value, key) {
  1691. input = document.createElement('input');
  1692. input.name = key;
  1693. input.type = 'hidden';
  1694. input.value = value;
  1695. form.appendChild(input);
  1696. });
  1697. container.appendChild(form);
  1698. return form;
  1699. };
  1700. /**********
  1701. * private methods
  1702. **********/
  1703. /**
  1704. * Return an query string made by parsing the given object
  1705. * @param {Object} obj - An object that has information for query string
  1706. * @returns {string} - Query string
  1707. * @private
  1708. */
  1709. Popup.prototype._parameterize = function(obj) {
  1710. var query = [];
  1711. collection.forEachOwnProperties(obj, function(value, key) {
  1712. query.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
  1713. });
  1714. return query.join('&');
  1715. };
  1716. /**
  1717. * Open popup
  1718. * @param {boolean} useIEPostBridge - A switch option whether to use alternative
  1719. * of tossing POST data to the popup window in IE11
  1720. * @param {Object} param - A data for tossing to popup
  1721. * @param {string} url - Popup url
  1722. * @param {string} popupName - Popup name
  1723. * @param {string} optionStr - Setting for popup, ex) 'width=640,height=320,scrollbars=yes'
  1724. * @returns {Window} Window context of popup
  1725. * @private
  1726. */
  1727. Popup.prototype._open = function(useIEPostBridge, param, url, popupName, optionStr) {
  1728. var popup;
  1729. if (useIEPostBridge) {
  1730. popup = window.open(this.postBridgeUrl, popupName, optionStr);
  1731. setTimeout(function() {
  1732. popup.redirect(url, param);
  1733. }, 100);
  1734. } else {
  1735. popup = window.open(url, popupName, optionStr);
  1736. }
  1737. return popup;
  1738. };
  1739. module.exports = new Popup();
  1740. /***/ }),
  1741. /* 11 */
  1742. /***/ (function(module, exports, __webpack_require__) {
  1743. /**
  1744. * @fileoverview This module has a function for date format.
  1745. * @author NHN Ent.
  1746. * FE Development Lab <dl_javascript@nhnent.com>
  1747. * @dependency type.js, object.js
  1748. */
  1749. 'use strict';
  1750. var type = __webpack_require__(2);
  1751. var object = __webpack_require__(1);
  1752. var tokens = /[\\]*YYYY|[\\]*YY|[\\]*MMMM|[\\]*MMM|[\\]*MM|[\\]*M|[\\]*DD|[\\]*D|[\\]*HH|[\\]*H|[\\]*A/gi;
  1753. var MONTH_STR = [
  1754. 'Invalid month', 'January', 'February', 'March', 'April', 'May',
  1755. 'June', 'July', 'August', 'September', 'October', 'November', 'December'
  1756. ];
  1757. var MONTH_DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1758. var replaceMap = {
  1759. M: function(date) {
  1760. return Number(date.month);
  1761. },
  1762. MM: function(date) {
  1763. var month = date.month;
  1764. return (Number(month) < 10) ? '0' + month : month;
  1765. },
  1766. MMM: function(date) {
  1767. return MONTH_STR[Number(date.month)].substr(0, 3);
  1768. },
  1769. MMMM: function(date) {
  1770. return MONTH_STR[Number(date.month)];
  1771. },
  1772. D: function(date) {
  1773. return Number(date.date);
  1774. },
  1775. d: function(date) {
  1776. return replaceMap.D(date); // eslint-disable-line new-cap
  1777. },
  1778. DD: function(date) {
  1779. var dayInMonth = date.date;
  1780. return (Number(dayInMonth) < 10) ? '0' + dayInMonth : dayInMonth;
  1781. },
  1782. dd: function(date) {
  1783. return replaceMap.DD(date); // eslint-disable-line new-cap
  1784. },
  1785. YY: function(date) {
  1786. return Number(date.year) % 100;
  1787. },
  1788. yy: function(date) {
  1789. return replaceMap.YY(date); // eslint-disable-line new-cap
  1790. },
  1791. YYYY: function(date) {
  1792. var prefix = '20',
  1793. year = date.year;
  1794. if (year > 69 && year < 100) {
  1795. prefix = '19';
  1796. }
  1797. return (Number(year) < 100) ? prefix + String(year) : year;
  1798. },
  1799. yyyy: function(date) {
  1800. return replaceMap.YYYY(date); // eslint-disable-line new-cap
  1801. },
  1802. A: function(date) {
  1803. return date.meridiem;
  1804. },
  1805. a: function(date) {
  1806. return date.meridiem;
  1807. },
  1808. hh: function(date) {
  1809. var hour = date.hour;
  1810. return (Number(hour) < 10) ? '0' + hour : hour;
  1811. },
  1812. HH: function(date) {
  1813. return replaceMap.hh(date);
  1814. },
  1815. h: function(date) {
  1816. return String(Number(date.hour));
  1817. },
  1818. H: function(date) {
  1819. return replaceMap.h(date);
  1820. },
  1821. m: function(date) {
  1822. return String(Number(date.minute));
  1823. },
  1824. mm: function(date) {
  1825. var minute = date.minute;
  1826. return (Number(minute) < 10) ? '0' + minute : minute;
  1827. }
  1828. };
  1829. /**
  1830. * Check whether the given variables are valid date or not.
  1831. * @param {number} year - Year
  1832. * @param {number} month - Month
  1833. * @param {number} date - Day in month.
  1834. * @returns {boolean} Is valid?
  1835. * @private
  1836. */
  1837. function isValidDate(year, month, date) { // eslint-disable-line complexity
  1838. var isValidYear, isValidMonth, isValid, lastDayInMonth;
  1839. year = Number(year);
  1840. month = Number(month);
  1841. date = Number(date);
  1842. isValidYear = (year > -1 && year < 100) || (year > 1969) && (year < 2070);
  1843. isValidMonth = (month > 0) && (month < 13);
  1844. if (!isValidYear || !isValidMonth) {
  1845. return false;
  1846. }
  1847. lastDayInMonth = MONTH_DAYS[month];
  1848. if (month === 2 && year % 4 === 0) {
  1849. if (year % 100 !== 0 || year % 400 === 0) {
  1850. lastDayInMonth = 29;
  1851. }
  1852. }
  1853. isValid = (date > 0) && (date <= lastDayInMonth);
  1854. return isValid;
  1855. }
  1856. /**
  1857. * Return a string that transformed from the given form and date.
  1858. * @param {string} form - Date form
  1859. * @param {Date|Object} date - Date object
  1860. * @param {{meridiemSet: {AM: string, PM: string}}} option - Option
  1861. * @returns {boolean|string} A transformed string or false.
  1862. * @memberof tui.util
  1863. * @example
  1864. * // key | Shorthand
  1865. * // --------------- |-----------------------
  1866. * // years | YY / YYYY / yy / yyyy
  1867. * // months(n) | M / MM
  1868. * // months(str) | MMM / MMMM
  1869. * // days | D / DD / d / dd
  1870. * // hours | H / HH / h / hh
  1871. * // minutes | m / mm
  1872. * // meridiem(AM,PM) | A / a
  1873. *
  1874. * var dateStr1 = formatDate('yyyy-MM-dd', {
  1875. * year: 2014,
  1876. * month: 12,
  1877. * date: 12
  1878. * });
  1879. * alert(dateStr1); // '2014-12-12'
  1880. *
  1881. * var dateStr2 = formatDate('MMM DD YYYY HH:mm', {
  1882. * year: 1999,
  1883. * month: 9,
  1884. * date: 9,
  1885. * hour: 0,
  1886. * minute: 2
  1887. * })
  1888. * alert(dateStr2); // 'Sep 09 1999 00:02'
  1889. *
  1890. * var dt = new Date(2010, 2, 13),
  1891. * dateStr3 = formatDate('yyyy년 M월 dd일', dt);
  1892. *
  1893. * alert(dateStr3); // '2010년 3월 13일'
  1894. *
  1895. * var option4 = {
  1896. * meridiemSet: {
  1897. * AM: '오전',
  1898. * PM: '오후'
  1899. * }
  1900. * };
  1901. * var date4 = {year: 1999, month: 9, date: 9, hour: 13, minute: 2};
  1902. * var dateStr4 = formatDate('yyyy-MM-dd A hh:mm', date4, option4));
  1903. *
  1904. * alert(dateStr4); // '1999-09-09 오후 01:02'
  1905. */
  1906. function formatDate(form, date, option) { // eslint-disable-line complexity
  1907. var meridiem, nDate, resultStr;
  1908. if (type.isDate(date)) {
  1909. nDate = {
  1910. year: date.getFullYear(),
  1911. month: date.getMonth() + 1,
  1912. date: date.getDate(),
  1913. hour: date.getHours(),
  1914. minute: date.getMinutes()
  1915. };
  1916. } else {
  1917. nDate = {
  1918. year: date.year,
  1919. month: date.month,
  1920. date: date.date,
  1921. hour: date.hour,
  1922. minute: date.minute
  1923. };
  1924. }
  1925. if (!isValidDate(nDate.year, nDate.month, nDate.date)) {
  1926. return false;
  1927. }
  1928. nDate.meridiem = '';
  1929. if (/([^\\]|^)[aA]\b/.test(form)) {
  1930. meridiem = (nDate.hour > 11) ?
  1931. object.pick(option, 'meridiemSet', 'PM') || 'PM'
  1932. : object.pick(option, 'meridiemSet', 'AM') || 'AM';
  1933. if (nDate.hour > 12) { //See the clock system: https://en.wikipedia.org/wiki/12-hour_clock
  1934. nDate.hour %= 12;
  1935. }
  1936. if (nDate.hour === 0) {
  1937. nDate.hour = 12;
  1938. }
  1939. nDate.meridiem = meridiem;
  1940. }
  1941. resultStr = form.replace(tokens, function(key) {
  1942. if (key.indexOf('\\') > -1) { // escape character
  1943. return key.replace(/\\/, '');
  1944. }
  1945. return replaceMap[key](nDate) || '';
  1946. });
  1947. return resultStr;
  1948. }
  1949. module.exports = formatDate;
  1950. /***/ }),
  1951. /* 12 */
  1952. /***/ (function(module, exports, __webpack_require__) {
  1953. /**
  1954. * @fileoverview
  1955. * This module provides a function to make a constructor
  1956. * that can inherit from the other constructors like the CLASS easily.
  1957. * @author NHN Ent.
  1958. * FE Development Lab <dl_javascript@nhnent.com>
  1959. * @dependencies inheritance.js, object.js
  1960. */
  1961. 'use strict';
  1962. var inherit = __webpack_require__(6).inherit;
  1963. var extend = __webpack_require__(1).extend;
  1964. /**
  1965. * Help a constructor to be defined and to inherit from the other constructors
  1966. * @param {*} [parent] Parent constructor
  1967. * @param {Object} props Members of constructor
  1968. * @param {Function} props.init Initialization method
  1969. * @param {Object} [props.static] Static members of constructor
  1970. * @returns {*} Constructor
  1971. * @memberof tui.util
  1972. * @example
  1973. * var Parent = tui.util.defineClass({
  1974. * init: function() {
  1975. * this.name = 'made by def';
  1976. * },
  1977. * method: function() {
  1978. * //..can do something with this
  1979. * },
  1980. * static: {
  1981. * staticMethod: function() {
  1982. * //..do something
  1983. * }
  1984. * }
  1985. * });
  1986. *
  1987. * var Child = tui.util.defineClass(Parent, {
  1988. * method2: function() {}
  1989. * });
  1990. *
  1991. * Parent.staticMethod();
  1992. *
  1993. * var parentInstance = new Parent();
  1994. * console.log(parentInstance.name); //made by def
  1995. * parentInstance.staticMethod(); // Error
  1996. *
  1997. * var childInstance = new Child();
  1998. * childInstance.method();
  1999. * childInstance.method2();
  2000. */
  2001. function defineClass(parent, props) {
  2002. var obj;
  2003. if (!props) {
  2004. props = parent;
  2005. parent = null;
  2006. }
  2007. obj = props.init || function() {};
  2008. if (parent) {
  2009. inherit(obj, parent);
  2010. }
  2011. if (props.hasOwnProperty('static')) {
  2012. extend(obj, props['static']);
  2013. delete props['static'];
  2014. }
  2015. extend(obj.prototype, props);
  2016. return obj;
  2017. }
  2018. module.exports = defineClass;
  2019. /***/ }),
  2020. /* 13 */
  2021. /***/ (function(module, exports, __webpack_require__) {
  2022. /**
  2023. * @fileoverview Define module
  2024. * @author NHN Ent.
  2025. * FE Development Lab <dl_javscript@nhnent.com>
  2026. * @dependency type.js, defineNamespace.js
  2027. */
  2028. 'use strict';
  2029. var defineNamespace = __webpack_require__(14);
  2030. var type = __webpack_require__(2);
  2031. var INITIALIZATION_METHOD_NAME = 'initialize';
  2032. /**
  2033. * Define module
  2034. * @param {string} namespace - Namespace of module
  2035. * @param {Object} moduleDefinition - Object literal for module
  2036. * @returns {Object} Defined module
  2037. * @memberof tui.util
  2038. * @example
  2039. * var myModule = tui.util.defineModule('modules.myModule', {
  2040. * name: 'john',
  2041. * message: '',
  2042. * initialize: function() {
  2043. * this.message = 'hello world';
  2044. * },
  2045. * getMessage: function() {
  2046. * return this.name + ': ' + this.message
  2047. * }
  2048. * });
  2049. *
  2050. * console.log(myModule.getMessage()); // 'john: hello world';
  2051. * console.log(window.modules.myModule.getMessage()); // 'john: hello world';
  2052. */
  2053. function defineModule(namespace, moduleDefinition) {
  2054. var base = moduleDefinition || {};
  2055. if (type.isFunction(base[INITIALIZATION_METHOD_NAME])) {
  2056. base[INITIALIZATION_METHOD_NAME]();
  2057. }
  2058. return defineNamespace(namespace, base);
  2059. }
  2060. module.exports = defineModule;
  2061. /***/ }),
  2062. /* 14 */
  2063. /***/ (function(module, exports, __webpack_require__) {
  2064. /**
  2065. * @fileoverview Define namespace
  2066. * @author NHN Ent.
  2067. * FE Development Lab <dl_javascript@nhnent.com>
  2068. * @dependency object.js, collection.js
  2069. */
  2070. 'use strict';
  2071. var collection = __webpack_require__(4);
  2072. var object = __webpack_require__(1);
  2073. /**
  2074. * Define namespace
  2075. * @param {string} namespace - Namespace (ex- 'foo.bar.baz')
  2076. * @param {(object|function)} props - A set of modules or one module
  2077. * @param {boolean} [isOverride] - Override the props to the namespace.<br>
  2078. * (It removes previous properties of this namespace)
  2079. * @returns {(object|function)} Defined namespace
  2080. * @memberof tui.util
  2081. * @example
  2082. * var neComp = tui.util.defineNamespace('ne.component');
  2083. * neComp.listMenu = defineClass({
  2084. * init: function() {
  2085. * // code
  2086. * }
  2087. * });
  2088. */
  2089. function defineNamespace(namespace, props, isOverride) {
  2090. var names, result, prevLast, last;
  2091. names = namespace.split('.');
  2092. names.unshift(window);
  2093. result = collection.reduce(names, function(obj, name) {
  2094. obj[name] = obj[name] || {};
  2095. return obj[name];
  2096. });
  2097. if (isOverride) {
  2098. last = names.pop();
  2099. prevLast = object.pick.apply(null, names);
  2100. result = prevLast[last] = props;
  2101. } else {
  2102. object.extend(result, props);
  2103. }
  2104. return result;
  2105. }
  2106. module.exports = defineNamespace;
  2107. /***/ }),
  2108. /* 15 */
  2109. /***/ (function(module, exports, __webpack_require__) {
  2110. /**
  2111. * @fileoverview
  2112. * This module provides some functions for custom events.<br>
  2113. * And it is implemented in the observer design pattern.
  2114. * @author NHN Ent.
  2115. * FE Development Lab <dl_javascript@nhnent.com>
  2116. * @dependency type.js, collection.js object.js
  2117. */
  2118. 'use strict';
  2119. var collection = __webpack_require__(4);
  2120. var type = __webpack_require__(2);
  2121. var object = __webpack_require__(1);
  2122. var R_EVENTNAME_SPLIT = /\s+/g;
  2123. /**
  2124. * A unit of event handler item.
  2125. * @ignore
  2126. * @typedef {object} HandlerItem
  2127. * @property {function} fn - event handler
  2128. * @property {object} ctx - context of event handler
  2129. */
  2130. /**
  2131. * @class
  2132. * @memberof tui.util
  2133. */
  2134. function CustomEvents() {
  2135. /**
  2136. * @type {HandlerItem[]}
  2137. */
  2138. this.events = null;
  2139. /**
  2140. * only for checking specific context event was binded
  2141. * @type {object[]}
  2142. */
  2143. this.contexts = null;
  2144. }
  2145. /**
  2146. * Mixin custom events feature to specific constructor
  2147. * @param {function} func - constructor
  2148. * @example
  2149. * function Model() {
  2150. * this.name = '';
  2151. * }
  2152. * tui.util.CustomEvents.mixin(Model);
  2153. *
  2154. * var model = new Model();
  2155. * model.on('change', function() { this.name = 'model'; }, this);
  2156. *
  2157. * model.fire('change');
  2158. * alert(model.name); // 'model';
  2159. */
  2160. CustomEvents.mixin = function(func) {
  2161. object.extend(func.prototype, CustomEvents.prototype);
  2162. };
  2163. /**
  2164. * Get HandlerItem object
  2165. * @param {function} handler - handler function
  2166. * @param {object} [context] - context for handler
  2167. * @returns {HandlerItem} HandlerItem object
  2168. * @private
  2169. */
  2170. CustomEvents.prototype._getHandlerItem = function(handler, context) {
  2171. var item = {handler: handler};
  2172. if (context) {
  2173. item.context = context;
  2174. }
  2175. return item;
  2176. };
  2177. /**
  2178. * Get event object safely
  2179. * @param {string} [eventName] - create sub event map if not exist.
  2180. * @returns {(object|array)} event object. if you supplied `eventName`
  2181. * parameter then make new array and return it
  2182. * @private
  2183. */
  2184. CustomEvents.prototype._safeEvent = function(eventName) {
  2185. var events = this.events;
  2186. var byName;
  2187. if (!events) {
  2188. events = this.events = {};
  2189. }
  2190. if (eventName) {
  2191. byName = events[eventName];
  2192. if (!byName) {
  2193. byName = [];
  2194. events[eventName] = byName;
  2195. }
  2196. events = byName;
  2197. }
  2198. return events;
  2199. };
  2200. /**
  2201. * Get context array safely
  2202. * @returns {array} context array
  2203. * @private
  2204. */
  2205. CustomEvents.prototype._safeContext = function() {
  2206. var context = this.contexts;
  2207. if (!context) {
  2208. context = this.contexts = [];
  2209. }
  2210. return context;
  2211. };
  2212. /**
  2213. * Get index of context
  2214. * @param {object} ctx - context that used for bind custom event
  2215. * @returns {number} index of context
  2216. * @private
  2217. */
  2218. CustomEvents.prototype._indexOfContext = function(ctx) {
  2219. var context = this._safeContext();
  2220. var index = 0;
  2221. while (context[index]) {
  2222. if (ctx === context[index][0]) {
  2223. return index;
  2224. }
  2225. index += 1;
  2226. }
  2227. return -1;
  2228. };
  2229. /**
  2230. * Memorize supplied context for recognize supplied object is context or
  2231. * name: handler pair object when off()
  2232. * @param {object} ctx - context object to memorize
  2233. * @private
  2234. */
  2235. CustomEvents.prototype._memorizeContext = function(ctx) {
  2236. var context, index;
  2237. if (!type.isExisty(ctx)) {
  2238. return;
  2239. }
  2240. context = this._safeContext();
  2241. index = this._indexOfContext(ctx);
  2242. if (index > -1) {
  2243. context[index][1] += 1;
  2244. } else {
  2245. context.push([ctx, 1]);
  2246. }
  2247. };
  2248. /**
  2249. * Forget supplied context object
  2250. * @param {object} ctx - context object to forget
  2251. * @private
  2252. */
  2253. CustomEvents.prototype._forgetContext = function(ctx) {
  2254. var context, contextIndex;
  2255. if (!type.isExisty(ctx)) {
  2256. return;
  2257. }
  2258. context = this._safeContext();
  2259. contextIndex = this._indexOfContext(ctx);
  2260. if (contextIndex > -1) {
  2261. context[contextIndex][1] -= 1;
  2262. if (context[contextIndex][1] <= 0) {
  2263. context.splice(contextIndex, 1);
  2264. }
  2265. }
  2266. };
  2267. /**
  2268. * Bind event handler
  2269. * @param {(string|{name:string, handler:function})} eventName - custom
  2270. * event name or an object {eventName: handler}
  2271. * @param {(function|object)} [handler] - handler function or context
  2272. * @param {object} [context] - context for binding
  2273. * @private
  2274. */
  2275. CustomEvents.prototype._bindEvent = function(eventName, handler, context) {
  2276. var events = this._safeEvent(eventName);
  2277. this._memorizeContext(context);
  2278. events.push(this._getHandlerItem(handler, context));
  2279. };
  2280. /**
  2281. * Bind event handlers
  2282. * @param {(string|{name:string, handler:function})} eventName - custom
  2283. * event name or an object {eventName: handler}
  2284. * @param {(function|object)} [handler] - handler function or context
  2285. * @param {object} [context] - context for binding
  2286. * @example
  2287. * // 1. Basic
  2288. * ustomEvent.on('onload', handler);
  2289. *
  2290. * // 2. With context
  2291. * customEvent.on('onload', handler, myObj);
  2292. *
  2293. * // 3. Bind by object that name, handler pairs
  2294. * customEvent.on({
  2295. * 'play': handler,
  2296. * 'pause': handler2
  2297. * });
  2298. *
  2299. * // 4. Bind by object that name, handler pairs with context object
  2300. * customEvent.on({
  2301. * 'play': handler
  2302. * }, myObj);
  2303. */
  2304. CustomEvents.prototype.on = function(eventName, handler, context) {
  2305. var self = this;
  2306. if (type.isString(eventName)) {
  2307. // [syntax 1, 2]
  2308. eventName = eventName.split(R_EVENTNAME_SPLIT);
  2309. collection.forEach(eventName, function(name) {
  2310. self._bindEvent(name, handler, context);
  2311. });
  2312. } else if (type.isObject(eventName)) {
  2313. // [syntax 3, 4]
  2314. context = handler;
  2315. collection.forEach(eventName, function(func, name) {
  2316. self.on(name, func, context);
  2317. });
  2318. }
  2319. };
  2320. /**
  2321. * Bind one-shot event handlers
  2322. * @param {(string|{name:string,handler:function})} eventName - custom
  2323. * event name or an object {eventName: handler}
  2324. * @param {function|object} [handler] - handler function or context
  2325. * @param {object} [context] - context for binding
  2326. */
  2327. CustomEvents.prototype.once = function(eventName, handler, context) {
  2328. var self = this;
  2329. if (type.isObject(eventName)) {
  2330. context = handler;
  2331. collection.forEach(eventName, function(func, name) {
  2332. self.once(name, func, context);
  2333. });
  2334. return;
  2335. }
  2336. function onceHandler() { // eslint-disable-line require-jsdoc
  2337. handler.apply(context, arguments);
  2338. self.off(eventName, onceHandler, context);
  2339. }
  2340. this.on(eventName, onceHandler, context);
  2341. };
  2342. /**
  2343. * Splice supplied array by callback result
  2344. * @param {array} arr - array to splice
  2345. * @param {function} predicate - function return boolean
  2346. * @private
  2347. */
  2348. CustomEvents.prototype._spliceMatches = function(arr, predicate) {
  2349. var i = 0;
  2350. var len;
  2351. if (!type.isArray(arr)) {
  2352. return;
  2353. }
  2354. for (len = arr.length; i < len; i += 1) {
  2355. if (predicate(arr[i]) === true) {
  2356. arr.splice(i, 1);
  2357. len -= 1;
  2358. i -= 1;
  2359. }
  2360. }
  2361. };
  2362. /**
  2363. * Get matcher for unbind specific handler events
  2364. * @param {function} handler - handler function
  2365. * @returns {function} handler matcher
  2366. * @private
  2367. */
  2368. CustomEvents.prototype._matchHandler = function(handler) {
  2369. var self = this;
  2370. return function(item) {
  2371. var needRemove = handler === item.handler;
  2372. if (needRemove) {
  2373. self._forgetContext(item.context);
  2374. }
  2375. return needRemove;
  2376. };
  2377. };
  2378. /**
  2379. * Get matcher for unbind specific context events
  2380. * @param {object} context - context
  2381. * @returns {function} object matcher
  2382. * @private
  2383. */
  2384. CustomEvents.prototype._matchContext = function(context) {
  2385. var self = this;
  2386. return function(item) {
  2387. var needRemove = context === item.context;
  2388. if (needRemove) {
  2389. self._forgetContext(item.context);
  2390. }
  2391. return needRemove;
  2392. };
  2393. };
  2394. /**
  2395. * Get matcher for unbind specific hander, context pair events
  2396. * @param {function} handler - handler function
  2397. * @param {object} context - context
  2398. * @returns {function} handler, context matcher
  2399. * @private
  2400. */
  2401. CustomEvents.prototype._matchHandlerAndContext = function(handler, context) {
  2402. var self = this;
  2403. return function(item) {
  2404. var matchHandler = (handler === item.handler);
  2405. var matchContext = (context === item.context);
  2406. var needRemove = (matchHandler && matchContext);
  2407. if (needRemove) {
  2408. self._forgetContext(item.context);
  2409. }
  2410. return needRemove;
  2411. };
  2412. };
  2413. /**
  2414. * Unbind event by event name
  2415. * @param {string} eventName - custom event name to unbind
  2416. * @param {function} [handler] - handler function
  2417. * @private
  2418. */
  2419. CustomEvents.prototype._offByEventName = function(eventName, handler) {
  2420. var self = this;
  2421. var forEach = collection.forEachArray;
  2422. var andByHandler = type.isFunction(handler);
  2423. var matchHandler = self._matchHandler(handler);
  2424. eventName = eventName.split(R_EVENTNAME_SPLIT);
  2425. forEach(eventName, function(name) {
  2426. var handlerItems = self._safeEvent(name);
  2427. if (andByHandler) {
  2428. self._spliceMatches(handlerItems, matchHandler);
  2429. } else {
  2430. forEach(handlerItems, function(item) {
  2431. self._forgetContext(item.context);
  2432. });
  2433. self.events[name] = [];
  2434. }
  2435. });
  2436. };
  2437. /**
  2438. * Unbind event by handler function
  2439. * @param {function} handler - handler function
  2440. * @private
  2441. */
  2442. CustomEvents.prototype._offByHandler = function(handler) {
  2443. var self = this;
  2444. var matchHandler = this._matchHandler(handler);
  2445. collection.forEach(this._safeEvent(), function(handlerItems) {
  2446. self._spliceMatches(handlerItems, matchHandler);
  2447. });
  2448. };
  2449. /**
  2450. * Unbind event by object(name: handler pair object or context object)
  2451. * @param {object} obj - context or {name: handler} pair object
  2452. * @param {function} handler - handler function
  2453. * @private
  2454. */
  2455. CustomEvents.prototype._offByObject = function(obj, handler) {
  2456. var self = this;
  2457. var matchFunc;
  2458. if (this._indexOfContext(obj) < 0) {
  2459. collection.forEach(obj, function(func, name) {
  2460. self.off(name, func);
  2461. });
  2462. } else if (type.isString(handler)) {
  2463. matchFunc = this._matchContext(obj);
  2464. self._spliceMatches(this._safeEvent(handler), matchFunc);
  2465. } else if (type.isFunction(handler)) {
  2466. matchFunc = this._matchHandlerAndContext(handler, obj);
  2467. collection.forEach(this._safeEvent(), function(handlerItems) {
  2468. self._spliceMatches(handlerItems, matchFunc);
  2469. });
  2470. } else {
  2471. matchFunc = this._matchContext(obj);
  2472. collection.forEach(this._safeEvent(), function(handlerItems) {
  2473. self._spliceMatches(handlerItems, matchFunc);
  2474. });
  2475. }
  2476. };
  2477. /**
  2478. * Unbind custom events
  2479. * @param {(string|object|function)} eventName - event name or context or
  2480. * {name: handler} pair object or handler function
  2481. * @param {(function)} handler - handler function
  2482. * @example
  2483. * // 1. off by event name
  2484. * customEvent.off('onload');
  2485. *
  2486. * // 2. off by event name and handler
  2487. * customEvent.off('play', handler);
  2488. *
  2489. * // 3. off by handler
  2490. * customEvent.off(handler);
  2491. *
  2492. * // 4. off by context
  2493. * customEvent.off(myObj);
  2494. *
  2495. * // 5. off by context and handler
  2496. * customEvent.off(myObj, handler);
  2497. *
  2498. * // 6. off by context and event name
  2499. * customEvent.off(myObj, 'onload');
  2500. *
  2501. * // 7. off by an Object.<string, function> that is {eventName: handler}
  2502. * customEvent.off({
  2503. * 'play': handler,
  2504. * 'pause': handler2
  2505. * });
  2506. *
  2507. * // 8. off the all events
  2508. * customEvent.off();
  2509. */
  2510. CustomEvents.prototype.off = function(eventName, handler) {
  2511. if (type.isString(eventName)) {
  2512. // [syntax 1, 2]
  2513. this._offByEventName(eventName, handler);
  2514. } else if (!arguments.length) {
  2515. // [syntax 8]
  2516. this.events = {};
  2517. this.contexts = [];
  2518. } else if (type.isFunction(eventName)) {
  2519. // [syntax 3]
  2520. this._offByHandler(eventName);
  2521. } else if (type.isObject(eventName)) {
  2522. // [syntax 4, 5, 6]
  2523. this._offByObject(eventName, handler);
  2524. }
  2525. };
  2526. /**
  2527. * Fire custom event
  2528. * @param {string} eventName - name of custom event
  2529. */
  2530. CustomEvents.prototype.fire = function(eventName) { // eslint-disable-line
  2531. this.invoke.apply(this, arguments);
  2532. };
  2533. /**
  2534. * Fire a event and returns the result of operation 'boolean AND' with all
  2535. * listener's results.
  2536. *
  2537. * So, It is different from {@link CustomEvents#fire}.
  2538. *
  2539. * In service code, use this as a before event in component level usually
  2540. * for notifying that the event is cancelable.
  2541. * @param {string} eventName - Custom event name
  2542. * @param {...*} data - Data for event
  2543. * @returns {boolean} The result of operation 'boolean AND'
  2544. * @example
  2545. * if (this.invoke('beforeZoom')) { // check the result of 'beforeZoom'
  2546. * // if true,
  2547. * // doSomething
  2548. * }
  2549. *
  2550. * // In service code,
  2551. * map.on({
  2552. * 'beforeZoom': function() {
  2553. * // It should cancel the 'zoom' event by some conditions.
  2554. * if (that.disabled && this.getState()) {
  2555. * return false;
  2556. * }
  2557. * return true;
  2558. * }
  2559. * });
  2560. */
  2561. CustomEvents.prototype.invoke = function(eventName) {
  2562. var events, args, index, item;
  2563. if (!this.hasListener(eventName)) {
  2564. return true;
  2565. }
  2566. events = this._safeEvent(eventName);
  2567. args = Array.prototype.slice.call(arguments, 1);
  2568. index = 0;
  2569. while (events[index]) {
  2570. item = events[index];
  2571. if (item.handler.apply(item.context, args) === false) {
  2572. return false;
  2573. }
  2574. index += 1;
  2575. }
  2576. return true;
  2577. };
  2578. /**
  2579. * Return whether at least one of the handlers is registered in the given
  2580. * event name.
  2581. * @param {string} eventName - Custom event name
  2582. * @returns {boolean} Is there at least one handler in event name?
  2583. */
  2584. CustomEvents.prototype.hasListener = function(eventName) {
  2585. return this.getListenerLength(eventName) > 0;
  2586. };
  2587. /**
  2588. * Return a count of events registered.
  2589. * @param {string} eventName - Custom event name
  2590. * @returns {number} number of event
  2591. */
  2592. CustomEvents.prototype.getListenerLength = function(eventName) {
  2593. var events = this._safeEvent(eventName);
  2594. return events.length;
  2595. };
  2596. module.exports = CustomEvents;
  2597. /***/ }),
  2598. /* 16 */
  2599. /***/ (function(module, exports, __webpack_require__) {
  2600. /**
  2601. * @fileoverview This module provides a Enum Constructor.
  2602. * @author NHN Ent.
  2603. * FE Development Lab <dl_javascript@nhnent.com>
  2604. * @dependency type, collection.js
  2605. */
  2606. 'use strict';
  2607. var collection = __webpack_require__(4);
  2608. var type = __webpack_require__(2);
  2609. /**
  2610. * Check whether the defineProperty() method is supported.
  2611. * @type {boolean}
  2612. * @ignore
  2613. */
  2614. var isSupportDefinedProperty = (function() {
  2615. try {
  2616. Object.defineProperty({}, 'x', {});
  2617. return true;
  2618. } catch (e) {
  2619. return false;
  2620. }
  2621. })();
  2622. /**
  2623. * A unique value of a constant.
  2624. * @type {number}
  2625. * @ignore
  2626. */
  2627. var enumValue = 0;
  2628. /**
  2629. * Make a constant-list that has unique values.<br>
  2630. * In modern browsers (except IE8 and lower),<br>
  2631. * a value defined once can not be changed.
  2632. *
  2633. * @param {...string|string[]} itemList Constant-list (An array of string is available)
  2634. * @class
  2635. * @memberof tui.util
  2636. * @example
  2637. * //create
  2638. * var MYENUM = new tui.util.Enum('TYPE1', 'TYPE2');
  2639. * var MYENUM2 = new tui.util.Enum(['TYPE1', 'TYPE2']);
  2640. *
  2641. * //usage
  2642. * if (value === MYENUM.TYPE1) {
  2643. * ....
  2644. * }
  2645. *
  2646. * //add (If a duplicate name is inputted, will be disregarded.)
  2647. * MYENUM.set('TYPE3', 'TYPE4');
  2648. *
  2649. * //get name of a constant by a value
  2650. * MYENUM.getName(MYENUM.TYPE1); // 'TYPE1'
  2651. *
  2652. * // In modern browsers (except IE8 and lower), a value can not be changed in constants.
  2653. * var originalValue = MYENUM.TYPE1;
  2654. * MYENUM.TYPE1 = 1234; // maybe TypeError
  2655. * MYENUM.TYPE1 === originalValue; // true
  2656. *
  2657. **/
  2658. function Enum(itemList) {
  2659. if (itemList) {
  2660. this.set.apply(this, arguments);
  2661. }
  2662. }
  2663. /**
  2664. * Define a constants-list
  2665. * @param {...string|string[]} itemList Constant-list (An array of string is available)
  2666. */
  2667. Enum.prototype.set = function(itemList) {
  2668. var self = this;
  2669. if (!type.isArray(itemList)) {
  2670. itemList = collection.toArray(arguments);
  2671. }
  2672. collection.forEach(itemList, function itemListIteratee(item) {
  2673. self._addItem(item);
  2674. });
  2675. };
  2676. /**
  2677. * Return a key of the constant.
  2678. * @param {number} value A value of the constant.
  2679. * @returns {string|undefined} Key of the constant.
  2680. */
  2681. Enum.prototype.getName = function(value) {
  2682. var self = this;
  2683. var foundedKey;
  2684. collection.forEach(this, function(itemValue, key) { // eslint-disable-line consistent-return
  2685. if (self._isEnumItem(key) && value === itemValue) {
  2686. foundedKey = key;
  2687. return false;
  2688. }
  2689. });
  2690. return foundedKey;
  2691. };
  2692. /**
  2693. * Create a constant.
  2694. * @private
  2695. * @param {string} name Constant name. (It will be a key of a constant)
  2696. */
  2697. Enum.prototype._addItem = function(name) {
  2698. var value;
  2699. if (!this.hasOwnProperty(name)) {
  2700. value = this._makeEnumValue();
  2701. if (isSupportDefinedProperty) {
  2702. Object.defineProperty(this, name, {
  2703. enumerable: true,
  2704. configurable: false,
  2705. writable: false,
  2706. value: value
  2707. });
  2708. } else {
  2709. this[name] = value;
  2710. }
  2711. }
  2712. };
  2713. /**
  2714. * Return a unique value for assigning to a constant.
  2715. * @private
  2716. * @returns {number} A unique value
  2717. */
  2718. Enum.prototype._makeEnumValue = function() {
  2719. var value;
  2720. value = enumValue;
  2721. enumValue += 1;
  2722. return value;
  2723. };
  2724. /**
  2725. * Return whether a constant from the given key is in instance or not.
  2726. * @param {string} key - A constant key
  2727. * @returns {boolean} Result
  2728. * @private
  2729. */
  2730. Enum.prototype._isEnumItem = function(key) {
  2731. return type.isNumber(this[key]);
  2732. };
  2733. module.exports = Enum;
  2734. /***/ }),
  2735. /* 17 */
  2736. /***/ (function(module, exports, __webpack_require__) {
  2737. /**
  2738. * @fileoverview
  2739. * Implements the ExMap (Extended Map) object.
  2740. * @author NHN Ent.
  2741. * FE Development Lab <dl_javascript@nhnent.com>
  2742. * @dependency Map.js, collection.js
  2743. */
  2744. 'use strict';
  2745. var collection = __webpack_require__(4);
  2746. var Map = __webpack_require__(18);
  2747. // Caching tui.util for performance enhancing
  2748. var mapAPIsForRead = ['get', 'has', 'forEach', 'keys', 'values', 'entries'];
  2749. var mapAPIsForDelete = ['delete', 'clear'];
  2750. /**
  2751. * The ExMap object is Extended Version of the tui.util.Map object.<br>
  2752. * and added some useful feature to make it easy to manage the Map object.
  2753. * @constructor
  2754. * @param {Array} initData - Array of key-value pairs (2-element Arrays).
  2755. * Each key-value pair will be added to the new Map
  2756. * @memberof tui.util
  2757. */
  2758. function ExMap(initData) {
  2759. this._map = new Map(initData);
  2760. this.size = this._map.size;
  2761. }
  2762. collection.forEachArray(mapAPIsForRead, function(name) {
  2763. ExMap.prototype[name] = function() {
  2764. return this._map[name].apply(this._map, arguments);
  2765. };
  2766. });
  2767. collection.forEachArray(mapAPIsForDelete, function(name) {
  2768. ExMap.prototype[name] = function() {
  2769. var result = this._map[name].apply(this._map, arguments);
  2770. this.size = this._map.size;
  2771. return result;
  2772. };
  2773. });
  2774. ExMap.prototype.set = function() {
  2775. this._map.set.apply(this._map, arguments);
  2776. this.size = this._map.size;
  2777. return this;
  2778. };
  2779. /**
  2780. * Sets all of the key-value pairs in the specified object to the Map object.
  2781. * @param {Object} object - Plain object that has a key-value pair
  2782. */
  2783. ExMap.prototype.setObject = function(object) {
  2784. collection.forEachOwnProperties(object, function(value, key) {
  2785. this.set(key, value);
  2786. }, this);
  2787. };
  2788. /**
  2789. * Removes the elements associated with keys in the specified array.
  2790. * @param {Array} keys - Array that contains keys of the element to remove
  2791. */
  2792. ExMap.prototype.deleteByKeys = function(keys) {
  2793. collection.forEachArray(keys, function(key) {
  2794. this['delete'](key);
  2795. }, this);
  2796. };
  2797. /**
  2798. * Sets all of the key-value pairs in the specified Map object to this Map object.
  2799. * @param {Map} map - Map object to be merged into this Map object
  2800. */
  2801. ExMap.prototype.merge = function(map) {
  2802. map.forEach(function(value, key) {
  2803. this.set(key, value);
  2804. }, this);
  2805. };
  2806. /**
  2807. * Looks through each key-value pair in the map and returns the new ExMap object of
  2808. * all key-value pairs that pass a truth test implemented by the provided function.
  2809. * @param {function} predicate - Function to test each key-value pair of the Map object.<br>
  2810. * Invoked with arguments (value, key). Return true to keep the element, false otherwise.
  2811. * @returns {ExMap} A new ExMap object
  2812. */
  2813. ExMap.prototype.filter = function(predicate) {
  2814. var filtered = new ExMap();
  2815. this.forEach(function(value, key) {
  2816. if (predicate(value, key)) {
  2817. filtered.set(key, value);
  2818. }
  2819. });
  2820. return filtered;
  2821. };
  2822. module.exports = ExMap;
  2823. /***/ }),
  2824. /* 18 */
  2825. /***/ (function(module, exports, __webpack_require__) {
  2826. /**
  2827. * @fileoverview
  2828. * Implements the Map object.
  2829. * @author NHN Ent.
  2830. * FE Development Lab <dl_javascript@nhnent.com>
  2831. * @dependency type.js, collection.js
  2832. */
  2833. 'use strict';
  2834. var collection = __webpack_require__(4);
  2835. var type = __webpack_require__(2);
  2836. var array = __webpack_require__(3);
  2837. var browser = __webpack_require__(9);
  2838. var func = __webpack_require__(5);
  2839. /**
  2840. * Using undefined for a key can be ambiguous if there's deleted item in the array,<br>
  2841. * which is also undefined when accessed by index.<br>
  2842. * So use this unique object as an undefined key to distinguish it from deleted keys.
  2843. * @private
  2844. * @constant
  2845. */
  2846. var _KEY_FOR_UNDEFINED = {};
  2847. /**
  2848. * For using NaN as a key, use this unique object as a NaN key.<br>
  2849. * This makes it easier and faster to compare an object with each keys in the array<br>
  2850. * through no exceptional comapring for NaN.
  2851. * @private
  2852. * @constant
  2853. */
  2854. var _KEY_FOR_NAN = {};
  2855. /**
  2856. * Constructor of MapIterator<br>
  2857. * Creates iterator object with new keyword.
  2858. * @constructor
  2859. * @param {Array} keys - The array of keys in the map
  2860. * @param {function} valueGetter - Function that returns certain value,
  2861. * taking key and keyIndex as arguments.
  2862. * @ignore
  2863. */
  2864. function MapIterator(keys, valueGetter) {
  2865. this._keys = keys;
  2866. this._valueGetter = valueGetter;
  2867. this._length = this._keys.length;
  2868. this._index = -1;
  2869. this._done = false;
  2870. }
  2871. /**
  2872. * Implementation of Iterator protocol.
  2873. * @returns {{done: boolean, value: *}} Object that contains done(boolean) and value.
  2874. */
  2875. MapIterator.prototype.next = function() {
  2876. var data = {};
  2877. do {
  2878. this._index += 1;
  2879. } while (type.isUndefined(this._keys[this._index]) && this._index < this._length);
  2880. if (this._index >= this._length) {
  2881. data.done = true;
  2882. } else {
  2883. data.done = false;
  2884. data.value = this._valueGetter(this._keys[this._index], this._index);
  2885. }
  2886. return data;
  2887. };
  2888. /**
  2889. * The Map object implements the ES6 Map specification as closely as possible.<br>
  2890. * For using objects and primitive values as keys, this object uses array internally.<br>
  2891. * So if the key is not a string, get(), set(), has(), delete() will operates in O(n),<br>
  2892. * and it can cause performance issues with a large dataset.
  2893. *
  2894. * Features listed below are not supported. (can't be implented without native support)
  2895. * - Map object is iterable<br>
  2896. * - Iterable object can be used as an argument of constructor
  2897. *
  2898. * If the browser supports full implementation of ES6 Map specification, native Map obejct
  2899. * will be used internally.
  2900. * @class
  2901. * @param {Array} initData - Array of key-value pairs (2-element Arrays).
  2902. * Each key-value pair will be added to the new Map
  2903. * @memberof tui.util
  2904. */
  2905. function Map(initData) {
  2906. this._valuesForString = {};
  2907. this._valuesForIndex = {};
  2908. this._keys = [];
  2909. if (initData) {
  2910. this._setInitData(initData);
  2911. }
  2912. this.size = 0;
  2913. }
  2914. /* eslint-disable no-extend-native */
  2915. /**
  2916. * Add all elements in the initData to the Map object.
  2917. * @private
  2918. * @param {Array} initData - Array of key-value pairs to add to the Map object
  2919. */
  2920. Map.prototype._setInitData = function(initData) {
  2921. if (!type.isArray(initData)) {
  2922. throw new Error('Only Array is supported.');
  2923. }
  2924. collection.forEachArray(initData, function(pair) {
  2925. this.set(pair[0], pair[1]);
  2926. }, this);
  2927. };
  2928. /**
  2929. * Returns true if the specified value is NaN.<br>
  2930. * For unsing NaN as a key, use this method to test equality of NaN<br>
  2931. * because === operator doesn't work for NaN.
  2932. * @private
  2933. * @param {*} value - Any object to be tested
  2934. * @returns {boolean} True if value is NaN, false otherwise.
  2935. */
  2936. Map.prototype._isNaN = function(value) {
  2937. return typeof value === 'number' && value !== value; // eslint-disable-line no-self-compare
  2938. };
  2939. /**
  2940. * Returns the index of the specified key.
  2941. * @private
  2942. * @param {*} key - The key object to search for.
  2943. * @returns {number} The index of the specified key
  2944. */
  2945. Map.prototype._getKeyIndex = function(key) {
  2946. var result = -1;
  2947. var value;
  2948. if (type.isString(key)) {
  2949. value = this._valuesForString[key];
  2950. if (value) {
  2951. result = value.keyIndex;
  2952. }
  2953. } else {
  2954. result = array.inArray(key, this._keys);
  2955. }
  2956. return result;
  2957. };
  2958. /**
  2959. * Returns the original key of the specified key.
  2960. * @private
  2961. * @param {*} key - key
  2962. * @returns {*} Original key
  2963. */
  2964. Map.prototype._getOriginKey = function(key) {
  2965. var originKey = key;
  2966. if (key === _KEY_FOR_UNDEFINED) {
  2967. originKey = undefined; // eslint-disable-line no-undefined
  2968. } else if (key === _KEY_FOR_NAN) {
  2969. originKey = NaN;
  2970. }
  2971. return originKey;
  2972. };
  2973. /**
  2974. * Returns the unique key of the specified key.
  2975. * @private
  2976. * @param {*} key - key
  2977. * @returns {*} Unique key
  2978. */
  2979. Map.prototype._getUniqueKey = function(key) {
  2980. var uniqueKey = key;
  2981. if (type.isUndefined(key)) {
  2982. uniqueKey = _KEY_FOR_UNDEFINED;
  2983. } else if (this._isNaN(key)) {
  2984. uniqueKey = _KEY_FOR_NAN;
  2985. }
  2986. return uniqueKey;
  2987. };
  2988. /**
  2989. * Returns the value object of the specified key.
  2990. * @private
  2991. * @param {*} key - The key of the value object to be returned
  2992. * @param {number} keyIndex - The index of the key
  2993. * @returns {{keyIndex: number, origin: *}} Value object
  2994. */
  2995. Map.prototype._getValueObject = function(key, keyIndex) { // eslint-disable-line consistent-return
  2996. if (type.isString(key)) {
  2997. return this._valuesForString[key];
  2998. }
  2999. if (type.isUndefined(keyIndex)) {
  3000. keyIndex = this._getKeyIndex(key);
  3001. }
  3002. if (keyIndex >= 0) {
  3003. return this._valuesForIndex[keyIndex];
  3004. }
  3005. };
  3006. /**
  3007. * Returns the original value of the specified key.
  3008. * @private
  3009. * @param {*} key - The key of the value object to be returned
  3010. * @param {number} keyIndex - The index of the key
  3011. * @returns {*} Original value
  3012. */
  3013. Map.prototype._getOriginValue = function(key, keyIndex) {
  3014. return this._getValueObject(key, keyIndex).origin;
  3015. };
  3016. /**
  3017. * Returns key-value pair of the specified key.
  3018. * @private
  3019. * @param {*} key - The key of the value object to be returned
  3020. * @param {number} keyIndex - The index of the key
  3021. * @returns {Array} Key-value Pair
  3022. */
  3023. Map.prototype._getKeyValuePair = function(key, keyIndex) {
  3024. return [this._getOriginKey(key), this._getOriginValue(key, keyIndex)];
  3025. };
  3026. /**
  3027. * Creates the wrapper object of original value that contains a key index
  3028. * and returns it.
  3029. * @private
  3030. * @param {type} origin - Original value
  3031. * @param {type} keyIndex - Index of the key
  3032. * @returns {{keyIndex: number, origin: *}} Value object
  3033. */
  3034. Map.prototype._createValueObject = function(origin, keyIndex) {
  3035. return {
  3036. keyIndex: keyIndex,
  3037. origin: origin
  3038. };
  3039. };
  3040. /**
  3041. * Sets the value for the key in the Map object.
  3042. * @param {*} key - The key of the element to add to the Map object
  3043. * @param {*} value - The value of the element to add to the Map object
  3044. * @returns {Map} The Map object
  3045. */
  3046. Map.prototype.set = function(key, value) {
  3047. var uniqueKey = this._getUniqueKey(key);
  3048. var keyIndex = this._getKeyIndex(uniqueKey);
  3049. var valueObject;
  3050. if (keyIndex < 0) {
  3051. keyIndex = this._keys.push(uniqueKey) - 1;
  3052. this.size += 1;
  3053. }
  3054. valueObject = this._createValueObject(value, keyIndex);
  3055. if (type.isString(key)) {
  3056. this._valuesForString[key] = valueObject;
  3057. } else {
  3058. this._valuesForIndex[keyIndex] = valueObject;
  3059. }
  3060. return this;
  3061. };
  3062. /**
  3063. * Returns the value associated to the key, or undefined if there is none.
  3064. * @param {*} key - The key of the element to return
  3065. * @returns {*} Element associated with the specified key
  3066. */
  3067. Map.prototype.get = function(key) {
  3068. var uniqueKey = this._getUniqueKey(key);
  3069. var value = this._getValueObject(uniqueKey);
  3070. return value && value.origin;
  3071. };
  3072. /**
  3073. * Returns a new Iterator object that contains the keys for each element
  3074. * in the Map object in insertion order.
  3075. * @returns {Iterator} A new Iterator object
  3076. */
  3077. Map.prototype.keys = function() {
  3078. return new MapIterator(this._keys, func.bind(this._getOriginKey, this));
  3079. };
  3080. /**
  3081. * Returns a new Iterator object that contains the values for each element
  3082. * in the Map object in insertion order.
  3083. * @returns {Iterator} A new Iterator object
  3084. */
  3085. Map.prototype.values = function() {
  3086. return new MapIterator(this._keys, func.bind(this._getOriginValue, this));
  3087. };
  3088. /**
  3089. * Returns a new Iterator object that contains the [key, value] pairs
  3090. * for each element in the Map object in insertion order.
  3091. * @returns {Iterator} A new Iterator object
  3092. */
  3093. Map.prototype.entries = function() {
  3094. return new MapIterator(this._keys, func.bind(this._getKeyValuePair, this));
  3095. };
  3096. /**
  3097. * Returns a boolean asserting whether a value has been associated to the key
  3098. * in the Map object or not.
  3099. * @param {*} key - The key of the element to test for presence
  3100. * @returns {boolean} True if an element with the specified key exists;
  3101. * Otherwise false
  3102. */
  3103. Map.prototype.has = function(key) {
  3104. return !!this._getValueObject(key);
  3105. };
  3106. /**
  3107. * Removes the specified element from a Map object.
  3108. * @param {*} key - The key of the element to remove
  3109. * @function delete
  3110. * @memberof tui.util.Map.prototype
  3111. */
  3112. // cannot use reserved keyword as a property name in IE8 and under.
  3113. Map.prototype['delete'] = function(key) {
  3114. var keyIndex;
  3115. if (type.isString(key)) {
  3116. if (this._valuesForString[key]) {
  3117. keyIndex = this._valuesForString[key].keyIndex;
  3118. delete this._valuesForString[key];
  3119. }
  3120. } else {
  3121. keyIndex = this._getKeyIndex(key);
  3122. if (keyIndex >= 0) {
  3123. delete this._valuesForIndex[keyIndex];
  3124. }
  3125. }
  3126. if (keyIndex >= 0) {
  3127. delete this._keys[keyIndex];
  3128. this.size -= 1;
  3129. }
  3130. };
  3131. /**
  3132. * Executes a provided function once per each key/value pair in the Map object,
  3133. * in insertion order.
  3134. * @param {function} callback - Function to execute for each element
  3135. * @param {thisArg} thisArg - Value to use as this when executing callback
  3136. */
  3137. Map.prototype.forEach = function(callback, thisArg) {
  3138. thisArg = thisArg || this;
  3139. collection.forEachArray(this._keys, function(key) {
  3140. if (!type.isUndefined(key)) {
  3141. callback.call(thisArg, this._getValueObject(key).origin, key, this);
  3142. }
  3143. }, this);
  3144. };
  3145. /**
  3146. * Removes all elements from a Map object.
  3147. */
  3148. Map.prototype.clear = function() {
  3149. Map.call(this);
  3150. };
  3151. /* eslint-enable no-extend-native */
  3152. // Use native Map object if exists.
  3153. // But only latest versions of Chrome and Firefox support full implementation.
  3154. (function() {
  3155. if (window.Map && (
  3156. (browser.firefox && browser.version >= 37) ||
  3157. (browser.chrome && browser.version >= 42)
  3158. )
  3159. ) {
  3160. Map = window.Map; // eslint-disable-line no-func-assign
  3161. }
  3162. })();
  3163. module.exports = Map;
  3164. /***/ }),
  3165. /* 19 */
  3166. /***/ (function(module, exports, __webpack_require__) {
  3167. /**
  3168. * @fileoverview This module provides the HashMap constructor.
  3169. * @author NHN Ent.
  3170. * FE Development Lab <dl_javascript@nhnent.com>
  3171. * @dependency type, collection.js
  3172. */
  3173. 'use strict';
  3174. var collection = __webpack_require__(4);
  3175. var type = __webpack_require__(2);
  3176. /**
  3177. * All the data in hashMap begin with _MAPDATAPREFIX;
  3178. * @type {string}
  3179. * @private
  3180. */
  3181. var _MAPDATAPREFIX = 'å';
  3182. /**
  3183. * HashMap can handle the key-value pairs.<br>
  3184. * Caution:<br>
  3185. * HashMap instance has a length property but is not an instance of Array.
  3186. * @param {Object} [obj] A initial data for creation.
  3187. * @constructor
  3188. * @memberof tui.util
  3189. * @deprecated since version 1.3.0
  3190. * @example
  3191. * var hm = new tui.util.HashMap({
  3192. * 'mydata': {
  3193. * 'hello': 'imfine'
  3194. * },
  3195. * 'what': 'time'
  3196. * });
  3197. */
  3198. function HashMap(obj) {
  3199. /**
  3200. * size
  3201. * @type {number}
  3202. */
  3203. this.length = 0;
  3204. if (obj) {
  3205. this.setObject(obj);
  3206. }
  3207. }
  3208. /**
  3209. * Set a data from the given key with value or the given object.
  3210. * @param {string|Object} key A string or object for key
  3211. * @param {*} [value] A data
  3212. * @example
  3213. * var hm = new HashMap();
  3214. *
  3215. * hm.set('key', 'value');
  3216. * hm.set({
  3217. * 'key1': 'data1',
  3218. * 'key2': 'data2'
  3219. * });
  3220. */
  3221. HashMap.prototype.set = function(key, value) {
  3222. if (arguments.length === 2) {
  3223. this.setKeyValue(key, value);
  3224. } else {
  3225. this.setObject(key);
  3226. }
  3227. };
  3228. /**
  3229. * Set a data from the given key with value.
  3230. * @param {string} key A string for key
  3231. * @param {*} value A data
  3232. * @example
  3233. * var hm = new HashMap();
  3234. * hm.setKeyValue('key', 'value');
  3235. */
  3236. HashMap.prototype.setKeyValue = function(key, value) {
  3237. if (!this.has(key)) {
  3238. this.length += 1;
  3239. }
  3240. this[this.encodeKey(key)] = value;
  3241. };
  3242. /**
  3243. * Set a data from the given object.
  3244. * @param {Object} obj A object for data
  3245. * @example
  3246. * var hm = new HashMap();
  3247. *
  3248. * hm.setObject({
  3249. * 'key1': 'data1',
  3250. * 'key2': 'data2'
  3251. * });
  3252. */
  3253. HashMap.prototype.setObject = function(obj) {
  3254. var self = this;
  3255. collection.forEachOwnProperties(obj, function(value, key) {
  3256. self.setKeyValue(key, value);
  3257. });
  3258. };
  3259. /**
  3260. * Merge with the given another hashMap.
  3261. * @param {HashMap} hashMap Another hashMap instance
  3262. */
  3263. HashMap.prototype.merge = function(hashMap) {
  3264. var self = this;
  3265. hashMap.each(function(value, key) {
  3266. self.setKeyValue(key, value);
  3267. });
  3268. };
  3269. /**
  3270. * Encode the given key for hashMap.
  3271. * @param {string} key A string for key
  3272. * @returns {string} A encoded key
  3273. * @private
  3274. */
  3275. HashMap.prototype.encodeKey = function(key) {
  3276. return _MAPDATAPREFIX + key;
  3277. };
  3278. /**
  3279. * Decode the given key in hashMap.
  3280. * @param {string} key A string for key
  3281. * @returns {string} A decoded key
  3282. * @private
  3283. */
  3284. HashMap.prototype.decodeKey = function(key) {
  3285. var decodedKey = key.split(_MAPDATAPREFIX);
  3286. return decodedKey[decodedKey.length - 1];
  3287. };
  3288. /**
  3289. * Return the value from the given key.
  3290. * @param {string} key A string for key
  3291. * @returns {*} The value from a key
  3292. * @example
  3293. * var hm = new HashMap();
  3294. * hm.set('key', 'value');
  3295. *
  3296. * hm.get('key') // value
  3297. */
  3298. HashMap.prototype.get = function(key) {
  3299. return this[this.encodeKey(key)];
  3300. };
  3301. /**
  3302. * Check the existence of a value from the key.
  3303. * @param {string} key A string for key
  3304. * @returns {boolean} Indicating whether a value exists or not.
  3305. * @example
  3306. * var hm = new HashMap();
  3307. * hm.set('key', 'value');
  3308. *
  3309. * hm.has('key') // true
  3310. */
  3311. HashMap.prototype.has = function(key) {
  3312. return this.hasOwnProperty(this.encodeKey(key));
  3313. };
  3314. /**
  3315. * Remove a data(key-value pairs) from the given key or the given key-list.
  3316. * @param {...string|string[]} key A string for key
  3317. * @returns {string|string[]} A removed data
  3318. * @example
  3319. * var hm = new HashMap();
  3320. * hm.set('key', 'value');
  3321. * hm.set('key2', 'value');
  3322. *
  3323. * //ex1
  3324. * hm.remove('key');
  3325. *
  3326. * //ex2
  3327. * hm.remove('key', 'key2');
  3328. *
  3329. * //ex3
  3330. * hm.remove(['key', 'key2']);
  3331. */
  3332. HashMap.prototype.remove = function(key) {
  3333. if (arguments.length > 1) {
  3334. key = collection.toArray(arguments);
  3335. }
  3336. return type.isArray(key) ? this.removeByKeyArray(key) : this.removeByKey(key);
  3337. };
  3338. /**
  3339. * Remove data(key-value pair) from the given key.
  3340. * @param {string} key A string for key
  3341. * @returns {*|null} A removed data
  3342. * @example
  3343. * var hm = new HashMap();
  3344. * hm.set('key', 'value');
  3345. *
  3346. * hm.removeByKey('key')
  3347. */
  3348. HashMap.prototype.removeByKey = function(key) {
  3349. var data = this.has(key) ? this.get(key) : null;
  3350. if (data !== null) {
  3351. delete this[this.encodeKey(key)];
  3352. this.length -= 1;
  3353. }
  3354. return data;
  3355. };
  3356. /**
  3357. * Remove a data(key-value pairs) from the given key-list.
  3358. * @param {string[]} keyArray An array of keys
  3359. * @returns {string[]} A removed data
  3360. * @example
  3361. * var hm = new HashMap();
  3362. * hm.set('key', 'value');
  3363. * hm.set('key2', 'value');
  3364. *
  3365. * hm.removeByKeyArray(['key', 'key2']);
  3366. */
  3367. HashMap.prototype.removeByKeyArray = function(keyArray) {
  3368. var data = [];
  3369. var self = this;
  3370. collection.forEach(keyArray, function(key) {
  3371. data.push(self.removeByKey(key));
  3372. });
  3373. return data;
  3374. };
  3375. /**
  3376. * Remove all the data
  3377. */
  3378. HashMap.prototype.removeAll = function() {
  3379. var self = this;
  3380. this.each(function(value, key) {
  3381. self.remove(key);
  3382. });
  3383. };
  3384. /**
  3385. * Execute the provided callback once for each all the data.
  3386. * @param {Function} iteratee Callback function
  3387. * @example
  3388. * var hm = new HashMap();
  3389. * hm.set('key', 'value');
  3390. * hm.set('key2', 'value');
  3391. *
  3392. * hm.each(function(value, key) {
  3393. * //do something...
  3394. * });
  3395. */
  3396. HashMap.prototype.each = function(iteratee) {
  3397. var self = this;
  3398. var flag;
  3399. collection.forEachOwnProperties(this, function(value, key) { // eslint-disable-line consistent-return
  3400. if (key.charAt(0) === _MAPDATAPREFIX) {
  3401. flag = iteratee(value, self.decodeKey(key));
  3402. }
  3403. if (flag === false) {
  3404. return flag;
  3405. }
  3406. });
  3407. };
  3408. /**
  3409. * Return the key-list stored.
  3410. * @returns {Array} A key-list
  3411. * @example
  3412. * var hm = new HashMap();
  3413. * hm.set('key', 'value');
  3414. * hm.set('key2', 'value');
  3415. *
  3416. * hm.keys(); //['key', 'key2');
  3417. */
  3418. HashMap.prototype.keys = function() {
  3419. var keys = [];
  3420. var self = this;
  3421. this.each(function(value, key) {
  3422. keys.push(self.decodeKey(key));
  3423. });
  3424. return keys;
  3425. };
  3426. /**
  3427. * Work similarly to Array.prototype.map().<br>
  3428. * It executes the provided callback that checks conditions once for each element of hashMap,<br>
  3429. * and returns a new array having elements satisfying the conditions
  3430. * @param {Function} condition A function that checks conditions
  3431. * @returns {Array} A new array having elements satisfying the conditions
  3432. * @example
  3433. * //ex1
  3434. * var hm = new HashMap();
  3435. * hm.set('key', 'value');
  3436. * hm.set('key2', 'value');
  3437. *
  3438. * hm.find(function(value, key) {
  3439. * return key === 'key2';
  3440. * }); // ['value']
  3441. *
  3442. * //ex2
  3443. * var hm = new HashMap({
  3444. * 'myobj1': {
  3445. * visible: true
  3446. * },
  3447. * 'mybobj2': {
  3448. * visible: false
  3449. * }
  3450. * });
  3451. *
  3452. * hm.find(function(obj, key) {
  3453. * return obj.visible === true;
  3454. * }); // [{visible: true}];
  3455. */
  3456. HashMap.prototype.find = function(condition) {
  3457. var founds = [];
  3458. this.each(function(value, key) {
  3459. if (condition(value, key)) {
  3460. founds.push(value);
  3461. }
  3462. });
  3463. return founds;
  3464. };
  3465. /**
  3466. * Return a new Array having all values.
  3467. * @returns {Array} A new array having all values
  3468. */
  3469. HashMap.prototype.toArray = function() {
  3470. var result = [];
  3471. this.each(function(v) {
  3472. result.push(v);
  3473. });
  3474. return result;
  3475. };
  3476. module.exports = HashMap;
  3477. /***/ })
  3478. /******/ ])
  3479. });
  3480. ;