function parse_responsive() { $responsive = $this->responsive; if (!is_array($responsive) || count($responsive) == 0) { return; } $media_queries = maxUtils::get_media_query(2); // query names $output = ''; $query_array = array(); foreach ($responsive as $element => $queries) { foreach ($queries as $query => $qdata) { foreach ($qdata as $index => $data) { $query_array[$query][$index][$element] = $data; } } } foreach ($query_array as $query => $vdata) { if ($query == 'custom') { // first discover the custom size properties. foreach ($vdata as $index => $data) { foreach ($data as $element => $values) { if (isset($values["custom_maxwidth"]) || isset($values["custom_minwidth"])) { $minwidth = isset($values["custom_minwidth"]) ? intval($values["custom_minwidth"]) : -1; $maxwidth = isset($values["custom_maxwidth"]) ? intval($values["custom_maxwidth"]) : -1; unset($vdata[$index][$element]["custom_minwidth"]); unset($vdata[$index][$element]["custom_maxwidth"]); // make it always an integer if ($minwidth == '') { $minwidth = 0; } if ($maxwidth == '') { $maxwidth = 0; } // if minwidth is not set and maxwidth zero or not set - ignore since it would result in an empty media line. //if ($minwidth <= 0 && $maxwidth <= 0) //{ //continue; //} if ($minwidth > 0 && $maxwidth > 0) { $qdef = "only screen and (min-width: {$minwidth}" . "px) and (max-width: {$maxwidth}" . "px)"; } if ($minwidth >= 0 && $maxwidth <= 0) { $qdef = "only screen and (min-width: {$minwidth}" . "px) "; } if ($minwidth <= 0 && $maxwidth > 0) { $qdef = "only screen and (max-width: {$maxwidth}" . "px) "; } //break; } } //foreach data // The problem is that every 'custom' query needs to run with a different qdef unlike other queries. $qdata = array($vdata[$index]); $output = $this->parse_responsive_definition($output, $qdef, $qdata); } // foreach vdata } else { $qdef = $media_queries[$query]; $output = $this->parse_responsive_definition($output, $qdef, $vdata); } // never write empty media queries /* if (! isset($qdef) || $qdef == '') { continue; } $output .= "@media ". $qdef . " { "; foreach($vdata as $index => $data) { foreach($data as $element => $values) { //foreach($vdat as $index => $values): $output .= $element . " { "; $css_end = ';'; // same as parse part, maybe merge in future foreach($values as $cssTag => $cssVal) { // unit check - two ways; either unitable items is first or unit declaration. $statement = $this->parse_cssline($values, $cssTag,$cssVal); if($statement) $output .= $statement; } $output .= " } "; // endforeach; } } $output .= " } "; */ } $this->output_css .= $output; }
public function admin_fields() { $data = $this->data[$this->blockname]; $media_names = maxUtils::get_media_query(1); // nicenames $media_desc = maxUtils::get_media_query(3); $units = array("px" => __("px", "maxbuttons"), "%" => __("%", "maxbuttons")); $container_floats = array("" => "", "none" => __("None", "maxbuttons"), "left" => __("Left", "maxbuttons"), "right" => __("Right", "maxbuttons")); foreach ($this->fields as $field => $options) { $default = isset($options["default"]) ? $options["default"] : ''; ${$field} = isset($data[$field]) ? $data[$field] : $default; ${$field . "_default"} = $default; } // sorting routine via array merge. $fk = array_flip(array_keys($media_query)); $names_used = array_intersect_key($media_names, $fk); $media_query = array_merge($names_used, $media_query); ?> <div class="mb_tab option-container"> <div class="title"><?php _e('Responsive Settings', 'maxbuttons'); ?> </div> <div class="inside"> <div class="option-design"> <p class="note"><?php _e("Responsive settings let you decide the behavior of the button on different devices and screen sizes. For instance large buttons on small screens.", "maxbuttons"); ?> </p> <div class="label"><?php _e("Auto Responsive", 'maxbuttons'); ?> <?php _e("(Experimental)", "maxbuttons"); ?> </div> <div class="input"> <input type='checkbox' name='auto_responsive' value='1' <?php checked(1, $auto_responsive); ?> > </div> <div class="clear"></div> <p class="note"><strong><?php _e("Note:", "maxbuttons"); ?> </strong><?php _e(" Auto responsive settings will take a guess only on small screens. To control your responsive settings uncheck this button. This will show more options.", "maxbuttons"); ?> </p> </div> <div class='option-design media_queries_options'> <?php $i = 0; foreach ($media_query as $item => $data) { foreach ($data as $index => $fields) { ?> <div class='media_query'> <span class='removebutton'><img src="<?php echo MB()->get_plugin_url(); ?> /assets/icons/remove.png"></span> <input type="hidden" name="media_query[<?php echo $i; ?> ]" value="<?php echo $item; ?> "> <label class='title'><?php echo $media_names[$item]; ?> </label> <p class='description'><?php echo $media_desc[$item]; ?> </p> <?php if ($item == "custom") { $custom_class = ''; } else { $custom_class = 'hidden'; } ?> <div class="custom" <?php echo $custom_class; ?> > <div class="label"><?php _e("Min width", "maxbuttons"); ?> </div> <div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[<?php echo $i; ?> ]" value="<?php echo $fields["mq_custom_minwidth"]; ?> " />px</div> <div class="label max"> <?php _e("Max width", "maxbuttons"); ?> </div> <div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[<?php echo $i; ?> ]" value="<?php echo $fields["mq_custom_maxwidth"]; ?> " />px</div> </div> <div class='label'><?php _e("Font size", "maxbuttons"); ?> </div> <div class='input'><input type='text' name='mq_font_size[<?php echo $i; ?> ]' class='tiny' value="<?php echo $fields["mq_font_size"]; ?> "> <?php echo maxUtils::selectify("mq_font_size_unit[{$i}]", $units, $fields["mq_font_size_unit"]); ?> </div> <div class='label'><?php _e("Button width", 'maxbuttons'); ?> </div> <div class='input'><input type='text' name="mq_button_width[<?php echo $i; ?> ]" value="<?php echo $fields["mq_button_width"]; ?> " class='tiny'> <?php echo maxUtils::selectify("mq_button_width_unit[{$i}]", $units, $fields["mq_button_width_unit"]); ?> </div> <div class='label'><?php _e("Container width", 'maxbuttons'); ?> </div> <div class='input'><input type='text' name="mq_container_width[<?php echo $i; ?> ]" value="<?php echo $fields["mq_container_width"]; ?> " class='tiny'> <?php echo maxUtils::selectify("mq_container_width_unit[{$i}]", $units, $fields["mq_container_width_unit"]); ?> </div> <div class='label'><?php _e("Container float", "maxbuttons"); ?> </div> <div class="input"><?php echo maxUtils::selectify("mq_container_float[{$i}]", $container_floats, $fields["mq_container_float"]); ?> </div> <?php $mq_hide = isset($fields["mq_hide"]) ? $fields["mq_hide"] : ''; ?> <div class="label"><?php _e("Hide button on this view", "maxbuttons"); ?> </div> <div class="input"> <input type="checkbox" name="mq_hide[<?php echo $i; ?> ]" value="none" <?php checked('none', $mq_hide); ?> ></div> </div> <?php $i++; if ($item != 'custom') { unset($media_names[$item]); } // remove existing queries from new query selection } } ?> <div class="new_query_space"></div> <div class="clear"></div> <div class="option-design new-query"> <div class="label"><?php _e('New Query', 'maxbuttons'); ?> </div> <div class="input"> <?php echo maxUtils::selectify("new_query", $media_names, ''); ?> <a class="button add_media_query"><?php _e("Add", "maxbuttons"); ?> </a> </div> <div class="clear"></div> </div> </div> </div> <!-- inside --> <input type="hidden" name="next_media_index" value="<?php echo $i; ?> " > <div class='media_option_prot'> <div class='media_query'> <span class='removebutton'><img src="<?php echo MB()->get_plugin_url(); ?> assets/icons/remove.png"></span> <input type="hidden" name="media_query[]" value=""> <label class='title'></label> <p class='description'>Description here</p> <div class="custom"> <div class="label"><?php _e("Min width", "maxbuttons"); ?> </div> <div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[]" value="0" />px</div> <div class="label max"> <?php _e("Max width", "maxbuttons"); ?> </div> <div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[]" value="0" />px</div> </div> <div class='label'><?php _e("Font size", "maxbuttons"); ?> </div> <div class='input'><input type='text' name='mq_font_size[]' class='tiny' value="90"> <?php echo maxUtils::selectify("mq_font_size_unit[]", $units, "%"); ?> </div> <div class='label'><?php _e("Button width", "maxbuttons"); ?> </div> <div class='input'><input type='text' name="mq_button_width[]" value="0" class='tiny'> <?php echo maxUtils::selectify("mq_button_width_unit[]", $units, ""); ?> </div> <div class='label'><?php _e("Container width", "maxbuttons"); ?> </div> <div class='input'> <input type='text' name="mq_container_width[]" value="0" class='tiny'> <?php echo maxUtils::selectify("mq_container_width_unit[]", $units, ""); ?> </div> <div class='label'><?php _e("Container float", "maxbuttons"); ?> </div> <div class="input"><?php echo maxUtils::selectify("mq_container_float[]", $container_floats, ""); ?> </div> <div class="label"><?php _e("Hide button on this view", "maxbuttons"); ?> </div> <div class="input"><input type="checkbox" name="mq_hide[]" value="none"> </div> `</div> </div> <div id="media_desc"> <?php foreach ($media_desc as $key => $desc) { echo "<span id='{$key}'>{$desc}</span>"; } ?> </div> </div> <!-- container --> <?php }