PageSourceSearch

https://coops.or.kr/assets/controllers/base/index-160e205b.js

js coops.or.kr collected 2026-10-05 05:54:01 UTC 2,812 bytes, 71 lines download raw bytes

1import { application } from 'controllers/application';
2import { Controller } from '@hotwired/stimulus';
3import { eagerLoadControllersFrom } from '@hotwired/stimulus-loading';
4
5eagerLoadControllersFrom('controllers/base', application);
6
7// <script type="text/stimulus-controllers"> 읽고 localControllers에 저장 + wrapper 생성하여 application에 등록합니다.
8// 아래와 같은 형식으로 스크립트를 body내에 작성할 수 있습니다. 이 방법은 각 페이지 특화된 컨트롤러를 정의할 때 유용합니다. 특히 페이지 블록 내에 포함시킬 수 있습니다.
9//
10// <script type="text/stimulus-controllers">
11// (function(localControllers, Controller) {
12//   localControllers["hindex-indicator"] = class extends Controller {
13//     connect() {
14//       console.log("Connected!");
15//     }
16//   };
17// })(localControllers, Controller);
18// </script>
19//
20// 위 예시에서는 "local--hindex-indicator"라는 이름의 컨트롤러가 정의됩니다. 이 컨트롤러는 application에 "local--hindex-indicator"라는 이름으로 등록됩니다.
21//
22// <div data-controller="local--hindex-indicator">
23//   ...
24// </div>
25//
26// 위와 같이 data-controller 속성에 "local--hindex-indicator"를 지정하여 사용할 수 있습니다.
27
28function registerScriptControllers(root = document) {
29  const scripts = root.querySelectorAll('script[type="text/stimulus-controllers"]');
30
31  scripts.forEach((script) => {
32    try {
33      // Function 내부 스코프에서 클래스 정의
34      const controllers = (function (Controller) {
35        const localControllers = {};
36
37        // eval 대신 Function 사용 (안전하게 지역 스코프 유지)
38        new Function('localControllers', 'Controller', script.textContent)(localControllers, Controller);
39
40        return localControllers;
41      })(Controller);
42
43      // 클래스 등록
44      Object.entries(controllers).forEach(([name, controllerClass]) => {
45        const fullName = `local--${name}`;
46        if (!application.router.modulesByIdentifier.has(fullName)) {
47          application.register(fullName, controllerClass);
48          if (application.debug) {
49            console.log(`Registered controller: ${fullName}`);
50          }
51        }
52      });
53    } catch (err) {
54      console.error('Failed to execute script controller', err);
55    }
56  });
57}
58
59// 페이지 로드 직후
60registerScriptControllers();
61
62// MutationObserver로 동적 삽입된 <script> 처리 가능
63new MutationObserver((mutations) => {
64  mutations.forEach(({ addedNodes }) => {
65    addedNodes.forEach((node) => {
66      if (node.tagName === 'SCRIPT' && node.type === 'text/stimulus-controllers') {
67        registerScriptControllers(node.parentNode || document);
68      }
69    });
70  });
71}).observe(document, { subtree: true, childList: true });

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.