ExternalLibs.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. <template>
  2. <Window ref="window" @close="close" margin="2px">
  3. <template slot="header">
  4. {{ header }}
  5. </template>
  6. <template slot="buttons">
  7. <span class="full-screen-button row justify-center items-center" @mousedown.stop @click="fullScreenToggle">
  8. <q-icon :name="(fullScreenActive ? 'la la-compress-arrows-alt': 'la la-expand-arrows-alt')" size="16px"/>
  9. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">На весь экран</q-tooltip>
  10. </span>
  11. </template>
  12. <div v-show="ready" class="col column" style="min-width: 600px">
  13. <div class="row items-center q-px-sm" style="height: 50px">
  14. <q-select class="q-mr-sm" ref="rootLink" v-model="rootLink" :options="rootLinkOptions" @input="rootLinkInput"
  15. @popup-show="onSelectPopupShow" @popup-hide="onSelectPopupHide"
  16. style="width: 230px"
  17. dropdown-icon="la la-angle-down la-sm"
  18. rounded outlined dense emit-value map-options display-value-sanitize options-sanitize
  19. >
  20. <template v-slot:prepend>
  21. <q-btn class="q-mr-xs" round dense color="blue" icon="la la-plus" @click.stop="addBookmark" size="12px">
  22. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Добавить закладку</q-tooltip>
  23. </q-btn>
  24. <q-btn round dense color="blue" icon="la la-bars" @click.stop="bookmarkSettings" size="12px">
  25. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Настроить закладки</q-tooltip>
  26. </q-btn>
  27. </template>
  28. <template v-slot:selected>
  29. <div style="overflow: hidden; white-space: nowrap;">{{ rootLinkWithoutProtocol }}</div>
  30. </template>
  31. </q-select>
  32. <q-select class="q-mr-sm" ref="selectedLink" v-model="selectedLink" :options="selectedLinkOptions" @input="selectedLinkInput" style="width: 50px"
  33. @popup-show="onSelectPopupShow" @popup-hide="onSelectPopupHide"
  34. dropdown-icon="la la-angle-down la-sm"
  35. rounded outlined dense emit-value map-options hide-selected display-value-sanitize options-sanitize
  36. >
  37. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Закладки</q-tooltip>
  38. </q-select>
  39. <q-input class="col q-mr-sm" ref="input" rounded outlined dense bg-color="white" v-model="bookUrl" placeholder="Скопируйте сюда URL книги"
  40. @focus="selectAllOnFocus" @keydown="bookUrlKeyDown"
  41. >
  42. <template v-slot:prepend>
  43. <q-btn class="q-mr-xs" round dense color="blue" icon="la la-home" @click="goToLink(selectedLink)" size="12px">
  44. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Вернуться на стартовую страницу</q-tooltip>
  45. </q-btn>
  46. <q-btn round dense color="blue" icon="la la-angle-double-down" @click="openBookUrlInFrame" size="12px" :disabled="!bookUrl">
  47. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Загрузить URL во фрейм</q-tooltip>
  48. </q-btn>
  49. </template>
  50. <template v-slot:append>
  51. <q-btn round dense color="blue" icon="la la-cog" @click.stop="optionsVisible = true" size="12px">
  52. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Опции</q-tooltip>
  53. </q-btn>
  54. </template>
  55. </q-input>
  56. <q-btn rounded color="green-7" no-caps size="14px" @click="submitUrl" :disabled="!bookUrl">Открыть
  57. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Открыть в читалке</q-tooltip>
  58. </q-btn>
  59. </div>
  60. <div class="separator"></div>
  61. <div class="col fit" style="position: relative;">
  62. <iframe v-if="frameVisible" class="fit" ref="frame" :src="frameSrc" frameborder="0"></iframe>
  63. <div v-show="transparentLayoutVisible" ref="transparentLayout" class="fit transparent-layout" @click="transparentLayoutClick"></div>
  64. </div>
  65. <Dialog ref="dialogAddBookmark" v-model="addBookmarkVisible">
  66. <template slot="header">
  67. <div class="row items-center">
  68. <q-icon class="q-mr-sm" name="la la-bookmark" size="28px"></q-icon>
  69. <div v-if="addBookmarkMode == 'edit'">Редактировать закладку</div>
  70. <div v-else>Добавить закладку</div>
  71. </div>
  72. </template>
  73. <div class="q-mx-md row">
  74. <q-input ref="bookmarkLink" class="col q-mr-sm" outlined dense bg-color="white" v-model="bookmarkLink" @keydown="bookmarkLinkKeyDown"
  75. placeholder="Ссылка для закладки" maxlength="2000" @focus="selectAllOnFocus">
  76. </q-input>
  77. <q-select class="q-mr-sm" ref="defaultRootLink" v-model="defaultRootLink" :options="defaultRootLinkOptions" @input="defaultRootLinkInput" style="width: 50px"
  78. dropdown-icon="la la-angle-down la-sm"
  79. outlined dense emit-value map-options hide-selected display-value-sanitize options-sanitize
  80. >
  81. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Предустановленные ссылки</q-tooltip>
  82. </q-select>
  83. </div>
  84. <div class="q-mx-md q-mt-md">
  85. <q-input class="col q-mr-sm" ref="bookmarkDesc" outlined dense bg-color="white" v-model="bookmarkDesc" @keydown="bookmarkDescKeyDown"
  86. placeholder="Описание" style="width: 400px" maxlength="100" @focus="selectAllOnFocus">
  87. </q-input>
  88. </div>
  89. <template slot="footer">
  90. <q-btn class="q-px-md q-ml-sm" dense no-caps v-close-popup>Отмена</q-btn>
  91. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okAddBookmark" :disabled="!bookmarkLink">OK</q-btn>
  92. </template>
  93. </Dialog>
  94. <Dialog ref="options" v-model="optionsVisible">
  95. <template slot="header">
  96. <div class="row items-center">
  97. <q-icon class="q-mr-sm" name="la la-cog" size="28px"></q-icon>
  98. Опции
  99. </div>
  100. </template>
  101. <div class="q-mx-md column">
  102. <q-checkbox v-model="closeAfterSubmit" size="36px" label="Закрыть окно при отправке ссылки в читалку" />
  103. <q-checkbox v-model="openInFrameOnEnter" size="36px" label="Открывать ссылку во фрейме при нажатии 'Enter'" />
  104. <q-checkbox v-model="openFullscreen" size="36px" label="Открывать окно на весь экран" />
  105. </div>
  106. <template slot="footer">
  107. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="optionsVisible = false">OK</q-btn>
  108. </template>
  109. </Dialog>
  110. </div>
  111. <BookmarkSettings v-if="bookmarkSettingsActive" ref="bookmarkSettings" :libs="libs" :addBookmarkVisible="addBookmarkVisible"
  112. @do-action="doAction" @close="closeBookmarkSettings">
  113. </BookmarkSettings>
  114. </Window>
  115. </template>
  116. <script>
  117. //-----------------------------------------------------------------------------
  118. import Vue from 'vue';
  119. import Component from 'vue-class-component';
  120. import _ from 'lodash';
  121. import Window from '../share/Window.vue';
  122. import Dialog from '../share/Dialog.vue';
  123. import BookmarkSettings from './BookmarkSettings/BookmarkSettings.vue';
  124. import rstore from '../../store/modules/reader';
  125. import * as utils from '../../share/utils';
  126. import * as lu from './linkUtils';
  127. const proxySubst = {
  128. 'http://flibusta.is': 'http://b.liberama.top:23480',
  129. };
  130. export default @Component({
  131. components: {
  132. Window,
  133. Dialog,
  134. BookmarkSettings
  135. },
  136. watch: {
  137. libs: function() {
  138. this.loadLibs();
  139. },
  140. defaultRootLink: function() {
  141. this.updateBookmarkLink();
  142. },
  143. bookUrl: function(newValue) {
  144. const value = lu.addProtocol(newValue);
  145. const subst = this.makeProxySubst(value, true);
  146. if (value != subst) {
  147. this.$nextTick(() => {
  148. this.bookUrl = subst;
  149. });
  150. }
  151. },
  152. bookmarkLink: function(newValue) {
  153. const value = lu.addProtocol(newValue);
  154. const subst = this.makeProxySubst(value, true);
  155. if (value != subst) {
  156. this.$nextTick(() => {
  157. this.bookmarkLink = subst;
  158. });
  159. }
  160. },
  161. closeAfterSubmit: function(newValue) {
  162. this.commitProp('closeAfterSubmit', newValue);
  163. },
  164. openInFrameOnEnter: function(newValue) {
  165. this.commitProp('openInFrameOnEnter', newValue);
  166. },
  167. openFullscreen: function(newValue) {
  168. this.commitProp('openFullscreen', newValue);
  169. },
  170. }
  171. })
  172. class ExternalLibs extends Vue {
  173. ready = false;
  174. frameVisible = false;
  175. rootLink = '';
  176. selectedLink = '';
  177. frameSrc = '';
  178. bookUrl = '';
  179. libs = {};
  180. fullScreenActive = false;
  181. transparentLayoutVisible = false;
  182. addBookmarkVisible = false;
  183. optionsVisible = false;
  184. addBookmarkMode = '';
  185. bookmarkLink = '';
  186. bookmarkDesc = '';
  187. defaultRootLink = '';
  188. bookmarkSettingsActive = false;
  189. closeAfterSubmit = false;
  190. openInFrameOnEnter = false;
  191. openFullscreen = false;
  192. created() {
  193. this.oldStartLink = '';
  194. this.$root.addKeyHook(this.keyHook);
  195. document.addEventListener('fullscreenchange', () => {
  196. this.fullScreenActive = (document.fullscreenElement !== null);
  197. });
  198. this.debouncedGoToLink = _.debounce((link) => {
  199. this.goToLink(link);
  200. }, 100, {'maxWait':200});
  201. //this.commit = this.$store.commit;
  202. //this.commit('reader/setLibs', rstore.libsDefaults);
  203. }
  204. mounted() {
  205. //Поправка метода toggleOption компонента select фреймворка quasar, необходимо другое поведение
  206. //$emit('input'.. вызывается всегда
  207. this.toggleOption = function(opt, keepOpen) {
  208. if (this.editable !== true || opt === void 0 || this.isOptionDisabled(opt) === true) {
  209. return;
  210. }
  211. const optValue = this.getOptionValue(opt);
  212. if (this.multiple !== true) {
  213. if (keepOpen !== true) {
  214. this.updateInputValue(this.fillInput === true ? this.getOptionLabel(opt) : '', true, true);
  215. this.hidePopup();
  216. }
  217. this.$refs.target !== void 0 && this.$refs.target.focus();
  218. this.$emit('input', this.emitValue === true ? optValue : opt);
  219. }
  220. };
  221. this.$refs.rootLink.toggleOption = this.toggleOption;
  222. this.$refs.selectedLink.toggleOption = this.toggleOption;
  223. (async() => {
  224. //подождем this.mode
  225. let i = 0;
  226. while(!this.mode && i < 100) {
  227. await utils.sleep(100);
  228. i++;
  229. }
  230. if (this.mode != 'liberama.top') {
  231. this.$router.replace('/404');
  232. return;
  233. }
  234. this.$refs.window.init();
  235. this.opener = null;
  236. const host = window.location.host;
  237. const openerHost = (host.indexOf('b.') == 0 ? host.substring(2) : host);
  238. const openerOrigin1 = `http://${openerHost}`;
  239. const openerOrigin2 = `https://${openerHost}`;
  240. window.addEventListener('message', (event) => {
  241. if (event.origin !== openerOrigin1 && event.origin !== openerOrigin2)
  242. return;
  243. if (!_.isObject(event.data) || event.data.from != 'LibsPage')
  244. return;
  245. if (event.origin == openerOrigin1)
  246. this.opener = window.opener;
  247. else
  248. this.opener = event.source;
  249. this.openerOrigin = event.origin;
  250. //console.log(event);
  251. this.recvMessage(event.data);
  252. });
  253. //Ожидаем родителя
  254. i = 0;
  255. while(!this.opener) {
  256. await utils.sleep(1000);
  257. i++;
  258. if (i >= 5) {
  259. await this.$root.stdDialog.alert('Нет связи с читалкой. Окно будет закрыто', 'Ошибка');
  260. window.close();
  261. }
  262. }
  263. //Проверка закрытия родительского окна
  264. while(this.opener) {
  265. await this.checkOpener();
  266. await utils.sleep(1000);
  267. }
  268. })();
  269. }
  270. recvMessage(d) {
  271. if (d.type == 'mes') {
  272. switch(d.data) {
  273. case 'hello': this.sendMessage({type: 'mes', data: 'ready'}); break;
  274. }
  275. } else if (d.type == 'libs') {
  276. this.ready = true;
  277. this.libs = _.cloneDeep(d.data);
  278. } else if (d.type == 'notify') {
  279. this.$root.notify.success(d.data, '', {position: 'bottom-right'});
  280. }
  281. }
  282. sendMessage(d) {
  283. (async() => {
  284. await this.checkOpener();
  285. if (this.opener && this.openerOrigin)
  286. this.opener.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.openerOrigin);
  287. })();
  288. }
  289. async checkOpener() {
  290. if (this.opener.closed) {
  291. await this.$root.stdDialog.alert('Потеряна связь с читалкой. Окно будет закрыто', 'Ошибка');
  292. window.close();
  293. }
  294. }
  295. commitLibs(libs) {
  296. this.sendMessage({type: 'libs', data: libs});
  297. }
  298. commitProp(prop, value) {
  299. let libs = _.cloneDeep(this.libs);
  300. libs[prop] = value;
  301. this.commitLibs(libs);
  302. }
  303. loadLibs() {
  304. const libs = this.libs;
  305. this.selectedLink = libs.startLink;
  306. this.closeAfterSubmit = libs.closeAfterSubmit || false;
  307. this.openInFrameOnEnter = libs.openInFrameOnEnter || false;
  308. this.openFullscreen = libs.openFullscreen || false;
  309. this.updateStartLink();
  310. }
  311. doAction(event) {
  312. switch (event.action) {
  313. case 'setLibs': this.commitLibs(event.data); break;
  314. case 'setRootLink': this.rootLink = event.data; this.rootLinkInput(); break;
  315. case 'setSelectedLink': this.selectedLink = event.data; this.selectedLinkInput(); break;
  316. case 'editBookmark': this.addBookmark('edit', event.data.link, event.data.desc); break;
  317. case 'addBookmark': this.addBookmark('add'); break;
  318. }
  319. }
  320. get mode() {
  321. return this.$store.state.config.mode;
  322. }
  323. get header() {
  324. let result = (this.ready ? 'Библиотека' : 'Загрузка...');
  325. if (this.ready && this.selectedLink) {
  326. result += ` | ${(this.libs.comment ? this.libs.comment + ' ': '') + lu.removeProtocol(this.libs.startLink)}`;
  327. }
  328. this.$root.$emit('set-app-title', result);
  329. return result;
  330. }
  331. get rootLinkWithoutProtocol() {
  332. return lu.removeProtocol(this.rootLink);
  333. }
  334. updateSelectedLinkByRoot() {
  335. if (!this.ready)
  336. return;
  337. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.rootLink);
  338. if (index >= 0)
  339. this.selectedLink = this.libs.groups[index].s;
  340. else
  341. this.selectedLink = '';
  342. }
  343. updateStartLink(force) {
  344. if (!this.ready)
  345. return;
  346. let index = -1;
  347. try {
  348. this.rootLink = lu.getOrigin(this.selectedLink);
  349. index = lu.getRootIndexByUrl(this.libs.groups, this.rootLink);
  350. } catch(e) {
  351. //
  352. }
  353. if (index >= 0) {
  354. let libs = _.cloneDeep(this.libs);
  355. const com = this.getCommentByLink(libs.groups[index].list, this.selectedLink);
  356. if (libs.groups[index].s != this.selectedLink ||
  357. libs.startLink != this.selectedLink ||
  358. libs.comment != com) {
  359. libs.groups[index].s = this.selectedLink;
  360. libs.startLink = this.selectedLink;
  361. libs.comment = com;
  362. this.commitLibs(libs);
  363. }
  364. if (force || this.oldStartLink != libs.startLink) {
  365. this.oldStartLink = libs.startLink;
  366. this.debouncedGoToLink(this.selectedLink);
  367. }
  368. } else {
  369. this.rootLink = '';
  370. this.selectedLink = '';
  371. this.debouncedGoToLink(this.selectedLink);
  372. }
  373. }
  374. get rootLinkOptions() {
  375. let result = [];
  376. if (!this.ready)
  377. return result;
  378. this.libs.groups.forEach(group => {
  379. result.push({label: lu.removeProtocol(group.r), value: group.r});
  380. });
  381. return result;
  382. }
  383. get defaultRootLinkOptions() {
  384. let result = [];
  385. rstore.libsDefaults.groups.forEach(group => {
  386. result.push({label: lu.removeProtocol(group.r), value: group.r});
  387. });
  388. return result;
  389. }
  390. get selectedLinkOptions() {
  391. let result = [];
  392. if (!this.ready)
  393. return result;
  394. const index = lu.getSafeRootIndexByUrl(this.libs.groups, this.rootLink);
  395. if (index >= 0) {
  396. this.libs.groups[index].list.forEach(link => {
  397. result.push({label: (link.c ? link.c + ' ': '') + lu.removeOrigin(link.l), value: link.l});
  398. });
  399. }
  400. return result;
  401. }
  402. openBookUrlInFrame() {
  403. if (this.bookUrl) {
  404. this.goToLink(lu.addProtocol(this.bookUrl));
  405. }
  406. }
  407. goToLink(link) {
  408. if (!this.ready || !link)
  409. return;
  410. if (!link) {
  411. this.frameVisible = false;
  412. return;
  413. }
  414. this.frameSrc = this.makeProxySubst(link);
  415. this.frameVisible = false;
  416. this.$nextTick(() => {
  417. this.frameVisible = true;
  418. this.$nextTick(() => {
  419. if (this.$refs.frame)
  420. this.$refs.frame.contentWindow.focus();
  421. });
  422. });
  423. }
  424. getCommentByLink(list, link) {
  425. const item = lu.getListItemByLink(list, link);
  426. return (item ? item.c : '');
  427. }
  428. makeProxySubst(url, reverse = false) {
  429. for (const [key, value] of Object.entries(proxySubst)) {
  430. if (reverse && value == url.substring(0, value.length)) {
  431. return key + url.substring(value.length);
  432. } else if (!reverse && key == url.substring(0, key.length)) {
  433. return value + url.substring(key.length);
  434. }
  435. }
  436. return url;
  437. }
  438. selectAllOnFocus(event) {
  439. if (event.target.select)
  440. event.target.select();
  441. }
  442. rootLinkInput() {
  443. this.updateSelectedLinkByRoot();
  444. this.updateStartLink(true);
  445. }
  446. selectedLinkInput() {
  447. this.updateStartLink(true);
  448. }
  449. submitUrl() {
  450. if (this.bookUrl) {
  451. this.sendMessage({type: 'submitUrl', data: {
  452. url: this.bookUrl,
  453. force: true
  454. }});
  455. this.bookUrl = '';
  456. if (this.closeAfterSubmit)
  457. this.close();
  458. }
  459. }
  460. addBookmark(mode = 'add', link = '', desc = '') {
  461. if (mode == 'edit') {
  462. this.editBookmarkLink = this.bookmarkLink = link;
  463. this.editBookmarkDesc = this.bookmarkDesc = desc;
  464. } else {
  465. this.bookmarkLink = this.bookUrl;
  466. this.bookmarkDesc = '';
  467. }
  468. this.addBookmarkMode = mode;
  469. this.addBookmarkVisible = true;
  470. this.$nextTick(() => {
  471. this.$refs.bookmarkLink.focus();
  472. this.$refs.defaultRootLink.toggleOption = this.toggleOption;
  473. });
  474. }
  475. updateBookmarkLink() {
  476. const index = lu.getSafeRootIndexByUrl(rstore.libsDefaults.groups, this.defaultRootLink);
  477. if (index >= 0) {
  478. this.bookmarkLink = rstore.libsDefaults.groups[index].s;
  479. this.bookmarkDesc = this.getCommentByLink(rstore.libsDefaults.groups[index].list, this.bookmarkLink);
  480. } else {
  481. this.bookmarkLink = '';
  482. this.bookmarkDesc = '';
  483. }
  484. }
  485. defaultRootLinkInput() {
  486. this.updateBookmarkLink();
  487. }
  488. bookmarkLinkKeyDown(event) {
  489. if (event.key == 'Enter') {
  490. this.$refs.bookmarkDesc.focus();
  491. event.preventDefault();
  492. }
  493. }
  494. bookmarkDescKeyDown(event) {
  495. if (event.key == 'Enter') {
  496. event.stopPropagation();
  497. event.preventDefault();
  498. this.okAddBookmark();
  499. }
  500. }
  501. async okAddBookmark() {
  502. if (!this.bookmarkLink)
  503. return;
  504. const link = (this.addBookmarkMode == 'edit' ? lu.addProtocol(this.editBookmarkLink) : lu.addProtocol(this.bookmarkLink));
  505. let index = -1;
  506. try {
  507. index = lu.getRootIndexByUrl(this.libs.groups, link);
  508. } catch (e) {
  509. await this.$root.stdDialog.alert('Неверный формат ссылки', 'Ошибка');
  510. return;
  511. }
  512. let libs = _.cloneDeep(this.libs);
  513. //добавление
  514. //есть группа в закладках
  515. if (index >= 0) {
  516. const item = lu.getListItemByLink(libs.groups[index].list, link);
  517. //редактирование
  518. if (item && this.addBookmarkMode == 'edit') {
  519. if (item) {
  520. //редактируем
  521. item.l = link;
  522. item.c = this.bookmarkDesc;
  523. this.commitLibs(libs);
  524. } else {
  525. await this.$root.stdDialog.alert('Не удалось отредактировать закладку', 'Ошибка');
  526. }
  527. } else if (!item) {
  528. //добавляем
  529. if (libs.groups[index].list.length >= 100) {
  530. await this.$root.stdDialog.alert('Достигнут предел количества закладок для этого сайта', 'Ошибка');
  531. return;
  532. }
  533. libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
  534. this.commitLibs(libs);
  535. } else if (item.c != this.bookmarkDesc) {
  536. if (await this.$root.stdDialog.confirm(`Такая закладка уже существует с другим описанием.<br>` +
  537. `Заменить '${this.$sanitize(item.c)}' на '${this.$sanitize(this.bookmarkDesc)}'?`, ' ')) {
  538. item.c = this.bookmarkDesc;
  539. this.commitLibs(libs);
  540. } else
  541. return;
  542. } else {
  543. await this.$root.stdDialog.alert('Такая закладка уже существует', ' ');
  544. return;
  545. }
  546. } else {//нет группы в закладках
  547. if (libs.groups.length >= 100) {
  548. await this.$root.stdDialog.alert('Достигнут предел количества различных сайтов в закладках', 'Ошибка');
  549. return;
  550. }
  551. //добавляем сначала группу
  552. libs.groups.push({r: lu.getOrigin(link), s: link, list: []});
  553. index = lu.getSafeRootIndexByUrl(libs.groups, link);
  554. if (index >= 0)
  555. libs.groups[index].list.push({l: link, c: this.bookmarkDesc});
  556. this.commitLibs(libs);
  557. }
  558. this.addBookmarkVisible = false;
  559. }
  560. fullScreenToggle() {
  561. this.fullScreenActive = !this.fullScreenActive;
  562. if (this.fullScreenActive) {
  563. this.$q.fullscreen.request();
  564. } else {
  565. this.$q.fullscreen.exit();
  566. }
  567. }
  568. transparentLayoutClick() {
  569. this.transparentLayoutVisible = false;
  570. }
  571. onSelectPopupShow() {
  572. this.transparentLayoutVisible = true;
  573. }
  574. onSelectPopupHide() {
  575. this.transparentLayoutVisible = false;
  576. }
  577. close() {
  578. this.sendMessage({type: 'close'});
  579. }
  580. bookUrlKeyDown(event) {
  581. if (event.key == 'Enter') {
  582. if (!this.openInFrameOnEnter) {
  583. this.submitUrl();
  584. } else {
  585. if (this.bookUrl)
  586. this.goToLink(this.bookUrl);
  587. }
  588. event.preventDefault();
  589. }
  590. }
  591. bookmarkSettings() {
  592. this.bookmarkSettingsActive = true;
  593. this.$nextTick(() => {
  594. this.$refs.bookmarkSettings.init();
  595. });
  596. }
  597. closeBookmarkSettings() {
  598. this.bookmarkSettingsActive = false;
  599. }
  600. keyHook(event) {
  601. if (this.$root.rootRoute() == '/external-libs') {
  602. if (this.$root.stdDialog.active)
  603. return false;
  604. if (this.bookmarkSettingsActive && this.$refs.bookmarkSettings.keyHook(event))
  605. return true;
  606. if (this.addBookmarkVisible || this.optionsVisible)
  607. return false;
  608. if (event.type == 'keydown' && event.key == 'F4') {
  609. this.addBookmark();
  610. return true;
  611. }
  612. if (event.type == 'keydown' && event.key == 'Escape' &&
  613. (document.activeElement != this.$refs.rootLink.$refs.target || !this.$refs.rootLink.menu) &&
  614. (document.activeElement != this.$refs.selectedLink.$refs.target || !this.$refs.selectedLink.menu)
  615. ) {
  616. this.close();
  617. return true;
  618. }
  619. }
  620. return false;
  621. }
  622. }
  623. //-----------------------------------------------------------------------------
  624. </script>
  625. <style scoped>
  626. .separator {
  627. height: 1px;
  628. background-color: #A0A0A0;
  629. }
  630. .full-screen-button {
  631. width: 30px;
  632. height: 30px;
  633. cursor: pointer;
  634. }
  635. .full-screen-button:hover {
  636. background-color: #69C05F;
  637. }
  638. .transparent-layout {
  639. top: 0;
  640. left: 0;
  641. position: absolute;
  642. }
  643. </style>