diff --git a/app/View/Components/WowheadLink.php b/app/View/Components/WowheadLink.php new file mode 100644 index 0000000..9700326 --- /dev/null +++ b/app/View/Components/WowheadLink.php @@ -0,0 +1,104 @@ +id = $whId; + $this->type = $type; + $this->href = $href; + $this->renameLink = $renameLink; + $this->iconSize = $iconSize; + $this->domain = $domain ?? config('wowhead.domain'); + } + + /** + * Get the view / contents that represent the component. + * + * @return \Illuminate\Contracts\View\View|\Closure|string + */ + public function render() + { + $attr = collect([ + 'data-wh-rename-link' => $this->renameLink, + 'data-wh-icon-size' => $this->iconSize + ]); + + // If we have custom url, we must set the + // 'data-wowhead' attribute with the options. + if ($this->href) { + $attr['href'] = $this->href; + $attr['data-wowhead'] = $this->formatOptions(); + } + // Otherwise, get a wowhead url that automaticlly will be picked up + // by the javascript code and render a tooltip. + else { + $attr['href'] = $this->renderUrl(); + $attr['target'] = '_blank'; + } + + return view("components.wowhead-link", [ + 'component_attr' => $attr->filter()->toArray() + ]); + } + + /** + * Render a wowhead url. + */ + protected function renderUrl() : string + { + return sprintf('https://%s.wowhead.com/%s=%s', + $this->domain, $this->type, $this->id); + } + + /** + * Format options for 'data-wowhead' attribute. + */ + protected function formatOptions() : string + { + return http_build_query([ + $this->type => $this->id, + 'domain' => $this->domain + ]); + } +} diff --git a/app/View/Components/WowheadScript.php b/app/View/Components/WowheadScript.php new file mode 100644 index 0000000..44dfa23 --- /dev/null +++ b/app/View/Components/WowheadScript.php @@ -0,0 +1,43 @@ +options = collect(config('wowhead')) + ->only(self::$keys) + ->filter(function ($value, $key) { + return is_array($value) ? count($value) : $value !== null; + }); + + return <<<'html' + + + html; + } +} diff --git a/config/wowhead.php b/config/wowhead.php new file mode 100644 index 0000000..371ce92 --- /dev/null +++ b/config/wowhead.php @@ -0,0 +1,87 @@ + 'tbc', + + /* + |-------------------------------------------------------------------------- + | Rename links + |-------------------------------------------------------------------------- + | + | Set this to true to make wowhead replace the name for all wowhead links + | on the page. + | + */ + + 'renameLinks' => false, + + /* + |-------------------------------------------------------------------------- + | Icon Size + |-------------------------------------------------------------------------- + | + | Configure the default size of the icons on the site. Available sizes: + | tiny (the default), small, medium, and large. + | + */ + + 'iconSize' => 'small', + + /* + |-------------------------------------------------------------------------- + | Iconize Links + |-------------------------------------------------------------------------- + | + | Set to true if icons should be added to all links. If you set this to + | false, you can allow _some_ links on the site to have an icon by + | setting the `icon-size=` attribute on individual links. + | + */ + + 'iconizeLinks' => true, + + /* + |-------------------------------------------------------------------------- + | Color Links + |-------------------------------------------------------------------------- + | + | Set to true if wowhead should automatically set link text color + | for all links on the page. + | + */ + + 'colorLinks' => false, + + /* + |-------------------------------------------------------------------------- + | Disabling components + |-------------------------------------------------------------------------- + | + | You can disable some components in the tooltip by setting the component + | in question to true. + | + */ + + "hide" => [ + // "maxstack" => true, + // "droppedby" => true, + // "dropchance" => true, + // "reagents" => true, + // "ilvl" => true, + // "extra" => true, + // "sellprice" => true + ], + +]; diff --git a/resources/views/components/wowhead-link.blade.php b/resources/views/components/wowhead-link.blade.php new file mode 100644 index 0000000..b4b9872 --- /dev/null +++ b/resources/views/components/wowhead-link.blade.php @@ -0,0 +1,3 @@ +merge($component_attr) }}> + {{ $slot }} +