|
| 1 | +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/azu/.ghq/github.com/azu/todo-app-jquery-to-backbone/src/app.js":[function(require,module,exports){ |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +var _interopRequire = function (obj) { |
| 5 | + return obj && (obj["default"] || obj); |
| 6 | +}; |
| 7 | + |
| 8 | +var TodoItemView = _interopRequire(require("./todo-item-view.js")); |
| 9 | + |
| 10 | +var TodoItem = _interopRequire(require("./todo-item-model.js")); |
| 11 | + |
| 12 | +$(function () { |
| 13 | + var createTodoItem = function (text) { |
| 14 | + var model = new TodoItem({ |
| 15 | + title: text |
| 16 | + }); |
| 17 | + var item = new TodoItemView({ model: model }); |
| 18 | + return item.render().el; |
| 19 | + }; |
| 20 | + |
| 21 | + var $form = $(".todoForm"); |
| 22 | + var $list = $(".todoList"); |
| 23 | + |
| 24 | + |
| 25 | + $form.on("submit", function (e) { |
| 26 | + e.preventDefault(); |
| 27 | + |
| 28 | + var $input = $("input[type=\"text\"]"); |
| 29 | + var val = $input.val(); |
| 30 | + var $li = createTodoItem(val); |
| 31 | + |
| 32 | + $list.append($li); |
| 33 | + |
| 34 | + $input.val(""); |
| 35 | + }); |
| 36 | +}); |
| 37 | + |
| 38 | +},{"./todo-item-model.js":"/Users/azu/.ghq/github.com/azu/todo-app-jquery-to-backbone/src/todo-item-model.js","./todo-item-view.js":"/Users/azu/.ghq/github.com/azu/todo-app-jquery-to-backbone/src/todo-item-view.js"}],"/Users/azu/.ghq/github.com/azu/todo-app-jquery-to-backbone/src/todo-item-model.js":[function(require,module,exports){ |
| 39 | +// LICENSE : MIT |
| 40 | +"use strict"; |
| 41 | +var _prototypeProperties = function (child, staticProps, instanceProps) { |
| 42 | + if (staticProps) Object.defineProperties(child, staticProps); |
| 43 | + if (instanceProps) Object.defineProperties(child.prototype, instanceProps); |
| 44 | +}; |
| 45 | + |
| 46 | +var _inherits = function (subClass, superClass) { |
| 47 | + if (typeof superClass !== "function" && superClass !== null) { |
| 48 | + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); |
| 49 | + } |
| 50 | + subClass.prototype = Object.create(superClass && superClass.prototype, { |
| 51 | + constructor: { |
| 52 | + value: subClass, |
| 53 | + enumerable: false, |
| 54 | + writable: true, |
| 55 | + configurable: true |
| 56 | + } |
| 57 | + }); |
| 58 | + if (superClass) subClass.__proto__ = superClass; |
| 59 | +}; |
| 60 | + |
| 61 | +var Model = Backbone.Model; |
| 62 | +var TodoItem = (function (Model) { |
| 63 | + function TodoItem() { |
| 64 | + if (Object.getPrototypeOf(TodoItem) !== null) { |
| 65 | + Object.getPrototypeOf(TodoItem).apply(this, arguments); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + _inherits(TodoItem, Model); |
| 70 | + |
| 71 | + _prototypeProperties(TodoItem, null, { |
| 72 | + defaults: { |
| 73 | + value: function defaults() { |
| 74 | + return { |
| 75 | + title: "", |
| 76 | + completed: false |
| 77 | + }; |
| 78 | + }, |
| 79 | + writable: true, |
| 80 | + enumerable: true, |
| 81 | + configurable: true |
| 82 | + }, |
| 83 | + toggle: { |
| 84 | + value: function toggle() { |
| 85 | + this.save({ |
| 86 | + completed: !this.get("completed") |
| 87 | + }); |
| 88 | + }, |
| 89 | + writable: true, |
| 90 | + enumerable: true, |
| 91 | + configurable: true |
| 92 | + } |
| 93 | + }); |
| 94 | + |
| 95 | + return TodoItem; |
| 96 | +})(Model); |
| 97 | + |
| 98 | +module.exports = TodoItem; |
| 99 | + |
| 100 | +},{}],"/Users/azu/.ghq/github.com/azu/todo-app-jquery-to-backbone/src/todo-item-view.js":[function(require,module,exports){ |
| 101 | +// LICENSE : MIT |
| 102 | +"use strict"; |
| 103 | +var _prototypeProperties = function (child, staticProps, instanceProps) { |
| 104 | + if (staticProps) Object.defineProperties(child, staticProps); |
| 105 | + if (instanceProps) Object.defineProperties(child.prototype, instanceProps); |
| 106 | +}; |
| 107 | + |
| 108 | +var _get = function get(object, property, receiver) { |
| 109 | + var desc = Object.getOwnPropertyDescriptor(object, property); |
| 110 | + |
| 111 | + if (desc === undefined) { |
| 112 | + var parent = Object.getPrototypeOf(object); |
| 113 | + |
| 114 | + if (parent === null) { |
| 115 | + return undefined; |
| 116 | + } else { |
| 117 | + return get(parent, property, receiver); |
| 118 | + } |
| 119 | + } else if ("value" in desc && desc.writable) { |
| 120 | + return desc.value; |
| 121 | + } else { |
| 122 | + var getter = desc.get; |
| 123 | + if (getter === undefined) { |
| 124 | + return undefined; |
| 125 | + } |
| 126 | + return getter.call(receiver); |
| 127 | + } |
| 128 | +}; |
| 129 | + |
| 130 | +var _inherits = function (subClass, superClass) { |
| 131 | + if (typeof superClass !== "function" && superClass !== null) { |
| 132 | + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); |
| 133 | + } |
| 134 | + subClass.prototype = Object.create(superClass && superClass.prototype, { |
| 135 | + constructor: { |
| 136 | + value: subClass, |
| 137 | + enumerable: false, |
| 138 | + writable: true, |
| 139 | + configurable: true |
| 140 | + } |
| 141 | + }); |
| 142 | + if (superClass) subClass.__proto__ = superClass; |
| 143 | +}; |
| 144 | + |
| 145 | +var View = Backbone.View; |
| 146 | +var TodoItemView = (function (View) { |
| 147 | + function TodoItemView(options) { |
| 148 | + // *... is a list tag.* |
| 149 | + this.tagName = "li"; |
| 150 | + // *Cache the template function for a single item.* |
| 151 | + this.template = _.template("\n <input type=\"checkbox\" class=\"<%= completed ? 'is-complete' : '' %>\" <%= completed ? 'checked' : '' %>>\n <span class=\"todoText\"><%- title %></span>\n <i class=\"removeBtn fa fa-times\"></i>\n "); |
| 152 | + this.input = ""; |
| 153 | + // *Define the DOM events specific to an item.* |
| 154 | + this.events = { |
| 155 | + "click input": "toggleComplete", |
| 156 | + "click .removeBtn": "removeItem" |
| 157 | + }; |
| 158 | + _get(Object.getPrototypeOf(TodoItemView.prototype), "constructor", this).call(this, options); |
| 159 | + |
| 160 | + this.listenTo(this.model, "change", this.render); |
| 161 | + this.listenTo(this.model, "destroy", this.remove); |
| 162 | + } |
| 163 | + |
| 164 | + _inherits(TodoItemView, View); |
| 165 | + |
| 166 | + _prototypeProperties(TodoItemView, null, { |
| 167 | + render: { |
| 168 | + |
| 169 | + // *Re-render the contents of the todo item.* |
| 170 | + value: function render() { |
| 171 | + this.$el.html(this.template(this.model.toJSON())); |
| 172 | + this.$el.toggleClass("completed", this.model.get("completed")); |
| 173 | + return this; |
| 174 | + }, |
| 175 | + writable: true, |
| 176 | + enumerable: true, |
| 177 | + configurable: true |
| 178 | + }, |
| 179 | + toggleComplete: { |
| 180 | + value: function toggleComplete() { |
| 181 | + this.model.toggle(); |
| 182 | + }, |
| 183 | + writable: true, |
| 184 | + enumerable: true, |
| 185 | + configurable: true |
| 186 | + }, |
| 187 | + removeItem: { |
| 188 | + value: function removeItem() { |
| 189 | + if (!window.confirm("消しますよ")) { |
| 190 | + return; |
| 191 | + } |
| 192 | + this.model.destroy(); |
| 193 | + return this; |
| 194 | + }, |
| 195 | + writable: true, |
| 196 | + enumerable: true, |
| 197 | + configurable: true |
| 198 | + } |
| 199 | + }); |
| 200 | + |
| 201 | + return TodoItemView; |
| 202 | +})(View); |
| 203 | + |
| 204 | +module.exports = TodoItemView; |
| 205 | + |
| 206 | +},{}]},{},["/Users/azu/.ghq/github.com/azu/todo-app-jquery-to-backbone/src/app.js"]); |
0 commit comments