gosora/common/module_ottojs.go
Azareal 8f2f47e8aa Added the In-Progress Widget Manager UI.
Added the IsoCode field to phrase files.
Rewrote a good portion of the widget system logic.
Added some tests for the widget system.
Added the Online Users widget.
Added a few sealed incomplete widgets like the Search & Filter Widget.
Added the AllUsers method to WsHubImpl for Online Users. Please don't abuse it.

Added the optional *DBTableKey field to AddColumn.
Added the panel_analytics_time_range template to reduce the amount of duplication.
Failed registrations now show up in red in the registration logs for Nox.
Failed logins now show up in red in the login logs for Nox.
Added basic h2 CSS to the other themes.
Added .show_on_block_edit and .hide_on_block_edit to the other themes.
Updated contributing.
Updated a bunch of dates to 2019.
Replaced tblKey{} with nil where possible.
Switched out some &s for &s to reduce the number of possible bugs.
Fixed a bug with selector messages where the inspector would get really jittery due to unnecessary DOM updates.
Moved header.Zone and associated fields to the bottom of ViewTopic to reduce the chances of problems arising.
Added the ZoneData field to *Header.
Added IDs to the items in the forum list template.
Split the fetchPhrases function into the initPhrases and fetchPhrases functions in init.js
Added .colstack_sub_head.
Fixed the CSS in the menu list.
Removed an inline style from the simple topic like and unlike buttons.
Removed an inline style from the simple topic IP button.
Simplified the LoginRequired error handler.
Fixed a typo in the comment prior to DatabaseError()
Reduce the number of false leaves for WebSocket page transitions.
Added the error zone.
De-duped the logic in WsHubImpl.getUsers.
Fixed a potential widget security issue.

Added twenty new phrases.
Added the wid column to the widgets table.

You will need to run the patcher / updater for this commit.
2019-01-21 22:27:59 +10:00

100 lines
1.8 KiB
Go

/*
*
* OttoJS Plugin Module
* Copyright Azareal 2016 - 2019
*
*/
package common
import (
"errors"
"github.com/robertkrimen/otto"
)
type OttoPluginLang struct {
vm *otto.Otto
plugins map[string]*otto.Script
vars map[string]*otto.Object
}
func init() {
pluginLangs["ottojs"] = &OttoPluginLang{
plugins: make(map[string]*otto.Script),
vars: make(map[string]*otto.Object),
}
}
func (js *OttoPluginLang) Init() (err error) {
js.vm = otto.New()
js.vars["current_page"], err = js.vm.Object(`var current_page = {}`)
return err
}
func (js *OttoPluginLang) GetName() string {
return "ottojs"
}
func (js *OttoPluginLang) GetExts() []string {
return []string{".js"}
}
func (js *OttoPluginLang) AddPlugin(meta PluginMeta) (plugin *Plugin, err error) {
script, err := js.vm.Compile("./extend/"+meta.UName+"/"+meta.Main, nil)
if err != nil {
return nil, err
}
var pluginInit = func() error {
retValue, err := js.vm.Run(script)
if err != nil {
return err
}
if retValue.IsString() {
ret, err := retValue.ToString()
if err != nil {
return err
}
if ret != "" {
return errors.New(ret)
}
}
return nil
}
plugin = new(Plugin)
plugin.UName = meta.UName
plugin.Name = meta.Name
plugin.Author = meta.Author
plugin.URL = meta.URL
plugin.Settings = meta.Settings
plugin.Tag = meta.Tag
plugin.Type = "ottojs"
plugin.Init = pluginInit
// TODO: Implement plugin life cycle events
buildPlugin(plugin)
plugin.Data = script
return plugin, nil
}
/*func (js *OttoPluginLang) addHook(hook string, plugin string) {
hooks[hook] = func(data interface{}) interface{} {
switch d := data.(type) {
case Page:
currentPage := js.vars["current_page"]
currentPage.Set("Title", d.Title)
case TopicPage:
case ProfilePage:
case Reply:
default:
log.Print("Not a valid JS datatype")
}
}
}*/