From a37311eb3875b60f4f9e48fabc38972352cdbc91 Mon Sep 17 00:00:00 2001 From: Vijaya Chandran Mani Date: Tue, 2 Jan 2018 20:26:56 +0000 Subject: [PATCH] Initial commit --- README.md | 25 + composer.json | 7 + ...tity_form_display.node.snippet.default.yml | 81 ++ ...tity_view_display.node.snippet.default.yml | 34 + ...ntity_view_display.node.snippet.teaser.yml | 27 + .../install/entityqueue.entity_queue.faq.yml | 25 + .../install/field.field.node.snippet.body.yml | 21 + ....field.node.snippet.field_snippet_type.yml | 32 + .../field.storage.node.field_snippet_type.yml | 19 + config/install/node.type.snippet.yml | 11 + .../taxonomy.vocabulary.snippet_types.yml | 8 + config/install/views.view.snippets.yml | 745 ++++++++++++++++++ .../0739849e-e0ee-4f86-bb07-97b9c4dff9bc.json | 63 ++ js/smooth_scrolling.js | 57 ++ simplelist.info.yml | 12 + simplelist.libraries.yml | 8 + simplelist.module | 28 + simplelist.permissions.yml | 7 + 18 files changed, 1210 insertions(+) create mode 100644 README.md create mode 100644 composer.json create mode 100644 config/install/core.entity_form_display.node.snippet.default.yml create mode 100644 config/install/core.entity_view_display.node.snippet.default.yml create mode 100644 config/install/core.entity_view_display.node.snippet.teaser.yml create mode 100644 config/install/entityqueue.entity_queue.faq.yml create mode 100644 config/install/field.field.node.snippet.body.yml create mode 100644 config/install/field.field.node.snippet.field_snippet_type.yml create mode 100644 config/install/field.storage.node.field_snippet_type.yml create mode 100644 config/install/node.type.snippet.yml create mode 100644 config/install/taxonomy.vocabulary.snippet_types.yml create mode 100644 config/install/views.view.snippets.yml create mode 100644 content/taxonomy_term/0739849e-e0ee-4f86-bb07-97b9c4dff9bc.json create mode 100644 js/smooth_scrolling.js create mode 100644 simplelist.info.yml create mode 100644 simplelist.libraries.yml create mode 100644 simplelist.module create mode 100644 simplelist.permissions.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..49ae162 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +## Simple List +Simplelist module provides set of configurations to create simple list page like drupal.org [FAQ](https://www.drupal.org/about/faq) page. + +### How does it work? + +This module provides snippet **content type** with snippet type **taxonomy vocabulary** to create content in different categories. Using [entityqueue]() module to list/order snippets and [views]() module to expose page. All these content can be easily updated to work with different use-cases. + +### Install + +1. Install module usual. +2. Create term (e.g. FAQ) under [snippet types]() taxonomy +3. Create new [snippet]() nodes +4. Update [view page display]() field with new term created in step 2. + +### Create new page + +Additional pages can be created by: +1. Create new term. +2. Create snippet nodes with new term +3. Create new node queue and add new nodes. +4. copying both page and attachment displays. +5. Update term and node queue details in both displays. + +#### Screenshots +![Simplelist](https://user-images.githubusercontent.com/1220029/34498438-765aeeea-eff9-11e7-896e-7ebc075a354d.gif) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..328a11d --- /dev/null +++ b/composer.json @@ -0,0 +1,7 @@ +{ + "name": "drupal/simplelist", + "description": "Provides an easy way to build simple FAQ like list pages.", + "type": "drupal-module", + "homepage": "http://drupal.org/project/simplelist", + "license": "GPL-2.0+" +} diff --git a/config/install/core.entity_form_display.node.snippet.default.yml b/config/install/core.entity_form_display.node.snippet.default.yml new file mode 100644 index 0000000..d32c623 --- /dev/null +++ b/config/install/core.entity_form_display.node.snippet.default.yml @@ -0,0 +1,81 @@ +langcode: en +status: true +dependencies: + config: + - field.field.node.snippet.body + - field.field.node.snippet.field_snippet_type + - node.type.snippet + module: + - path + - text +id: node.snippet.default +targetEntityType: node +bundle: snippet +mode: default +content: + body: + type: text_textarea_with_summary + weight: 2 + settings: + rows: 9 + summary_rows: 3 + placeholder: '' + third_party_settings: { } + region: content + created: + type: datetime_timestamp + weight: 4 + region: content + settings: { } + third_party_settings: { } + field_snippet_type: + weight: 1 + settings: { } + third_party_settings: { } + type: options_select + region: content + path: + type: path + weight: 7 + region: content + settings: { } + third_party_settings: { } + promote: + type: boolean_checkbox + settings: + display_label: true + weight: 5 + region: content + third_party_settings: { } + status: + type: boolean_checkbox + settings: + display_label: true + weight: 8 + region: content + third_party_settings: { } + sticky: + type: boolean_checkbox + settings: + display_label: true + weight: 6 + region: content + third_party_settings: { } + title: + type: string_textfield + weight: 0 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + uid: + type: entity_reference_autocomplete + weight: 3 + settings: + match_operator: CONTAINS + size: 60 + placeholder: '' + region: content + third_party_settings: { } +hidden: { } diff --git a/config/install/core.entity_view_display.node.snippet.default.yml b/config/install/core.entity_view_display.node.snippet.default.yml new file mode 100644 index 0000000..f779e56 --- /dev/null +++ b/config/install/core.entity_view_display.node.snippet.default.yml @@ -0,0 +1,34 @@ +langcode: en +status: true +dependencies: + config: + - field.field.node.snippet.body + - field.field.node.snippet.field_snippet_type + - node.type.snippet + module: + - text + - user +id: node.snippet.default +targetEntityType: node +bundle: snippet +mode: default +content: + body: + label: hidden + type: text_default + weight: 101 + settings: { } + third_party_settings: { } + region: content + field_snippet_type: + weight: 102 + label: above + settings: + link: true + third_party_settings: { } + type: entity_reference_label + region: content + links: + weight: 100 + region: content +hidden: { } diff --git a/config/install/core.entity_view_display.node.snippet.teaser.yml b/config/install/core.entity_view_display.node.snippet.teaser.yml new file mode 100644 index 0000000..9697ffa --- /dev/null +++ b/config/install/core.entity_view_display.node.snippet.teaser.yml @@ -0,0 +1,27 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.teaser + - field.field.node.snippet.body + - node.type.snippet + module: + - text + - user +id: node.snippet.teaser +targetEntityType: node +bundle: snippet +mode: teaser +content: + body: + label: hidden + type: text_summary_or_trimmed + weight: 101 + settings: + trim_length: 600 + third_party_settings: { } + region: content + links: + weight: 100 + region: content +hidden: { } diff --git a/config/install/entityqueue.entity_queue.faq.yml b/config/install/entityqueue.entity_queue.faq.yml new file mode 100644 index 0000000..51e46a5 --- /dev/null +++ b/config/install/entityqueue.entity_queue.faq.yml @@ -0,0 +1,25 @@ +langcode: en +status: true +dependencies: + module: + - node +id: faq +label: FAQ +handler: simple +handler_configuration: { } +entity_settings: + target_type: node + handler: 'default:node' + handler_settings: + target_bundles: + snippet: snippet + sort: + field: title + direction: ASC + auto_create: false + auto_create_bundle: '' +queue_settings: + min_size: 0 + max_size: 0 + act_as_queue: false + reverse_in_admin: false diff --git a/config/install/field.field.node.snippet.body.yml b/config/install/field.field.node.snippet.body.yml new file mode 100644 index 0000000..4d1c3f0 --- /dev/null +++ b/config/install/field.field.node.snippet.body.yml @@ -0,0 +1,21 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.body + - node.type.snippet + module: + - text +id: node.snippet.body +field_name: body +entity_type: node +bundle: snippet +label: Body +description: '' +required: false +translatable: true +default_value: { } +default_value_callback: '' +settings: + display_summary: true +field_type: text_with_summary diff --git a/config/install/field.field.node.snippet.field_snippet_type.yml b/config/install/field.field.node.snippet.field_snippet_type.yml new file mode 100644 index 0000000..9c347f0 --- /dev/null +++ b/config/install/field.field.node.snippet.field_snippet_type.yml @@ -0,0 +1,32 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_snippet_type + - node.type.snippet + - taxonomy.vocabulary.snippet_type + content: + - 'taxonomy_term:snippet_type:0739849e-e0ee-4f86-bb07-97b9c4dff9bc' +id: node.snippet.field_snippet_type +field_name: field_snippet_type +entity_type: node +bundle: snippet +label: Type +description: '' +required: true +translatable: false +default_value: + - + target_uuid: 0739849e-e0ee-4f86-bb07-97b9c4dff9bc +default_value_callback: '' +settings: + handler: 'default:taxonomy_term' + handler_settings: + target_bundles: + snippet_type: snippet_type + sort: + field: name + direction: asc + auto_create: false + auto_create_bundle: '' +field_type: entity_reference diff --git a/config/install/field.storage.node.field_snippet_type.yml b/config/install/field.storage.node.field_snippet_type.yml new file mode 100644 index 0000000..a1c76ca --- /dev/null +++ b/config/install/field.storage.node.field_snippet_type.yml @@ -0,0 +1,19 @@ +langcode: en +status: true +dependencies: + module: + - node + - taxonomy +id: node.field_snippet_type +field_name: field_snippet_type +entity_type: node +type: entity_reference +settings: + target_type: taxonomy_term +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/config/install/node.type.snippet.yml b/config/install/node.type.snippet.yml new file mode 100644 index 0000000..4ae4194 --- /dev/null +++ b/config/install/node.type.snippet.yml @@ -0,0 +1,11 @@ +langcode: en +status: true +dependencies: {} +third_party_settings: {} +name: Snippet +type: snippet +description: 'Simple content type with title and Description for simple list.' +help: '' +new_revision: true +preview_mode: 1 +display_submitted: true diff --git a/config/install/taxonomy.vocabulary.snippet_types.yml b/config/install/taxonomy.vocabulary.snippet_types.yml new file mode 100644 index 0000000..c951e17 --- /dev/null +++ b/config/install/taxonomy.vocabulary.snippet_types.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +name: 'Snippet types' +vid: snippet_types +description: 'Snippet category' +hierarchy: 0 +weight: 0 diff --git a/config/install/views.view.snippets.yml b/config/install/views.view.snippets.yml new file mode 100644 index 0000000..fc48077 --- /dev/null +++ b/config/install/views.view.snippets.yml @@ -0,0 +1,745 @@ +langcode: en +status: true +dependencies: + config: + - entityqueue.entity_queue.faq + - field.storage.node.body + - node.type.snippet + - taxonomy.vocabulary.snippet_type + content: + - 'taxonomy_term:snippet_type:0739849e-e0ee-4f86-bb07-97b9c4dff9bc' + module: + - entityqueue + - node + - taxonomy + - text + - user +id: snippets +label: Snippets +module: views +description: '' +tag: '' +base_table: node_field_data +base_field: nid +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: 0 + display_options: + access: + type: perm + options: + perm: 'access simplelist' + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: none + options: + offset: 0 + style: + type: html_list + options: + grouping: { } + row_class: '' + default_row_class: true + type: ol + wrapper_class: item-list + class: '' + row: + type: fields + fields: + title: + id: title + table: node_field_data + field: title + entity_type: node + entity_field: title + alter: + alter_text: false + make_link: false + absolute: false + trim: false + word_boundary: false + ellipsis: false + strip_tags: false + html: false + hide_empty: false + empty_zero: false + settings: + link_to_entity: true + plugin_id: field + relationship: none + group_type: group + admin_label: '' + label: Title + exclude: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: true + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_alter_empty: true + click_sort_column: value + type: string + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + body: + id: body + table: node__body + field: body + plugin_id: field + filters: + status: + value: '1' + table: node_field_data + field: status + plugin_id: boolean + entity_type: node + entity_field: status + id: status + expose: + operator: '' + group: 1 + type: + id: type + table: node_field_data + field: type + value: + snippet: snippet + entity_type: node + entity_field: type + plugin_id: bundle + field_snippet_type_target_id: + id: field_snippet_type_target_id + table: node__field_snippet_type + field: field_snippet_type_target_id + relationship: none + group_type: group + admin_label: '' + operator: or + value: + 1: 1 + group: 1 + exposed: false + expose: + operator_id: '' + label: '' + description: '' + use_operator: false + operator: '' + identifier: '' + required: false + remember: false + multiple: false + remember_roles: + authenticated: authenticated + reduce: false + is_grouped: false + group_info: + label: '' + description: '' + identifier: '' + optional: true + widget: select + multiple: false + remember: false + default_group: All + default_group_multiple: { } + group_items: { } + reduce_duplicates: false + type: select + limit: true + vid: snippet_type + hierarchy: false + error_message: true + plugin_id: taxonomy_index_tid + sorts: { } + title: Snippets + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + display_extenders: { } + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - user + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:field.storage.node.body' + attachment_1: + display_plugin: attachment + id: attachment_1 + display_title: 'FAQ Attachment' + position: 3 + display_options: + display_extenders: { } + relationships: + entityqueue_relationship: + id: entityqueue_relationship + table: node_field_data + field: entityqueue_relationship + relationship: none + group_type: group + admin_label: 'Content queue' + required: false + limit_queue: faq + entity_type: node + plugin_id: entity_queue + defaults: + relationships: false + title: false + fields: false + title: 'FAQ Attachement' + display_description: '' + attachment_position: after + displays: + page_2: page_2 + fields: + nid: + id: nid + table: node_field_data + field: nid + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: nid + plugin_id: field + title: + id: title + table: node_field_data + field: title + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '{{ title }}' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: false + ellipsis: false + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: strong + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: title + plugin_id: field + body: + id: body + table: node__body + field: body + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: text_default + settings: { } + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + plugin_id: field + pager: + type: none + options: + offset: 0 + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - user + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:entityqueue.entity_queue.faq' + - 'config:field.storage.node.body' + - entity_field_info + - views_data + page_1: + display_plugin: page + id: page_1 + display_title: Admin + position: 1 + display_options: + display_extenders: { } + path: admin/content/snippets + style: + type: table + options: + grouping: { } + row_class: '' + default_row_class: true + override: true + sticky: false + caption: '' + summary: '' + description: '' + columns: + title: title + info: + title: + sortable: false + default_sort_order: asc + align: '' + separator: '' + empty_column: false + responsive: '' + default: '-1' + empty_table: false + defaults: + style: false + row: false + access: false + pager: false + filters: false + filter_groups: false + row: + type: fields + options: { } + display_description: '' + access: + type: perm + options: + perm: 'administer simplelist' + pager: + type: mini + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + tags: + previous: ‹‹ + next: ›› + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + filters: + status: + value: '1' + table: node_field_data + field: status + plugin_id: boolean + entity_type: node + entity_field: status + id: status + expose: + operator: '' + group: 1 + type: + id: type + table: node_field_data + field: type + value: + snippet: snippet + entity_type: node + entity_field: type + plugin_id: bundle + filter_groups: + operator: AND + groups: + 1: AND + cache_metadata: + max-age: 0 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:field.storage.node.body' + page_2: + display_plugin: page + id: page_2 + display_title: 'FAQ Page' + position: 2 + display_options: + display_extenders: { } + title: 'Frequently Asked Questions' + defaults: + title: false + relationships: false + fields: false + sorts: false + header: false + path: faq + relationships: + entityqueue_relationship: + id: entityqueue_relationship + table: node_field_data + field: entityqueue_relationship + relationship: none + group_type: group + admin_label: 'Content queue' + required: false + limit_queue: faq + entity_type: node + plugin_id: entity_queue + fields: + nid: + id: nid + table: node_field_data + field: nid + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: true + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: number_integer + settings: + thousand_separator: '' + prefix_suffix: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: nid + plugin_id: field + title: + id: title + table: node_field_data + field: title + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: true + path: '/faq#snippet-{{ nid }}' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: false + ellipsis: false + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: node + entity_field: title + plugin_id: field + sorts: + entityqueue_relationship: + id: entityqueue_relationship + table: node_field_data + field: entityqueue_relationship + relationship: none + group_type: group + admin_label: '' + order: ASC + exposed: false + expose: + label: '' + entity_type: node + plugin_id: entity_queue_position + display_description: '' + header: + area: + id: area + table: views + field: area + relationship: none + group_type: group + admin_label: '' + empty: false + tokenize: false + content: + value: 'FAQ description (update at view header area).' + format: basic_html + plugin_id: text + cache_metadata: + max-age: -1 + contexts: + - 'languages:language_content' + - 'languages:language_interface' + - user + - 'user.node_grants:view' + - user.permissions + tags: + - 'config:entityqueue.entity_queue.faq' + - entity_field_info + - views_data diff --git a/content/taxonomy_term/0739849e-e0ee-4f86-bb07-97b9c4dff9bc.json b/content/taxonomy_term/0739849e-e0ee-4f86-bb07-97b9c4dff9bc.json new file mode 100644 index 0000000..ba59ea0 --- /dev/null +++ b/content/taxonomy_term/0739849e-e0ee-4f86-bb07-97b9c4dff9bc.json @@ -0,0 +1,63 @@ +{ + "_links": { + "self": { + "href": "http:\/\/default\/taxonomy\/term\/1?_format=hal_json" + }, + "type": { + "href": "http:\/\/drupal.org\/rest\/type\/taxonomy_term\/snippet_type" + } + }, + "tid": [ + { + "value": 1 + } + ], + "uuid": [ + { + "value": "0739849e-e0ee-4f86-bb07-97b9c4dff9bc" + } + ], + "langcode": [ + { + "value": "en", + "lang": "en" + } + ], + "vid": [ + { + "target_id": "snippet_type" + } + ], + "name": [ + { + "value": "FAQ", + "lang": "en" + } + ], + "weight": [ + { + "value": 0 + } + ], + "changed": [ + { + "value": "2018-01-02T18:51:39+00:00", + "lang": "en", + "format": "Y-m-d\\TH:i:sP" + } + ], + "default_langcode": [ + { + "value": true, + "lang": "en" + } + ], + "path": [ + { + "alias": null, + "pid": null, + "langcode": "en", + "lang": "en" + } + ] +} diff --git a/js/smooth_scrolling.js b/js/smooth_scrolling.js new file mode 100644 index 0000000..3a8a0cd --- /dev/null +++ b/js/smooth_scrolling.js @@ -0,0 +1,57 @@ +/** + * @file + * JavaScript for smooth scrolling. + */ + +(function ($, Drupal) { + + 'use strict'; + + /** + * Attaches the behavior for smooth scrolling. + * + * @type {Drupal~behavior} + */ + Drupal.behaviors.smooth_scrolling = { + attach: function (context, settings) { + if (context !== document) { + return; + } + + // Select all links with hashes in snippets view. + $('.view-snippets a[href*="#"]') + .not('[href="#"]') + .not('[href="#0"]') + .click(function (event) { + // Make sure on-page links. + if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { + // Figure out element to scroll to + var target = $(this.hash); + target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); + // Does a scroll target exist? + if (target.length) { + // Only prevent default if animation is actually gonna happen + event.preventDefault(); + $('html, body').animate({ + scrollTop: target.offset().top + }, 1000, function () { + // Callback after animation + // Must change focus! + var $target = $(target); + $target.focus(); + // Checking if the target was focused. + if ($target.is(":focus")) { + return false; + } else { + // Adding tabindex for elements not focusable. + $target.attr('tabindex', '-1'); + // Set focus again. + $target.focus(); + }; + }); + } + } + }); + } + }; +})(jQuery, Drupal); diff --git a/simplelist.info.yml b/simplelist.info.yml new file mode 100644 index 0000000..6287f7c --- /dev/null +++ b/simplelist.info.yml @@ -0,0 +1,12 @@ +type: module +name: Simple List +description: Provides an easy way to build simple FAQ like list pages. +core: 8.x +dependecies: + - views + - entityqueue + - default_content + +default_content: + taxonomy_term: + - 0739849e-e0ee-4f86-bb07-97b9c4dff9bc diff --git a/simplelist.libraries.yml b/simplelist.libraries.yml new file mode 100644 index 0000000..b4c3795 --- /dev/null +++ b/simplelist.libraries.yml @@ -0,0 +1,8 @@ +smooth_scrolling: + version: VERSION + js: + js/smooth_scrolling.js: {} + dependencies: + - core/jquery + - core/jquery.once + - core/drupal.ajax diff --git a/simplelist.module b/simplelist.module new file mode 100644 index 0000000..6ec4e19 --- /dev/null +++ b/simplelist.module @@ -0,0 +1,28 @@ +display_handler->getPluginId(); + if ($plugin_id == 'attachment' && isset($variables['fields']['title'])) { + $nid = $variables['row']->nid; + /** @var \Drupal\Core\Template\Attribute $wrapper_attributes */ + $wrapper_attributes = $variables['fields']['title']->wrapper_attributes; + // Set an id to do in-page scrolling. + $wrapper_attributes->setAttribute('id', 'snippet-' . $nid); + } +} + +/** + * Implements hook_views_pre_render(). + */ +function simplelist_views_pre_render($view) { + // Add smooth scroll to snippet views. + if ($view->storage->id() == 'snippets' && empty($view->live_preview)) { + $view->element['#attached']['library'][] = 'simplelist/smooth_scrolling'; + } + return $view; +} diff --git a/simplelist.permissions.yml b/simplelist.permissions.yml new file mode 100644 index 0000000..b424f64 --- /dev/null +++ b/simplelist.permissions.yml @@ -0,0 +1,7 @@ +administer simplelist: + title: 'Administer Simple List' + restrict access: true + +access simplelist: + title: 'Access Simple List' + restrict access: true