Skip to content

Commit

Permalink
Fix drivers options
Browse files Browse the repository at this point in the history
  • Loading branch information
parsagholipour committed Oct 3, 2022
1 parent 967b4f6 commit 685fe7d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/assets/styles/style-dropdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
min-height: 2.6em;
}

.sharee__dropdown:not(.sharee__dropdown__row) > *:first-child:last-child {
border-radius: inherit;
}

.sharee__dropdown:not(.sharee__dropdown__row) > *:first-child:not(:last-child) {
border-radius: var(--border-radius) var(--border-radius) 0 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/ShareeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default interface ShareeOptions {
shareLink?: string;
shareText?: string;
ripple?: boolean;
mode?: 'dropdown'|'dropdownRow'|'dropdownGrid'|'text'|'normal'|'fixed';
mode?: 'dropdown'|'text'|'normal'|'fixed';
modeOptions?: any
}

Expand Down
10 changes: 10 additions & 0 deletions src/lib/Sharee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ import BaseStrategy from "./strategies/BaseStrategy";
import strategies from "./strategies";
import merge from 'lodash.merge'
import '../assets/styles/style.css'
import drivers from './drivers'
import Driver from "./drivers/Driver";

export default class Sharee {
public options: ShareeOptions;
public lang: Lang = fa as Lang;
protected strategy: BaseStrategy;
public targetElement: HTMLElement;
public static drivers = {...drivers};


constructor(element: HTMLElement, options: ShareeOptions = shareeDefaultOptions) {
this.targetElement = element;
this.options = merge({}, shareeDefaultOptions, options);
this.options.drivers = options.drivers || this.options.drivers // Shouldn't merge drivers
// @ts-ignore
const strategyClass: new(sharee: Sharee) => BaseStrategy = strategies[this.options.mode!]
if (typeof strategyClass === 'undefined') {
Expand All @@ -27,6 +32,11 @@ export default class Sharee {
});
}

public static addDriver(driverName: string, driver: typeof Driver) {
// @ts-ignore
this.drivers[driverName] = driver
}

protected async init() {
// @ts-ignore
this.targetElement.sharee = this;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/drivers/LinkedinDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export default class LinkedinDriver extends Driver implements hasLink {
}

getLink(): string {
return `https://twitter.com/share?text=${encodeURIComponent(this.options?.shareText!)}&url=${this.options?.shareLink}`
return `https://www.linkedin.com/sharing/share-offsite/?url=${this.options?.shareLink}`
}
}
6 changes: 3 additions & 3 deletions src/lib/strategies/BaseStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Sharee from "../Sharee";
import Lang from "../../common/Lang";
import DriverOptions from "../../common/DriverOptions";
import Driver from "../drivers/Driver";
import drivers from '../drivers'

export default abstract class BaseStrategy {
public abstract render(): void;
Expand All @@ -12,9 +11,10 @@ export default abstract class BaseStrategy {

protected resolveDriver(driverName: string):
(new (lang: Lang, options: DriverOptions) => Driver) {
if (drivers.hasOwnProperty(driverName)) {
console.log(Sharee.drivers)
if (Sharee.drivers.hasOwnProperty(driverName)) {
// @ts-ignore
return drivers[driverName]
return Sharee.drivers[driverName]
} else {
throw new Error(`Unknown driver: ${driverName}`)
}
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './style.css'
import Sharee from "./lib/Sharee";
import initVue from './vue/main';
import initReact from './react/main';
import TelegramDriver from "./lib/drivers/TelegramDriver";

if (document.location.pathname === '/vue') {
initVue()
Expand Down Expand Up @@ -30,10 +31,11 @@ if (document.location.pathname === '/vue') {
</div>
</div>
`

Sharee.addDriver('tel', TelegramDriver)
new Sharee(document.querySelector('#sharee')!, {
mode: 'dropdown',
lang: 'fa'
lang: 'fa',
drivers: ['tel']
})

new Sharee(document.querySelector('#sharee-text')!, {
Expand Down

0 comments on commit 685fe7d

Please sign in to comment.