vuejs-rails 0.8.1

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