| 1 |
<?php |
| 2 |
namespace MBSocial; |
| 3 |
defined('ABSPATH') or die('No direct access permitted'); |
| 4 |
|
| 5 |
use \MaxButtons\maxBlocks as maxBlocks; |
| 6 |
use \MaxButtons\maxUtils as maxUtils; |
| 7 |
|
| 8 |
class style |
| 9 |
{ |
| 10 |
protected $collection; |
| 11 |
|
| 12 |
public $class; |
| 13 |
public $name; |
| 14 |
public $description = ' Lorum Ipsum Stylum '; |
| 15 |
|
| 16 |
// Defines if style supports label and share counts |
| 17 |
public $has_share = false; |
| 18 |
public $has_label = false; |
| 19 |
|
| 20 |
/* |
| 21 |
Controls what to display for this style and when |
| 22 |
Usage |
| 23 |
Pseudo (normal/hover) -> [item] , array('item', 'item'), 'item,item' |
| 24 |
^ one item, ^ or ^ and, show both |
| 25 |
*/ |
| 26 |
public $display = array('normal' => 'icon', |
| 27 |
'hover' => array('count', 'label'), |
| 28 |
); |
| 29 |
|
| 30 |
protected $display_active = array(); |
| 31 |
protected $effect_active = false; |
| 32 |
|
| 33 |
// possible ITEM css classes |
| 34 |
protected $items = array('count' => 'mb-share-count', |
| 35 |
'icon' => 'mb-icon-wrapper', |
| 36 |
'label' => 'mb-label', |
| 37 |
); |
| 38 |
|
| 39 |
public $css = array( |
| 40 |
'maxsocial' => array( // the container |
| 41 |
'normal' => |
| 42 |
array('display' => 'inline-block', |
| 43 |
'clear' => 'both', |
| 44 |
'z-index' => 9999, |
| 45 |
'position' => 'relative', |
| 46 |
'width' => '100%', |
| 47 |
'line-height' => '1.1', |
| 48 |
'box-sizing' => 'border-box', |
| 49 |
), |
| 50 |
// 'hover' => '', |
| 51 |
), |
| 52 |
|
| 53 |
'mb-item' => array('normal' => |
| 54 |
array ( 'display' => 'flex', |
| 55 |
'justify-content' => 'center', |
| 56 |
'align-items' => 'center', |
| 57 |
'box-sizing' => 'border-box', |
| 58 |
'position' => 'relative', |
| 59 |
'line-height' => 'inherit', |
| 60 |
'text-align' => 'center', |
| 61 |
'margin' => '10px 0', |
| 62 |
|
| 63 |
), |
| 64 |
), |
| 65 |
'mb-social' => array('normal' => // the button |
| 66 |
array ( 'display' => 'flex', |
| 67 |
'justify-content' => 'center', |
| 68 |
'align-items' => 'center', |
| 69 |
'text-decoration' => 'none', |
| 70 |
'position' => 'relative', |
| 71 |
'border' => 0, |
| 72 |
'box-shadow' => 'none', |
| 73 |
'box-shadow-width' => 0, |
| 74 |
'box-shadow-offset-left' => 0, |
| 75 |
'box-shadow-offset-top' => 0, |
| 76 |
|
| 77 |
), |
| 78 |
// 'hover' => array(), |
| 79 |
), |
| 80 |
// 'mb-share-count' => array(); |
| 81 |
//'hover' => array('normal' => array( 'display' => 'none')), |
| 82 |
//'normal' => array('hover' => array( 'display' => 'none')), |
| 83 |
|
| 84 |
); |
| 85 |
|
| 86 |
|
| 87 |
public static function registerStyle($name) |
| 88 |
{ |
| 89 |
$class = get_called_class(); |
| 90 |
styles::registerStyle($class, $name); |
| 91 |
|
| 92 |
} |
| 93 |
|
| 94 |
public function __construct() |
| 95 |
{ |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
public function getCSS() |
| 100 |
{ |
| 101 |
return $this->css; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
/** Add effects to the styling . addCSS uses the last arg to bounce back CSS, since it's called by block |
| 106 |
* @param $effect Name of the effect |
| 107 |
* @param $args Arguments, some effects might need specific args. |
| 108 |
*/ |
| 109 |
public function addEffect($css, $effect, $args = array()) |
| 110 |
{ |
| 111 |
$this->effect_active = $effect; |
| 112 |
|
| 113 |
switch($effect) |
| 114 |
{ |
| 115 |
case 'drop': |
| 116 |
|
| 117 |
$line_height = intval($args['line_height']) * 2; |
| 118 |
|
| 119 |
$normcss = array( |
| 120 |
'position' => 'absolute', |
| 121 |
'left' => 0, |
| 122 |
'bottom' => '-3px', |
| 123 |
'width' => '100%', |
| 124 |
'transition' => 'bottom .2s linear', |
| 125 |
'z-index' => '-1', |
| 126 |
'line-height' => $line_height .'px', |
| 127 |
// 'display' => 'inline-block', |
| 128 |
'background-color' => '#000', |
| 129 |
|
| 130 |
); |
| 131 |
|
| 132 |
$css = $this->addCSS($normcss, false, 'mb-label', 'normal', $css); |
| 133 |
$css = $this->addCSS($normcss, false, 'mb-share-count', 'normal', $css); |
| 134 |
|
| 135 |
$hovercss = array( |
| 136 |
'bottom' => '-' . $line_height . 'px', |
| 137 |
); |
| 138 |
|
| 139 |
$css = $this->addCSS($hovercss, false, 'mb-label', 'hover', $css); |
| 140 |
$css = $this->addCSS($hovercss, false, 'mb-share-count','hover', $css); |
| 141 |
|
| 142 |
$css = $this->addCSS('overflow', 'visible', 'mb-social', 'normal', $css); |
| 143 |
|
| 144 |
$css = $this->addCSS('z-index', '0', 'mb-social', 'normal', $css); |
| 145 |
$css = $this->addCSS('position', 'static', 'mb-social', 'normal', $css); |
| 146 |
$css = $this->addCSS('display', 'inline-block', 'mb-item', 'normal', $css); |
| 147 |
|
| 148 |
|
| 149 |
break; |
| 150 |
case 'flip': |
| 151 |
$css = $this->addCSS('transform', 'translateY(0)', 'mb-label', 'hover', $css); |
| 152 |
$css = $this->addCSS('transform', 'translateY(0)', 'mb-share-count','hover', $css); |
| 153 |
$css = $this->addCSS('transform', 'translateY(-100%)', 'mb-icon-wrapper', 'hover', $css); |
| 154 |
$css = $this->addCSS('overflow', 'hidden','mb-social', 'normal', $css); |
| 155 |
$css = $this->addCSS('display','inline-block', 'mb-social', 'normal', $css); |
| 156 |
|
| 157 |
$normcss = array( |
| 158 |
'transition' => 'all .2s linear', |
| 159 |
'height' => '100%', |
| 160 |
'width' => '100%', |
| 161 |
// 'display' => 'flex', |
| 162 |
'align-items' => 'center', |
| 163 |
'justify-content' => 'center', |
| 164 |
'transform' => 'translateY(100%)', |
| 165 |
); |
| 166 |
|
| 167 |
$css = $this->addCSS($normcss, false, 'mb-label', 'normal', $css); |
| 168 |
$css = $this->addCSS($normcss, false, 'mb-share-count', 'normal', $css); |
| 169 |
$css = $this->addCSS($normcss, false, 'mb-icon-wrapper', 'normal', $css); |
| 170 |
$css = $this->addCSS('transform', 'translateY(0)', 'mb-icon-wrapper', 'normal', $css); |
| 171 |
$css = $this->addCSS('position', 'absolute', 'mb-icon-wrapper', 'normal', $css); |
| 172 |
|
| 173 |
/* $css['mb-label']['hover']['transform'] = 'translateY(0)'; |
| 174 |
$css['mb-share-count']['hover']['transform'] = 'translateY(0)'; |
| 175 |
$css['mb-icon-wrapper']['hover']['transform'] = 'translateY(0)'; |
| 176 |
*/ |
| 177 |
$hoverCSS = array( |
| 178 |
// 'display' => 'flex', |
| 179 |
'align-items' => 'center', |
| 180 |
'justify-content' => 'center', |
| 181 |
//'transform' => 'translateY(0)', |
| 182 |
); |
| 183 |
|
| 184 |
|
| 185 |
$css = $this->addCSS($hoverCSS, false, 'mb-label', 'hover', $css); |
| 186 |
$css = $this->addCSS($hoverCSS, false, 'mb-share-count', 'hover', $css); |
| 187 |
$css = $this->addCSS($hoverCSS, false, 'mb-icon-wrapper', 'hover', $css); |
| 188 |
$css = $this->addCSS('transform', 'translateY(-100%)', 'mb-icon-wrapper', 'hover', $css); // move up |
| 189 |
|
| 190 |
|
| 191 |
break; |
| 192 |
case 'hover'; |
| 193 |
/*$color = $css['mb-social']['normal']['background-color']; |
| 194 |
$css = $this->addCSS('background-color', 'darken(' . $color . ', 20%)', 'mb-social', 'hover', $css); |
| 195 |
*/ |
| 196 |
break; |
| 197 |
case 'lift': |
| 198 |
$line_height = intval($args['line_height']) * 1.5; |
| 199 |
|
| 200 |
//$this->addCSS('overflow', 'hidden', 'collection-item'); |
| 201 |
$css = $this->addCSS('transform', 'translateY(-10px)', 'mb-icon-wrapper', 'hover', $css); |
| 202 |
$css = $this->addCSS('transition', 'all .2s linear', 'mb-icon-wrapper', 'normal', $css); |
| 203 |
|
| 204 |
$normcss = array( |
| 205 |
'bottom' => '-' . $line_height . 'px', |
| 206 |
'z-index' => 'auto', |
| 207 |
'background' => 'transparent', |
| 208 |
'position' => 'absolute', |
| 209 |
'line-height' => $line_height . 'px', |
| 210 |
'transition' => 'bottom .2s linear', |
| 211 |
//'z-index' => '-1', |
| 212 |
'width' => '100%', |
| 213 |
|
| 214 |
); |
| 215 |
|
| 216 |
$css = $this->addCSS($normcss, '', 'mb-label', 'normal', $css); |
| 217 |
$css = $this->addCSS($normcss, '', 'mb-share-count', 'normal', $css); |
| 218 |
|
| 219 |
$hovercss = array( |
| 220 |
'bottom' => '0px', |
| 221 |
'background' => 'transparent', |
| 222 |
|
| 223 |
); |
| 224 |
|
| 225 |
$css = $this->addCSS($hovercss, '', 'mb-label', 'hover', $css); |
| 226 |
$css = $this->addCSS($hovercss, '', 'mb-share-count', 'hover', $css); |
| 227 |
|
| 228 |
$css = $this->addCSS('overflow', 'hidden', 'mb-social', 'normal', $css); |
| 229 |
|
| 230 |
break; |
| 231 |
case 'none': |
| 232 |
|
| 233 |
$this->display['hover'] = 'icon'; |
| 234 |
//$css = $this->addCSS('display', 'none', 'mb-label', 'hover', $css); |
| 235 |
//$css = $this->addCSS('display', 'none', 'mb-share-count','hover', $css); |
| 236 |
break; |
| 237 |
case 'shift': |
| 238 |
$this->display = array('normal' => 'icon,count', |
| 239 |
'hover' => 'icon,label,count'); |
| 240 |
$line_height = $args['line_height']; |
| 241 |
|
| 242 |
$css = $this->addCSS('overflow', 'hidden','mb-social', 'normal', $css); |
| 243 |
|
| 244 |
$css = $this->addCSS( array( |
| 245 |
'position' => 'absolute', |
| 246 |
'bottom' => '3px', |
| 247 |
'height' => $line_height, |
| 248 |
'z-index' => '1', |
| 249 |
'transition' => 'all .2s ease-in-out', |
| 250 |
'background' => 'transparent', |
| 251 |
'right' => 0, |
| 252 |
'left' => 0, |
| 253 |
), |
| 254 |
'', |
| 255 |
'mb-share-count', |
| 256 |
'normal', |
| 257 |
$css); |
| 258 |
|
| 259 |
$css = $this->addCSS ( array( |
| 260 |
'transform' => 'translateX(60px)', |
| 261 |
'bottom' => '0', |
| 262 |
'background' => 'transparent', |
| 263 |
), |
| 264 |
'', |
| 265 |
'mb-share-count', |
| 266 |
'hover', |
| 267 |
$css |
| 268 |
); |
| 269 |
|
| 270 |
$css = $this->addCSS ( array ( |
| 271 |
'transform' => 'translateX(-60px)', |
| 272 |
'position' => 'absolute', |
| 273 |
'bottom' => 0, |
| 274 |
'transition' => 'all .2s ease-in-out', |
| 275 |
'background-color' => 'transparent', |
| 276 |
'left' => 0, |
| 277 |
'text-align' => 'center', |
| 278 |
'width' => '100%', |
| 279 |
'height' => $line_height, |
| 280 |
), |
| 281 |
'', |
| 282 |
'mb-label', |
| 283 |
'normal', |
| 284 |
$css |
| 285 |
); |
| 286 |
|
| 287 |
$css = $this->addCSS ( array ( |
| 288 |
'transform' => 'translateX(0px)', |
| 289 |
'z-index' => '1', |
| 290 |
'bottom' => '3px', |
| 291 |
'background-color' => 'transparent', |
| 292 |
), |
| 293 |
'', |
| 294 |
'mb-label', |
| 295 |
'hover', |
| 296 |
$css |
| 297 |
); |
| 298 |
|
| 299 |
$css = $this->addCSS ('transform', 'translateY(-8px)', 'mb-icon-wrapper', 'hover', $css); |
| 300 |
$css = $this->addCSS ('transition', 'all .2s ease-in-out', 'mb-icon-wrapper', 'normal', $css); |
| 301 |
|
| 302 |
break; |
| 303 |
case 'stretch': |
| 304 |
$this->display = array('normal' => 'icon,count', |
| 305 |
'hover' => 'icon,label,count'); |
| 306 |
$css = $this->addStretch($css,$args); |
| 307 |
|
| 308 |
break; |
| 309 |
case 'transform': |
| 310 |
$scale = intval($args['scale']); |
| 311 |
$scale = $scale / 10; |
| 312 |
//$css['mb-social']['hover']['transform'] = 'scale(' . $scale . ')'; |
| 313 |
//$css['mb-social']['hover']['transform'] = 'scale(' . $scale . ')'; |
| 314 |
$css = $this->addCSS('transform', 'scale('. $scale . ')', 'mb-social','hover', $css); |
| 315 |
break; |
| 316 |
} |
| 317 |
|
| 318 |
return $css; |
| 319 |
} |
| 320 |
|
| 321 |
protected function addStretch($css, $args) |
| 322 |
{ |
| 323 |
$css = $this->addCSS('display', 'flex', 'maxsocial', 'normal', $css); |
| 324 |
|
| 325 |
$css = $this->addCSS('flex', '1.2', 'mb-item', 'hover', $css); |
| 326 |
|
| 327 |
$itemcss = array( |
| 328 |
'flex' => 1, |
| 329 |
'float' => 'left', |
| 330 |
'height' => '100%', |
| 331 |
'-webkit-transition' => 'all .2s linear', |
| 332 |
'transition' => 'all .2s linear', |
| 333 |
); |
| 334 |
$css = $this->addCSS($itemcss, '','mb-item', 'normal', $css); |
| 335 |
|
| 336 |
$css = $this->addCSS ( array ( |
| 337 |
'display' => 'block', |
| 338 |
'display' => '-webkit-box', |
| 339 |
'display' => '-webkit-flex', |
| 340 |
'display' => '-moz-box', |
| 341 |
'display' => '-ms-flexbox', |
| 342 |
'display' => 'flex', |
| 343 |
'text-transform' => 'none', |
| 344 |
'-webkit-flex-flow' => 'row wrap', |
| 345 |
'-ms-flex-flow' => 'row wrap', |
| 346 |
'flex-flow' => 'row wrap', |
| 347 |
'width' => '100%', |
| 348 |
), |
| 349 |
'', |
| 350 |
'mb-social', 'normal', $css); |
| 351 |
|
| 352 |
$css = $this->addCSS('flex', '1.2', 'mb-social', 'hover', $css); |
| 353 |
|
| 354 |
// the label |
| 355 |
$css = $this->addCSS ( array ( |
| 356 |
'text-align' => 'center', |
| 357 |
'flex-grow' => 3, |
| 358 |
'margin' => 'auto', |
| 359 |
'display' => 'none', |
| 360 |
'opacity' => 0, |
| 361 |
'-webkit-transition' => 'all .4s linear', |
| 362 |
'transition' => 'all .4s linear', |
| 363 |
), |
| 364 |
'', |
| 365 |
'mb-label', |
| 366 |
'normal', |
| 367 |
$css |
| 368 |
); |
| 369 |
|
| 370 |
// label hover |
| 371 |
$css = $this->addCSS( array( |
| 372 |
'display' => 'inline-block', |
| 373 |
'opacity' => '1', |
| 374 |
|
| 375 |
), |
| 376 |
'', |
| 377 |
'mb-label', |
| 378 |
'hover', |
| 379 |
$css |
| 380 |
|
| 381 |
); |
| 382 |
|
| 383 |
$css = $this->addCSS ( array ( |
| 384 |
'text-align' => 'center', |
| 385 |
'flex-grow' => 2, |
| 386 |
'margin' => 'auto', |
| 387 |
), |
| 388 |
'', |
| 389 |
'mb-icon-wrapper', |
| 390 |
'normal', |
| 391 |
$css |
| 392 |
); |
| 393 |
|
| 394 |
$css = $this->addCSS ( array ( |
| 395 |
// 'font-size' => '16px', |
| 396 |
'margin' => 'auto 0', |
| 397 |
//'flex-grow' => '1', |
| 398 |
'display' => 'inline-block', |
| 399 |
'transform' => 'translateX(-10px)', |
| 400 |
), |
| 401 |
'', |
| 402 |
'mb-share-count', |
| 403 |
'normal', |
| 404 |
$css |
| 405 |
); |
| 406 |
|
| 407 |
$css = $this->addCSS('flex-grow', '1', 'mb-share-count', 'hover', $css); |
| 408 |
|
| 409 |
return $css; |
| 410 |
} |
| 411 |
|
| 412 |
/* Total element is counting all shares and displays some label */ |
| 413 |
protected function addTotal($css) |
| 414 |
{ |
| 415 |
// total main element |
| 416 |
//$this->addFlex('maxbutton-social-total'); |
| 417 |
$styleBlock = $this->collection->getBlock('styleBlock'); |
| 418 |
$layoutBlock = $this->collection->getBlock('layoutBlock'); |
| 419 |
|
| 420 |
$width = $styleBlock->getValue('mbs-width'); |
| 421 |
$height = $styleBlock->getValue('mbs-height'); |
| 422 |
|
| 423 |
// $this->css['maxbutton-social-total']; |
| 424 |
//$width = $css['mb-social']['normal']['width']; |
| 425 |
//$height = $css['mb-social']['normal']['height']; |
| 426 |
|
| 427 |
/*$width = isset($css['mbsocial']['normal']['width']) ? $css['mbsocial']['normal']['width'] : 'auto'; |
| 428 |
$height = isset($css['mbsocial']['normal']['height']) ? $css['mbsocial']['normal']['height'] : 'auto'; |
| 429 |
*/ |
| 430 |
$width = maxUtils::strip_px($width); |
| 431 |
$height = maxUtils::strip_px($height); |
| 432 |
|
| 433 |
// copy mb-item and put it to mb-item-total. Not going to be exactly the same. |
| 434 |
$itemcss = $css['mb-item']; |
| 435 |
|
| 436 |
$css = $this->addCSS($itemcss['normal'], '', 'mb-total-container', 'normal', $css); |
| 437 |
|
| 438 |
$margin = maxUtils::strip_px($layoutBlock->getValue('button_spacing')); |
| 439 |
|
| 440 |
if ($this->collection->orientation == 'vertical') |
| 441 |
{ |
| 442 |
$width = '100%'; |
| 443 |
} |
| 444 |
else { // horizontal |
| 445 |
$width = ($width + $margin) * 2; |
| 446 |
$width = $width . 'px'; |
| 447 |
} |
| 448 |
|
| 449 |
// attempt to auto-custmz. |
| 450 |
$count_size = (isset($css['mb-share-count']['normal']['font-size'])) ? $css['mb-share-count']['normal']['font-size'] : '13'; |
| 451 |
$count_size = maxUtils::strip_px($count_size); |
| 452 |
|
| 453 |
$total_count_size = $count_size * 1.5; |
| 454 |
|
| 455 |
|
| 456 |
$css = $this->addCSS ( array( |
| 457 |
'width' => $width, |
| 458 |
'height' => $height . 'px', |
| 459 |
'display' => 'flex', |
| 460 |
'align-items' => 'center', |
| 461 |
'justify-content' => 'center', |
| 462 |
//'font-size' => '16px', |
| 463 |
), |
| 464 |
'', |
| 465 |
'maxbutton-social-total', |
| 466 |
'normal', |
| 467 |
$css |
| 468 |
); |
| 469 |
|
| 470 |
|
| 471 |
$css = $this->addCSS ( array( |
| 472 |
//'float' => 'left', |
| 473 |
'font-size' => '20px', |
| 474 |
'width' => '45%', |
| 475 |
'text-align' => 'left', |
| 476 |
'height' => 'inherit', |
| 477 |
//'height' => 'inherit', |
| 478 |
'display' => 'flex', |
| 479 |
'align-items' => 'center', |
| 480 |
'justify-content' => 'center', |
| 481 |
), |
| 482 |
'', |
| 483 |
'mb-icon-total', |
| 484 |
'normal', |
| 485 |
$css |
| 486 |
); |
| 487 |
|
| 488 |
$css = $this->addCSS ( array ( // *sigh* |
| 489 |
'font-size' => '35px', |
| 490 |
//'height' => 'auto', |
| 491 |
'vertical-align' => 'top', |
| 492 |
), |
| 493 |
'', |
| 494 |
'mb-icon-total-icon', |
| 495 |
'before', |
| 496 |
$css |
| 497 |
); |
| 498 |
|
| 499 |
$css = $this->addCSS ( array ( |
| 500 |
'width' => '35px', |
| 501 |
'height' => '35px' |
| 502 |
), |
| 503 |
'', |
| 504 |
'mb-icon-total-icon', |
| 505 |
'normal', |
| 506 |
$css |
| 507 |
); |
| 508 |
|
| 509 |
$css = $this->addCSS ( array ( |
| 510 |
//'float' => 'right', |
| 511 |
'clear' => 'right', |
| 512 |
'text-align' => 'center', |
| 513 |
// 'width' => '45%', |
| 514 |
'text-transform' => 'uppercase', |
| 515 |
'font-size' => '13px', |
| 516 |
), |
| 517 |
'', |
| 518 |
'mb-label-total', |
| 519 |
'normal', |
| 520 |
$css |
| 521 |
); |
| 522 |
|
| 523 |
$css = $this->addCSS ( array ( |
| 524 |
//'float' => 'right', |
| 525 |
'text-align' => 'center', |
| 526 |
'font-size' => $total_count_size .'px', |
| 527 |
|
| 528 |
), |
| 529 |
'', |
| 530 |
'mb-count-total', |
| 531 |
'normal', |
| 532 |
$css |
| 533 |
); |
| 534 |
|
| 535 |
|
| 536 |
return $css; |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
public function addCSS($name, $value = '', $element = 'mb-social', $pseudo = 'normal', $css = false) |
| 541 |
{ |
| 542 |
if (! $css && !isset($this->css[$element][$pseudo])) |
| 543 |
{ |
| 544 |
$this->css[$element][$pseudo] = array(); |
| 545 |
} |
| 546 |
if ($css && !isset($css[$element][$pseudo])) |
| 547 |
{ |
| 548 |
$css[$element][$pseudo] = array(); |
| 549 |
} |
| 550 |
|
| 551 |
if ( is_array($name)) |
| 552 |
{ |
| 553 |
foreach ($name as $n => $v) |
| 554 |
{ |
| 555 |
if ($css) |
| 556 |
$css[$element][$pseudo][$n] = $v; |
| 557 |
else |
| 558 |
{ |
| 559 |
$this->css[$element][$pseudo][$n] = $v; |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
} |
| 564 |
else |
| 565 |
{ |
| 566 |
if ($css) |
| 567 |
{ |
| 568 |
$css[$element][$pseudo][$name] = $value; |
| 569 |
} |
| 570 |
else |
| 571 |
$this->css[$element][$pseudo][$name] = $value; |
| 572 |
} |
| 573 |
|
| 574 |
if ($css) |
| 575 |
return $css; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
/* Function that runs before the CSS output is collected from the blocks to be brought to the CSSParser. Load with env. details will allow for relevant changes */ |
| 582 |
public function prepareCSS($args) |
| 583 |
{ |
| 584 |
|
| 585 |
$default_args = array( |
| 586 |
'orientation' => 'horizontal', |
| 587 |
'is_static' => false, |
| 588 |
'is_post' => false, |
| 589 |
'is_mobile' => false, |
| 590 |
'is_tablet' => false, |
| 591 |
); |
| 592 |
|
| 593 |
$args = wp_parse_args($args, $default_args); |
| 594 |
|
| 595 |
if ($args['orientation'] == 'vertical') |
| 596 |
{ |
| 597 |
$this->addCSS(array( |
| 598 |
/* 'width' => $this->width . 'px', |
| 599 |
'height' => $this->height . 'px', */ |
| 600 |
// 'width' => '100%', |
| 601 |
'flex-direction' => 'column' |
| 602 |
), |
| 603 |
'', |
| 604 |
'maxbutton-social-total' |
| 605 |
); |
| 606 |
|
| 607 |
$this->addCSS('display', 'none', 'mb-icon-total'); |
| 608 |
$this->addCSS('width', 'auto', 'mb-label-total'); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
} |
| 613 |
|
| 614 |
public function processDisplay($css = false) |
| 615 |
{ |
| 616 |
$display = $this->display; |
| 617 |
$active_displays = $this->display_active; |
| 618 |
|
| 619 |
foreach($display as $pseudo => $item) |
| 620 |
{ |
| 621 |
//$normal = $display['normal']; |
| 622 |
$hides = array(); |
| 623 |
|
| 624 |
if (is_array($item)) // if display list is an array |
| 625 |
{ |
| 626 |
foreach($item as $i) |
| 627 |
{ |
| 628 |
if (in_array($i, $active_displays)) |
| 629 |
{ |
| 630 |
$hides = $this->items; |
| 631 |
|
| 632 |
$statement = 'inline-block'; |
| 633 |
|
| 634 |
$css = $this->addCSS('display',$statement, $this->items[$i], $pseudo, $css); |
| 635 |
unset($hides[$i]); |
| 636 |
break; |
| 637 |
} |
| 638 |
} |
| 639 |
} |
| 640 |
elseif (strpos($item, ',') !== false) // if display list is comma-separated |
| 641 |
{ |
| 642 |
$show_items = explode(',', $item); |
| 643 |
$hides = $this->items; |
| 644 |
foreach($show_items as $i) |
| 645 |
{ |
| 646 |
unset($hides[$i]); |
| 647 |
$statement = 'inline-block'; |
| 648 |
|
| 649 |
$css = $this->addCSS('display', $statement, $this->items[$i], $pseudo, $css); |
| 650 |
} |
| 651 |
} |
| 652 |
else { // if display list is just one item. |
| 653 |
$hides = $this->items; |
| 654 |
unset($hides[$item]); |
| 655 |
|
| 656 |
$statement = 'inline-block'; |
| 657 |
|
| 658 |
$css = $this->addCSS('display',$statement,$this->items[$item], $pseudo, $css); |
| 659 |
} |
| 660 |
|
| 661 |
foreach($hides as $name => $cname) |
| 662 |
{ |
| 663 |
$css = $this->addCSS('display','none', $cname, $pseudo, $css); |
| 664 |
} |
| 665 |
|
| 666 |
} |
| 667 |
|
| 668 |
return $css; |
| 669 |
} |
| 670 |
|
| 671 |
// Let The style know some display item has been added. |
| 672 |
public function addDisplay($item) |
| 673 |
{ |
| 674 |
$this->display_active[] = $item; |
| 675 |
|
| 676 |
} |
| 677 |
|
| 678 |
/* Function for changes to CSS ( eg styling exceptions ) after blocks generated CSS. Runs BEFORE the final CSS Parse run */ |
| 679 |
public function preParse($css) |
| 680 |
{ |
| 681 |
$w = MBSocial()->whistle(); |
| 682 |
|
| 683 |
$css = $this->processDisplay($css); |
| 684 |
//$w->tell('display/env/has_totals', true); |
| 685 |
|
| 686 |
$display = $this->display; |
| 687 |
|
| 688 |
$active_displays = $this->display_active; |
| 689 |
$effect_active = $this->effect_active; |
| 690 |
|
| 691 |
$has_totals = $w->ask('display/env/has_totals'); |
| 692 |
if ($has_totals) |
| 693 |
{ |
| 694 |
$css = $this->addTotal($css); |
| 695 |
} |
| 696 |
|
| 697 |
if ($effect_active) |
| 698 |
{ |
| 699 |
switch($effect_active) |
| 700 |
{ |
| 701 |
case "flip": |
| 702 |
|
| 703 |
$items = array('mb-share-count', 'mb-label'); |
| 704 |
|
| 705 |
foreach($items as $item) |
| 706 |
{ |
| 707 |
if (isset($css[$item]['hover']['display']) && $css[$item]['hover']['display'] != 'none') |
| 708 |
{ |
| 709 |
$css[$item]['hover']['display'] = 'flex'; |
| 710 |
$css[$item]['normal']['display'] = 'flex'; |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
$css['mb-icon-wrapper']['hover']['display'] = 'flex'; |
| 715 |
$css['mb-icon-wrapper']['normal']['display'] = 'flex'; |
| 716 |
break; |
| 717 |
case 'stretch': |
| 718 |
if ( isset( $css['mb-total-container'] ) && isset($css['mb-total-container']['normal']['flex']) ) |
| 719 |
{ |
| 720 |
unset($css['mb-total-container']['normal']['flex']); // remove flex on total container |
| 721 |
} |
| 722 |
|
| 723 |
break; |
| 724 |
case 'lift': |
| 725 |
case 'shift': |
| 726 |
case 'drop': |
| 727 |
|
| 728 |
$items = array('mb-share-count', 'mb-label'); |
| 729 |
|
| 730 |
foreach($items as $item) |
| 731 |
{ |
| 732 |
if (isset($css[$item]['hover']['display']) && $css[$item]['hover']['display'] != 'none') |
| 733 |
{ |
| 734 |
$css[$item]['hover']['display'] = 'inline-block'; |
| 735 |
$css[$item]['normal']['display'] = 'inline-block'; |
| 736 |
} |
| 737 |
} |
| 738 |
$css['mb-icon-wrapper']['hover']['display'] = 'inline-block'; |
| 739 |
// $css['mb-icon-wrapper']['normal']['display'] = 'inline-block'; |
| 740 |
|
| 741 |
|
| 742 |
break; |
| 743 |
} // switch |
| 744 |
} // if |
| 745 |
|
| 746 |
$this->display_active = array(); // just before parse, prepare for next. |
| 747 |
|
| 748 |
return $css; |
| 749 |
|
| 750 |
} |
| 751 |
|
| 752 |
// function to plug into when the style is set active in a collection. Can be used to hook into style specific layout options. |
| 753 |
|
| 754 |
public function setActive($collection) |
| 755 |
{ |
| 756 |
$this->collection = $collection; |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
} // class |
| 761 |
|