forked from discourse/discourse-category-banners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTOR: full component refactoring
- drops jquery - uses new codelayout structure - more explicit site setting - apply code standards - various cleanups - do not show an empty category-title-desription if we don't show the category description
- Loading branch information
Showing
11 changed files
with
1,711 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "eslint-config-discourse", | ||
"globals": { | ||
"settings": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
plugins: ["ember-template-lint-plugin-discourse"], | ||
extends: "discourse:recommended" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
javascripts/discourse/connectors/below-site-header/category-header-widget.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{mount-widget widget="category-header-widget"}} |
15 changes: 15 additions & 0 deletions
15
javascripts/discourse/initializers/discourse-category-banners.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { withPluginApi } from "discourse/lib/plugin-api"; | ||
|
||
export default { | ||
name: "discourse-category-banners", | ||
|
||
initialize() { | ||
withPluginApi("0.8", (api) => { | ||
api.decorateWidget("category-header-widget:after", (helper) => { | ||
helper.widget.appEvents.on("page:changed", () => { | ||
helper.widget.scheduleRerender(); | ||
}); | ||
}); | ||
}); | ||
}, | ||
}; |
73 changes: 73 additions & 0 deletions
73
javascripts/discourse/widgets/category-header-widget.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { h } from "virtual-dom"; | ||
import { iconNode } from "discourse-common/lib/icon-library"; | ||
import { createWidget } from "discourse/widgets/widget"; | ||
|
||
function buildCategory(category) { | ||
const content = []; | ||
|
||
if (category.read_restricted) { | ||
content.push(iconNode("lock")); | ||
} | ||
|
||
content.push(h("h1.category-title", category.name)); | ||
|
||
if (settings.show_description) { | ||
content.push( | ||
h( | ||
"div.category-title-description", | ||
h("div.cooked", { innerHTML: category.description }) | ||
) | ||
); | ||
} | ||
|
||
return content; | ||
} | ||
|
||
export default createWidget("category-header-widget", { | ||
tagName: "span.discourse-category-banners", | ||
|
||
html() { | ||
const path = window.location.pathname; | ||
const category = this.register | ||
.lookup("controller:navigation/category") | ||
.get("category"); | ||
|
||
if (!category) { | ||
return; | ||
} | ||
|
||
const isException = settings.exceptions | ||
.split("|") | ||
.filter(Boolean) | ||
.includes(category.name); | ||
|
||
if (/^\/c\//.test(path)) { | ||
const hideMobile = !settings.show_mobile && this.site.mobileView; | ||
const isSubCategory = | ||
!settings.show_subcategory && category.parentCategory; | ||
const hasNoCategoryDescription = | ||
settings.hide_if_no_description && !category.description_text; | ||
|
||
if ( | ||
!isException && | ||
!hasNoCategoryDescription && | ||
!isSubCategory && | ||
!hideMobile | ||
) { | ||
document.body.classList.add("category-header"); | ||
|
||
return h( | ||
`div.category-title-header.category-banner-${category.slug}`, | ||
{ | ||
attributes: { | ||
style: `background-color: #${category.color}; color: #${category.text_color};`, | ||
}, | ||
}, | ||
h("div.category-title-contents", buildCategory(category)) | ||
); | ||
} | ||
} else { | ||
document.body.classList.remove("category-header"); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"author": "Discourse", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"eslint-config-discourse": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.