示例#1
0
// JQMRouteOnce ensures that each jQuery Mobile page is only routed once, even when the event is triggered twice (which is common for certain events)
func JQMRouteOnce(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, p url.Values) bool {
		if ui.Get("_jqmrouteonce").Bool() {
			fmt.Printf("pagecontainerbeforechange already ran. Skipping.\n")
			return true
		}
		ui.Set("_jqmrouteonce", true)
		return h.HandleEvent(event, ui, p)
	})
}
示例#2
0
func SetupSyncButton(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, p url.Values) bool {
		fmt.Printf("Setting up the button\n")
		btn := jQuery("[data-id='syncbutton']")
		btn.Off("click")
		btn.On("click", SyncButton)
		if syncInProgress == true {
			disableButton()
		}
		return h.HandleEvent(event, ui, p)
	})
}
示例#3
0
func CheckAuth(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, p url.Values) bool {
		uri := util.JqmTargetUri(ui)
		if uri != "/login.html" && util.CurrentUser() == "" {
			// Nobody's logged in
			ui.Set("toPage", "login.html")
			event.StopImmediatePropagation()
			jquery.NewJQuery(":mobile-pagecontainer").Trigger("pagecontainerbeforechange", ui)
			return true
		}
		return h.HandleEvent(event, ui, p)
	})
}
示例#4
0
文件: auth.go 项目: flimzy/flashback
func CheckAuth(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object) bool {
		console.Log("CheckAuth")
		uri := util.JqmTargetUri(ui)
		console.Log("Auth URI = %s", uri)
		if uri != "/login.html" && util.CurrentUser() == "" {
			console.Log("nobody's logged in")
			// Nobody's logged in
			ui.Set("toPage", "login.html")
			event.StopImmediatePropagation()
			console.Log("Attempting to re-trigger the event")
			jquery.NewJQuery(":mobile-pagecontainer").Trigger("pagecontainerbeforechange", ui)
			return true
		}
		console.Log("Auth allowing to proceed")
		return h.HandleEvent(event, ui)
	})
}
示例#5
0
func CleanFacebookURI(h jqeventrouter.Handler) jqeventrouter.Handler {
	// This handler cleans up the URL after a redirect from a Facebook login
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object) bool {
		uri := util.JqmTargetUri(ui)
		// Having '#_=_' in the URL can mess up our routing
		if strings.HasSuffix(uri, "#_=_") {
			uri = strings.TrimSuffix(uri, "#_=_")
			ui.Set("toPage", uri)
		}
		// It's also ugly, so remove it from the visible location bar
		location := js.Global.Get("location")
		href := location.Get("href").String()
		if strings.HasSuffix(href, "#_=_") {
			location.Set("href", strings.TrimSuffix(href, "#_=_"))
		}
		return h.HandleEvent(event, ui)
	})
}
示例#6
0
func LocalizePage(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, p url.Values) bool {
		go localize()
		return h.HandleEvent(event, ui, p)
	})
}