Index: sifr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sifr/sifr.module,v
retrieving revision 1.13
diff -u -r1.13 sifr.module
--- sifr.module	20 Feb 2007 19:50:42 -0000	1.13
+++ sifr.module	20 Feb 2007 22:06:50 -0000
@@ -359,11 +359,12 @@
     '#size' => 12,
     '#default_value' => $edit['bgcolor'] ? $edit['bgcolor'] : '#FFFFFF',
   );
+  $transparency_options = array(0 => t('No transparency'), 1 => t('Use transparency'), 2 => t('Opaque background'));
   $form['colors']['transparent'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Use transparency'),
+    '#title' => t('Transparency'),
+    '#type' => 'radios',
+    '#options' => $transparency_options,
     '#default_value' => $edit['transparent'],
-    '#return_value' => 1,
     '#description' => t('<strong>Warning:</strong> Flash transparency is not well supported in all browsers and therefore not recommended.'),
   );
   $form['tweaks'] = array(
@@ -603,11 +604,13 @@
   db_query("INSERT INTO {sifr} ($keys) VALUES ($valsubs) ", $vals);
   drupal_set_message($edit['name'] .' '. t('saved.'));
   sifr_css_screen(FALSE); // create the file
+  variable_del('sifr_rules');
 }
 
 function sifr_rule_delete($rid){
   db_query('DELETE FROM {sifr} WHERE rid = %d', $rid);
   drupal_set_message(t('Rule deleted.'));
+  variable_del('sifr_rules');
 }
 
 function sifr_font_delete($fontfile){
@@ -668,33 +671,58 @@
 }
 
 function sifr_render_rules_js(){
+  $rules = variable_get('sifr_rules', null);
+  if (isset($rules)) {
+    return $rules;
+  }
   $rules = array();
   foreach(sifr_get_rules() as $rule){
     $rules[] = sifr_render_rule_js($rule);
   }
   $output = sifr_wrap_rules($rules);
+  variable_set('sifr_rules', $output);
   return $output;
 }
 
 function sifr_render_rule_js($rule){
-  $base = base_path();
-  $fontpath = str_replace(' ', "%20", $base.$rule->font); // convert spaces
-  //sIFR.replaceElement("h1", named({sFlashSrc: "./vandenkeere.swf", sColor: "#000", sCase: "upper"}));
-  //$output .= "  sIFR.replaceElement(\"$rule->selector\", \"$base$rule->font\");\n";
-  $padding = is_numeric($rule->paddingtop) ? ", nPaddingTop: $rule->paddingtop" : '';
-  $padding .= is_numeric($rule->paddingright) ? ", nPaddingRight: $rule->paddingright" : '';
-  $padding .= is_numeric($rule->paddingbottom) ? ", nPaddingBottom: $rule->paddingbottom" : '';
-  $padding .= is_numeric($rule->paddingleft) ? ", nPaddingLeft: $rule->paddingleft" : ''; 
-  $wsmode = $rule->transparent ? ", sWmode: 'transparent'" : '';
-  $case = in_array($rule->lettercase,array('upper','lower')) ? ", sCase: \"$rule->lettercase\"" : '';
-  if($rule->underline){
+  $properties = array();
+  // convert spaces in filename
+  $fontpath = base_path() . str_replace( '%2F', '/', rawurlencode($rule->font));
+  $properties['sFlashSrc'] = $fontpath;
+  $properties['sColor'] = $rule->color;
+  $properties['sLinkColor'] = $rule->linkcolor;
+  $properties['sHoverColor'] = $rule->hovercolor;
+  $properties['sBgColor'] = $rule->bgcolor;
+  $properties['nPaddingTop'] = is_numeric($rule->paddingtop) ? $rule->paddingtop : null;
+  $properties['nPaddingRight'] = is_numeric($rule->paddingright) ? $rule->paddingright : null;
+  $properties['nPaddingBottom'] = is_numeric($rule->paddingbottom) ? $rule->paddingbottom : null;
+  $properties['nPaddingLeft'] = is_numeric($rule->paddingleft) ? $rule->paddingleft : null; 
+  switch ($rule->transparent) {
+    case '1':
+      $properties['sWmode'] = 'transparent';
+      break;
+    case '2':
+      $properties['sWmode'] = 'opaque';
+      break;
+  }
+  $properties['sCase'] = in_array($rule->lettercase, array('upper', 'lower')) ? $rule->lettercase : '';
+  $vars = array();
+  if ($rule->underline) {
     $vars[] = 'underline=true';
   }
-  if( in_array($rule->textalign,array('left','center','right'))){
-    $vars[] = "textalign=$rule->textalign";
+  if (in_array($rule->textalign, array('left', 'center', 'right'))) {
+    $vars[] = 'textalign='. $rule->textalign;
+  }
+  $properties['sFlashVars'] = implode($vars, '&');
+  
+  $output = "  sIFR.replaceElement(\"$rule->selector\", named({";
+  foreach ($properties as $property => $value) {
+    if (!empty( $value )) {
+      $output .= $property .': "'. $value .'", ';
+    }
   }
-  $flashvars = is_array($vars) ? ', sFlashVars: "'.join($vars, '&').'"' : '';
-  $output .= "  sIFR.replaceElement(\"$rule->selector\", named({sFlashSrc: \"$fontpath\",  sColor: \"$rule->color\", sLinkColor: \"$rule->linkcolor\", sHoverColor: \"$rule->hovercolor\", sBgColor: \"$rule->bgcolor\" $padding$wsmode$case$flashvars}));\n";
+  $output = substr( $output, 0, -2);
+  $output .= "}));\n";
   return $output;
 }
 
