1 33 34 package com.icesoft.faces.context.effects; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.w3c.dom.Element ; 39 40 import javax.faces.component.UIComponent; 41 import javax.faces.context.FacesContext; 42 import java.util.Map ; 43 44 47 public class LocalEffectEncoder { 48 49 private static final String [] EVENTS = { 50 "click", "dblclick", "mousedown", 51 "mouseup", "mousemove", "mouseover", "mouseout", 52 "change", "reset", "submit", 53 "keypress", "keydown", "keyup" 54 }; 55 56 private static String [] ATTRIBUTES = new String [EVENTS.length]; 57 private static final String ATTRIBUTE_PREFIX = "on"; 58 private static String [] EFFECTS = new String [EVENTS.length]; 59 private static final String EFFECT_SUFFIX = "effect"; 60 61 static { 62 for (int index = 0; index < EVENTS.length; index++) { 63 ATTRIBUTES[index] = ATTRIBUTE_PREFIX + EVENTS[index]; 64 EFFECTS[index] = ATTRIBUTES[index] + EFFECT_SUFFIX; 65 } 66 } 67 68 private static final Log log = LogFactory.getLog(LocalEffectEncoder.class); 69 70 71 public static void encodeLocalEffects(UIComponent comp, Element rootNode, 72 FacesContext facesContext) { 73 Map atts = comp.getAttributes(); 74 try { 75 for (int i = 0; i < EVENTS.length; i++) { 76 Effect fx = (Effect) atts.get(EFFECTS[i]); 77 if (fx == null) { 78 if (comp.getValueBinding(EFFECTS[i]) != null) { 82 fx = new BlankEffect(); 83 } 84 } 85 86 if (fx != null) { 87 String value = JavascriptContext.applyEffect(fx, 88 comp.getClientId( 89 facesContext), 90 facesContext); 91 92 String original = (String ) atts.get(ATTRIBUTES[i]); 93 if (original == null) { 94 original = ""; 95 } 96 97 rootNode.setAttribute(ATTRIBUTES[i], value + original); 98 } 99 } 100 } catch (Exception e) { 101 102 if (log.isErrorEnabled()) { 103 log.error(e.getMessage(), e); 104 } 105 } 106 } 107 108 public static void encodeLocalEffect(String id, Effect fx, String event, FacesContext facesContext){ 109 String value = JavascriptContext.applyEffect(fx, id, facesContext); 110 String js = "$('" + id + "').on"+event + "=function(){" + value + "};"; 112 JavascriptContext.addJavascriptCall(facesContext, js); 113 } 114 } 115 | Popular Tags |