Skip to content

Commit

Permalink
replacing indecies with names in dropdown. closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
BFTrick committed Jan 17, 2013
1 parent 8884cbf commit 82edac7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
9 changes: 5 additions & 4 deletions assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ jQuery(document).ready(function($) {
// get index of clicked element
var index = $(".fancyDisplay ul li", thisFontPickerCustomControl).index(this);

// change the selected option in the select box
$('select', thisFontPickerCustomControl).val(index);
// unselect all options
$('select option', thisFontPickerCustomControl).removeAttr('selected');

// simulate a change on the select box
$("select", thisFontPickerCustomControl).change();
// select new element
// simulate a change
$('select :nth-child('+(index+1)+')', thisFontPickerCustomControl).attr('selected', 'selected').change();
});

});
Expand Down
8 changes: 4 additions & 4 deletions control.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ public function render_content()
<select <?php $this->link(); ?>>
<?php
foreach ( $this->choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
echo '<option value="' . esc_attr( $label ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
?>
</select>
<div class="fancyDisplay">
<ul>
<?php
$getTotalNumberOfFonts = $this->fonts->getTotalNumberOfFonts();
for ($i=0; $i<=$getTotalNumberOfFonts-1; $i++)
$cssClassArray = $this->fonts->getCssClassArray();
foreach ($cssClassArray as $key => $value)
{
?>
<li class="<?= $this->fonts->getCssClass($i); ?>">WebFonts</li>
<li class="<?= $value; ?>">WebFonts</li>
<?php
}
?>
Expand Down
15 changes: 4 additions & 11 deletions google-font-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct($fonts)
// create fonts
foreach ($fonts as $key => $value)
{
$this->fonts[] = new Google_Font($value["title"], $value["location"], $value["cssDeclaration"], $value["cssClass"]);
$this->fonts[$value["title"]] = new Google_Font($value["title"], $value["location"], $value["cssDeclaration"], $value["cssClass"]);
}
}

Expand Down Expand Up @@ -68,26 +68,19 @@ function getCssDeclaration($key)
return $this->fonts[$key]->__get("cssDeclaration");
}

/**
* getCssClass
* this function returns the font css class
**/
function getCssClass($key)
{
return $this->fonts[$key]->__get("cssClass");
}

/**
* getCssClassArray
* this function returns an array of css classes
* this function is used to send a JS file an array for the postMessage transport option in the theme customizer should you use it
* this function is used when displaying the fancy list of fonts in the theme customizer
* this function is used to send a JS file an array for the postMessage transport option in the theme customizer
**/
function getCssClassArray()
{
$result;
foreach ($this->fonts as $key => $value)
{
$result[] = $value->__get("cssClass");
$result[$value->__get("title")] = $value->__get("cssClass");
}
return $result;
}
Expand Down

0 comments on commit 82edac7

Please sign in to comment.