1 | (function webpackUniversalModuleDefinition(root, factory) {
|
2 | if(typeof exports === 'object' && typeof module === 'object')
|
3 | module.exports = factory(require("react"), require("react-dom"), require("react-dom/server"));
|
4 | else if(typeof define === 'function' && define.amd)
|
5 | define(["react", "react-dom", "react-dom/server"], factory);
|
6 | else if(typeof exports === 'object')
|
7 | exports["ReactRailsUJS"] = factory(require("react"), require("react-dom"), require("react-dom/server"));
|
8 | else
|
9 | root["ReactRailsUJS"] = factory(root["React"], root["ReactDOM"], root["ReactDOMServer"]);
|
10 | })(this, function(__WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_4__, __WEBPACK_EXTERNAL_MODULE_5__) {
|
11 | return (function(modules) {
|
12 |
|
13 | var installedModules = {};
|
14 |
|
15 |
|
16 | function __webpack_require__(moduleId) {
|
17 |
|
18 |
|
19 | if(installedModules[moduleId]) {
|
20 | return installedModules[moduleId].exports;
|
21 | }
|
22 |
|
23 | var module = installedModules[moduleId] = {
|
24 | i: moduleId,
|
25 | l: false,
|
26 | exports: {}
|
27 | };
|
28 |
|
29 |
|
30 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
31 |
|
32 |
|
33 | module.l = true;
|
34 |
|
35 |
|
36 | return module.exports;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | __webpack_require__.m = modules;
|
42 |
|
43 |
|
44 | __webpack_require__.c = installedModules;
|
45 |
|
46 |
|
47 | __webpack_require__.i = function(value) { return value; };
|
48 |
|
49 |
|
50 | __webpack_require__.d = function(exports, name, getter) {
|
51 | if(!__webpack_require__.o(exports, name)) {
|
52 | Object.defineProperty(exports, name, {
|
53 | configurable: false,
|
54 | enumerable: true,
|
55 | get: getter
|
56 | /******/ });
|
57 | /******/ }
|
58 | /******/ };
|
59 | /******/
|
60 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
61 | /******/ __webpack_require__.n = function(module) {
|
62 | var getter = module && module.__esModule ?
|
63 | function getDefault() { return module['default']; } :
|
64 | function getModuleExports() { return module; };
|
65 | __webpack_require__.d(getter, 'a', getter);
|
66 | return getter;
|
67 | };
|
68 |
|
69 |
|
70 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
71 |
|
72 |
|
73 | __webpack_require__.p = "";
|
74 |
|
75 |
|
76 | return __webpack_require__(__webpack_require__.s = 6);
|
77 | })
|
78 |
|
79 | ([
|
80 |
|
81 | (function(module, exports) {
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | var topLevel = typeof window === "undefined" ? this : window;
|
87 |
|
88 | module.exports = function(className) {
|
89 | var constructor;
|
90 | // Try to access the class globally first
|
91 | constructor = topLevel[className];
|
92 |
|
93 | // If that didn't work, try eval
|
94 | if (!constructor) {
|
95 | constructor = eval(className);
|
96 | }
|
97 |
|
98 | // Lastly, if there is a default attribute try that
|
99 | if (constructor && constructor['default']) {
|
100 | constructor = constructor['default'];
|
101 | }
|
102 |
|
103 | return constructor;
|
104 | }
|
105 |
|
106 |
|
107 | /***/ }),
|
108 | /* 1 */
|
109 | /***/ (function(module, exports, __webpack_require__) {
|
110 |
|
111 | var nativeEvents = __webpack_require__(7)
|
112 | var pjaxEvents = __webpack_require__(8)
|
113 | var turbolinksEvents = __webpack_require__(9)
|
114 | var turbolinksClassicDeprecatedEvents = __webpack_require__(11)
|
115 | var turbolinksClassicEvents = __webpack_require__(10)
|
116 |
|
117 |
|
118 |
|
119 | module.exports = function(ujs) {
|
120 | if (ujs.handleEvent) {
|
121 |
|
122 | if (typeof Turbolinks.EVENTS !== "undefined") {
|
123 | turbolinksClassicEvents.teardown(ujs);
|
124 | }
|
125 | turbolinksEvents.teardown(ujs);
|
126 | turbolinksClassicDeprecatedEvents.teardown(ujs);
|
127 | pjaxEvents.teardown(ujs);
|
128 | nativeEvents.teardown(ujs);
|
129 | }
|
130 |
|
131 | if (ujs.jQuery) {
|
132 | ujs.handleEvent = function(eventName, callback) {
|
133 | ujs.jQuery(document).on(eventName, callback);
|
134 | };
|
135 | ujs.removeEvent = function(eventName, callback) {
|
136 | ujs.jQuery(document).off(eventName, callback);
|
137 | }
|
138 | } else if ('addEventListener' in window) {
|
139 | ujs.handleEvent = function(eventName, callback) {
|
140 | document.addEventListener(eventName, callback);
|
141 | };
|
142 | ujs.removeEvent = function(eventName, callback) {
|
143 | document.removeEventListener(eventName, callback);
|
144 | };
|
145 | } else {
|
146 | ujs.handleEvent = function(eventName, callback) {
|
147 | window.attachEvent(eventName, callback);
|
148 | };
|
149 | ujs.removeEvent = function(eventName, callback) {
|
150 | window.detachEvent(eventName, callback);
|
151 | };
|
152 | }
|
153 |
|
154 |
|
155 | if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
|
156 | if (typeof Turbolinks.EVENTS !== 'undefined') {
|
157 |
|
158 | turbolinksClassicEvents.setup(ujs)
|
159 | } else if (typeof Turbolinks.controller !== "undefined") {
|
160 |
|
161 | turbolinksEvents.setup(ujs);
|
162 | } else {
|
163 | turbolinksClassicDeprecatedEvents.setup(ujs);
|
164 | }
|
165 | } else if (typeof $ !== "undefined" && typeof $.pjax === 'function') {
|
166 | pjaxEvents.setup(ujs);
|
167 | } else {
|
168 | nativeEvents.setup(ujs);
|
169 | }
|
170 | }
|
171 |
|
172 |
|
173 | }),
|
174 |
|
175 | (function(module, exports, __webpack_require__) {
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | var fromGlobal = __webpack_require__(0)
|
181 | var fromRequireContext = __webpack_require__(12)
|
182 |
|
183 | module.exports = function(reqctx) {
|
184 | var fromCtx = fromRequireContext(reqctx)
|
185 | return function(className) {
|
186 | var component;
|
187 | try {
|
188 |
|
189 | component = fromCtx(className)
|
190 | } catch (firstErr) {
|
191 |
|
192 | try {
|
193 | component = fromGlobal(className)
|
194 | } catch (secondErr) {
|
195 | console.error(firstErr)
|
196 | console.error(secondErr)
|
197 | }
|
198 | }
|
199 | return component
|
200 | }
|
201 | }
|
202 |
|
203 |
|
204 | }),
|
205 |
|
206 | (function(module, exports) {
|
207 |
|
208 | module.exports = __WEBPACK_EXTERNAL_MODULE_3__;
|
209 |
|
210 | }),
|
211 |
|
212 | (function(module, exports) {
|
213 |
|
214 | module.exports = __WEBPACK_EXTERNAL_MODULE_4__;
|
215 |
|
216 | }),
|
217 |
|
218 | (function(module, exports) {
|
219 |
|
220 | module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
|
221 |
|
222 | }),
|
223 |
|
224 | (function(module, exports, __webpack_require__) {
|
225 |
|
226 | var React = __webpack_require__(3)
|
227 | var ReactDOM = __webpack_require__(4)
|
228 | var ReactDOMServer = __webpack_require__(5)
|
229 |
|
230 | var detectEvents = __webpack_require__(1)
|
231 | var constructorFromGlobal = __webpack_require__(0)
|
232 | var constructorFromRequireContextWithGlobalFallback = __webpack_require__(2)
|
233 |
|
234 | var ReactRailsUJS = {
|
235 |
|
236 |
|
237 | CLASS_NAME_ATTR: 'data-react-class',
|
238 |
|
239 |
|
240 |
|
241 | PROPS_ATTR: 'data-react-props',
|
242 |
|
243 |
|
244 | jQuery: (typeof window !== 'undefined') && (typeof window.jQuery !== 'undefined') && window.jQuery,
|
245 |
|
246 |
|
247 |
|
248 | findDOMNodes: function(searchSelector) {
|
249 | var classNameAttr = ReactRailsUJS.CLASS_NAME_ATTR
|
250 |
|
251 | var selector, parent;
|
252 |
|
253 | switch (typeof searchSelector) {
|
254 | case 'undefined':
|
255 | selector = '[' + classNameAttr + ']';
|
256 | parent = document;
|
257 | break;
|
258 | case 'object':
|
259 | selector = '[' + classNameAttr + ']';
|
260 | parent = searchSelector;
|
261 | break;
|
262 | case 'string':
|
263 | selector = searchSelector + '[' + classNameAttr + '], ' +
|
264 | searchSelector + ' [' + classNameAttr + ']';
|
265 | parent = document;
|
266 | break
|
267 | default:
|
268 | break;
|
269 | }
|
270 |
|
271 | if (ReactRailsUJS.jQuery) {
|
272 | return ReactRailsUJS.jQuery(selector, parent);
|
273 | } else {
|
274 | return parent.querySelectorAll(selector);
|
275 | }
|
276 | },
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | getConstructor: constructorFromGlobal,
|
282 |
|
283 |
|
284 |
|
285 |
|
286 | useContext: function(requireContext) {
|
287 | this.getConstructor = constructorFromRequireContextWithGlobalFallback(requireContext)
|
288 | },
|
289 |
|
290 |
|
291 |
|
292 | serverRender: function(renderFunction, componentName, props) {
|
293 | var componentClass = this.getConstructor(componentName)
|
294 | var element = React.createElement(componentClass, props)
|
295 | return ReactDOMServer[renderFunction](element)
|
296 | },
|
297 |
|
298 |
|
299 |
|
300 | mountComponents: function(searchSelector) {
|
301 | var ujs = ReactRailsUJS
|
302 | var nodes = ujs.findDOMNodes(searchSelector);
|
303 |
|
304 | for (var i = 0; i < nodes.length; ++i) {
|
305 | var node = nodes[i];
|
306 | var className = node.getAttribute(ujs.CLASS_NAME_ATTR);
|
307 | var constructor = ujs.getConstructor(className);
|
308 | var propsJson = node.getAttribute(ujs.PROPS_ATTR);
|
309 | var props = propsJson && JSON.parse(propsJson);
|
310 |
|
311 | if (!constructor) {
|
312 | var message = "Cannot find component: '" + className + "'"
|
313 | if (console && console.log) {
|
314 | console.log("%c[react-rails] %c" + message + " for element", "font-weight: bold", "", node)
|
315 | }
|
316 | throw new Error(message + ". Make sure your component is available to render.")
|
317 | } else {
|
318 | ReactDOM.render(React.createElement(constructor, props), node);
|
319 | }
|
320 | }
|
321 | },
|
322 |
|
323 | // Within `searchSelector`, find nodes which have React components
|
324 | // inside them, and unmount those components.
|
325 | unmountComponents: function(searchSelector) {
|
326 | var nodes = ReactRailsUJS.findDOMNodes(searchSelector);
|
327 |
|
328 | for (var i = 0; i < nodes.length; ++i) {
|
329 | var node = nodes[i];
|
330 | ReactDOM.unmountComponentAtNode(node);
|
331 | }
|
332 | },
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | detectEvents: function() {
|
339 | detectEvents(this)
|
340 | },
|
341 | }
|
342 |
|
343 |
|
344 | ReactRailsUJS.handleMount = function(e) {
|
345 | var target = undefined;
|
346 | if (e && e.target) {
|
347 | target = e.target;
|
348 | }
|
349 | ReactRailsUJS.mountComponents(target);
|
350 | }
|
351 | ReactRailsUJS.handleUnmount = function(e) {
|
352 | var target = undefined;
|
353 | if (e && e.target) {
|
354 | target = e.target;
|
355 | }
|
356 | ReactRailsUJS.unmountComponents(target);
|
357 | }
|
358 |
|
359 |
|
360 | if (typeof window !== "undefined") {
|
361 |
|
362 | ReactRailsUJS.detectEvents()
|
363 | }
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | self.ReactRailsUJS = ReactRailsUJS
|
370 |
|
371 | module.exports = ReactRailsUJS
|
372 |
|
373 |
|
374 | }),
|
375 |
|
376 | (function(module, exports) {
|
377 |
|
378 | module.exports = {
|
379 |
|
380 |
|
381 | setup: function(ujs) {
|
382 | if (ujs.jQuery) {
|
383 |
|
384 | ujs.handleEvent("ready", ujs.handleMount);
|
385 | } else if ('addEventListener' in window) {
|
386 | ujs.handleEvent('DOMContentLoaded', ujs.handleMount);
|
387 | } else {
|
388 |
|
389 | ujs.handleEvent('onload', ujs.handleMount);
|
390 | }
|
391 | },
|
392 |
|
393 | teardown: function(ujs) {
|
394 | ujs.removeEvent("ready", ujs.handleMount);
|
395 | ujs.removeEvent('DOMContentLoaded', ujs.handleMount);
|
396 | ujs.removeEvent('onload', ujs.handleMount);
|
397 | }
|
398 | }
|
399 |
|
400 |
|
401 | }),
|
402 |
|
403 | (function(module, exports) {
|
404 |
|
405 | module.exports = {
|
406 |
|
407 | setup: function(ujs) {
|
408 | ujs.handleEvent('ready', ujs.handleMount);
|
409 | ujs.handleEvent('pjax:end', ujs.handleMount);
|
410 | ujs.handleEvent('pjax:beforeReplace', ujs.handleUnmount);
|
411 | },
|
412 |
|
413 | teardown: function(ujs) {
|
414 | ujs.removeEvent('ready', ujs.handleMount);
|
415 | ujs.removeEvent('pjax:end', ujs.handleMount);
|
416 | ujs.removeEvent('pjax:beforeReplace', ujs.handleUnmount);
|
417 | },
|
418 | }
|
419 |
|
420 |
|
421 | }),
|
422 |
|
423 | (function(module, exports) {
|
424 |
|
425 | module.exports = {
|
426 |
|
427 | setup: function(ujs) {
|
428 | ujs.handleEvent('DOMContentLoaded', ujs.handleMount)
|
429 | ujs.handleEvent('turbolinks:render', ujs.handleMount)
|
430 | ujs.handleEvent('turbolinks:before-render', ujs.handleUnmount)
|
431 | },
|
432 |
|
433 | teardown: function(ujs) {
|
434 | ujs.removeEvent('DOMContentLoaded', ujs.handleMount)
|
435 | ujs.removeEvent('turbolinks:render', ujs.handleMount)
|
436 | ujs.removeEvent('turbolinks:before-render', ujs.handleUnmount)
|
437 | },
|
438 | }
|
439 |
|
440 |
|
441 | }),
|
442 |
|
443 | (function(module, exports) {
|
444 |
|
445 | module.exports = {
|
446 |
|
447 |
|
448 | setup: function(ujs) {
|
449 | ujs.handleEvent(Turbolinks.EVENTS.CHANGE, ujs.handleMount);
|
450 | ujs.handleEvent(Turbolinks.EVENTS.BEFORE_UNLOAD, ujs.handleUnmount);
|
451 | },
|
452 | teardown: function(ujs) {
|
453 | ujs.removeEvent(Turbolinks.EVENTS.CHANGE, ujs.handleMount);
|
454 | ujs.removeEvent(Turbolinks.EVENTS.BEFORE_UNLOAD, ujs.handleUnmount);
|
455 | }
|
456 | }
|
457 |
|
458 |
|
459 | }),
|
460 |
|
461 | (function(module, exports) {
|
462 |
|
463 | module.exports = {
|
464 |
|
465 |
|
466 |
|
467 |
|
468 | setup: function(ujs) {
|
469 | Turbolinks.pagesCached(0)
|
470 | ujs.handleEvent('page:change', ujs.handleMount);
|
471 | ujs.handleEvent('page:receive', ujs.handleUnmount);
|
472 | },
|
473 | teardown: function(ujs) {
|
474 | ujs.removeEvent('page:change', ujs.handleMount);
|
475 | ujs.removeEvent('page:receive', ujs.handleUnmount);
|
476 | }
|
477 | }
|
478 |
|
479 |
|
480 | }),
|
481 |
|
482 | (function(module, exports) {
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 | module.exports = function(reqctx) {
|
491 | return function(className) {
|
492 | var parts = className.split(".")
|
493 | var filename = parts.shift()
|
494 | var keys = parts
|
495 |
|
496 | var component = reqctx("./" + filename)
|
497 |
|
498 | keys.forEach(function(k) {
|
499 | component = component[k]
|
500 | })
|
501 |
|
502 | if (component.__esModule) {
|
503 | component = component["default"]
|
504 | }
|
505 | return component
|
506 | }
|
507 | }
|
508 |
|
509 |
|
510 | })
|
511 | ]);
|
512 | }); |
\ | No newline at end of file |