summaryrefslogtreecommitdiffstats
path: root/browser/html/multidocs.html
blob: 65c93a087c27837d068e98904a4202888b3bf1fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<!DOCTYPE html>

<!-- Proof of concept of running multiple instance of cool.html

     at the same time (each one in a different iframe).



     To open the first document add the path into the input and click

     open. That will open an iframe containing the document as well as

     adding the document name to the left side menu.



     To open another document press the 'Add new document' link, which is

     the first link on the left side menu.



     To switch between the documents click on their names on the left side menu.

     That will keep the other documents opened, but not in focus.



     To test this, do 'make run', and then in your browser open:

     https://localhost:9980/browser/dist/multidocs.html?file_path=/opt/libreoffice/online/test/data/hello-world.ods

-->

<meta name="robots" content="noindex">
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Multiple docs opened in parallel</title>
    <style>
      html, body, .container {
        height: 100%;
      }
      html, body, .container, ul, li, iframe {
        margin: 0;
        padding: 0;
        border: 0;
      }
      ul {
        list-style: none;
      }
      nav {
        width: 20rem;
        flex-direction: column;
        padding: 1rem;
      }
      .container, nav {
        display: flex;
      }
      .link {
        margin-bottom: 0.25rem;
      }
      .link a {
        color: rgb(107, 114, 128);      
        text-decoration: none;
        font-size: 1.25rem;
        line-height: 1.75rem;
      }
      .link:not(.open-doc) a:hover {
        border-bottom: 2px solid rgb(17, 24, 39);
      }
      .open-doc {
        color: rgb(17, 24, 39);
        font-weight: 800;
        border-bottom: 1px solid rgb(229, 231, 235);
      }
      .open-doc a:hover {
        opacity: 0.9;
      }
      .doc .selected {
        border-bottom: 2px solid rgb(107, 114, 128);
      }
      main {
        width: 100%;
        display: flex;
      }
      iframe {
        width: 100%;
        margin: 1rem;
        border: 1px solid rgb(107, 114, 128);
      }
      .overlay {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        overflow-y: auto;
        z-index: 99;
        background: rgb(243, 244, 246);
        display: flex;
        justify-content: center;
        align-items: center;  
      }
      .modal {
        max-width: 30rem;
        background: #FFF;
        padding: 2rem;
        font-weight: 800;
        border: 1px solid rgb(229, 231, 235);
      }
      .modal input {
        display: block;
        width: 100%;
        margin: 1rem 0;
      }
      iframe, .overlay, .hidden {
        display: none;
      }
      iframe.opened {
        display: block;
      }
      .overlay.opened {
        display: flex;
      }
    </style>
  </head>
  <body>

    <div class="container">
      <div class="overlay opened">
        <div class="modal">
          <p>What file do you want to open? (enter absolute file path)</p>

          <form>
            <input type="text" name="path"
                               pattern="(.+)\.[0-9a-zA-Z]{2,5}$"
                               required="required"
                               placeholder="/home/your-username/Documents/Spreadsheet.ods" />

            <button type="submit">Open</button>
            <a href="#" class="js-cancel hidden">Cancel</a>
          </form>
        </div>
      </div>

      <nav>
        <ul>
          <li class="link open-doc">
            <a href="#">Add new Document</a>
          </li>
          <!-- Sample document 

          <li id="doc-link-111" class="link doc">

            <a href="#" class="selected">Doc-111.ods</a>

          </li>

          -->
        </ul>
      </nav>

      <main>

        <!-- doc iframes go here -->

        <!-- Sample iframe: <iframe id="doc-111">Content iframe 111</iframe> -->

      </main>
    </div>


    <script id="jsbin-javascript">
      (function() {
        var openedDocs = {};
        var id = 0;
        
        // this function will create an iframe
        function openDocument(path) {
          var fileName = path.split('\\').pop().split('/').pop();
          
          // add menu link
          var liEl = document.createElement('li');
          liEl.id = 'doc-link-' + id;
          liEl.classList.add('link');
          liEl.classList.add('doc');
          var aEl = document.createElement('a');
          aEl.dataset.iframeId = id;
          aEl.setAttribute('href', '#');
          aEl.textContent = fileName;
          liEl.appendChild(aEl);
          document.querySelector('nav ul').appendChild(liEl);
          
          // add iframe
          var docEl = document.createElement('iframe');
          docEl.id = 'doc-' + id;
          docEl.setAttribute('src', getIframeSrc(path));
          document.querySelector('main').appendChild(docEl);
          
          openedDocs[path] = { fileName: fileName, id: id };
          
          setActiveDocument(id);
          
          id++;
        }
        
        function getIframeSrc(path) {
          var query = '?';
          query += 'file_path=file://' + path;
          query += '&NotWOPIButIframe=true';

          var editorPath = window.location.pathname.substr(0, window.location.pathname.lastIndexOf('/') + 1) + 'cool.html';
          var src = window.location.protocol + '//' + window.location.host + editorPath + query;
          
          return src;
        }
        
        function setActiveDocument(id) {
          // remove selected status from previous active document
          var currentActiveDoc = document.querySelector('.doc .selected');
          
          if (currentActiveDoc) {
            currentActiveDoc.classList.remove('selected');      
          }
          
          var currentActiveIframe = document.querySelector('iframe.opened');
          
          if (currentActiveIframe) {
            currentActiveIframe.classList.remove('opened');
          }
          
          // add selected status to new document
          document.querySelector('#doc-link-' + id + ' a').classList.add('selected');
          
          // set selected status to current opened document iframe
          document.querySelector('#doc-' + id).classList.add('opened');
        }
        
        function toggleModal() {
          if (Object.keys(openedDocs).length > 0) {
            document.querySelector('.js-cancel').classList.remove('hidden');
          }
          
          var overlayEl = document.querySelector('.overlay');
          var operation = overlayEl.classList.contains('opened') ? 'remove' : 'add';
          
          overlayEl.classList[operation]('opened');
        }
        
        function onFormSubmit(formEl) {
          return function (evt) {
            evt.preventDefault();
            
            var pathEl = formEl.querySelector('[name=path]');
            var path = pathEl.value;
            pathEl.value = '';
            
            // already opened
            if (openedDocs[path]) {
              alert('already opened');
              return;
            }
            
            openDocument(path);
            
            toggleModal();      
          }
        }
        
        function onToggleModal(evt) {
          evt.preventDefault();
          toggleModal();
        }
        
        function onMenuItemClick(evt) {
          evt.preventDefault();
          
          var el = evt.target;
          
          if (el.classList.contains('selected') || el.nodeName !== 'A') {
            return;
          }
          
          var id = el.parentElement.id;
          
          if (id) {
            id = id.replace('doc-link-', '');
            setActiveDocument(id);
          }
        }

        function load() {
          var formEl = document.querySelector('.modal form');
          
          formEl.addEventListener('submit', onFormSubmit(formEl));
          
          document.querySelector('.open-doc a').addEventListener('click', onToggleModal);
          document.querySelector('.js-cancel').addEventListener('click', onToggleModal);
          
          document.querySelector('nav ul').addEventListener('click', onMenuItemClick);
        }
        
        window.onload = load;
        
      }());
    </script>
  </body>
</html>