Skip to content
Snippets Groups Projects
Select Git revision
  • fe39d9ee94acad2d3a61475a946c9368b46cca0e
  • main default protected
  • dev protected
  • f-render-html-properties
  • f-vishesh0932-ext-cosmetics
  • f-table-references
  • f-update-legacy-adapter
  • f-refactor-refs
  • f-fix-caosadvancedtools-refs
  • f-linkahead-rename
  • f-citation-cff
  • f-map-resolve-reference
  • dev-bmpg
  • f-form-select
  • f-doc-extention
  • f-geo-position-records
  • f-data-analysis
  • f-area-folder-drop
  • f-fix-get-parents
  • f-fix-110
  • f-entity-state
  • v0.16.0
  • v0.15.2
  • v0.15.1
  • v0.15.0
  • v0.14.0
  • v0.13.3
  • v0.13.2
  • v0.13.1
  • v0.13.0
  • v0.12.0
  • v0.11.1
  • v0.11.0
  • v0.10.1
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.0
  • v0.5.0
  • v0.4.2
41 results

ext_cosmetics.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ext_cosmetics.js 2.70 KiB
    /*
     * This file is a part of the CaosDB Project.
     *
     * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
     * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU Affero General Public License for more details.
     *
     * You should have received a copy of the GNU Affero General Public License
     * along with this program. If not, see <https://www.gnu.org/licenses/>.
     */
    
    "use strict";
    
    /**
     * Cosmetics module is a collection of small look-and-feel tweaks for the
     * caosdb webui.
     *
     * @author Timm Fitschen
     */
    var cosmetics = new function () {
    
        /**
         * Cut-off length of links. When linkify processes the links any href
         * longer than this will be cut off at character 25 and "[...]" will be
         * appended for the link text.
         */
        var _link_cut_off_length = 40;
    
        var _linkify = function () {
            $('.caosdb-f-property-text-value').each(function (index) {
                if (/https?:\/\//.test(this.innerText)) {
                    var result = this.innerText.replace(/https?:\/\/[^\s]*/g, function (href, index) {
                        var link_text = href;
                        if (_link_cut_off_length > 4 && link_text.length > _link_cut_off_length) {
                            link_text = link_text.substring(0, _link_cut_off_length - 5) + "[...]";
                        }
    
                        return `<a title="Open ${href} in a new tab." target="_blank" class="caosdb-v-property-href-value" href="${href}">${link_text} <i class="bi bi-box-arrow-up-right"></i></a>`;
                    });
    
                    $(this).html(result);
                }
            });
        }
    
        /**
         * Convert any substring of a text-value beginning with 'http(s)://' into a
         * link.
         *
         * A listener detects edit-mode changes and previews
         */
        var linkify = function () {
            _linkify();
    
            // edit-mode-listener
            document.body.addEventListener(edit_mode.end_edit.type, _linkify, true);
            // preview listener
            document.body.addEventListener(preview.previewReadyEvent.type, _linkify, true);
        }
    
        this.init = function () {
            this.linkify = linkify;
            if ("${BUILD_MODULE_EXT_COSMETICS_LINKIFY}" == "ENABLED") {
                linkify();
            }
        }
    
    }
    
    
    $(document).ready(function () {
        caosdb_modules.register(cosmetics);
    });