org.jgrapes.webconsole.provider.jquitouchpunch.JQueryUiTouchPunchProvider Maven / Gradle / Ivy
/*
* JGrapes Event Driven Framework
* Copyright (C) 2017-2012 Michael N. Lipp
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see .
*/
package org.jgrapes.webconsole.provider.jquitouchpunch;
import freemarker.core.ParseException;
import freemarker.template.MalformedTemplateNameException;
import freemarker.template.TemplateNotFoundException;
import java.io.IOException;
import org.jgrapes.core.Channel;
import org.jgrapes.core.Event;
import org.jgrapes.core.Manager;
import org.jgrapes.core.annotation.Handler;
import org.jgrapes.webconsole.base.ConsoleSession;
import org.jgrapes.webconsole.base.PageResourceProvider;
import org.jgrapes.webconsole.base.events.AddPageResources;
import org.jgrapes.webconsole.base.events.AddPageResources.ScriptResource;
import org.jgrapes.webconsole.base.events.ConsoleReady;
/**
* Provider for the [jQuery UI Touch Punch](http://touchpunch.furf.com/)
* library.
*/
public class JQueryUiTouchPunchProvider extends PageResourceProvider {
/**
* Creates a new component with its channel set to the given
* channel.
*
* @param componentChannel the channel that the component's
* handlers listen on by default and that
* {@link Manager#fire(Event, Channel...)} sends the event to
*/
public JQueryUiTouchPunchProvider(Channel componentChannel) {
super(componentChannel);
}
/**
* On {@link ConsoleReady}, fire the appropriate {@link AddPageResources}.
*
* @param event the event
* @param consoleSession the web console session
* @throws TemplateNotFoundException the template not found exception
* @throws MalformedTemplateNameException the malformed template name exception
* @throws ParseException the parse exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@Handler(priority = 100)
public void onConsoleReady(ConsoleReady event,
ConsoleSession consoleSession)
throws TemplateNotFoundException, MalformedTemplateNameException,
ParseException, IOException {
String minExt = event.renderSupport()
.useMinifiedResources() ? ".min" : "";
consoleSession.respond(new AddPageResources()
.addScriptResource(new ScriptResource()
.setRequires("jquery-ui")
.setProvides("jquery-ui.touch-punch")
.setScriptUri(event.renderSupport().pageResource(
"jquery-ui-touch-punch/jquery.ui.touch-punch" + minExt
+ ".js"))));
}
}