func replace(t jquery.JQuery) { href := t.Attr("href") id := t.Attr("replace") if len(id) == 0 || len(href) == 0 { log.Printf("%s: replace fails id '%s' href '%s'", currentPath, id, href) return } if page, doc, _ := mySite.Match(href); page == nil { log.Printf("page not found %s", href) } else { idSelector := "#" + id elt := jq(idSelector) if elt.Length > 0 { currentPath = href bn := doc.BodyNodeById[id] elt.ReplaceWith(bn.Markup(doc)) doc.AddBodyNodeEventListeners(document, bn) // Select again since we've just changed it. elt := jq(idSelector) jqBind(elt) elt.Call("foundation", "reflow") // Change displayed page path without reloading page. window.Get("history").Call("pushState", "object or string", "Title", href) } } }
func getDrawerListener(c jquery.JQuery) (d canvas.Drawer, l canvas.Listener) { id := c.Attr("id") page := mySite.PageByPath[currentPath] switch p := page.(type) { case canvas.Interface: var ok bool if d, ok = p.Drawer(id); !ok { log.Printf("%s: no canvas drawer for id '%s'", currentPath, id) } l, _ = p.Listener(id) default: log.Printf("%s: found canvas on page with no interface", currentPath) } return }
func canvasDraw(c jquery.JQuery) { if c.Attr("width") == "" && c.Attr("height") == "" { // Determine height from aspect ratio and parent's width. aspect := 1.5 // 3 by 2 aspect ratio attr := c.Attr("aspect") if attr != "" { _, err := fmt.Sscanf(attr, "%f", &aspect) if err != nil { panic(err) } } parent := c.Parent() w := parent.Width() c.SetAttr("width", w) c.SetAttr("height", float64(w)/aspect) } d, _ := getDrawerListener(c) if d != nil { go d.Draw(canvasContext(c)) } }