seed.js 82 KB

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