Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 23x 23x 23x 58x 58x 58x 58x 58x 58x 58x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 23x 23x 23x 23x 12x 12x 23x 11x 11x 11x 11x 11x 2x 2x 2x 1x 1x 1x 1x 1x 11x 11x 11x 10x 10x 11x 23x 58x 58x 58x 58x 58x 58x 58x 58x 23x 13x 13x 13x 13x 13x 13x 13x 13x 23x 10x 10x 10x 10x 10x 23x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 58x 22x | /*!
* Page Title composable for Vue 3 Composition API.
* Provides functions to change page titles outside Vue scope
*
* @module ext.wikilambda.app.composables.usePageTitle
* @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
* @license MIT
*/
'use strict';
const { inject, ref } = require( 'vue' );
const { storeToRefs } = require( 'pinia' );
const useMainStore = require( '../store/index.js' );
const { getZMonolingualLangValue } = require( '../utils/zobjectUtils.js' );
/**
* Page Title composable
*
* @return {Object} Page Title composable API
*/
module.exports = function usePageTitle() {
const i18n = inject( 'i18n' );
const pageTitleObject = ref( {} );
const mainStore = useMainStore();
const {
getFallbackLanguageZids,
getLabelData,
getLanguageIsoCodeOfZLang,
getUserLangZid,
getZObjectByKeyPath,
getZPersistentName
} = storeToRefs( mainStore );
/**
* Update the page title and language chip based on the provided data.
* - First construct a new page title object based on the provided name.
* - Then update the DOM elements of page title and language chip based on the new object.
*/
function updatePageTitle() {
updatePageTitleObject();
updatePageTitleElements();
}
/**
* Update the DOM elements of page title and language chip based on the provided data
* - page title: update the page title with the provided title
* - language chip: update the language chip with the provided language code
*/
function updatePageTitleElements() {
// eslint-disable-next-line no-jquery/no-global-selector
const $firstHeading = $( '#firstHeading' );
const $langChip = $firstHeading.find( '.ext-wikilambda-editpage-header__bcp47-code-name' );
const $pageTitle = $firstHeading.find( '.ext-wikilambda-editpage-header__title--function-name' ).first();
// Update the title
$pageTitle
.toggleClass( 'ext-wikilambda-editpage-header__title--untitled', !pageTitleObject.value.title )
.text( pageTitleObject.value.title || i18n( 'wikilambda-editor-default-name' ).text() );
// Update the language chip
$langChip
.toggleClass( 'ext-wikilambda-editpage-header__bcp47-code--hidden', !pageTitleObject.value.hasChip )
.text( pageTitleObject.value.chip )
.attr( 'data-title', pageTitleObject.value.chipName );
}
/**
* Update the page title object based on the provided name;
* - Is there a title in my language?
* - Yes: { title: "Title", hasChip: false }
* - No: for each lang in fallback languages [ "A", "B", "C" ], check:
* - Is there a title in a fallback language?
* - Yes: { title: "Title", hasChip: true }
* - No: { title: null, hasChip: false }
* Finally update the title DOM elements to reflect the new state.
*/
function updatePageTitleObject() {
const name = getZPersistentName.value( getUserLangZid.value );
pageTitleObject.value = pageTitleObject.value || {};
// Is there a title in my language?
if ( name ) {
// Yes
setPageTitleObject( name, false );
} else {
// No
const fallbackLanguages = getFallbackLanguageZids.value
.slice( getFallbackLanguageZids.value.indexOf( getUserLangZid.value ) + 1 );
// Is there a title in a fallback language?
const hasTitle = fallbackLanguages.some( ( lang ) => {
const fallbackName = getZPersistentName.value( lang );
// Yes, title in a fallback language
if ( fallbackName ) {
setPageTitleObject( fallbackName, true );
return true;
}
// No, no title available in a fallback language
return false;
} );
// No title available in any language
if ( !hasTitle ) {
setPageTitleObject( null, false );
}
}
}
/**
* Set the page title object based on the provided name object and chip flag
*
* @param {Object} name - terminal value to set as a title, contains value and keyPath
* @param {boolean} hasChip - flag to indicate if the language chip should be displayed
*/
function setPageTitleObject( name, hasChip ) {
if ( name ) {
const parentKeyPath = name.keyPath.split( '.' ).slice( 0, -2 );
const monolingual = getZObjectByKeyPath.value( parentKeyPath );
const langZid = getZMonolingualLangValue( monolingual );
const langCode = getLanguageIsoCodeOfZLang.value( langZid );
pageTitleObject.value.title = name.value;
pageTitleObject.value.hasChip = hasChip;
pageTitleObject.value.chip = langCode;
pageTitleObject.value.chipName = getLabelData.value( langZid ).label;
} else {
pageTitleObject.value.title = null;
pageTitleObject.value.hasChip = false;
pageTitleObject.value.chip = null;
pageTitleObject.value.chipName = null;
}
}
return {
pageTitleObject,
getFallbackLanguageZids,
getLabelData,
getLanguageIsoCodeOfZLang,
getUserLangZid,
getZObjectByKeyPath,
getZPersistentName,
updatePageTitle,
updatePageTitleElements,
updatePageTitleObject,
setPageTitleObject
};
};
|