Browse Source

Added query selector functionality to gather collection of links to be registered

Wirecog 6 years ago
parent
commit
305a19ebc8
3 changed files with 13 additions and 10 deletions
  1. 1
    1
      route.go
  2. 9
    6
      router.go
  3. 3
    3
      templatebundle.go

+ 1
- 1
route.go View File

51
 	for _, routePart := range routeParts {
51
 	for _, routePart := range routeParts {
52
 		if strings.HasPrefix(routePart, `{`) && strings.HasSuffix(routePart, `}`) {
52
 		if strings.HasPrefix(routePart, `{`) && strings.HasSuffix(routePart, `}`) {
53
 			routePattern += RouteWithParamsPattern
53
 			routePattern += RouteWithParamsPattern
54
-			routePart = strings.TrimPrefix(path, `}`)
54
+			routePart = strings.TrimPrefix(path, `{`)
55
 			routePart = strings.TrimSuffix(path, `}`)
55
 			routePart = strings.TrimSuffix(path, `}`)
56
 			r.varNames = append(r.varNames, routePart)
56
 			r.varNames = append(r.varNames, routePart)
57
 		} else {
57
 		} else {

+ 9
- 6
router.go View File

35
 }
35
 }
36
 
36
 
37
 func (r *Router) Listen() {
37
 func (r *Router) Listen() {
38
-	r.RegisterLinks()
38
+	r.RegisterLinks("body a")
39
 }
39
 }
40
 
40
 
41
-func (r *Router) RegisterLinks() {
41
+func (r *Router) RegisterLinks(querySelector string) {
42
 	document := dom.GetWindow().Document().(dom.HTMLDocument)
42
 	document := dom.GetWindow().Document().(dom.HTMLDocument)
43
-	for _, link := range document.Links() {
43
+	links := document.QuerySelectorAll(querySelector)
44
+
45
+	for _, link := range links {
44
 		href := link.GetAttribute("href")
46
 		href := link.GetAttribute("href")
45
 		switch {
47
 		switch {
46
 
48
 
47
 		case strings.HasPrefix(href, "/") && !strings.HasPrefix(href, "//"):
49
 		case strings.HasPrefix(href, "/") && !strings.HasPrefix(href, "//"):
48
 
50
 
49
 			if r.listener != nil {
51
 			if r.listener != nil {
50
-				link.RemoveEventListener("click", true, r.listener)
52
+				link.RemoveEventListener("click", false, r.listener)
51
 			}
53
 			}
52
-			r.listener = link.AddEventListener("click", true, r.linkHandler)
54
+
55
+			r.listener = link.AddEventListener("click", false, r.linkHandler)
53
 		}
56
 		}
54
 	}
57
 	}
55
 }
58
 }
83
 		routeVars := make(map[string]string)
86
 		routeVars := make(map[string]string)
84
 
87
 
85
 		for i, part := range parts {
88
 		for i, part := range parts {
86
-			routeVars[matchedRoute.varNames[i]] = part
89
+			routeVars[matchedRoute.varNames[i]+`}`] = part
87
 		}
90
 		}
88
 
91
 
89
 		var ctx context.Context
92
 		var ctx context.Context

+ 3
- 3
templatebundle.go View File

6
 package isokit
6
 package isokit
7
 
7
 
8
 import (
8
 import (
9
-	"fmt"
10
 	"io/ioutil"
9
 	"io/ioutil"
10
+	"log"
11
 	"os"
11
 	"os"
12
 	"path/filepath"
12
 	"path/filepath"
13
 	"strings"
13
 	"strings"
41
 			t.items[name] = string(contents)
41
 			t.items[name] = string(contents)
42
 
42
 
43
 			if err != nil {
43
 			if err != nil {
44
-				fmt.Println("error encountered while walking directory: ", err)
44
+				log.Println("error encountered while walking directory: ", err)
45
 				return err
45
 				return err
46
 			}
46
 			}
47
 
47
 
68
 			t.items[name] = string(contents)
68
 			t.items[name] = string(contents)
69
 
69
 
70
 			if err != nil {
70
 			if err != nil {
71
-				fmt.Println("error encountered while walking directory: ", err)
71
+				log.Println("error encountered while walking directory: ", err)
72
 				return err
72
 				return err
73
 			}
73
 			}
74
 
74