-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from YUCLing/some-refactors
Frontend refactors
- Loading branch information
Showing
8 changed files
with
1,973 additions
and
4,244 deletions.
There are no files selected for viewing
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
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.
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,74 @@ | ||
import app from 'flarum/forum/app'; | ||
import {extend} from 'flarum/common/extend'; | ||
import CommentPost from 'flarum/forum/components/CommentPost'; | ||
|
||
import {Carousel, Fancybox} from '@fancyapps/ui'; | ||
|
||
app.initializers.add('darkle/fancybox', () => { | ||
extend(CommentPost.prototype, 'refreshContent', function () { | ||
if (this.isEditing()) return; | ||
|
||
const postBody = this.$('.Post-body'); | ||
if (postBody.length == 0) return; | ||
|
||
// Initialize Carousel for each gallery | ||
postBody.children('.fancybox-gallery:not(.fancybox-ready)') // The galleries should be only at the first level of Post-body | ||
.addClass('fancybox-ready') | ||
.each((_, gallery) => { | ||
new Carousel(gallery, { | ||
Dots: false, | ||
infinite: false, | ||
dragFree: false, | ||
preload: 0, | ||
}); | ||
}); | ||
|
||
postBody.find('a[data-fancybox]:not(.fancybox-ready)') | ||
.addClass('fancybox-ready') | ||
.each((_, el) => { | ||
const link = $(el); | ||
let isDragging = false; | ||
let startX: number, startY: number; | ||
|
||
link | ||
.on('mousedown', (e) => { | ||
isDragging = false; | ||
startX = e.clientX; | ||
startY = e.clientY; | ||
}) | ||
.on('mousemove', (e) => { | ||
if (Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5) { | ||
isDragging = true; | ||
} | ||
}) | ||
.on('click', (e) => { | ||
e.preventDefault(); | ||
if (isDragging) return; | ||
const groupName = link.attr('data-fancybox'); | ||
const carouselEl = link.closest('.fancybox-gallery'); | ||
const group = (carouselEl.length > 0 ? carouselEl : postBody).find(`a[data-fancybox="${groupName}"]`).toArray(); | ||
const startIndex = group.indexOf(el); | ||
|
||
Fancybox.fromNodes(group, { | ||
Carousel: { | ||
infinite: false, | ||
preload: 0, | ||
}, | ||
Toolbar: { | ||
display: { | ||
left: ['infobar'], | ||
middle: ['rotateCCW', 'rotateCW', 'flipX', 'flipY'], | ||
right: ['slideshow', 'fullscreen', 'close'], | ||
}, | ||
}, | ||
Images: { | ||
initialSize: 'fit' as 'fit', | ||
}, | ||
dragToClose: true, | ||
Hash: false, | ||
startIndex, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
{ | ||
// Use Flarum's tsconfig as a starting point | ||
"extends": "flarum-tsconfig", | ||
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder | ||
// and also tells your Typescript server to read core's global typings for | ||
// access to `dayjs` and `$` in the global namespace. | ||
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"], | ||
"compilerOptions": { | ||
// This will output typings to `dist-typings` | ||
"declarationDir": "./dist-typings", | ||
"paths": { | ||
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"] | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
const config = require('flarum-webpack-config'); | ||
const { merge } = require('webpack-merge'); | ||
|
||
const CopyPlugin = require('copy-webpack-plugin'); | ||
|
||
const customConfig = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/i, | ||
use: ['style-loader', 'css-loader'], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new CopyPlugin({ | ||
patterns: [ | ||
{ from: './node_modules/@fancyapps/ui/dist/fancybox/fancybox.css', to: '../../less' }, | ||
{ from: './node_modules/@fancyapps/ui/dist/carousel/carousel.css', to: '../../less' } | ||
] | ||
}) | ||
] | ||
}; | ||
|
||
module.exports = merge(config(), customConfig); |
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