|
57 | 57 | </div> |
58 | 58 | </div> |
59 | 59 |
|
60 | | - <div class="preview__window"> |
| 60 | + <div class="preview__window flex-col"> |
| 61 | + <div class="w-full px-2 bg-white border-b border-gray-300 flex items-center py-1"> |
| 62 | + <button class="mr-1 w-8 h-8 focus:outline-none hover:bg-gray-200 rounded-full" @click.prevent="navigateBack"><fa-icon :icon="['fas', 'arrow-left']" class="fa-fw text-gray-700"></fa-icon></button> |
| 63 | + <button class="mr-1 w-8 h-8 focus:outline-none hover:bg-gray-200 rounded-full" @click.prevent="navigateForward"><fa-icon :icon="['fas', 'arrow-right']" class="fa-fw text-gray-700"></fa-icon></button> |
| 64 | + <button class="mr-1 w-8 h-8 focus:outline-none hover:bg-gray-200 rounded-full" @click.prevent="navigateRefresh"><fa-icon :icon="['fas', 'redo']" class="fa-fw text-gray-700"></fa-icon></button> |
| 65 | + <button class="mr-1 w-8 h-8 focus:outline-none hover:bg-gray-200 rounded-full" @click.prevent="navigateHome"><fa-icon :icon="['fas', 'home']" class="fa-fw text-gray-700"></fa-icon></button> |
| 66 | + |
| 67 | + <div class="px-6 py-2 bg-gray-200 rounded-full text-gray-700 flex flex-1 mr-2 items-center leading-none"> |
| 68 | + <span>{{ prettyURL }}</span> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + |
61 | 72 | <div class="window" :class="'window--' + window"> |
62 | 73 | <iframe ref="iframe" @load="onLoadIframe"></iframe> |
63 | 74 | </div> |
|
88 | 99 | theme: {}, |
89 | 100 | form: null, |
90 | 101 | url: '/customize', |
| 102 | + history: [], |
| 103 | + current: 0, |
91 | 104 | window: 'desktop', |
92 | 105 | showControls: true, |
93 | 106 | } |
|
105 | 118 | isMobile() { |
106 | 119 | return this.window == 'mobile' |
107 | 120 | }, |
| 121 | +
|
| 122 | + prettyURL() { |
| 123 | + let url = this.url.replace(/([^:]\/)\/+/g, "$1") |
| 124 | + return this.parseURL(url) |
| 125 | + }, |
108 | 126 | }, |
109 | 127 |
|
110 | 128 | watch: { |
|
119 | 137 | }, |
120 | 138 |
|
121 | 139 | methods: { |
| 140 | + navigateBack() { |
| 141 | + if (this.history.length > 0) { |
| 142 | + let current = this.current - 1 |
| 143 | + let url = this.history[(this.history.length - 1) + current] |
| 144 | +
|
| 145 | + if (url) { |
| 146 | + this.current = current |
| 147 | + this.url = url |
| 148 | + this.update() |
| 149 | + } |
| 150 | + } |
| 151 | + }, |
| 152 | +
|
| 153 | + navigateForward() { |
| 154 | + if (this.current !== 0) { |
| 155 | + let current = this.current + 1 |
| 156 | + let url = this.history[(this.history.length - 1) + current] |
| 157 | +
|
| 158 | + if (url) { |
| 159 | + this.current = current |
| 160 | + this.url = url |
| 161 | + this.update() |
| 162 | + } |
| 163 | + } |
| 164 | + }, |
| 165 | +
|
| 166 | + navigateRefresh() { |
| 167 | + this.update() |
| 168 | + }, |
| 169 | +
|
| 170 | + navigateHome() { |
| 171 | + this.url = '/customize' |
| 172 | + this.update() |
| 173 | + }, |
| 174 | +
|
122 | 175 | update: _.debounce(function() { |
123 | 176 | if (cancel != undefined) { |
124 | 177 | cancel(); |
|
151 | 204 | const iframe = this.$refs.iframe |
152 | 205 | const url = iframe.contentWindow.location.toString() |
153 | 206 |
|
154 | | - if (url != 'about:blank' && !_.endsWith(url, '/customize')) { |
| 207 | + if (url == 'about:blank') { |
| 208 | + this.url = '/customize' |
| 209 | +
|
| 210 | + if (this.history[this.history.length - 1] != this.url) { |
| 211 | + this.history.push(this.url) |
| 212 | + this.current = 0 |
| 213 | + } |
| 214 | +
|
| 215 | + this.update() |
| 216 | + } else if (!_.endsWith(url, '/customize')) { |
155 | 217 | this.url = url + '/customize' |
| 218 | +
|
| 219 | + if (this.history[this.history.length - 1] != this.url) { |
| 220 | + this.history.push(this.url) |
| 221 | + this.current = 0 |
| 222 | + } |
| 223 | +
|
156 | 224 | this.update() |
157 | 225 | } |
| 226 | +
|
| 227 | + if (this.history[this.history.length + this.current] == this.url) { |
| 228 | + this.current = this.current + 1 |
| 229 | + } |
| 230 | + }, |
| 231 | +
|
| 232 | + parseURL(url) { |
| 233 | + let parser = document.createElement('a') |
| 234 | + parser.href = url |
| 235 | +
|
| 236 | + return parser |
158 | 237 | }, |
159 | 238 |
|
160 | 239 | submit() { |
|
0 commit comments