vue.js 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673
  1. /*
  2. Vue.js v0.8.5
  3. (c) 2014 Evan You
  4. License: MIT
  5. */
  6. ;(function(){
  7. 'use strict';
  8. /**
  9. * Require the given path.
  10. *
  11. * @param {String} path
  12. * @return {Object} exports
  13. * @api public
  14. */
  15. function require(path, parent, orig) {
  16. var resolved = require.resolve(path);
  17. // lookup failed
  18. if (null == resolved) {
  19. orig = orig || path;
  20. parent = parent || 'root';
  21. var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
  22. err.path = orig;
  23. err.parent = parent;
  24. err.require = true;
  25. throw err;
  26. }
  27. var module = require.modules[resolved];
  28. // perform real require()
  29. // by invoking the module's
  30. // registered function
  31. if (!module._resolving && !module.exports) {
  32. var mod = {};
  33. mod.exports = {};
  34. mod.client = mod.component = true;
  35. module._resolving = true;
  36. module.call(this, mod.exports, require.relative(resolved), mod);
  37. delete module._resolving;
  38. module.exports = mod.exports;
  39. }
  40. return module.exports;
  41. }
  42. /**
  43. * Registered modules.
  44. */
  45. require.modules = {};
  46. /**
  47. * Registered aliases.
  48. */
  49. require.aliases = {};
  50. /**
  51. * Resolve `path`.
  52. *
  53. * Lookup:
  54. *
  55. * - PATH/index.js
  56. * - PATH.js
  57. * - PATH
  58. *
  59. * @param {String} path
  60. * @return {String} path or null
  61. * @api private
  62. */
  63. require.resolve = function(path) {
  64. if (path.charAt(0) === '/') path = path.slice(1);
  65. var paths = [
  66. path,
  67. path + '.js',
  68. path + '.json',
  69. path + '/index.js',
  70. path + '/index.json'
  71. ];
  72. for (var i = 0; i < paths.length; i++) {
  73. var path = paths[i];
  74. if (require.modules.hasOwnProperty(path)) return path;
  75. if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
  76. }
  77. };
  78. /**
  79. * Normalize `path` relative to the current path.
  80. *
  81. * @param {String} curr
  82. * @param {String} path
  83. * @return {String}
  84. * @api private
  85. */
  86. require.normalize = function(curr, path) {
  87. var segs = [];
  88. if ('.' != path.charAt(0)) return path;
  89. curr = curr.split('/');
  90. path = path.split('/');
  91. for (var i = 0; i < path.length; ++i) {
  92. if ('..' == path[i]) {
  93. curr.pop();
  94. } else if ('.' != path[i] && '' != path[i]) {
  95. segs.push(path[i]);
  96. }
  97. }
  98. return curr.concat(segs).join('/');
  99. };
  100. /**
  101. * Register module at `path` with callback `definition`.
  102. *
  103. * @param {String} path
  104. * @param {Function} definition
  105. * @api private
  106. */
  107. require.register = function(path, definition) {
  108. require.modules[path] = definition;
  109. };
  110. /**
  111. * Alias a module definition.
  112. *
  113. * @param {String} from
  114. * @param {String} to
  115. * @api private
  116. */
  117. require.alias = function(from, to) {
  118. if (!require.modules.hasOwnProperty(from)) {
  119. throw new Error('Failed to alias "' + from + '", it does not exist');
  120. }
  121. require.aliases[to] = from;
  122. };
  123. /**
  124. * Return a require function relative to the `parent` path.
  125. *
  126. * @param {String} parent
  127. * @return {Function}
  128. * @api private
  129. */
  130. require.relative = function(parent) {
  131. var p = require.normalize(parent, '..');
  132. /**
  133. * lastIndexOf helper.
  134. */
  135. function lastIndexOf(arr, obj) {
  136. var i = arr.length;
  137. while (i--) {
  138. if (arr[i] === obj) return i;
  139. }
  140. return -1;
  141. }
  142. /**
  143. * The relative require() itself.
  144. */
  145. function localRequire(path) {
  146. var resolved = localRequire.resolve(path);
  147. return require(resolved, parent, path);
  148. }
  149. /**
  150. * Resolve relative to the parent.
  151. */
  152. localRequire.resolve = function(path) {
  153. var c = path.charAt(0);
  154. if ('/' == c) return path.slice(1);
  155. if ('.' == c) return require.normalize(p, path);
  156. // resolve deps by returning
  157. // the dep in the nearest "deps"
  158. // directory
  159. var segs = parent.split('/');
  160. var i = lastIndexOf(segs, 'deps') + 1;
  161. if (!i) i = 0;
  162. path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
  163. return path;
  164. };
  165. /**
  166. * Check if module is defined at `path`.
  167. */
  168. localRequire.exists = function(path) {
  169. return require.modules.hasOwnProperty(localRequire.resolve(path));
  170. };
  171. return localRequire;
  172. };
  173. require.register("component-emitter/index.js", function(exports, require, module){
  174. /**
  175. * Expose `Emitter`.
  176. */
  177. module.exports = Emitter;
  178. /**
  179. * Initialize a new `Emitter`.
  180. *
  181. * @api public
  182. */
  183. function Emitter(obj) {
  184. if (obj) return mixin(obj);
  185. };
  186. /**
  187. * Mixin the emitter properties.
  188. *
  189. * @param {Object} obj
  190. * @return {Object}
  191. * @api private
  192. */
  193. function mixin(obj) {
  194. for (var key in Emitter.prototype) {
  195. obj[key] = Emitter.prototype[key];
  196. }
  197. return obj;
  198. }
  199. /**
  200. * Listen on the given `event` with `fn`.
  201. *
  202. * @param {String} event
  203. * @param {Function} fn
  204. * @return {Emitter}
  205. * @api public
  206. */
  207. Emitter.prototype.on =
  208. Emitter.prototype.addEventListener = function(event, fn){
  209. this._callbacks = this._callbacks || {};
  210. (this._callbacks[event] = this._callbacks[event] || [])
  211. .push(fn);
  212. return this;
  213. };
  214. /**
  215. * Adds an `event` listener that will be invoked a single
  216. * time then automatically removed.
  217. *
  218. * @param {String} event
  219. * @param {Function} fn
  220. * @return {Emitter}
  221. * @api public
  222. */
  223. Emitter.prototype.once = function(event, fn){
  224. var self = this;
  225. this._callbacks = this._callbacks || {};
  226. function on() {
  227. self.off(event, on);
  228. fn.apply(this, arguments);
  229. }
  230. on.fn = fn;
  231. this.on(event, on);
  232. return this;
  233. };
  234. /**
  235. * Remove the given callback for `event` or all
  236. * registered callbacks.
  237. *
  238. * @param {String} event
  239. * @param {Function} fn
  240. * @return {Emitter}
  241. * @api public
  242. */
  243. Emitter.prototype.off =
  244. Emitter.prototype.removeListener =
  245. Emitter.prototype.removeAllListeners =
  246. Emitter.prototype.removeEventListener = function(event, fn){
  247. this._callbacks = this._callbacks || {};
  248. // all
  249. if (0 == arguments.length) {
  250. this._callbacks = {};
  251. return this;
  252. }
  253. // specific event
  254. var callbacks = this._callbacks[event];
  255. if (!callbacks) return this;
  256. // remove all handlers
  257. if (1 == arguments.length) {
  258. delete this._callbacks[event];
  259. return this;
  260. }
  261. // remove specific handler
  262. var cb;
  263. for (var i = 0; i < callbacks.length; i++) {
  264. cb = callbacks[i];
  265. if (cb === fn || cb.fn === fn) {
  266. callbacks.splice(i, 1);
  267. break;
  268. }
  269. }
  270. return this;
  271. };
  272. /**
  273. * Emit `event` with the given args.
  274. *
  275. * @param {String} event
  276. * @param {Mixed} ...
  277. * @return {Emitter}
  278. */
  279. Emitter.prototype.emit = function(event){
  280. this._callbacks = this._callbacks || {};
  281. var args = [].slice.call(arguments, 1)
  282. , callbacks = this._callbacks[event];
  283. if (callbacks) {
  284. callbacks = callbacks.slice(0);
  285. for (var i = 0, len = callbacks.length; i < len; ++i) {
  286. callbacks[i].apply(this, args);
  287. }
  288. }
  289. return this;
  290. };
  291. /**
  292. * Return array of callbacks for `event`.
  293. *
  294. * @param {String} event
  295. * @return {Array}
  296. * @api public
  297. */
  298. Emitter.prototype.listeners = function(event){
  299. this._callbacks = this._callbacks || {};
  300. return this._callbacks[event] || [];
  301. };
  302. /**
  303. * Check if this emitter has `event` handlers.
  304. *
  305. * @param {String} event
  306. * @return {Boolean}
  307. * @api public
  308. */
  309. Emitter.prototype.hasListeners = function(event){
  310. return !! this.listeners(event).length;
  311. };
  312. });
  313. require.register("vue/src/main.js", function(exports, require, module){
  314. var config = require('./config'),
  315. ViewModel = require('./viewmodel'),
  316. directives = require('./directives'),
  317. filters = require('./filters'),
  318. utils = require('./utils')
  319. /**
  320. * Set config options
  321. */
  322. ViewModel.config = function (opts, val) {
  323. if (typeof opts === 'string') {
  324. if (val === undefined) {
  325. return config[opts]
  326. } else {
  327. config[opts] = val
  328. }
  329. } else {
  330. utils.extend(config, opts)
  331. }
  332. return this
  333. }
  334. /**
  335. * Allows user to register/retrieve a directive definition
  336. */
  337. ViewModel.directive = function (id, fn) {
  338. if (!fn) return directives[id]
  339. directives[id] = fn
  340. return this
  341. }
  342. /**
  343. * Allows user to register/retrieve a filter function
  344. */
  345. ViewModel.filter = function (id, fn) {
  346. if (!fn) return filters[id]
  347. filters[id] = fn
  348. return this
  349. }
  350. /**
  351. * Allows user to register/retrieve a ViewModel constructor
  352. */
  353. ViewModel.component = function (id, Ctor) {
  354. if (!Ctor) return utils.components[id]
  355. utils.components[id] = utils.toConstructor(Ctor)
  356. return this
  357. }
  358. /**
  359. * Allows user to register/retrieve a template partial
  360. */
  361. ViewModel.partial = function (id, partial) {
  362. if (!partial) return utils.partials[id]
  363. utils.partials[id] = utils.toFragment(partial)
  364. return this
  365. }
  366. /**
  367. * Allows user to register/retrieve a transition definition object
  368. */
  369. ViewModel.transition = function (id, transition) {
  370. if (!transition) return utils.transitions[id]
  371. utils.transitions[id] = transition
  372. return this
  373. }
  374. /**
  375. * Expose internal modules for plugins
  376. */
  377. ViewModel.require = function (path) {
  378. return require('./' + path)
  379. }
  380. /**
  381. * Expose an interface for plugins
  382. */
  383. ViewModel.use = function (plugin) {
  384. if (typeof plugin === 'string') {
  385. try {
  386. plugin = require(plugin)
  387. } catch (e) {
  388. return utils.warn('Cannot find plugin: ' + plugin)
  389. }
  390. }
  391. if (typeof plugin === 'function') {
  392. plugin(ViewModel)
  393. } else if (plugin.install) {
  394. plugin.install(ViewModel)
  395. }
  396. }
  397. ViewModel.extend = extend
  398. ViewModel.nextTick = utils.nextTick
  399. /**
  400. * Expose the main ViewModel class
  401. * and add extend method
  402. */
  403. function extend (options) {
  404. var ParentVM = this
  405. // inherit options
  406. options = inheritOptions(options, ParentVM.options, true)
  407. utils.processOptions(options)
  408. var ExtendedVM = function (opts, asParent) {
  409. if (!asParent) {
  410. opts = inheritOptions(opts, options, true)
  411. }
  412. ParentVM.call(this, opts, true)
  413. }
  414. // inherit prototype props
  415. var proto = ExtendedVM.prototype = Object.create(ParentVM.prototype)
  416. utils.defProtected(proto, 'constructor', ExtendedVM)
  417. // copy prototype props
  418. var methods = options.methods
  419. if (methods) {
  420. for (var key in methods) {
  421. if (
  422. !(key in ViewModel.prototype) &&
  423. typeof methods[key] === 'function'
  424. ) {
  425. proto[key] = methods[key]
  426. }
  427. }
  428. }
  429. // allow extended VM to be further extended
  430. ExtendedVM.extend = extend
  431. ExtendedVM.super = ParentVM
  432. ExtendedVM.options = options
  433. return ExtendedVM
  434. }
  435. /**
  436. * Inherit options
  437. *
  438. * For options such as `data`, `vms`, `directives`, 'partials',
  439. * they should be further extended. However extending should only
  440. * be done at top level.
  441. *
  442. * `proto` is an exception because it's handled directly on the
  443. * prototype.
  444. *
  445. * `el` is an exception because it's not allowed as an
  446. * extension option, but only as an instance option.
  447. */
  448. function inheritOptions (child, parent, topLevel) {
  449. child = child || utils.hash()
  450. if (!parent) return child
  451. for (var key in parent) {
  452. if (key === 'el' || key === 'methods') continue
  453. var val = child[key],
  454. parentVal = parent[key],
  455. type = utils.typeOf(val)
  456. if (topLevel && type === 'Function' && parentVal) {
  457. // merge hook functions into an array
  458. child[key] = [val]
  459. if (Array.isArray(parentVal)) {
  460. child[key] = child[key].concat(parentVal)
  461. } else {
  462. child[key].push(parentVal)
  463. }
  464. } else if (topLevel && type === 'Object') {
  465. // merge toplevel object options
  466. inheritOptions(val, parentVal)
  467. } else if (val === undefined) {
  468. // inherit if child doesn't override
  469. child[key] = parentVal
  470. }
  471. }
  472. return child
  473. }
  474. module.exports = ViewModel
  475. });
  476. require.register("vue/src/emitter.js", function(exports, require, module){
  477. // shiv to make this work for Component, Browserify and Node at the same time.
  478. var Emitter,
  479. componentEmitter = 'emitter'
  480. try {
  481. // Requiring without a string literal will make browserify
  482. // unable to parse the dependency, thus preventing it from
  483. // stopping the compilation after a failed lookup.
  484. Emitter = require(componentEmitter)
  485. } catch (e) {
  486. Emitter = require('events').EventEmitter
  487. Emitter.prototype.off = function () {
  488. var method = arguments.length > 1
  489. ? this.removeListener
  490. : this.removeAllListeners
  491. return method.apply(this, arguments)
  492. }
  493. }
  494. module.exports = Emitter
  495. });
  496. require.register("vue/src/config.js", function(exports, require, module){
  497. var prefix = 'v',
  498. specialAttributes = [
  499. 'pre',
  500. 'text',
  501. 'repeat',
  502. 'partial',
  503. 'with',
  504. 'component',
  505. 'component-id',
  506. 'transition'
  507. ],
  508. config = module.exports = {
  509. debug : false,
  510. silent : false,
  511. enterClass : 'v-enter',
  512. leaveClass : 'v-leave',
  513. attrs : {},
  514. get prefix () {
  515. return prefix
  516. },
  517. set prefix (val) {
  518. prefix = val
  519. updatePrefix()
  520. }
  521. }
  522. function updatePrefix () {
  523. specialAttributes.forEach(function (attr) {
  524. config.attrs[attr] = prefix + '-' + attr
  525. })
  526. }
  527. updatePrefix()
  528. });
  529. require.register("vue/src/utils.js", function(exports, require, module){
  530. var config = require('./config'),
  531. attrs = config.attrs,
  532. toString = Object.prototype.toString,
  533. join = Array.prototype.join,
  534. console = window.console,
  535. hasClassList = 'classList' in document.documentElement,
  536. ViewModel // late def
  537. var defer =
  538. window.requestAnimationFrame ||
  539. window.webkitRequestAnimationFrame ||
  540. window.setTimeout
  541. /**
  542. * Create a prototype-less object
  543. * which is a better hash/map
  544. */
  545. function makeHash () {
  546. return Object.create(null)
  547. }
  548. var utils = module.exports = {
  549. hash: makeHash,
  550. // global storage for user-registered
  551. // vms, partials and transitions
  552. components : makeHash(),
  553. partials : makeHash(),
  554. transitions : makeHash(),
  555. /**
  556. * get an attribute and remove it.
  557. */
  558. attr: function (el, type, noRemove) {
  559. var attr = attrs[type],
  560. val = el.getAttribute(attr)
  561. if (!noRemove && val !== null) el.removeAttribute(attr)
  562. return val
  563. },
  564. /**
  565. * Define an ienumerable property
  566. * This avoids it being included in JSON.stringify
  567. * or for...in loops.
  568. */
  569. defProtected: function (obj, key, val, enumerable, configurable) {
  570. if (obj.hasOwnProperty(key)) return
  571. Object.defineProperty(obj, key, {
  572. value : val,
  573. enumerable : !!enumerable,
  574. configurable : !!configurable
  575. })
  576. },
  577. /**
  578. * Accurate type check
  579. * internal use only, so no need to check for NaN
  580. */
  581. typeOf: function (obj) {
  582. return toString.call(obj).slice(8, -1)
  583. },
  584. /**
  585. * Most simple bind
  586. * enough for the usecase and fast than native bind()
  587. */
  588. bind: function (fn, ctx) {
  589. return function (arg) {
  590. return fn.call(ctx, arg)
  591. }
  592. },
  593. /**
  594. * Make sure only strings, booleans, numbers and
  595. * objects are output to html. otherwise, ouput empty string.
  596. */
  597. toText: function (value) {
  598. /* jshint eqeqeq: false */
  599. var type = typeof value
  600. return (type === 'string' ||
  601. type === 'boolean' ||
  602. (type === 'number' && value == value)) // deal with NaN
  603. ? value
  604. : type === 'object' && value !== null
  605. ? JSON.stringify(value)
  606. : ''
  607. },
  608. /**
  609. * simple extend
  610. */
  611. extend: function (obj, ext, protective) {
  612. for (var key in ext) {
  613. if (protective && obj[key]) continue
  614. obj[key] = ext[key]
  615. }
  616. },
  617. /**
  618. * filter an array with duplicates into uniques
  619. */
  620. unique: function (arr) {
  621. var hash = utils.hash(),
  622. i = arr.length,
  623. key, res = []
  624. while (i--) {
  625. key = arr[i]
  626. if (hash[key]) continue
  627. hash[key] = 1
  628. res.push(key)
  629. }
  630. return res
  631. },
  632. /**
  633. * Convert a string template to a dom fragment
  634. */
  635. toFragment: function (template) {
  636. if (typeof template !== 'string') {
  637. return template
  638. }
  639. if (template.charAt(0) === '#') {
  640. var templateNode = document.getElementById(template.slice(1))
  641. if (!templateNode) return
  642. template = templateNode.innerHTML
  643. }
  644. var node = document.createElement('div'),
  645. frag = document.createDocumentFragment(),
  646. child
  647. node.innerHTML = template.trim()
  648. /* jshint boss: true */
  649. while (child = node.firstChild) {
  650. frag.appendChild(child)
  651. }
  652. return frag
  653. },
  654. /**
  655. * Convert the object to a ViewModel constructor
  656. * if it is not already one
  657. */
  658. toConstructor: function (obj) {
  659. ViewModel = ViewModel || require('./viewmodel')
  660. return utils.typeOf(obj) === 'Object'
  661. ? ViewModel.extend(obj)
  662. : typeof obj === 'function'
  663. ? obj
  664. : null
  665. },
  666. /**
  667. * convert certain option values to the desired format.
  668. */
  669. processOptions: function (options) {
  670. var components = options.components,
  671. partials = options.partials,
  672. template = options.template,
  673. key
  674. if (components) {
  675. for (key in components) {
  676. components[key] = utils.toConstructor(components[key])
  677. }
  678. }
  679. if (partials) {
  680. for (key in partials) {
  681. partials[key] = utils.toFragment(partials[key])
  682. }
  683. }
  684. if (template) {
  685. options.template = utils.toFragment(template)
  686. }
  687. },
  688. /**
  689. * log for debugging
  690. */
  691. log: function () {
  692. if (config.debug && console) {
  693. console.log(join.call(arguments, ' '))
  694. }
  695. },
  696. /**
  697. * warnings, traces by default
  698. * can be suppressed by `silent` option.
  699. */
  700. warn: function() {
  701. if (!config.silent && console) {
  702. console.warn(join.call(arguments, ' '))
  703. if (config.debug) {
  704. console.trace()
  705. }
  706. }
  707. },
  708. /**
  709. * used to defer batch updates
  710. */
  711. nextTick: function (cb) {
  712. defer(cb, 0)
  713. },
  714. /**
  715. * add class for IE9
  716. * uses classList if available
  717. */
  718. addClass: function (el, cls) {
  719. if (hasClassList) {
  720. el.classList.add(cls)
  721. } else {
  722. var cur = ' ' + el.className + ' '
  723. if (cur.indexOf(' ' + cls + ' ') < 0) {
  724. el.className = (cur + cls).trim()
  725. }
  726. }
  727. },
  728. /**
  729. * remove class for IE9
  730. */
  731. removeClass: function (el, cls) {
  732. if (hasClassList) {
  733. el.classList.remove(cls)
  734. } else {
  735. var cur = ' ' + el.className + ' ',
  736. tar = ' ' + cls + ' '
  737. while (cur.indexOf(tar) >= 0) {
  738. cur = cur.replace(tar, ' ')
  739. }
  740. el.className = cur.trim()
  741. }
  742. }
  743. }
  744. });
  745. require.register("vue/src/compiler.js", function(exports, require, module){
  746. var Emitter = require('./emitter'),
  747. Observer = require('./observer'),
  748. config = require('./config'),
  749. utils = require('./utils'),
  750. Binding = require('./binding'),
  751. Directive = require('./directive'),
  752. TextParser = require('./text-parser'),
  753. DepsParser = require('./deps-parser'),
  754. ExpParser = require('./exp-parser'),
  755. // cache methods
  756. slice = Array.prototype.slice,
  757. log = utils.log,
  758. makeHash = utils.hash,
  759. extend = utils.extend,
  760. def = utils.defProtected,
  761. hasOwn = Object.prototype.hasOwnProperty,
  762. // hooks to register
  763. hooks = [
  764. 'created', 'ready',
  765. 'beforeDestroy', 'afterDestroy',
  766. 'enteredView', 'leftView'
  767. ]
  768. /**
  769. * The DOM compiler
  770. * scans a DOM node and compile bindings for a ViewModel
  771. */
  772. function Compiler (vm, options) {
  773. var compiler = this
  774. // indicate that we are intiating this instance
  775. // so we should not run any transitions
  776. compiler.init = true
  777. // process and extend options
  778. options = compiler.options = options || makeHash()
  779. utils.processOptions(options)
  780. // copy data, methods & compiler options
  781. var data = compiler.data = options.data || {}
  782. extend(vm, data, true)
  783. extend(vm, options.methods, true)
  784. extend(compiler, options.compilerOptions)
  785. // initialize element
  786. var el = compiler.setupElement(options)
  787. log('\nnew VM instance:', el.tagName, '\n')
  788. // set compiler properties
  789. compiler.vm = vm
  790. compiler.bindings = makeHash()
  791. compiler.dirs = []
  792. compiler.deferred = []
  793. compiler.exps = []
  794. compiler.computed = []
  795. compiler.childCompilers = []
  796. compiler.emitter = new Emitter()
  797. // set inenumerable VM properties
  798. def(vm, '$', makeHash())
  799. def(vm, '$el', el)
  800. def(vm, '$compiler', compiler)
  801. def(vm, '$root', getRoot(compiler).vm)
  802. // set parent VM
  803. // and register child id on parent
  804. var parent = compiler.parentCompiler,
  805. childId = utils.attr(el, 'component-id')
  806. if (parent) {
  807. parent.childCompilers.push(compiler)
  808. def(vm, '$parent', parent.vm)
  809. if (childId) {
  810. compiler.childId = childId
  811. parent.vm.$[childId] = vm
  812. }
  813. }
  814. // setup observer
  815. compiler.setupObserver()
  816. // create bindings for computed properties
  817. var computed = options.computed
  818. if (computed) {
  819. for (var key in computed) {
  820. compiler.createBinding(key)
  821. }
  822. }
  823. // beforeCompile hook
  824. compiler.execHook('created')
  825. // the user might have set some props on the vm
  826. // so copy it back to the data...
  827. extend(data, vm)
  828. // observe the data
  829. Observer.observe(data, '', compiler.observer)
  830. // for repeated items, create an index binding
  831. // which should be inenumerable but configurable
  832. if (compiler.repeat) {
  833. //data.$index = compiler.repeatIndex
  834. def(data, '$index', compiler.repeatIndex, false, true)
  835. compiler.createBinding('$index')
  836. }
  837. // allow the $data object to be swapped
  838. Object.defineProperty(vm, '$data', {
  839. enumerable: false,
  840. get: function () {
  841. return compiler.data
  842. },
  843. set: function (newData) {
  844. var oldData = compiler.data
  845. Observer.unobserve(oldData, '', compiler.observer)
  846. compiler.data = newData
  847. Observer.copyPaths(newData, oldData)
  848. Observer.observe(newData, '', compiler.observer)
  849. }
  850. })
  851. // now parse the DOM, during which we will create necessary bindings
  852. // and bind the parsed directives
  853. compiler.compile(el, true)
  854. // bind deferred directives (child components)
  855. compiler.deferred.forEach(compiler.bindDirective, compiler)
  856. // extract dependencies for computed properties
  857. compiler.parseDeps()
  858. // done!
  859. compiler.init = false
  860. // post compile / ready hook
  861. compiler.execHook('ready')
  862. }
  863. var CompilerProto = Compiler.prototype
  864. /**
  865. * Initialize the VM/Compiler's element.
  866. * Fill it in with the template if necessary.
  867. */
  868. CompilerProto.setupElement = function (options) {
  869. // create the node first
  870. var el = this.el = typeof options.el === 'string'
  871. ? document.querySelector(options.el)
  872. : options.el || document.createElement(options.tagName || 'div')
  873. var template = options.template
  874. if (template) {
  875. // replace option: use the first node in
  876. // the template directly
  877. if (options.replace && template.childNodes.length === 1) {
  878. var replacer = template.childNodes[0].cloneNode(true)
  879. if (el.parentNode) {
  880. el.parentNode.insertBefore(replacer, el)
  881. el.parentNode.removeChild(el)
  882. }
  883. el = replacer
  884. } else {
  885. el.innerHTML = ''
  886. el.appendChild(template.cloneNode(true))
  887. }
  888. }
  889. // apply element options
  890. if (options.id) el.id = options.id
  891. if (options.className) el.className = options.className
  892. var attrs = options.attributes
  893. if (attrs) {
  894. for (var attr in attrs) {
  895. el.setAttribute(attr, attrs[attr])
  896. }
  897. }
  898. return el
  899. }
  900. /**
  901. * Setup observer.
  902. * The observer listens for get/set/mutate events on all VM
  903. * values/objects and trigger corresponding binding updates.
  904. * It also listens for lifecycle hooks.
  905. */
  906. CompilerProto.setupObserver = function () {
  907. var compiler = this,
  908. bindings = compiler.bindings,
  909. options = compiler.options,
  910. observer = compiler.observer = new Emitter()
  911. // a hash to hold event proxies for each root level key
  912. // so they can be referenced and removed later
  913. observer.proxies = makeHash()
  914. // add own listeners which trigger binding updates
  915. observer
  916. .on('get', function (key) {
  917. check(key)
  918. DepsParser.catcher.emit('get', bindings[key])
  919. })
  920. .on('set', function (key, val) {
  921. observer.emit('change:' + key, val)
  922. check(key)
  923. bindings[key].update(val)
  924. })
  925. .on('mutate', function (key, val, mutation) {
  926. observer.emit('change:' + key, val, mutation)
  927. check(key)
  928. bindings[key].pub()
  929. })
  930. // register hooks
  931. hooks.forEach(function (hook) {
  932. var fns = options[hook]
  933. if (Array.isArray(fns)) {
  934. var i = fns.length
  935. // since hooks were merged with child at head,
  936. // we loop reversely.
  937. while (i--) {
  938. register(hook, fns[i])
  939. }
  940. } else if (fns) {
  941. register(hook, fns)
  942. }
  943. })
  944. function register (hook, fn) {
  945. observer.on('hook:' + hook, function () {
  946. fn.call(compiler.vm, options)
  947. })
  948. }
  949. function check (key) {
  950. if (!bindings[key]) {
  951. compiler.createBinding(key)
  952. }
  953. }
  954. }
  955. /**
  956. * Compile a DOM node (recursive)
  957. */
  958. CompilerProto.compile = function (node, root) {
  959. var compiler = this,
  960. nodeType = node.nodeType,
  961. tagName = node.tagName
  962. if (nodeType === 1 && tagName !== 'SCRIPT') { // a normal node
  963. // skip anything with v-pre
  964. if (utils.attr(node, 'pre') !== null) return
  965. // special attributes to check
  966. var repeatExp,
  967. withKey,
  968. partialId,
  969. directive,
  970. componentId = utils.attr(node, 'component') || tagName.toLowerCase(),
  971. componentCtor = compiler.getOption('components', componentId)
  972. // It is important that we access these attributes
  973. // procedurally because the order matters.
  974. //
  975. // `utils.attr` removes the attribute once it gets the
  976. // value, so we should not access them all at once.
  977. // v-repeat has the highest priority
  978. // and we need to preserve all other attributes for it.
  979. /* jshint boss: true */
  980. if (repeatExp = utils.attr(node, 'repeat')) {
  981. // repeat block cannot have v-id at the same time.
  982. directive = Directive.parse('repeat', repeatExp, compiler, node)
  983. if (directive) {
  984. directive.Ctor = componentCtor
  985. // defer child component compilation
  986. // so by the time they are compiled, the parent
  987. // would have collected all bindings
  988. compiler.deferred.push(directive)
  989. }
  990. // v-with has 2nd highest priority
  991. } else if (root !== true && ((withKey = utils.attr(node, 'with')) || componentCtor)) {
  992. directive = Directive.parse('with', withKey || '', compiler, node)
  993. if (directive) {
  994. directive.Ctor = componentCtor
  995. compiler.deferred.push(directive)
  996. }
  997. } else {
  998. // check transition property
  999. node.vue_trans = utils.attr(node, 'transition')
  1000. // replace innerHTML with partial
  1001. partialId = utils.attr(node, 'partial')
  1002. if (partialId) {
  1003. var partial = compiler.getOption('partials', partialId)
  1004. if (partial) {
  1005. node.innerHTML = ''
  1006. node.appendChild(partial.cloneNode(true))
  1007. }
  1008. }
  1009. // finally, only normal directives left!
  1010. compiler.compileNode(node)
  1011. }
  1012. } else if (nodeType === 3) { // text node
  1013. compiler.compileTextNode(node)
  1014. }
  1015. }
  1016. /**
  1017. * Compile a normal node
  1018. */
  1019. CompilerProto.compileNode = function (node) {
  1020. var i, j,
  1021. attrs = slice.call(node.attributes),
  1022. prefix = config.prefix + '-'
  1023. // parse if has attributes
  1024. if (attrs && attrs.length) {
  1025. var attr, isDirective, exps, exp, directive
  1026. // loop through all attributes
  1027. i = attrs.length
  1028. while (i--) {
  1029. attr = attrs[i]
  1030. isDirective = false
  1031. if (attr.name.indexOf(prefix) === 0) {
  1032. // a directive - split, parse and bind it.
  1033. isDirective = true
  1034. exps = Directive.split(attr.value)
  1035. // loop through clauses (separated by ",")
  1036. // inside each attribute
  1037. j = exps.length
  1038. while (j--) {
  1039. exp = exps[j]
  1040. directive = Directive.parse(attr.name.slice(prefix.length), exp, this, node)
  1041. if (directive) {
  1042. this.bindDirective(directive)
  1043. }
  1044. }
  1045. } else {
  1046. // non directive attribute, check interpolation tags
  1047. exp = TextParser.parseAttr(attr.value)
  1048. if (exp) {
  1049. directive = Directive.parse('attr', attr.name + ':' + exp, this, node)
  1050. if (directive) {
  1051. this.bindDirective(directive)
  1052. }
  1053. }
  1054. }
  1055. if (isDirective) node.removeAttribute(attr.name)
  1056. }
  1057. }
  1058. // recursively compile childNodes
  1059. if (node.childNodes.length) {
  1060. slice.call(node.childNodes).forEach(this.compile, this)
  1061. }
  1062. }
  1063. /**
  1064. * Compile a text node
  1065. */
  1066. CompilerProto.compileTextNode = function (node) {
  1067. var tokens = TextParser.parse(node.nodeValue)
  1068. if (!tokens) return
  1069. var el, token, directive, partial, partialId, partialNodes
  1070. for (var i = 0, l = tokens.length; i < l; i++) {
  1071. token = tokens[i]
  1072. directive = partialNodes = null
  1073. if (token.key) { // a binding
  1074. if (token.key.charAt(0) === '>') { // a partial
  1075. partialId = token.key.slice(1).trim()
  1076. partial = this.getOption('partials', partialId)
  1077. if (partial) {
  1078. el = partial.cloneNode(true)
  1079. // save an Array reference of the partial's nodes
  1080. // so we can compile them AFTER appending the fragment
  1081. partialNodes = slice.call(el.childNodes)
  1082. }
  1083. } else { // a real binding
  1084. if (!token.html) { // text binding
  1085. el = document.createTextNode('')
  1086. directive = Directive.parse('text', token.key, this, el)
  1087. } else { // html binding
  1088. el = document.createComment(config.prefix + '-html')
  1089. directive = Directive.parse('html', token.key, this, el)
  1090. }
  1091. }
  1092. } else { // a plain string
  1093. el = document.createTextNode(token)
  1094. }
  1095. // insert node
  1096. node.parentNode.insertBefore(el, node)
  1097. // bind directive
  1098. if (directive) {
  1099. this.bindDirective(directive)
  1100. }
  1101. // compile partial after appending, because its children's parentNode
  1102. // will change from the fragment to the correct parentNode.
  1103. // This could affect directives that need access to its element's parentNode.
  1104. if (partialNodes) {
  1105. partialNodes.forEach(this.compile, this)
  1106. }
  1107. }
  1108. node.parentNode.removeChild(node)
  1109. }
  1110. /**
  1111. * Add a directive instance to the correct binding & viewmodel
  1112. */
  1113. CompilerProto.bindDirective = function (directive) {
  1114. // keep track of it so we can unbind() later
  1115. this.dirs.push(directive)
  1116. // for empty or literal directives, simply call its bind()
  1117. // and we're done.
  1118. if (directive.isEmpty || directive.isLiteral) {
  1119. if (directive.bind) directive.bind()
  1120. return
  1121. }
  1122. // otherwise, we got more work to do...
  1123. var binding,
  1124. compiler = this,
  1125. key = directive.key
  1126. if (directive.isExp) {
  1127. // expression bindings are always created on current compiler
  1128. binding = compiler.createBinding(key, true, directive.isFn)
  1129. } else {
  1130. // recursively locate which compiler owns the binding
  1131. while (compiler) {
  1132. if (compiler.hasKey(key)) {
  1133. break
  1134. } else {
  1135. compiler = compiler.parentCompiler
  1136. }
  1137. }
  1138. compiler = compiler || this
  1139. binding = compiler.bindings[key] || compiler.createBinding(key)
  1140. }
  1141. binding.instances.push(directive)
  1142. directive.binding = binding
  1143. // invoke bind hook if exists
  1144. if (directive.bind) {
  1145. directive.bind()
  1146. }
  1147. // set initial value
  1148. directive.update(binding.val(), true)
  1149. }
  1150. /**
  1151. * Create binding and attach getter/setter for a key to the viewmodel object
  1152. */
  1153. CompilerProto.createBinding = function (key, isExp, isFn) {
  1154. log(' created binding: ' + key)
  1155. var compiler = this,
  1156. bindings = compiler.bindings,
  1157. computed = compiler.options.computed,
  1158. binding = new Binding(compiler, key, isExp, isFn)
  1159. if (isExp) {
  1160. // expression bindings are anonymous
  1161. compiler.defineExp(key, binding)
  1162. } else {
  1163. bindings[key] = binding
  1164. if (binding.root) {
  1165. // this is a root level binding. we need to define getter/setters for it.
  1166. if (computed && computed[key]) {
  1167. // computed property
  1168. compiler.defineComputed(key, binding, computed[key])
  1169. } else {
  1170. // normal property
  1171. compiler.defineProp(key, binding)
  1172. }
  1173. } else {
  1174. // ensure path in data so it can be observed
  1175. Observer.ensurePath(compiler.data, key)
  1176. var parentKey = key.slice(0, key.lastIndexOf('.'))
  1177. if (!bindings[parentKey]) {
  1178. // this is a nested value binding, but the binding for its parent
  1179. // has not been created yet. We better create that one too.
  1180. compiler.createBinding(parentKey)
  1181. }
  1182. }
  1183. }
  1184. return binding
  1185. }
  1186. /**
  1187. * Define the getter/setter for a root-level property on the VM
  1188. * and observe the initial value
  1189. */
  1190. CompilerProto.defineProp = function (key, binding) {
  1191. var compiler = this,
  1192. data = compiler.data,
  1193. ob = data.__observer__
  1194. // make sure the key is present in data
  1195. // so it can be observed
  1196. if (!(key in data)) {
  1197. data[key] = undefined
  1198. }
  1199. // if the data object is already observed, but the key
  1200. // is not observed, we need to add it to the observed keys.
  1201. if (ob && !(key in ob.values)) {
  1202. Observer.convert(data, key)
  1203. }
  1204. binding.value = data[key]
  1205. Object.defineProperty(compiler.vm, key, {
  1206. get: function () {
  1207. return compiler.data[key]
  1208. },
  1209. set: function (val) {
  1210. compiler.data[key] = val
  1211. }
  1212. })
  1213. }
  1214. /**
  1215. * Define an expression binding, which is essentially
  1216. * an anonymous computed property
  1217. */
  1218. CompilerProto.defineExp = function (key, binding) {
  1219. var getter = ExpParser.parse(key, this)
  1220. if (getter) {
  1221. this.markComputed(binding, getter)
  1222. this.exps.push(binding)
  1223. }
  1224. }
  1225. /**
  1226. * Define a computed property on the VM
  1227. */
  1228. CompilerProto.defineComputed = function (key, binding, value) {
  1229. this.markComputed(binding, value)
  1230. var def = {
  1231. get: binding.value.$get,
  1232. set: binding.value.$set
  1233. }
  1234. Object.defineProperty(this.vm, key, def)
  1235. }
  1236. /**
  1237. * Process a computed property binding
  1238. * so its getter/setter are bound to proper context
  1239. */
  1240. CompilerProto.markComputed = function (binding, value) {
  1241. binding.isComputed = true
  1242. // bind the accessors to the vm
  1243. if (binding.isFn) {
  1244. binding.value = value
  1245. } else {
  1246. if (typeof value === 'function') {
  1247. value = { $get: value }
  1248. }
  1249. binding.value = {
  1250. $get: utils.bind(value.$get, this.vm),
  1251. $set: value.$set
  1252. ? utils.bind(value.$set, this.vm)
  1253. : undefined
  1254. }
  1255. }
  1256. // keep track for dep parsing later
  1257. this.computed.push(binding)
  1258. }
  1259. /**
  1260. * Retrive an option from the compiler
  1261. */
  1262. CompilerProto.getOption = function (type, id) {
  1263. var opts = this.options,
  1264. parent = this.parentCompiler
  1265. return (opts[type] && opts[type][id]) || (
  1266. parent
  1267. ? parent.getOption(type, id)
  1268. : utils[type] && utils[type][id]
  1269. )
  1270. }
  1271. /**
  1272. * Emit lifecycle events to trigger hooks
  1273. */
  1274. CompilerProto.execHook = function (event) {
  1275. event = 'hook:' + event
  1276. this.observer.emit(event)
  1277. this.emitter.emit(event)
  1278. }
  1279. /**
  1280. * Check if a compiler's data contains a keypath
  1281. */
  1282. CompilerProto.hasKey = function (key) {
  1283. var baseKey = key.split('.')[0]
  1284. return hasOwn.call(this.data, baseKey) ||
  1285. hasOwn.call(this.vm, baseKey)
  1286. }
  1287. /**
  1288. * Collect dependencies for computed properties
  1289. */
  1290. CompilerProto.parseDeps = function () {
  1291. if (!this.computed.length) return
  1292. DepsParser.parse(this.computed)
  1293. }
  1294. /**
  1295. * Unbind and remove element
  1296. */
  1297. CompilerProto.destroy = function () {
  1298. // avoid being called more than once
  1299. // this is irreversible!
  1300. if (this.destroyed) return
  1301. var compiler = this,
  1302. i, key, dir, instances, binding,
  1303. vm = compiler.vm,
  1304. el = compiler.el,
  1305. directives = compiler.dirs,
  1306. exps = compiler.exps,
  1307. bindings = compiler.bindings
  1308. compiler.execHook('beforeDestroy')
  1309. // unobserve data
  1310. Observer.unobserve(compiler.data, '', compiler.observer)
  1311. // unbind all direcitves
  1312. i = directives.length
  1313. while (i--) {
  1314. dir = directives[i]
  1315. // if this directive is an instance of an external binding
  1316. // e.g. a directive that refers to a variable on the parent VM
  1317. // we need to remove it from that binding's instances
  1318. // * empty and literal bindings do not have binding.
  1319. if (dir.binding && dir.binding.compiler !== compiler) {
  1320. instances = dir.binding.instances
  1321. if (instances) instances.splice(instances.indexOf(dir), 1)
  1322. }
  1323. dir.unbind()
  1324. }
  1325. // unbind all expressions (anonymous bindings)
  1326. i = exps.length
  1327. while (i--) {
  1328. exps[i].unbind()
  1329. }
  1330. // unbind all own bindings
  1331. for (key in bindings) {
  1332. binding = bindings[key]
  1333. if (binding) {
  1334. binding.unbind()
  1335. }
  1336. }
  1337. // remove self from parentCompiler
  1338. var parent = compiler.parentCompiler,
  1339. childId = compiler.childId
  1340. if (parent) {
  1341. parent.childCompilers.splice(parent.childCompilers.indexOf(compiler), 1)
  1342. if (childId) {
  1343. delete parent.vm.$[childId]
  1344. }
  1345. }
  1346. // finally remove dom element
  1347. if (el === document.body) {
  1348. el.innerHTML = ''
  1349. } else {
  1350. vm.$remove()
  1351. }
  1352. this.destroyed = true
  1353. // emit destroy hook
  1354. compiler.execHook('afterDestroy')
  1355. // finally, unregister all listeners
  1356. compiler.observer.off()
  1357. compiler.emitter.off()
  1358. }
  1359. // Helpers --------------------------------------------------------------------
  1360. /**
  1361. * shorthand for getting root compiler
  1362. */
  1363. function getRoot (compiler) {
  1364. while (compiler.parentCompiler) {
  1365. compiler = compiler.parentCompiler
  1366. }
  1367. return compiler
  1368. }
  1369. module.exports = Compiler
  1370. });
  1371. require.register("vue/src/viewmodel.js", function(exports, require, module){
  1372. var Compiler = require('./compiler'),
  1373. utils = require('./utils'),
  1374. transition = require('./transition'),
  1375. def = utils.defProtected,
  1376. nextTick = utils.nextTick
  1377. /**
  1378. * ViewModel exposed to the user that holds data,
  1379. * computed properties, event handlers
  1380. * and a few reserved methods
  1381. */
  1382. function ViewModel (options) {
  1383. // just compile. options are passed directly to compiler
  1384. new Compiler(this, options)
  1385. }
  1386. // All VM prototype methods are inenumerable
  1387. // so it can be stringified/looped through as raw data
  1388. var VMProto = ViewModel.prototype
  1389. /**
  1390. * Convenience function to set an actual nested value
  1391. * from a flat key string. Used in directives.
  1392. */
  1393. def(VMProto, '$set', function (key, value) {
  1394. var path = key.split('.'),
  1395. obj = getTargetVM(this, path)
  1396. if (!obj) return
  1397. for (var d = 0, l = path.length - 1; d < l; d++) {
  1398. obj = obj[path[d]]
  1399. }
  1400. obj[path[d]] = value
  1401. })
  1402. /**
  1403. * watch a key on the viewmodel for changes
  1404. * fire callback with new value
  1405. */
  1406. def(VMProto, '$watch', function (key, callback) {
  1407. var self = this
  1408. function on () {
  1409. var args = arguments
  1410. utils.nextTick(function () {
  1411. callback.apply(self, args)
  1412. })
  1413. }
  1414. callback._fn = on
  1415. self.$compiler.observer.on('change:' + key, on)
  1416. })
  1417. /**
  1418. * unwatch a key
  1419. */
  1420. def(VMProto, '$unwatch', function (key, callback) {
  1421. // workaround here
  1422. // since the emitter module checks callback existence
  1423. // by checking the length of arguments
  1424. var args = ['change:' + key],
  1425. ob = this.$compiler.observer
  1426. if (callback) args.push(callback._fn)
  1427. ob.off.apply(ob, args)
  1428. })
  1429. /**
  1430. * unbind everything, remove everything
  1431. */
  1432. def(VMProto, '$destroy', function () {
  1433. this.$compiler.destroy()
  1434. })
  1435. /**
  1436. * broadcast an event to all child VMs recursively.
  1437. */
  1438. def(VMProto, '$broadcast', function () {
  1439. var children = this.$compiler.childCompilers,
  1440. i = children.length,
  1441. child
  1442. while (i--) {
  1443. child = children[i]
  1444. child.emitter.emit.apply(child.emitter, arguments)
  1445. child.vm.$broadcast.apply(child.vm, arguments)
  1446. }
  1447. })
  1448. /**
  1449. * emit an event that propagates all the way up to parent VMs.
  1450. */
  1451. def(VMProto, '$dispatch', function () {
  1452. var compiler = this.$compiler,
  1453. emitter = compiler.emitter,
  1454. parent = compiler.parentCompiler
  1455. emitter.emit.apply(emitter, arguments)
  1456. if (parent) {
  1457. parent.vm.$dispatch.apply(parent.vm, arguments)
  1458. }
  1459. })
  1460. /**
  1461. * delegate on/off/once to the compiler's emitter
  1462. */
  1463. ;['emit', 'on', 'off', 'once'].forEach(function (method) {
  1464. def(VMProto, '$' + method, function () {
  1465. var emitter = this.$compiler.emitter
  1466. emitter[method].apply(emitter, arguments)
  1467. })
  1468. })
  1469. // DOM convenience methods
  1470. def(VMProto, '$appendTo', function (target, cb) {
  1471. target = query(target)
  1472. var el = this.$el
  1473. transition(el, 1, function () {
  1474. target.appendChild(el)
  1475. if (cb) nextTick(cb)
  1476. }, this.$compiler)
  1477. })
  1478. def(VMProto, '$remove', function (cb) {
  1479. var el = this.$el,
  1480. parent = el.parentNode
  1481. if (!parent) return
  1482. transition(el, -1, function () {
  1483. parent.removeChild(el)
  1484. if (cb) nextTick(cb)
  1485. }, this.$compiler)
  1486. })
  1487. def(VMProto, '$before', function (target, cb) {
  1488. target = query(target)
  1489. var el = this.$el,
  1490. parent = target.parentNode
  1491. if (!parent) return
  1492. transition(el, 1, function () {
  1493. parent.insertBefore(el, target)
  1494. if (cb) nextTick(cb)
  1495. }, this.$compiler)
  1496. })
  1497. def(VMProto, '$after', function (target, cb) {
  1498. target = query(target)
  1499. var el = this.$el,
  1500. parent = target.parentNode,
  1501. next = target.nextSibling
  1502. if (!parent) return
  1503. transition(el, 1, function () {
  1504. if (next) {
  1505. parent.insertBefore(el, next)
  1506. } else {
  1507. parent.appendChild(el)
  1508. }
  1509. if (cb) nextTick(cb)
  1510. }, this.$compiler)
  1511. })
  1512. function query (el) {
  1513. return typeof el === 'string'
  1514. ? document.querySelector(el)
  1515. : el
  1516. }
  1517. /**
  1518. * If a VM doesn't contain a path, go up the prototype chain
  1519. * to locate the ancestor that has it.
  1520. */
  1521. function getTargetVM (vm, path) {
  1522. var baseKey = path[0],
  1523. binding = vm.$compiler.bindings[baseKey]
  1524. return binding
  1525. ? binding.compiler.vm
  1526. : null
  1527. }
  1528. module.exports = ViewModel
  1529. });
  1530. require.register("vue/src/binding.js", function(exports, require, module){
  1531. var batcher = require('./batcher'),
  1532. id = 0
  1533. /**
  1534. * Binding class.
  1535. *
  1536. * each property on the viewmodel has one corresponding Binding object
  1537. * which has multiple directive instances on the DOM
  1538. * and multiple computed property dependents
  1539. */
  1540. function Binding (compiler, key, isExp, isFn) {
  1541. this.id = id++
  1542. this.value = undefined
  1543. this.isExp = !!isExp
  1544. this.isFn = isFn
  1545. this.root = !this.isExp && key.indexOf('.') === -1
  1546. this.compiler = compiler
  1547. this.key = key
  1548. this.instances = []
  1549. this.subs = []
  1550. this.deps = []
  1551. this.unbound = false
  1552. }
  1553. var BindingProto = Binding.prototype
  1554. /**
  1555. * Update value and queue instance updates.
  1556. */
  1557. BindingProto.update = function (value) {
  1558. if (!this.isComputed || this.isFn) {
  1559. this.value = value
  1560. }
  1561. batcher.queue(this)
  1562. }
  1563. /**
  1564. * Actually update the instances.
  1565. */
  1566. BindingProto._update = function () {
  1567. var i = this.instances.length,
  1568. value = this.val()
  1569. while (i--) {
  1570. this.instances[i].update(value)
  1571. }
  1572. this.pub()
  1573. }
  1574. /**
  1575. * Return the valuated value regardless
  1576. * of whether it is computed or not
  1577. */
  1578. BindingProto.val = function () {
  1579. return this.isComputed && !this.isFn
  1580. ? this.value.$get()
  1581. : this.value
  1582. }
  1583. /**
  1584. * Notify computed properties that depend on this binding
  1585. * to update themselves
  1586. */
  1587. BindingProto.pub = function () {
  1588. var i = this.subs.length
  1589. while (i--) {
  1590. this.subs[i].update()
  1591. }
  1592. }
  1593. /**
  1594. * Unbind the binding, remove itself from all of its dependencies
  1595. */
  1596. BindingProto.unbind = function () {
  1597. // Indicate this has been unbound.
  1598. // It's possible this binding will be in
  1599. // the batcher's flush queue when its owner
  1600. // compiler has already been destroyed.
  1601. this.unbound = true
  1602. var i = this.instances.length
  1603. while (i--) {
  1604. this.instances[i].unbind()
  1605. }
  1606. i = this.deps.length
  1607. var subs
  1608. while (i--) {
  1609. subs = this.deps[i].subs
  1610. subs.splice(subs.indexOf(this), 1)
  1611. }
  1612. }
  1613. module.exports = Binding
  1614. });
  1615. require.register("vue/src/observer.js", function(exports, require, module){
  1616. /* jshint proto:true */
  1617. var Emitter = require('./emitter'),
  1618. utils = require('./utils'),
  1619. // cache methods
  1620. typeOf = utils.typeOf,
  1621. def = utils.defProtected,
  1622. slice = Array.prototype.slice,
  1623. // types
  1624. OBJECT = 'Object',
  1625. ARRAY = 'Array',
  1626. // Array mutation methods to wrap
  1627. methods = ['push','pop','shift','unshift','splice','sort','reverse'],
  1628. // fix for IE + __proto__ problem
  1629. // define methods as inenumerable if __proto__ is present,
  1630. // otherwise enumerable so we can loop through and manually
  1631. // attach to array instances
  1632. hasProto = ({}).__proto__,
  1633. // lazy load
  1634. ViewModel
  1635. // The proxy prototype to replace the __proto__ of
  1636. // an observed array
  1637. var ArrayProxy = Object.create(Array.prototype)
  1638. // Define mutation interceptors so we can emit the mutation info
  1639. methods.forEach(function (method) {
  1640. def(ArrayProxy, method, function () {
  1641. var result = Array.prototype[method].apply(this, arguments)
  1642. this.__observer__.emit('mutate', this.__observer__.path, this, {
  1643. method: method,
  1644. args: slice.call(arguments),
  1645. result: result
  1646. })
  1647. return result
  1648. }, !hasProto)
  1649. })
  1650. /**
  1651. * Convenience method to remove an element in an Array
  1652. * This will be attached to observed Array instances
  1653. */
  1654. function removeElement (index) {
  1655. if (typeof index === 'function') {
  1656. var i = this.length,
  1657. removed = []
  1658. while (i--) {
  1659. if (index(this[i])) {
  1660. removed.push(this.splice(i, 1)[0])
  1661. }
  1662. }
  1663. return removed.reverse()
  1664. } else {
  1665. if (typeof index !== 'number') {
  1666. index = this.indexOf(index)
  1667. }
  1668. if (index > -1) {
  1669. return this.splice(index, 1)[0]
  1670. }
  1671. }
  1672. }
  1673. /**
  1674. * Convenience method to replace an element in an Array
  1675. * This will be attached to observed Array instances
  1676. */
  1677. function replaceElement (index, data) {
  1678. if (typeof index === 'function') {
  1679. var i = this.length,
  1680. replaced = [],
  1681. replacer
  1682. while (i--) {
  1683. replacer = index(this[i])
  1684. if (replacer !== undefined) {
  1685. replaced.push(this.splice(i, 1, replacer)[0])
  1686. }
  1687. }
  1688. return replaced.reverse()
  1689. } else {
  1690. if (typeof index !== 'number') {
  1691. index = this.indexOf(index)
  1692. }
  1693. if (index > -1) {
  1694. return this.splice(index, 1, data)[0]
  1695. }
  1696. }
  1697. }
  1698. // Augment the ArrayProxy with convenience methods
  1699. def(ArrayProxy, 'remove', removeElement, !hasProto)
  1700. def(ArrayProxy, 'set', replaceElement, !hasProto)
  1701. def(ArrayProxy, 'replace', replaceElement, !hasProto)
  1702. /**
  1703. * Watch an Object, recursive.
  1704. */
  1705. function watchObject (obj) {
  1706. for (var key in obj) {
  1707. convert(obj, key)
  1708. }
  1709. }
  1710. /**
  1711. * Watch an Array, overload mutation methods
  1712. * and add augmentations by intercepting the prototype chain
  1713. */
  1714. function watchArray (arr, path) {
  1715. var observer = arr.__observer__
  1716. if (!observer) {
  1717. observer = new Emitter()
  1718. def(arr, '__observer__', observer)
  1719. }
  1720. observer.path = path
  1721. if (hasProto) {
  1722. arr.__proto__ = ArrayProxy
  1723. } else {
  1724. for (var key in ArrayProxy) {
  1725. def(arr, key, ArrayProxy[key])
  1726. }
  1727. }
  1728. }
  1729. /**
  1730. * Define accessors for a property on an Object
  1731. * so it emits get/set events.
  1732. * Then watch the value itself.
  1733. */
  1734. function convert (obj, key) {
  1735. var keyPrefix = key.charAt(0)
  1736. if ((keyPrefix === '$' || keyPrefix === '_') && key !== '$index') {
  1737. return
  1738. }
  1739. // emit set on bind
  1740. // this means when an object is observed it will emit
  1741. // a first batch of set events.
  1742. var observer = obj.__observer__,
  1743. values = observer.values,
  1744. val = values[key] = obj[key]
  1745. observer.emit('set', key, val)
  1746. if (Array.isArray(val)) {
  1747. observer.emit('set', key + '.length', val.length)
  1748. }
  1749. Object.defineProperty(obj, key, {
  1750. get: function () {
  1751. var value = values[key]
  1752. // only emit get on tip values
  1753. if (pub.shouldGet && typeOf(value) !== OBJECT) {
  1754. observer.emit('get', key)
  1755. }
  1756. return value
  1757. },
  1758. set: function (newVal) {
  1759. var oldVal = values[key]
  1760. unobserve(oldVal, key, observer)
  1761. values[key] = newVal
  1762. copyPaths(newVal, oldVal)
  1763. observer.emit('set', key, newVal)
  1764. observe(newVal, key, observer)
  1765. }
  1766. })
  1767. observe(val, key, observer)
  1768. }
  1769. /**
  1770. * Check if a value is watchable
  1771. */
  1772. function isWatchable (obj) {
  1773. ViewModel = ViewModel || require('./viewmodel')
  1774. var type = typeOf(obj)
  1775. return (type === OBJECT || type === ARRAY) && !(obj instanceof ViewModel)
  1776. }
  1777. /**
  1778. * When a value that is already converted is
  1779. * observed again by another observer, we can skip
  1780. * the watch conversion and simply emit set event for
  1781. * all of its properties.
  1782. */
  1783. function emitSet (obj) {
  1784. var type = typeOf(obj),
  1785. emitter = obj && obj.__observer__
  1786. if (type === ARRAY) {
  1787. emitter.emit('set', 'length', obj.length)
  1788. } else if (type === OBJECT) {
  1789. var key, val
  1790. for (key in obj) {
  1791. val = obj[key]
  1792. emitter.emit('set', key, val)
  1793. emitSet(val)
  1794. }
  1795. }
  1796. }
  1797. /**
  1798. * Make sure all the paths in an old object exists
  1799. * in a new object.
  1800. * So when an object changes, all missing keys will
  1801. * emit a set event with undefined value.
  1802. */
  1803. function copyPaths (newObj, oldObj) {
  1804. if (typeOf(oldObj) !== OBJECT || typeOf(newObj) !== OBJECT) {
  1805. return
  1806. }
  1807. var path, type, oldVal, newVal
  1808. for (path in oldObj) {
  1809. if (!(path in newObj)) {
  1810. oldVal = oldObj[path]
  1811. type = typeOf(oldVal)
  1812. if (type === OBJECT) {
  1813. newVal = newObj[path] = {}
  1814. copyPaths(newVal, oldVal)
  1815. } else if (type === ARRAY) {
  1816. newObj[path] = []
  1817. } else {
  1818. newObj[path] = undefined
  1819. }
  1820. }
  1821. }
  1822. }
  1823. /**
  1824. * walk along a path and make sure it can be accessed
  1825. * and enumerated in that object
  1826. */
  1827. function ensurePath (obj, key) {
  1828. var path = key.split('.'), sec
  1829. for (var i = 0, d = path.length - 1; i < d; i++) {
  1830. sec = path[i]
  1831. if (!obj[sec]) {
  1832. obj[sec] = {}
  1833. if (obj.__observer__) convert(obj, sec)
  1834. }
  1835. obj = obj[sec]
  1836. }
  1837. if (typeOf(obj) === OBJECT) {
  1838. sec = path[i]
  1839. if (!(sec in obj)) {
  1840. obj[sec] = undefined
  1841. if (obj.__observer__) convert(obj, sec)
  1842. }
  1843. }
  1844. }
  1845. /**
  1846. * Observe an object with a given path,
  1847. * and proxy get/set/mutate events to the provided observer.
  1848. */
  1849. function observe (obj, rawPath, observer) {
  1850. if (!isWatchable(obj)) return
  1851. var path = rawPath ? rawPath + '.' : '',
  1852. ob, alreadyConverted = !!obj.__observer__
  1853. if (!alreadyConverted) {
  1854. def(obj, '__observer__', new Emitter())
  1855. }
  1856. ob = obj.__observer__
  1857. ob.values = ob.values || utils.hash()
  1858. observer.proxies = observer.proxies || {}
  1859. var proxies = observer.proxies[path] = {
  1860. get: function (key) {
  1861. observer.emit('get', path + key)
  1862. },
  1863. set: function (key, val) {
  1864. observer.emit('set', path + key, val)
  1865. },
  1866. mutate: function (key, val, mutation) {
  1867. // if the Array is a root value
  1868. // the key will be null
  1869. var fixedPath = key ? path + key : rawPath
  1870. observer.emit('mutate', fixedPath, val, mutation)
  1871. // also emit set for Array's length when it mutates
  1872. var m = mutation.method
  1873. if (m !== 'sort' && m !== 'reverse') {
  1874. observer.emit('set', fixedPath + '.length', val.length)
  1875. }
  1876. }
  1877. }
  1878. ob
  1879. .on('get', proxies.get)
  1880. .on('set', proxies.set)
  1881. .on('mutate', proxies.mutate)
  1882. if (alreadyConverted) {
  1883. emitSet(obj)
  1884. } else {
  1885. var type = typeOf(obj)
  1886. if (type === OBJECT) {
  1887. watchObject(obj)
  1888. } else if (type === ARRAY) {
  1889. watchArray(obj)
  1890. }
  1891. }
  1892. }
  1893. /**
  1894. * Cancel observation, turn off the listeners.
  1895. */
  1896. function unobserve (obj, path, observer) {
  1897. if (!obj || !obj.__observer__) return
  1898. path = path ? path + '.' : ''
  1899. var proxies = observer.proxies[path]
  1900. if (!proxies) return
  1901. obj.__observer__
  1902. .off('get', proxies.get)
  1903. .off('set', proxies.set)
  1904. .off('mutate', proxies.mutate)
  1905. observer.proxies[path] = null
  1906. }
  1907. var pub = module.exports = {
  1908. // whether to emit get events
  1909. // only enabled during dependency parsing
  1910. shouldGet : false,
  1911. observe : observe,
  1912. unobserve : unobserve,
  1913. ensurePath : ensurePath,
  1914. convert : convert,
  1915. copyPaths : copyPaths,
  1916. watchArray : watchArray
  1917. }
  1918. });
  1919. require.register("vue/src/directive.js", function(exports, require, module){
  1920. var utils = require('./utils'),
  1921. directives = require('./directives'),
  1922. filters = require('./filters'),
  1923. // Regexes!
  1924. // regex to split multiple directive expressions
  1925. // split by commas, but ignore commas within quotes, parens and escapes.
  1926. SPLIT_RE = /(?:['"](?:\\.|[^'"])*['"]|\((?:\\.|[^\)])*\)|\\.|[^,])+/g,
  1927. // match up to the first single pipe, ignore those within quotes.
  1928. KEY_RE = /^(?:['"](?:\\.|[^'"])*['"]|\\.|[^\|]|\|\|)+/,
  1929. ARG_RE = /^([\w-$ ]+):(.+)$/,
  1930. FILTERS_RE = /\|[^\|]+/g,
  1931. FILTER_TOKEN_RE = /[^\s']+|'[^']+'/g,
  1932. NESTING_RE = /^\$(parent|root)\./,
  1933. SINGLE_VAR_RE = /^[\w\.$]+$/
  1934. /**
  1935. * Directive class
  1936. * represents a single directive instance in the DOM
  1937. */
  1938. function Directive (definition, expression, rawKey, compiler, node) {
  1939. this.compiler = compiler
  1940. this.vm = compiler.vm
  1941. this.el = node
  1942. var isEmpty = expression === ''
  1943. // mix in properties from the directive definition
  1944. if (typeof definition === 'function') {
  1945. this[isEmpty ? 'bind' : '_update'] = definition
  1946. } else {
  1947. for (var prop in definition) {
  1948. if (prop === 'unbind' || prop === 'update') {
  1949. this['_' + prop] = definition[prop]
  1950. } else {
  1951. this[prop] = definition[prop]
  1952. }
  1953. }
  1954. }
  1955. // empty expression, we're done.
  1956. if (isEmpty) {
  1957. this.isEmpty = true
  1958. return
  1959. }
  1960. // for literal directives, all we need
  1961. // is the expression as the value.
  1962. if (this.isLiteral) {
  1963. this.value = expression.trim()
  1964. return
  1965. }
  1966. this.expression = expression.trim()
  1967. this.rawKey = rawKey
  1968. parseKey(this, rawKey)
  1969. this.isExp = !SINGLE_VAR_RE.test(this.key) || NESTING_RE.test(this.key)
  1970. var filterExps = this.expression.slice(rawKey.length).match(FILTERS_RE)
  1971. if (filterExps) {
  1972. this.filters = []
  1973. for (var i = 0, l = filterExps.length, filter; i < l; i++) {
  1974. filter = parseFilter(filterExps[i], this.compiler)
  1975. if (filter) this.filters.push(filter)
  1976. }
  1977. if (!this.filters.length) this.filters = null
  1978. } else {
  1979. this.filters = null
  1980. }
  1981. }
  1982. var DirProto = Directive.prototype
  1983. /**
  1984. * parse a key, extract argument and nesting/root info
  1985. */
  1986. function parseKey (dir, rawKey) {
  1987. var key = rawKey
  1988. if (rawKey.indexOf(':') > -1) {
  1989. var argMatch = rawKey.match(ARG_RE)
  1990. key = argMatch
  1991. ? argMatch[2].trim()
  1992. : key
  1993. dir.arg = argMatch
  1994. ? argMatch[1].trim()
  1995. : null
  1996. }
  1997. dir.key = key
  1998. }
  1999. /**
  2000. * parse a filter expression
  2001. */
  2002. function parseFilter (filter, compiler) {
  2003. var tokens = filter.slice(1).match(FILTER_TOKEN_RE)
  2004. if (!tokens) return
  2005. tokens = tokens.map(function (token) {
  2006. return token.replace(/'/g, '').trim()
  2007. })
  2008. var name = tokens[0],
  2009. apply = compiler.getOption('filters', name) || filters[name]
  2010. if (!apply) {
  2011. utils.warn('Unknown filter: ' + name)
  2012. return
  2013. }
  2014. return {
  2015. name : name,
  2016. apply : apply,
  2017. args : tokens.length > 1
  2018. ? tokens.slice(1)
  2019. : null
  2020. }
  2021. }
  2022. /**
  2023. * called when a new value is set
  2024. * for computed properties, this will only be called once
  2025. * during initialization.
  2026. */
  2027. DirProto.update = function (value, init) {
  2028. if (!init && value === this.value) return
  2029. this.value = value
  2030. if (this._update) {
  2031. this._update(
  2032. this.filters
  2033. ? this.applyFilters(value)
  2034. : value
  2035. )
  2036. }
  2037. }
  2038. /**
  2039. * pipe the value through filters
  2040. */
  2041. DirProto.applyFilters = function (value) {
  2042. var filtered = value, filter
  2043. for (var i = 0, l = this.filters.length; i < l; i++) {
  2044. filter = this.filters[i]
  2045. filtered = filter.apply.call(this.vm, filtered, filter.args)
  2046. }
  2047. return filtered
  2048. }
  2049. /**
  2050. * Unbind diretive
  2051. */
  2052. DirProto.unbind = function () {
  2053. // this can be called before the el is even assigned...
  2054. if (!this.el || !this.vm) return
  2055. if (this._unbind) this._unbind()
  2056. this.vm = this.el = this.binding = this.compiler = null
  2057. }
  2058. // exposed methods ------------------------------------------------------------
  2059. /**
  2060. * split a unquoted-comma separated expression into
  2061. * multiple clauses
  2062. */
  2063. Directive.split = function (exp) {
  2064. return exp.indexOf(',') > -1
  2065. ? exp.match(SPLIT_RE) || ['']
  2066. : [exp]
  2067. }
  2068. /**
  2069. * make sure the directive and expression is valid
  2070. * before we create an instance
  2071. */
  2072. Directive.parse = function (dirname, expression, compiler, node) {
  2073. var dir = compiler.getOption('directives', dirname) || directives[dirname]
  2074. if (!dir) return utils.warn('unknown directive: ' + dirname)
  2075. var rawKey
  2076. if (expression.indexOf('|') > -1) {
  2077. var keyMatch = expression.match(KEY_RE)
  2078. if (keyMatch) {
  2079. rawKey = keyMatch[0].trim()
  2080. }
  2081. } else {
  2082. rawKey = expression.trim()
  2083. }
  2084. // have a valid raw key, or be an empty directive
  2085. return (rawKey || expression === '')
  2086. ? new Directive(dir, expression, rawKey, compiler, node)
  2087. : utils.warn('invalid directive expression: ' + expression)
  2088. }
  2089. module.exports = Directive
  2090. });
  2091. require.register("vue/src/exp-parser.js", function(exports, require, module){
  2092. var utils = require('./utils'),
  2093. stringSaveRE = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g,
  2094. stringRestoreRE = /"(\d+)"/g,
  2095. constructorRE = new RegExp('constructor'.split('').join('[\'"+, ]*')),
  2096. unicodeRE = /\\u\d\d\d\d/
  2097. // Variable extraction scooped from https://github.com/RubyLouvre/avalon
  2098. var KEYWORDS =
  2099. // keywords
  2100. 'break,case,catch,continue,debugger,default,delete,do,else,false' +
  2101. ',finally,for,function,if,in,instanceof,new,null,return,switch,this' +
  2102. ',throw,true,try,typeof,var,void,while,with,undefined' +
  2103. // reserved
  2104. ',abstract,boolean,byte,char,class,const,double,enum,export,extends' +
  2105. ',final,float,goto,implements,import,int,interface,long,native' +
  2106. ',package,private,protected,public,short,static,super,synchronized' +
  2107. ',throws,transient,volatile' +
  2108. // ECMA 5 - use strict
  2109. ',arguments,let,yield' +
  2110. // allow using Math in expressions
  2111. ',Math',
  2112. KEYWORDS_RE = new RegExp(["\\b" + KEYWORDS.replace(/,/g, '\\b|\\b') + "\\b"].join('|'), 'g'),
  2113. REMOVE_RE = /\/\*(?:.|\n)*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|'[^']*'|"[^"]*"|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,
  2114. SPLIT_RE = /[^\w$]+/g,
  2115. NUMBER_RE = /\b\d[^,]*/g,
  2116. BOUNDARY_RE = /^,+|,+$/g
  2117. /**
  2118. * Strip top level variable names from a snippet of JS expression
  2119. */
  2120. function getVariables (code) {
  2121. code = code
  2122. .replace(REMOVE_RE, '')
  2123. .replace(SPLIT_RE, ',')
  2124. .replace(KEYWORDS_RE, '')
  2125. .replace(NUMBER_RE, '')
  2126. .replace(BOUNDARY_RE, '')
  2127. return code
  2128. ? code.split(/,+/)
  2129. : []
  2130. }
  2131. /**
  2132. * A given path could potentially exist not on the
  2133. * current compiler, but up in the parent chain somewhere.
  2134. * This function generates an access relationship string
  2135. * that can be used in the getter function by walking up
  2136. * the parent chain to check for key existence.
  2137. *
  2138. * It stops at top parent if no vm in the chain has the
  2139. * key. It then creates any missing bindings on the
  2140. * final resolved vm.
  2141. */
  2142. function getRel (path, compiler) {
  2143. var rel = '',
  2144. dist = 0,
  2145. self = compiler
  2146. while (compiler) {
  2147. if (compiler.hasKey(path)) {
  2148. break
  2149. } else {
  2150. compiler = compiler.parentCompiler
  2151. dist++
  2152. }
  2153. }
  2154. if (compiler) {
  2155. while (dist--) {
  2156. rel += '$parent.'
  2157. }
  2158. if (!compiler.bindings[path] && path.charAt(0) !== '$') {
  2159. compiler.createBinding(path)
  2160. }
  2161. } else {
  2162. self.createBinding(path)
  2163. }
  2164. return rel
  2165. }
  2166. /**
  2167. * Create a function from a string...
  2168. * this looks like evil magic but since all variables are limited
  2169. * to the VM's data it's actually properly sandboxed
  2170. */
  2171. function makeGetter (exp, raw) {
  2172. /* jshint evil: true */
  2173. var fn
  2174. try {
  2175. fn = new Function(exp)
  2176. } catch (e) {
  2177. utils.warn('Invalid expression: ' + raw)
  2178. }
  2179. return fn
  2180. }
  2181. /**
  2182. * Escape a leading dollar sign for regex construction
  2183. */
  2184. function escapeDollar (v) {
  2185. return v.charAt(0) === '$'
  2186. ? '\\' + v
  2187. : v
  2188. }
  2189. module.exports = {
  2190. /**
  2191. * Parse and return an anonymous computed property getter function
  2192. * from an arbitrary expression, together with a list of paths to be
  2193. * created as bindings.
  2194. */
  2195. parse: function (exp, compiler) {
  2196. // unicode and 'constructor' are not allowed for XSS security.
  2197. if (unicodeRE.test(exp) || constructorRE.test(exp)) {
  2198. utils.warn('Unsafe expression: ' + exp)
  2199. return function () {}
  2200. }
  2201. // extract variable names
  2202. var vars = getVariables(exp)
  2203. if (!vars.length) {
  2204. return makeGetter('return ' + exp, exp)
  2205. }
  2206. vars = utils.unique(vars)
  2207. var accessors = '',
  2208. has = utils.hash(),
  2209. strings = [],
  2210. // construct a regex to extract all valid variable paths
  2211. // ones that begin with "$" are particularly tricky
  2212. // because we can't use \b for them
  2213. pathRE = new RegExp(
  2214. "[^$\\w\\.](" +
  2215. vars.map(escapeDollar).join('|') +
  2216. ")[$\\w\\.]*\\b", 'g'
  2217. ),
  2218. body = ('return ' + exp)
  2219. .replace(stringSaveRE, saveStrings)
  2220. .replace(pathRE, replacePath)
  2221. .replace(stringRestoreRE, restoreStrings)
  2222. body = accessors + body
  2223. function saveStrings (str) {
  2224. var i = strings.length
  2225. strings[i] = str
  2226. return '"' + i + '"'
  2227. }
  2228. function replacePath (path) {
  2229. // keep track of the first char
  2230. var c = path.charAt(0)
  2231. path = path.slice(1)
  2232. var val = 'this.' + getRel(path, compiler) + path
  2233. if (!has[path]) {
  2234. accessors += val + ';'
  2235. has[path] = 1
  2236. }
  2237. // don't forget to put that first char back
  2238. return c + val
  2239. }
  2240. function restoreStrings (str, i) {
  2241. return strings[i]
  2242. }
  2243. return makeGetter(body, exp)
  2244. }
  2245. }
  2246. });
  2247. require.register("vue/src/text-parser.js", function(exports, require, module){
  2248. var BINDING_RE = /{{{?([^{}]+?)}?}}/,
  2249. TRIPLE_RE = /{{{[^{}]+}}}/
  2250. /**
  2251. * Parse a piece of text, return an array of tokens
  2252. */
  2253. function parse (text) {
  2254. if (!BINDING_RE.test(text)) return null
  2255. var m, i, token, tokens = []
  2256. /* jshint boss: true */
  2257. while (m = text.match(BINDING_RE)) {
  2258. i = m.index
  2259. if (i > 0) tokens.push(text.slice(0, i))
  2260. token = { key: m[1].trim() }
  2261. if (TRIPLE_RE.test(m[0])) token.html = true
  2262. tokens.push(token)
  2263. text = text.slice(i + m[0].length)
  2264. }
  2265. if (text.length) tokens.push(text)
  2266. return tokens
  2267. }
  2268. /**
  2269. * Parse an attribute value with possible interpolation tags
  2270. * return a Directive-friendly expression
  2271. */
  2272. function parseAttr (attr) {
  2273. var tokens = parse(attr)
  2274. if (!tokens) return null
  2275. var res = [], token
  2276. for (var i = 0, l = tokens.length; i < l; i++) {
  2277. token = tokens[i]
  2278. res.push(token.key || ('"' + token + '"'))
  2279. }
  2280. return res.join('+')
  2281. }
  2282. exports.parse = parse
  2283. exports.parseAttr = parseAttr
  2284. });
  2285. require.register("vue/src/deps-parser.js", function(exports, require, module){
  2286. var Emitter = require('./emitter'),
  2287. utils = require('./utils'),
  2288. Observer = require('./observer'),
  2289. catcher = new Emitter()
  2290. /**
  2291. * Auto-extract the dependencies of a computed property
  2292. * by recording the getters triggered when evaluating it.
  2293. */
  2294. function catchDeps (binding) {
  2295. if (binding.isFn) return
  2296. utils.log('\n- ' + binding.key)
  2297. var got = utils.hash()
  2298. binding.deps = []
  2299. catcher.on('get', function (dep) {
  2300. var has = got[dep.key]
  2301. if (has && has.compiler === dep.compiler) return
  2302. got[dep.key] = dep
  2303. utils.log(' - ' + dep.key)
  2304. binding.deps.push(dep)
  2305. dep.subs.push(binding)
  2306. })
  2307. binding.value.$get()
  2308. catcher.off('get')
  2309. }
  2310. module.exports = {
  2311. /**
  2312. * the observer that catches events triggered by getters
  2313. */
  2314. catcher: catcher,
  2315. /**
  2316. * parse a list of computed property bindings
  2317. */
  2318. parse: function (bindings) {
  2319. utils.log('\nparsing dependencies...')
  2320. Observer.shouldGet = true
  2321. bindings.forEach(catchDeps)
  2322. Observer.shouldGet = false
  2323. utils.log('\ndone.')
  2324. }
  2325. }
  2326. });
  2327. require.register("vue/src/filters.js", function(exports, require, module){
  2328. var keyCodes = {
  2329. enter : 13,
  2330. tab : 9,
  2331. 'delete' : 46,
  2332. up : 38,
  2333. left : 37,
  2334. right : 39,
  2335. down : 40,
  2336. esc : 27
  2337. }
  2338. module.exports = {
  2339. /**
  2340. * 'abc' => 'Abc'
  2341. */
  2342. capitalize: function (value) {
  2343. if (!value && value !== 0) return ''
  2344. value = value.toString()
  2345. return value.charAt(0).toUpperCase() + value.slice(1)
  2346. },
  2347. /**
  2348. * 'abc' => 'ABC'
  2349. */
  2350. uppercase: function (value) {
  2351. return (value || value === 0)
  2352. ? value.toString().toUpperCase()
  2353. : ''
  2354. },
  2355. /**
  2356. * 'AbC' => 'abc'
  2357. */
  2358. lowercase: function (value) {
  2359. return (value || value === 0)
  2360. ? value.toString().toLowerCase()
  2361. : ''
  2362. },
  2363. /**
  2364. * 12345 => $12,345.00
  2365. */
  2366. currency: function (value, args) {
  2367. if (!value && value !== 0) return ''
  2368. var sign = (args && args[0]) || '$',
  2369. s = Math.floor(value).toString(),
  2370. i = s.length % 3,
  2371. h = i > 0 ? (s.slice(0, i) + (s.length > 3 ? ',' : '')) : '',
  2372. f = '.' + value.toFixed(2).slice(-2)
  2373. return sign + h + s.slice(i).replace(/(\d{3})(?=\d)/g, '$1,') + f
  2374. },
  2375. /**
  2376. * args: an array of strings corresponding to
  2377. * the single, double, triple ... forms of the word to
  2378. * be pluralized. When the number to be pluralized
  2379. * exceeds the length of the args, it will use the last
  2380. * entry in the array.
  2381. *
  2382. * e.g. ['single', 'double', 'triple', 'multiple']
  2383. */
  2384. pluralize: function (value, args) {
  2385. return args.length > 1
  2386. ? (args[value - 1] || args[args.length - 1])
  2387. : (args[value - 1] || args[0] + 's')
  2388. },
  2389. /**
  2390. * A special filter that takes a handler function,
  2391. * wraps it so it only gets triggered on specific keypresses.
  2392. */
  2393. key: function (handler, args) {
  2394. if (!handler) return
  2395. var code = keyCodes[args[0]]
  2396. if (!code) {
  2397. code = parseInt(args[0], 10)
  2398. }
  2399. return function (e) {
  2400. if (e.keyCode === code) {
  2401. handler.call(this, e)
  2402. }
  2403. }
  2404. }
  2405. }
  2406. });
  2407. require.register("vue/src/transition.js", function(exports, require, module){
  2408. var endEvent = sniffTransitionEndEvent(),
  2409. config = require('./config'),
  2410. // exit codes for testing
  2411. codes = {
  2412. CSS_E : 1,
  2413. CSS_L : 2,
  2414. JS_E : 3,
  2415. JS_L : 4,
  2416. CSS_SKIP : -1,
  2417. JS_SKIP : -2,
  2418. JS_SKIP_E : -3,
  2419. JS_SKIP_L : -4,
  2420. INIT : -5,
  2421. SKIP : -6
  2422. }
  2423. /**
  2424. * stage:
  2425. * 1 = enter
  2426. * 2 = leave
  2427. */
  2428. var transition = module.exports = function (el, stage, cb, compiler) {
  2429. var changeState = function () {
  2430. cb()
  2431. compiler.execHook(stage > 0 ? 'enteredView' : 'leftView')
  2432. }
  2433. if (compiler.init) {
  2434. changeState()
  2435. return codes.INIT
  2436. }
  2437. var transitionId = el.vue_trans
  2438. if (transitionId) {
  2439. return applyTransitionFunctions(
  2440. el,
  2441. stage,
  2442. changeState,
  2443. transitionId,
  2444. compiler
  2445. )
  2446. } else if (transitionId === '') {
  2447. return applyTransitionClass(
  2448. el,
  2449. stage,
  2450. changeState
  2451. )
  2452. } else {
  2453. changeState()
  2454. return codes.SKIP
  2455. }
  2456. }
  2457. transition.codes = codes
  2458. /**
  2459. * Togggle a CSS class to trigger transition
  2460. */
  2461. function applyTransitionClass (el, stage, changeState) {
  2462. if (!endEvent) {
  2463. changeState()
  2464. return codes.CSS_SKIP
  2465. }
  2466. // if the browser supports transition,
  2467. // it must have classList...
  2468. var classList = el.classList,
  2469. lastLeaveCallback = el.vue_trans_cb
  2470. if (stage > 0) { // enter
  2471. // cancel unfinished leave transition
  2472. if (lastLeaveCallback) {
  2473. el.removeEventListener(endEvent, lastLeaveCallback)
  2474. el.vue_trans_cb = null
  2475. }
  2476. // set to hidden state before appending
  2477. classList.add(config.enterClass)
  2478. // append
  2479. changeState()
  2480. // force a layout so transition can be triggered
  2481. /* jshint unused: false */
  2482. var forceLayout = el.clientHeight
  2483. // trigger transition
  2484. classList.remove(config.enterClass)
  2485. return codes.CSS_E
  2486. } else { // leave
  2487. // trigger hide transition
  2488. classList.add(config.leaveClass)
  2489. var onEnd = function (e) {
  2490. if (e.target === el) {
  2491. el.removeEventListener(endEvent, onEnd)
  2492. el.vue_trans_cb = null
  2493. // actually remove node here
  2494. changeState()
  2495. classList.remove(config.leaveClass)
  2496. }
  2497. }
  2498. // attach transition end listener
  2499. el.addEventListener(endEvent, onEnd)
  2500. el.vue_trans_cb = onEnd
  2501. return codes.CSS_L
  2502. }
  2503. }
  2504. function applyTransitionFunctions (el, stage, changeState, functionId, compiler) {
  2505. var funcs = compiler.getOption('transitions', functionId)
  2506. if (!funcs) {
  2507. changeState()
  2508. return codes.JS_SKIP
  2509. }
  2510. var enter = funcs.enter,
  2511. leave = funcs.leave
  2512. if (stage > 0) { // enter
  2513. if (typeof enter !== 'function') {
  2514. changeState()
  2515. return codes.JS_SKIP_E
  2516. }
  2517. enter(el, changeState)
  2518. return codes.JS_E
  2519. } else { // leave
  2520. if (typeof leave !== 'function') {
  2521. changeState()
  2522. return codes.JS_SKIP_L
  2523. }
  2524. leave(el, changeState)
  2525. return codes.JS_L
  2526. }
  2527. }
  2528. /**
  2529. * Sniff proper transition end event name
  2530. */
  2531. function sniffTransitionEndEvent () {
  2532. var el = document.createElement('vue'),
  2533. defaultEvent = 'transitionend',
  2534. events = {
  2535. 'transition' : defaultEvent,
  2536. 'mozTransition' : defaultEvent,
  2537. 'webkitTransition' : 'webkitTransitionEnd'
  2538. }
  2539. for (var name in events) {
  2540. if (el.style[name] !== undefined) {
  2541. return events[name]
  2542. }
  2543. }
  2544. }
  2545. });
  2546. require.register("vue/src/batcher.js", function(exports, require, module){
  2547. var utils = require('./utils'),
  2548. queue, has, waiting
  2549. reset()
  2550. exports.queue = function (binding) {
  2551. if (!has[binding.id]) {
  2552. queue.push(binding)
  2553. has[binding.id] = true
  2554. if (!waiting) {
  2555. waiting = true
  2556. utils.nextTick(flush)
  2557. }
  2558. }
  2559. }
  2560. function flush () {
  2561. for (var i = 0; i < queue.length; i++) {
  2562. var b = queue[i]
  2563. if (b.unbound) continue
  2564. b._update()
  2565. has[b.id] = false
  2566. }
  2567. reset()
  2568. }
  2569. function reset () {
  2570. queue = []
  2571. has = utils.hash()
  2572. waiting = false
  2573. }
  2574. });
  2575. require.register("vue/src/directives/index.js", function(exports, require, module){
  2576. var utils = require('../utils'),
  2577. transition = require('../transition')
  2578. module.exports = {
  2579. on : require('./on'),
  2580. repeat : require('./repeat'),
  2581. model : require('./model'),
  2582. 'if' : require('./if'),
  2583. 'with' : require('./with'),
  2584. html : require('./html'),
  2585. style : require('./style'),
  2586. attr: function (value) {
  2587. if (value || value === 0) {
  2588. this.el.setAttribute(this.arg, value)
  2589. } else {
  2590. this.el.removeAttribute(this.arg)
  2591. }
  2592. },
  2593. text: function (value) {
  2594. this.el.textContent = utils.toText(value)
  2595. },
  2596. show: function (value) {
  2597. var el = this.el,
  2598. target = value ? '' : 'none',
  2599. change = function () {
  2600. el.style.display = target
  2601. }
  2602. transition(el, value ? 1 : -1, change, this.compiler)
  2603. },
  2604. 'class': function (value) {
  2605. if (this.arg) {
  2606. utils[value ? 'addClass' : 'removeClass'](this.el, this.arg)
  2607. } else {
  2608. if (this.lastVal) {
  2609. utils.removeClass(this.el, this.lastVal)
  2610. }
  2611. if (value) {
  2612. utils.addClass(this.el, value)
  2613. this.lastVal = value
  2614. }
  2615. }
  2616. }
  2617. }
  2618. });
  2619. require.register("vue/src/directives/if.js", function(exports, require, module){
  2620. var config = require('../config'),
  2621. transition = require('../transition')
  2622. module.exports = {
  2623. bind: function () {
  2624. this.parent = this.el.parentNode
  2625. this.ref = document.createComment(config.prefix + '-if-' + this.key)
  2626. this.el.vue_ref = this.ref
  2627. },
  2628. update: function (value) {
  2629. var el = this.el
  2630. if (!this.parent) { // the node was detached when bound
  2631. if (!el.parentNode) {
  2632. return
  2633. } else {
  2634. this.parent = el.parentNode
  2635. }
  2636. }
  2637. // should always have this.parent if we reach here
  2638. var parent = this.parent,
  2639. ref = this.ref,
  2640. compiler = this.compiler
  2641. if (!value) {
  2642. transition(el, -1, remove, compiler)
  2643. } else {
  2644. transition(el, 1, insert, compiler)
  2645. }
  2646. function remove () {
  2647. if (!el.parentNode) return
  2648. // insert the reference node
  2649. var next = el.nextSibling
  2650. if (next) {
  2651. parent.insertBefore(ref, next)
  2652. } else {
  2653. parent.appendChild(ref)
  2654. }
  2655. parent.removeChild(el)
  2656. }
  2657. function insert () {
  2658. if (el.parentNode) return
  2659. parent.insertBefore(el, ref)
  2660. parent.removeChild(ref)
  2661. }
  2662. },
  2663. unbind: function () {
  2664. this.el.vue_ref = null
  2665. }
  2666. }
  2667. });
  2668. require.register("vue/src/directives/repeat.js", function(exports, require, module){
  2669. var Observer = require('../observer'),
  2670. Emitter = require('../emitter'),
  2671. utils = require('../utils'),
  2672. config = require('../config'),
  2673. transition = require('../transition'),
  2674. ViewModel // lazy def to avoid circular dependency
  2675. /**
  2676. * Mathods that perform precise DOM manipulation
  2677. * based on mutator method triggered
  2678. */
  2679. var mutationHandlers = {
  2680. push: function (m) {
  2681. var i, l = m.args.length,
  2682. base = this.collection.length - l
  2683. for (i = 0; i < l; i++) {
  2684. this.buildItem(m.args[i], base + i)
  2685. }
  2686. },
  2687. pop: function () {
  2688. var vm = this.vms.pop()
  2689. if (vm) vm.$destroy()
  2690. },
  2691. unshift: function (m) {
  2692. m.args.forEach(this.buildItem, this)
  2693. },
  2694. shift: function () {
  2695. var vm = this.vms.shift()
  2696. if (vm) vm.$destroy()
  2697. },
  2698. splice: function (m) {
  2699. var i, l,
  2700. index = m.args[0],
  2701. removed = m.args[1],
  2702. added = m.args.length - 2,
  2703. removedVMs = this.vms.splice(index, removed)
  2704. for (i = 0, l = removedVMs.length; i < l; i++) {
  2705. removedVMs[i].$destroy()
  2706. }
  2707. for (i = 0; i < added; i++) {
  2708. this.buildItem(m.args[i + 2], index + i)
  2709. }
  2710. },
  2711. sort: function () {
  2712. var vms = this.vms,
  2713. col = this.collection,
  2714. l = col.length,
  2715. sorted = new Array(l),
  2716. i, j, vm, data
  2717. for (i = 0; i < l; i++) {
  2718. data = col[i]
  2719. for (j = 0; j < l; j++) {
  2720. vm = vms[j]
  2721. if (vm.$data === data) {
  2722. sorted[i] = vm
  2723. break
  2724. }
  2725. }
  2726. }
  2727. for (i = 0; i < l; i++) {
  2728. this.container.insertBefore(sorted[i].$el, this.ref)
  2729. }
  2730. this.vms = sorted
  2731. },
  2732. reverse: function () {
  2733. var vms = this.vms
  2734. vms.reverse()
  2735. for (var i = 0, l = vms.length; i < l; i++) {
  2736. this.container.insertBefore(vms[i].$el, this.ref)
  2737. }
  2738. }
  2739. }
  2740. module.exports = {
  2741. bind: function () {
  2742. var el = this.el,
  2743. ctn = this.container = el.parentNode
  2744. // extract child VM information, if any
  2745. ViewModel = ViewModel || require('../viewmodel')
  2746. this.Ctor = this.Ctor || ViewModel
  2747. // extract transition information
  2748. this.hasTrans = el.hasAttribute(config.attrs.transition)
  2749. // extract child Id, if any
  2750. this.childId = utils.attr(el, 'component-id')
  2751. // create a comment node as a reference node for DOM insertions
  2752. this.ref = document.createComment(config.prefix + '-repeat-' + this.key)
  2753. ctn.insertBefore(this.ref, el)
  2754. ctn.removeChild(el)
  2755. this.initiated = false
  2756. this.collection = null
  2757. this.vms = null
  2758. var self = this
  2759. this.mutationListener = function (path, arr, mutation) {
  2760. var method = mutation.method
  2761. mutationHandlers[method].call(self, mutation)
  2762. if (method !== 'push' && method !== 'pop') {
  2763. self.updateIndex()
  2764. }
  2765. if (method === 'push' || method === 'unshift' || method === 'splice') {
  2766. self.changed()
  2767. }
  2768. }
  2769. },
  2770. update: function (collection, init) {
  2771. this.reset()
  2772. // attach an object to container to hold handlers
  2773. this.container.vue_dHandlers = utils.hash()
  2774. // if initiating with an empty collection, we need to
  2775. // force a compile so that we get all the bindings for
  2776. // dependency extraction.
  2777. if (!this.initiated && (!collection || !collection.length)) {
  2778. this.buildItem()
  2779. this.initiated = true
  2780. }
  2781. collection = this.collection = collection || []
  2782. this.vms = []
  2783. if (this.childId) {
  2784. this.vm.$[this.childId] = this.vms
  2785. }
  2786. // listen for collection mutation events
  2787. // the collection has been augmented during Binding.set()
  2788. if (!collection.__observer__) Observer.watchArray(collection, null, new Emitter())
  2789. collection.__observer__.on('mutate', this.mutationListener)
  2790. // create child-vms and append to DOM
  2791. if (collection.length) {
  2792. collection.forEach(this.buildItem, this)
  2793. if (!init) this.changed()
  2794. }
  2795. },
  2796. /**
  2797. * Notify parent compiler that new items
  2798. * have been added to the collection, it needs
  2799. * to re-calculate computed property dependencies.
  2800. * Batched to ensure it's called only once every event loop.
  2801. */
  2802. changed: function () {
  2803. if (this.queued) return
  2804. this.queued = true
  2805. var self = this
  2806. setTimeout(function () {
  2807. self.compiler.parseDeps()
  2808. self.queued = false
  2809. }, 0)
  2810. },
  2811. /**
  2812. * Create a new child VM from a data object
  2813. * passing along compiler options indicating this
  2814. * is a v-repeat item.
  2815. */
  2816. buildItem: function (data, index) {
  2817. var el = this.el.cloneNode(true),
  2818. ctn = this.container,
  2819. vms = this.vms,
  2820. col = this.collection,
  2821. ref, item, primitive
  2822. // append node into DOM first
  2823. // so v-if can get access to parentNode
  2824. if (data) {
  2825. ref = vms.length > index
  2826. ? vms[index].$el
  2827. : this.ref
  2828. // make sure it works with v-if
  2829. if (!ref.parentNode) ref = ref.vue_ref
  2830. // process transition info before appending
  2831. el.vue_trans = utils.attr(el, 'transition', true)
  2832. transition(el, 1, function () {
  2833. ctn.insertBefore(el, ref)
  2834. }, this.compiler)
  2835. // wrap primitive element in an object
  2836. if (utils.typeOf(data) !== 'Object') {
  2837. primitive = true
  2838. data = { value: data }
  2839. }
  2840. }
  2841. item = new this.Ctor({
  2842. el: el,
  2843. data: data,
  2844. compilerOptions: {
  2845. repeat: true,
  2846. repeatIndex: index,
  2847. parentCompiler: this.compiler,
  2848. delegator: ctn
  2849. }
  2850. })
  2851. if (!data) {
  2852. // this is a forced compile for an empty collection.
  2853. // let's remove it...
  2854. item.$destroy()
  2855. } else {
  2856. vms.splice(index, 0, item)
  2857. // for primitive values, listen for value change
  2858. if (primitive) {
  2859. data.__observer__.on('set', function (key, val) {
  2860. if (key === 'value') {
  2861. col[item.$index] = val
  2862. }
  2863. })
  2864. }
  2865. // in case `$destroy` is called directly on a repeated vm
  2866. // make sure the vm's data is properly removed
  2867. item.$compiler.observer.on('hook:afterDestroy', function () {
  2868. col.remove(data)
  2869. })
  2870. }
  2871. },
  2872. /**
  2873. * Update index of each item after a mutation
  2874. */
  2875. updateIndex: function () {
  2876. var i = this.vms.length
  2877. while (i--) {
  2878. this.vms[i].$data.$index = i
  2879. }
  2880. },
  2881. reset: function () {
  2882. if (this.childId) {
  2883. delete this.vm.$[this.childId]
  2884. }
  2885. if (this.collection) {
  2886. this.collection.__observer__.off('mutate', this.mutationListener)
  2887. var i = this.vms.length
  2888. while (i--) {
  2889. this.vms[i].$destroy()
  2890. }
  2891. }
  2892. var ctn = this.container,
  2893. handlers = ctn.vue_dHandlers
  2894. for (var key in handlers) {
  2895. ctn.removeEventListener(handlers[key].event, handlers[key])
  2896. }
  2897. ctn.vue_dHandlers = null
  2898. },
  2899. unbind: function () {
  2900. this.reset()
  2901. }
  2902. }
  2903. });
  2904. require.register("vue/src/directives/on.js", function(exports, require, module){
  2905. var utils = require('../utils')
  2906. function delegateCheck (el, root, identifier) {
  2907. while (el && el !== root) {
  2908. if (el[identifier]) return el
  2909. el = el.parentNode
  2910. }
  2911. }
  2912. module.exports = {
  2913. isFn: true,
  2914. bind: function () {
  2915. if (this.compiler.repeat) {
  2916. // attach an identifier to the el
  2917. // so it can be matched during event delegation
  2918. this.el[this.expression] = true
  2919. // attach the owner viewmodel of this directive
  2920. this.el.vue_viewmodel = this.vm
  2921. }
  2922. },
  2923. update: function (handler) {
  2924. this.reset()
  2925. if (typeof handler !== 'function') {
  2926. return utils.warn('Directive "on" expects a function value.')
  2927. }
  2928. var compiler = this.compiler,
  2929. event = this.arg,
  2930. isExp = this.binding.isExp,
  2931. ownerVM = this.binding.compiler.vm
  2932. if (compiler.repeat &&
  2933. // do not delegate if the repeat is combined with an extended VM
  2934. !this.vm.constructor.super &&
  2935. // blur and focus events do not bubble
  2936. event !== 'blur' && event !== 'focus') {
  2937. // for each blocks, delegate for better performance
  2938. // focus and blur events dont bubble so exclude them
  2939. var delegator = compiler.delegator,
  2940. identifier = this.expression,
  2941. dHandler = delegator.vue_dHandlers[identifier]
  2942. if (dHandler) return
  2943. // the following only gets run once for the entire each block
  2944. dHandler = delegator.vue_dHandlers[identifier] = function (e) {
  2945. var target = delegateCheck(e.target, delegator, identifier)
  2946. if (target) {
  2947. e.el = target
  2948. e.targetVM = target.vue_viewmodel
  2949. handler.call(isExp ? e.targetVM : ownerVM, e)
  2950. }
  2951. }
  2952. dHandler.event = event
  2953. delegator.addEventListener(event, dHandler)
  2954. } else {
  2955. // a normal, single element handler
  2956. var vm = this.vm
  2957. this.handler = function (e) {
  2958. e.el = e.currentTarget
  2959. e.targetVM = vm
  2960. handler.call(ownerVM, e)
  2961. }
  2962. this.el.addEventListener(event, this.handler)
  2963. }
  2964. },
  2965. reset: function () {
  2966. this.el.removeEventListener(this.arg, this.handler)
  2967. this.handler = null
  2968. },
  2969. unbind: function () {
  2970. this.reset()
  2971. this.el.vue_viewmodel = null
  2972. }
  2973. }
  2974. });
  2975. require.register("vue/src/directives/model.js", function(exports, require, module){
  2976. var utils = require('../utils'),
  2977. isIE9 = navigator.userAgent.indexOf('MSIE 9.0') > 0
  2978. /**
  2979. * Returns an array of values from a multiple select
  2980. */
  2981. function getMultipleSelectOptions (select) {
  2982. return Array.prototype.filter
  2983. .call(select.options, function (option) {
  2984. return option.selected
  2985. })
  2986. .map(function (option) {
  2987. return option.value || option.text
  2988. })
  2989. }
  2990. module.exports = {
  2991. bind: function () {
  2992. var self = this,
  2993. el = self.el,
  2994. type = el.type,
  2995. tag = el.tagName
  2996. self.lock = false
  2997. // determine what event to listen to
  2998. self.event =
  2999. (self.compiler.options.lazy ||
  3000. tag === 'SELECT' ||
  3001. type === 'checkbox' || type === 'radio')
  3002. ? 'change'
  3003. : 'input'
  3004. // determine the attribute to change when updating
  3005. self.attr = type === 'checkbox'
  3006. ? 'checked'
  3007. : (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA')
  3008. ? 'value'
  3009. : 'innerHTML'
  3010. // select[multiple] support
  3011. if(tag === 'SELECT' && el.hasAttribute('multiple')) {
  3012. this.multi = true
  3013. }
  3014. var compositionLock = false
  3015. self.cLock = function () {
  3016. compositionLock = true
  3017. }
  3018. self.cUnlock = function () {
  3019. compositionLock = false
  3020. }
  3021. el.addEventListener('compositionstart', this.cLock)
  3022. el.addEventListener('compositionend', this.cUnlock)
  3023. // attach listener
  3024. self.set = self.filters
  3025. ? function () {
  3026. if (compositionLock) return
  3027. // if this directive has filters
  3028. // we need to let the vm.$set trigger
  3029. // update() so filters are applied.
  3030. // therefore we have to record cursor position
  3031. // so that after vm.$set changes the input
  3032. // value we can put the cursor back at where it is
  3033. var cursorPos
  3034. try { cursorPos = el.selectionStart } catch (e) {}
  3035. self._set()
  3036. // since updates are async
  3037. // we need to reset cursor position async too
  3038. utils.nextTick(function () {
  3039. if (cursorPos !== undefined) {
  3040. el.setSelectionRange(cursorPos, cursorPos)
  3041. }
  3042. })
  3043. }
  3044. : function () {
  3045. if (compositionLock) return
  3046. // no filters, don't let it trigger update()
  3047. self.lock = true
  3048. self._set()
  3049. utils.nextTick(function () {
  3050. self.lock = false
  3051. })
  3052. }
  3053. el.addEventListener(self.event, self.set)
  3054. // fix shit for IE9
  3055. // since it doesn't fire input on backspace / del / cut
  3056. if (isIE9) {
  3057. self.onCut = function () {
  3058. // cut event fires before the value actually changes
  3059. utils.nextTick(function () {
  3060. self.set()
  3061. })
  3062. }
  3063. self.onDel = function (e) {
  3064. if (e.keyCode === 46 || e.keyCode === 8) {
  3065. self.set()
  3066. }
  3067. }
  3068. el.addEventListener('cut', self.onCut)
  3069. el.addEventListener('keyup', self.onDel)
  3070. }
  3071. },
  3072. _set: function () {
  3073. this.vm.$set(
  3074. this.key, this.multi
  3075. ? getMultipleSelectOptions(this.el)
  3076. : this.el[this.attr]
  3077. )
  3078. },
  3079. update: function (value) {
  3080. /* jshint eqeqeq: false */
  3081. if (this.lock) return
  3082. var el = this.el
  3083. if (el.tagName === 'SELECT') { // select dropdown
  3084. el.selectedIndex = -1
  3085. if(this.multi && Array.isArray(value)) {
  3086. value.forEach(this.updateSelect, this)
  3087. } else {
  3088. this.updateSelect(value)
  3089. }
  3090. } else if (el.type === 'radio') { // radio button
  3091. el.checked = value == el.value
  3092. } else if (el.type === 'checkbox') { // checkbox
  3093. el.checked = !!value
  3094. } else {
  3095. el[this.attr] = utils.toText(value)
  3096. }
  3097. },
  3098. updateSelect: function (value) {
  3099. /* jshint eqeqeq: false */
  3100. // setting <select>'s value in IE9 doesn't work
  3101. // we have to manually loop through the options
  3102. var options = this.el.options,
  3103. i = options.length
  3104. while (i--) {
  3105. if (options[i].value == value) {
  3106. options[i].selected = true
  3107. break
  3108. }
  3109. }
  3110. },
  3111. unbind: function () {
  3112. var el = this.el
  3113. el.removeEventListener(this.event, this.set)
  3114. el.removeEventListener('compositionstart', this.cLock)
  3115. el.removeEventListener('compositionend', this.cUnlock)
  3116. if (isIE9) {
  3117. el.removeEventListener('cut', this.onCut)
  3118. el.removeEventListener('keyup', this.onDel)
  3119. }
  3120. }
  3121. }
  3122. });
  3123. require.register("vue/src/directives/with.js", function(exports, require, module){
  3124. var ViewModel
  3125. module.exports = {
  3126. bind: function () {
  3127. if (this.isEmpty) {
  3128. this.build()
  3129. }
  3130. },
  3131. update: function (value) {
  3132. if (!this.component) {
  3133. this.build(value)
  3134. } else {
  3135. this.component.$data = value
  3136. }
  3137. },
  3138. build: function (value) {
  3139. ViewModel = ViewModel || require('../viewmodel')
  3140. var Ctor = this.Ctor || ViewModel
  3141. this.component = new Ctor({
  3142. el: this.el,
  3143. data: value,
  3144. compilerOptions: {
  3145. parentCompiler: this.compiler
  3146. }
  3147. })
  3148. },
  3149. unbind: function () {
  3150. this.component.$destroy()
  3151. }
  3152. }
  3153. });
  3154. require.register("vue/src/directives/html.js", function(exports, require, module){
  3155. var toText = require('../utils').toText,
  3156. slice = Array.prototype.slice
  3157. module.exports = {
  3158. bind: function () {
  3159. // a comment node means this is a binding for
  3160. // {{{ inline unescaped html }}}
  3161. if (this.el.nodeType === 8) {
  3162. // hold nodes
  3163. this.holder = document.createElement('div')
  3164. this.nodes = []
  3165. }
  3166. },
  3167. update: function (value) {
  3168. value = toText(value)
  3169. if (this.holder) {
  3170. this.swap(value)
  3171. } else {
  3172. this.el.innerHTML = value
  3173. }
  3174. },
  3175. swap: function (value) {
  3176. var parent = this.el.parentNode,
  3177. holder = this.holder,
  3178. nodes = this.nodes,
  3179. i = nodes.length, l
  3180. while (i--) {
  3181. parent.removeChild(nodes[i])
  3182. }
  3183. holder.innerHTML = value
  3184. nodes = this.nodes = slice.call(holder.childNodes)
  3185. for (i = 0, l = nodes.length; i < l; i++) {
  3186. parent.insertBefore(nodes[i], this.el)
  3187. }
  3188. }
  3189. }
  3190. });
  3191. require.register("vue/src/directives/style.js", function(exports, require, module){
  3192. var camelRE = /-([a-z])/g,
  3193. prefixes = ['webkit', 'moz', 'ms']
  3194. function camelReplacer (m) {
  3195. return m[1].toUpperCase()
  3196. }
  3197. module.exports = {
  3198. bind: function () {
  3199. var prop = this.arg,
  3200. first = prop.charAt(0)
  3201. if (first === '$') {
  3202. // properties that start with $ will be auto-prefixed
  3203. prop = prop.slice(1)
  3204. this.prefixed = true
  3205. } else if (first === '-') {
  3206. // normal starting hyphens should not be converted
  3207. prop = prop.slice(1)
  3208. }
  3209. this.prop = prop.replace(camelRE, camelReplacer)
  3210. },
  3211. update: function (value) {
  3212. var prop = this.prop
  3213. this.el.style[prop] = value
  3214. if (this.prefixed) {
  3215. prop = prop.charAt(0).toUpperCase() + prop.slice(1)
  3216. var i = prefixes.length
  3217. while (i--) {
  3218. this.el.style[prefixes[i] + prop] = value
  3219. }
  3220. }
  3221. }
  3222. }
  3223. });
  3224. require.alias("component-emitter/index.js", "vue/deps/emitter/index.js");
  3225. require.alias("component-emitter/index.js", "emitter/index.js");
  3226. require.alias("vue/src/main.js", "vue/index.js");
  3227. if (typeof exports == 'object') {
  3228. module.exports = require('vue');
  3229. } else if (typeof define == 'function' && define.amd) {
  3230. define(function(){ return require('vue'); });
  3231. } else {
  3232. window['Vue'] = require('vue');
  3233. }})();