array("default" => "0px", "css" => "margin-left", "csspart" => "maxcollection"), "margin_right" => array("default" => "0px", "css" => "margin-right", "csspart" => "maxcollection"), "margin_top" => array("default" => "0px", "css" => "margin-top", "csspart" => "maxcollection"), "margin_bottom" => array("default" => "0px", "css" => "margin-bottom", "csspart" => "maxcollection"), "orientation" => array("default" => "auto"), "item_margin_right" => array("default" => "0px", "css" => "margin-right", "csspart" => "mb-collection-item", ), "item_margin_bottom" => array("default" => "0px", "css" => "margin-bottom", "csspart" => "mb-collection-item", ), "ignore_container" => array("default" => 1), "static_position_ver" => array("default" => "Auto", ), "static_position_hor" => array("default" => "Auto", ), ); public function map_fields($map) { $map = parent::map_fields($map); $map["orientation"]["func"] = "updatePlacement"; return $map; } function parseButtons($buttons) { // searches the cache for the container statement ending with -container or -center and tries to remove then // not very optimal code, but this is a way to maintain cache loading while altering css. if ($this->data["ignore_container"] == 0) return $buttons; // ignore container off . foreach($buttons as $button) { $cache = $button->getCache(); // chops all css statements in a different line preg_match_all('/([^{]+)\s*\{\s*([^}]+)\s*}/i',$cache, $matches); foreach($matches[0] as $cssline) { // tries to find the last part of the statement from - to { preg_match_all('/.([^-])*{/i', $cssline, $item); $item = trim(str_replace("{","",$item[0][0])); if ($item == '-center' || $item == '-container') { $cache = str_replace($cssline,'',$cache); } } //([^{]+)\s*\{\s*([^}]+)\s*} { split } // match last thing .([^-])*{ $button->setCache($cache); $data = $button->get(); $container = isset($data["container"]) ? $data["container"] : array(); foreach($container as $key => $value) { if ($key != 'container_enabled' && $key != 'container_center_div_wrap') // causes container to be removed otherwise $container[$key] = ''; } $button->setdata("container", $container); } return $buttons; } function parseCSS($css, $args) { $css = parent::parseCSS($css, $args); $css["mb-collection-item"]["normal"]["float"] = "left"; $css["mb-collection-item"]["normal"]["display"] = "inline-block"; $css["mb-collection-item a"]["normal"]["cursor"] = "pointer"; // by default social share = call to action. //$button_spacing = $this->data["button_spacing"]; $orientation = $this->data["orientation"]; $static_position_ver = $this->data["static_position_ver"]; $static_position_hor = $this->data["static_position_hor"]; $basic = $this->collection->getBlock("basic"); $picker_data = $basic->get(); $placement = $picker_data["placement"]; if ($orientation == 'auto') { // $basic = $this->collection->getBlock("basic"); switch($placement) // auto align on basis of placement on screen { case "static-left": // vertical items case "static-right": $orientation = "vertical"; break; case "static-top": // horizontal case "static-bottom": default: $orientation = "horizontal"; break; } } switch($orientation) { case "horizontal": //$css["mb_collection_item"]["normal"]["float"] // todo //$css["mb-collection-item"]["normal"]["margin-right"] = $button_spacing . "px"; //$css["mb-collection-item:last-child"]["normal"]["margin-right"] = "0"; break; case "vertical"; $css["mb-collection-item"]["normal"]["clear"] = "both"; //if ($button_spacing > 0) //{ //unset($css["mb-collection-item"]["normal"]["margin-right"]) ; //$css["mb-collection-item"]["normal"]["clear"] = "left"; //$css["mb-collection-item"]["normal"]["margin-bottom"] = $button_spacing . "px"; //} break; } if ($args["preview"] == true) return $css; // don't process move than this in preview. switch($placement) { case "static-left": case "static-right": switch($static_position_ver) { case "auto": case "center": $css["maxcollection"]["normal"]["top"] = "50%"; $css["maxcollection"]["normal"]["transform"] = "translateY(-50%)"; break; case "top": // nothing break; case "bottom": unset($css["maxcollection"]["normal"]["top"]); $css["maxcollection"]["normal"]["bottom"] = "0"; break; } break; case "static-top": case "static-bottom": switch($static_position_hor) { case "auto": case "center": $css["maxcollection"]["normal"]["left"] = "50%"; $css["maxcollection"]["normal"]["transform"] = "translateX(-50%)"; break; case "left": break; case "right": unset($css["maxcollection"]["normal"]["left"]); $css["maxcollection"]["normal"]["right"] = "0"; break; } break; } return $css; } function save_fields($data, $post) { $data = parent::save_fields($data, $post); if (! isset($post["ignore_container"])) $data[$this->blockname]["ignore_container"] = 0; return $data; } function admin_fields() { extract($this->data); $orientation_array = array( "auto" => __("Auto","maxbuttons"), "horizontal" => __("Horizontal","maxbuttons"), "vertical" => __("Vertical","maxbuttons") ); $staticposver = array( "auto" => __("Auto","maxbuttons"), "center" => __("Center","maxbuttons"), "top" => __("Top", "maxbuttons"), "bottom" => __("Bottom", "maxbuttons"), ); $staticposhor = array( "auto" => __("Auto","maxbuttons"), "center" => __("Center","maxbutton-pro"), "left" => __("Left","maxbuttons"), "right" => __("Right","maxbuttons"), ); $px = __("px","maxbuttons"); ?>