當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dom.Element類代碼示例

本文整理匯總了Golang中honnef/co/go/js/dom.Element的典型用法代碼示例。如果您正苦於以下問題:Golang Element類的具體用法?Golang Element怎麽用?Golang Element使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Element類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: settingsTab

func settingsTab(c dom.Element) {
	s, err := RPC.Settings()
	if err != nil {
		xjs.Alert("Error reading settings: %s", err)
		return
	}
	sn := xform.InputText("serverName", s.ServerName)
	sn.Required = true
	la := xform.InputText("listenAddr", s.ListenAddr)
	la.Required = true
	sp := xform.InputText("serversPath", s.DirServers)
	sp.Required = true
	mp := xform.InputText("mapsPath", s.DirMaps)
	mp.Required = true
	gp := xform.InputText("gensPath", s.DirGenerators)
	gp.Required = true
	ge := xform.InputText("genExe", s.GeneratorExecutable)
	ge.Required = true
	mm := xform.InputNumber("maxMem", 100, 10000, float64(s.GeneratorMaxMem/1024/1024))
	mm.Required = true
	sb := xform.InputSubmit("Save")
	sb.AddEventListener("click", false, func(e dom.Event) {
		if sn.Value == "" || la.Value == "" || sp.Value == "" || mp.Value == "" || gp.Value == "" || ge.Value == "" || !mm.CheckValidity() {
			return
		}
		e.PreventDefault()
		sb.Disabled = true
		go func() {
			s.ServerName = sn.Value
			s.ListenAddr = la.Value
			s.DirServers = sp.Value
			s.DirMaps = mp.Value
			s.DirGenerators = gp.Value
			s.GeneratorExecutable = ge.Value
			s.GeneratorMaxMem = uint64(mm.ValueAsNumber * 1024 * 1024)
			if err := RPC.SetSettings(s); err != nil {
				xjs.Alert("Error saving settings: %s", err)
				return
			}
			SetTitle(sn.Value)
			span := xdom.Span()
			span.Style().Set("color", "#f00")
			c.AppendChild(xjs.SetInnerText(span, "Saved!"))
			time.Sleep(5 * time.Second)
			c.RemoveChild(span)
			sb.Disabled = false
		}()
	})
	xjs.AppendChildren(c, xjs.AppendChildren(xdom.Form(), xjs.AppendChildren(xdom.Fieldset(),
		xjs.SetInnerText(xdom.Legend(), "Change Settings"),
		xform.Label("Server Name", "serverName"), sn, xdom.Br(),
		xform.Label("Listen Address", "listenAddr"), la, xdom.Br(),
		xform.Label("Servers Path", "serversPath"), sp, xdom.Br(),
		xform.Label("Maps Path", "mapsPath"), mp, xdom.Br(),
		xform.Label("Generators Path", "gensPath"), gp, xdom.Br(),
		xform.Label("Generator Executable", "genExe"), ge, xdom.Br(),
		xform.Label("Generator Memory (MB)", "maxMem"), mm, xdom.Br(),
		sb,
	)))
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:60,代碼來源:settings.go

示例2: addClass

// addClass adds class to the given element. It retains any other classes that
// the element may have.
func addClass(el dom.Element, class string) {
	newClasses := class
	if oldClasses := el.GetAttribute("class"); oldClasses != "" {
		newClasses = oldClasses + " " + class
	}
	el.SetAttribute("class", newClasses)
}
開發者ID:influx6,項目名稱:examples,代碼行數:9,代碼來源:app.go

示例3: OffsetParent

// OffsetParent returns the offset parent element for a specific element.
func OffsetParent(elem dom.Element) *js.Object {
	und := elem.Underlying()

	osp, err := GetProp(und, "offsetParent")
	if err != nil {
		osp = Document().Underlying()
	}

	for osp != nil && !MatchProp(osp, "nodeType", "html") && MatchProp(osp, "style.position", "static") {
		val, err := GetProp(osp, "offsetParent")
		if err != nil {
			break
		}

		osp = val
	}

	return osp
}
開發者ID:influx6,項目名稱:govfx,代碼行數:20,代碼來源:dom.go

示例4: checkParent

func checkParent(target, elm dom.Element) bool {
	for target.ParentElement() != nil {
		if target.IsEqualNode(elm) {
			return true
		}
		target = target.ParentElement()
	}
	return false
}
開發者ID:steveoc64,項目名稱:gopherjs-experiments,代碼行數:9,代碼來源:demo.go

示例5: removeClass

// removeClass removes the given class from the element it retains any other
// classes that the element may have.
func removeClass(el dom.Element, class string) {
	oldClasses := el.GetAttribute("class")
	if oldClasses == class {
		// The only class present was the one we want to remove. Remove the class
		// attribute entirely.
		el.RemoveAttribute("class")
	}
	classList := strings.Split(oldClasses, " ")
	for i, currentClass := range classList {
		if currentClass == class {
			newClassList := append(classList[:i], classList[i+1:]...)
			el.SetAttribute("class", strings.Join(newClassList, " "))
		}
	}
}
開發者ID:influx6,項目名稱:examples,代碼行數:17,代碼來源:app.go

示例6: registerUpdateStopper

func registerUpdateStopper(c dom.Element, updateStop chan struct{}) {
	if c.ParentNode() != nil {
		mutation.New(func(rs []*mutation.Record, o *mutation.Observer) {
			if len(rs) > 0 {
				for _, r := range rs {
					for _, n := range r.RemovedNodes() {
						if c.IsEqualNode(n) {
							o.Disconnect()
							close(updateStop)
							return
						}
					}
				}
			}
		}).Observe(c.ParentNode(), mutation.ObserverInit{ChildList: true})
	}
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:17,代碼來源:utils.go

示例7: BoundingBox

// BoundingBox returns the top,right,down,left corners of a dom.Element.
func BoundingBox(elem dom.Element) (float64, float64, float64, float64) {
	rect := elem.GetBoundingClientRect()
	return rect.Top, rect.Right, rect.Bottom, rect.Left
}
開發者ID:influx6,項目名稱:govfx,代碼行數:5,代碼來源:dom.go

示例8: editProperties

func editProperties(c dom.Element, name string, id int, rpcGet func(int) (map[string]string, error), rpcSet func(id int, properties map[string]string) error) {
	sp, err := rpcGet(id)
	if err != nil {
		c.AppendChild(xjs.SetInnerText(xdom.Div(), "Failed to get properties: "+err.Error()))
		return
	}
	props := make(PropertyList, 0, len(sp))
	for k, v := range sp {
		props = append(props, [2]string{k, v})
	}
	sort.Sort(props)
	propE := make([][2]*dom.HTMLSpanElement, len(props))
	df := xjs.DocumentFragment()

	toggleFunc := func(k, v *dom.HTMLSpanElement, toggle *dom.HTMLInputElement) func(dom.Event) {
		return func(dom.Event) {
			if toggle.Value == "-" {
				k.SetContentEditable("false")
				v.SetContentEditable("false")
				k.Style().SetProperty("background-color", "#888", "")
				v.Style().SetProperty("background-color", "#888", "")
				toggle.Value = "+"
			} else {
				k.SetContentEditable("true")
				v.SetContentEditable("true")
				k.Style().RemoveProperty("background-color")
				v.Style().RemoveProperty("background-color")
				toggle.Value = "-"
			}
		}
	}

	for i, prop := range props {
		k := xform.InputSizeable("", prop[0])
		v := xform.InputSizeable("", prop[1])
		toggle := xform.InputButton("", "-")
		toggle.AddEventListener("click", false, toggleFunc(k, v, toggle))
		propE[i][0] = k
		propE[i][1] = v
		xjs.AppendChildren(df,
			toggle,
			k,
			xjs.SetInnerText(xdom.Span(), "="),
			v,
			xdom.Br(),
		)
	}

	add := xform.InputButton("", "Add")
	submit := xform.InputButton("", "Save")
	fs := xjs.AppendChildren(xdom.Fieldset(),
		xjs.SetInnerText(xdom.Legend(), name+" Properties"),
		df,
		add,
		submit,
	)

	add.AddEventListener("click", false, func(dom.Event) {
		k := xform.InputSizeable("", "")
		v := xform.InputSizeable("", "")
		toggle := xform.InputButton("", "-")
		toggle.AddEventListener("click", false, toggleFunc(k, v, toggle))
		propE = append(propE, [2]*dom.HTMLSpanElement{k, v})
		fs.InsertBefore(toggle, add)
		fs.InsertBefore(k, add)
		fs.InsertBefore(xjs.SetInnerText(xdom.Span(), "="), add)
		fs.InsertBefore(v, add)
		fs.InsertBefore(xdom.Br(), add)
	})

	submit.AddEventListener("click", false, func(dom.Event) {
		submit.Disabled = true
		props := make(map[string]string, len(propE))
		for _, spans := range propE {
			if spans[0].IsContentEditable() {
				props[spans[0].TextContent()] = spans[1].TextContent()
			}
		}
		go func() {
			err := rpcSet(id, props)
			if err != nil {
				xjs.Alert("Error setting "+name+" properties: %s", err)
				return
			}
			span := xdom.Span()
			span.Style().Set("color", "#f00")
			fs.AppendChild(xjs.SetInnerText(span, "Saved!"))
			time.Sleep(5 * time.Second)
			fs.RemoveChild(span)
			submit.Disabled = false
		}()
	})

	xjs.AppendChildren(c, xjs.AppendChildren(xdom.Form(), fs))
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:95,代碼來源:utils.go


注:本文中的honnef/co/go/js/dom.Element類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。