| Total Complexity | 241 |
| Total Lines | 3443 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like AyeCode_UI_Settings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AyeCode_UI_Settings, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class AyeCode_UI_Settings { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Class version version. |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | public $version = '0.1.83'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Class textdomain. |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | public $textdomain = 'aui'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Latest version of Bootstrap at time of publish published. |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | public $latest = "4.5.3"; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Current version of select2 being used. |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | public $select2_version = "4.0.11"; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The title. |
||
| 63 | * |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | public $name = 'AyeCode UI'; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The relative url to the assets. |
||
| 70 | * |
||
| 71 | * @var string |
||
| 72 | */ |
||
| 73 | public $url = ''; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Holds the settings values. |
||
| 77 | * |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | private $settings; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * AyeCode_UI_Settings instance. |
||
| 84 | * |
||
| 85 | * @access private |
||
| 86 | * @since 1.0.0 |
||
| 87 | * @var AyeCode_UI_Settings There can be only one! |
||
| 88 | */ |
||
| 89 | private static $instance = null; |
||
| 90 | |||
| 91 | |||
| 92 | /** |
||
| 93 | * Main AyeCode_UI_Settings Instance. |
||
| 94 | * |
||
| 95 | * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
||
| 96 | * |
||
| 97 | * @since 1.0.0 |
||
| 98 | * @static |
||
| 99 | * @return AyeCode_UI_Settings - Main instance. |
||
| 100 | */ |
||
| 101 | public static function instance() { |
||
| 102 | if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
||
| 103 | |||
| 104 | self::$instance = new AyeCode_UI_Settings; |
||
| 105 | |||
| 106 | add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
||
| 107 | |||
| 108 | if ( is_admin() ) { |
||
| 109 | add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
||
| 110 | add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
||
| 111 | |||
| 112 | // Maybe show example page |
||
| 113 | add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
||
| 114 | |||
| 115 | if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
||
| 116 | add_filter( 'sd_aui_colors', array( self::$instance,'sd_aui_colors' ), 10, 3 ); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
||
| 121 | |||
| 122 | do_action( 'ayecode_ui_settings_loaded' ); |
||
| 123 | } |
||
| 124 | |||
| 125 | return self::$instance; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Add custom colors to the color selector. |
||
| 130 | * |
||
| 131 | * @param $theme_colors |
||
| 132 | * @param $include_outlines |
||
| 133 | * @param $include_branding |
||
| 134 | * |
||
| 135 | * @return mixed |
||
| 136 | */ |
||
| 137 | public function sd_aui_colors( $theme_colors, $include_outlines, $include_branding ){ |
||
| 138 | |||
| 139 | |||
| 140 | $setting = wp_get_global_settings(); |
||
| 141 | |||
| 142 | if(!empty($setting['color']['palette']['custom'])){ |
||
| 143 | foreach($setting['color']['palette']['custom'] as $color){ |
||
| 144 | $theme_colors[$color['slug']] = esc_attr($color['name']); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return $theme_colors; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Setup some constants. |
||
| 153 | */ |
||
| 154 | public function constants(){ |
||
| 155 | define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" ); |
||
| 156 | define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' ); |
||
| 157 | define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' ); |
||
| 158 | define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' ); |
||
| 159 | define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' ); |
||
| 160 | define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' ); |
||
| 161 | define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' ); |
||
| 162 | define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' ); |
||
| 163 | define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' ); |
||
| 164 | define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' ); |
||
| 165 | define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' ); |
||
| 166 | define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' ); |
||
| 167 | define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' ); |
||
| 168 | define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' ); |
||
| 169 | define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' ); |
||
| 170 | define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' ); |
||
| 171 | |||
| 172 | if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
||
| 173 | define( 'AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL ); |
||
| 174 | } |
||
| 175 | if ( ! defined( 'AUI_SECONDARY_COLOR' ) ) { |
||
| 176 | define( 'AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL ); |
||
| 177 | } |
||
| 178 | if ( ! defined( 'AUI_INFO_COLOR' ) ) { |
||
| 179 | define( 'AUI_INFO_COLOR', AUI_INFO_COLOR_ORIGINAL ); |
||
| 180 | } |
||
| 181 | if ( ! defined( 'AUI_WARNING_COLOR' ) ) { |
||
| 182 | define( 'AUI_WARNING_COLOR', AUI_WARNING_COLOR_ORIGINAL ); |
||
| 183 | } |
||
| 184 | if ( ! defined( 'AUI_DANGER_COLOR' ) ) { |
||
| 185 | define( 'AUI_DANGER_COLOR', AUI_DANGER_COLOR_ORIGINAL ); |
||
| 186 | } |
||
| 187 | if ( ! defined( 'AUI_SUCCESS_COLOR' ) ) { |
||
| 188 | define( 'AUI_SUCCESS_COLOR', AUI_SUCCESS_COLOR_ORIGINAL ); |
||
| 189 | } |
||
| 190 | if ( ! defined( 'AUI_LIGHT_COLOR' ) ) { |
||
| 191 | define( 'AUI_LIGHT_COLOR', AUI_LIGHT_COLOR_ORIGINAL ); |
||
| 192 | } |
||
| 193 | if ( ! defined( 'AUI_DARK_COLOR' ) ) { |
||
| 194 | define( 'AUI_DARK_COLOR', AUI_DARK_COLOR_ORIGINAL ); |
||
| 195 | } |
||
| 196 | if ( ! defined( 'AUI_WHITE_COLOR' ) ) { |
||
| 197 | define( 'AUI_WHITE_COLOR', AUI_WHITE_COLOR_ORIGINAL ); |
||
| 198 | } |
||
| 199 | if ( ! defined( 'AUI_PURPLE_COLOR' ) ) { |
||
| 200 | define( 'AUI_PURPLE_COLOR', AUI_PURPLE_COLOR_ORIGINAL ); |
||
| 201 | } |
||
| 202 | if ( ! defined( 'AUI_SALMON_COLOR' ) ) { |
||
| 203 | define( 'AUI_SALMON_COLOR', AUI_SALMON_COLOR_ORIGINAL ); |
||
| 204 | } |
||
| 205 | if ( ! defined( 'AUI_CYAN_COLOR' ) ) { |
||
| 206 | define( 'AUI_CYAN_COLOR', AUI_CYAN_COLOR_ORIGINAL ); |
||
| 207 | } |
||
| 208 | if ( ! defined( 'AUI_GRAY_COLOR' ) ) { |
||
| 209 | define( 'AUI_GRAY_COLOR', AUI_GRAY_COLOR_ORIGINAL ); |
||
| 210 | } |
||
| 211 | if ( ! defined( 'AUI_INDIGO_COLOR' ) ) { |
||
| 212 | define( 'AUI_INDIGO_COLOR', AUI_INDIGO_COLOR_ORIGINAL ); |
||
| 213 | } |
||
| 214 | if ( ! defined( 'AUI_ORANGE_COLOR' ) ) { |
||
| 215 | define( 'AUI_ORANGE_COLOR', AUI_ORANGE_COLOR_ORIGINAL ); |
||
| 216 | } |
||
| 217 | if ( ! defined( 'AUI_BLACK_COLOR' ) ) { |
||
| 218 | define( 'AUI_BLACK_COLOR', AUI_BLACK_COLOR_ORIGINAL ); |
||
| 219 | } |
||
| 220 | |||
| 221 | } |
||
| 222 | |||
| 223 | public static function get_colors( $original = false){ |
||
| 224 | |||
| 225 | if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
||
| 226 | return array(); |
||
| 227 | } |
||
| 228 | if ( $original ) { |
||
| 229 | return array( |
||
| 230 | 'primary' => AUI_PRIMARY_COLOR_ORIGINAL, |
||
| 231 | 'secondary' => AUI_SECONDARY_COLOR_ORIGINAL, |
||
| 232 | 'info' => AUI_INFO_COLOR_ORIGINAL, |
||
| 233 | 'warning' => AUI_WARNING_COLOR_ORIGINAL, |
||
| 234 | 'danger' => AUI_DANGER_COLOR_ORIGINAL, |
||
| 235 | 'success' => AUI_SUCCESS_COLOR_ORIGINAL, |
||
| 236 | 'light' => AUI_LIGHT_COLOR_ORIGINAL, |
||
| 237 | 'dark' => AUI_DARK_COLOR_ORIGINAL, |
||
| 238 | 'white' => AUI_WHITE_COLOR_ORIGINAL, |
||
| 239 | 'purple' => AUI_PURPLE_COLOR_ORIGINAL, |
||
| 240 | 'salmon' => AUI_SALMON_COLOR_ORIGINAL, |
||
| 241 | 'cyan' => AUI_CYAN_COLOR_ORIGINAL, |
||
| 242 | 'gray' => AUI_GRAY_COLOR_ORIGINAL, |
||
| 243 | 'indigo' => AUI_INDIGO_COLOR_ORIGINAL, |
||
| 244 | 'orange' => AUI_ORANGE_COLOR_ORIGINAL, |
||
| 245 | 'black' => AUI_BLACK_COLOR_ORIGINAL, |
||
| 246 | ); |
||
| 247 | } |
||
| 248 | |||
| 249 | return array( |
||
| 250 | 'primary' => AUI_PRIMARY_COLOR, |
||
| 251 | 'secondary' => AUI_SECONDARY_COLOR, |
||
| 252 | 'info' => AUI_INFO_COLOR, |
||
| 253 | 'warning' => AUI_WARNING_COLOR, |
||
| 254 | 'danger' => AUI_DANGER_COLOR, |
||
| 255 | 'success' => AUI_SUCCESS_COLOR, |
||
| 256 | 'light' => AUI_LIGHT_COLOR, |
||
| 257 | 'dark' => AUI_DARK_COLOR, |
||
| 258 | 'white' => AUI_WHITE_COLOR, |
||
| 259 | 'purple' => AUI_PURPLE_COLOR, |
||
| 260 | 'salmon' => AUI_SALMON_COLOR, |
||
| 261 | 'cyan' => AUI_CYAN_COLOR, |
||
| 262 | 'gray' => AUI_GRAY_COLOR, |
||
| 263 | 'indigo' => AUI_INDIGO_COLOR, |
||
| 264 | 'orange' => AUI_ORANGE_COLOR, |
||
| 265 | 'black' => AUI_BLACK_COLOR, |
||
| 266 | ); |
||
| 267 | } |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Initiate the settings and add the required action hooks. |
||
| 271 | */ |
||
| 272 | public function init() { |
||
| 273 | |||
| 274 | // Maybe fix settings |
||
| 275 | if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) { |
||
| 276 | $db_settings = get_option( 'ayecode-ui-settings' ); |
||
| 277 | if ( ! empty( $db_settings ) ) { |
||
| 278 | $db_settings['css_backend'] = 'compatibility'; |
||
| 279 | $db_settings['js_backend'] = 'core-popper'; |
||
| 280 | update_option( 'ayecode-ui-settings', $db_settings ); |
||
| 281 | wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true")); |
||
| 282 | } |
||
| 283 | } |
||
| 284 | |||
| 285 | $this->constants(); |
||
| 286 | $this->settings = $this->get_settings(); |
||
| 287 | $this->url = $this->get_url(); |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Maybe load CSS |
||
| 291 | * |
||
| 292 | * We load super early in case there is a theme version that might change the colors |
||
| 293 | */ |
||
| 294 | if ( $this->settings['css'] ) { |
||
| 295 | $priority = $this->is_bs3_compat() ? 100 : 1; |
||
| 296 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority ); |
||
| 297 | } |
||
| 298 | if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
||
| 299 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
||
| 300 | } |
||
| 301 | |||
| 302 | // maybe load JS |
||
| 303 | if ( $this->settings['js'] ) { |
||
| 304 | $priority = $this->is_bs3_compat() ? 100 : 1; |
||
| 305 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
||
| 306 | } |
||
| 307 | if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
||
| 308 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
||
| 309 | } |
||
| 310 | |||
| 311 | // Maybe set the HTML font size |
||
| 312 | if ( $this->settings['html_font_size'] ) { |
||
| 313 | add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
||
| 314 | } |
||
| 315 | |||
| 316 | // Maybe show backend style error |
||
| 317 | if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){ |
||
| 318 | //add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) ); |
||
| 319 | } |
||
| 320 | |||
| 321 | } |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Show admin notice if backend scripts not loaded. |
||
| 325 | */ |
||
| 326 | public function show_admin_style_notice(){ |
||
| 327 | $fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin')); |
||
| 328 | $button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>'; |
||
| 329 | $message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button; |
||
| 330 | echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>'; |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Check if we should load the admin scripts or not. |
||
| 335 | * |
||
| 336 | * @return bool |
||
| 337 | */ |
||
| 338 | public function load_admin_scripts(){ |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Add a html font size to the footer. |
||
| 356 | */ |
||
| 357 | public function html_font_size(){ |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Check if the current admin screen should load scripts. |
||
| 364 | * |
||
| 365 | * @return bool |
||
| 366 | */ |
||
| 367 | public function is_aui_screen(){ |
||
| 368 | // echo '###';exit; |
||
| 369 | $load = false; |
||
| 370 | // check if we should load or not |
||
| 371 | if ( is_admin() ) { |
||
| 372 | // Only enable on set pages |
||
| 373 | $aui_screens = array( |
||
| 374 | 'page', |
||
| 375 | 'post', |
||
| 376 | 'settings_page_ayecode-ui-settings', |
||
| 377 | 'appearance_page_gutenberg-widgets', |
||
| 378 | 'widgets', |
||
| 379 | 'ayecode-ui-settings', |
||
| 380 | 'site-editor' |
||
| 381 | ); |
||
| 382 | $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
||
| 383 | |||
| 384 | $screen = get_current_screen(); |
||
| 385 | |||
| 386 | // echo '###'.$screen->id; |
||
| 387 | |||
| 388 | // check if we are on a AUI screen |
||
| 389 | if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
||
| 390 | $load = true; |
||
| 391 | } |
||
| 392 | |||
| 393 | //load for widget previews in WP 5.8 |
||
| 394 | if( !empty($_REQUEST['legacy-widget-preview'])){ |
||
| 395 | $load = true; |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | return apply_filters( 'aui_load_on_admin' , $load ); |
||
| 400 | } |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Check if the current theme is a block theme. |
||
| 404 | * |
||
| 405 | * @return bool |
||
| 406 | */ |
||
| 407 | public static function is_block_theme() { |
||
| 413 | } |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Adds the styles. |
||
| 417 | */ |
||
| 418 | public function enqueue_style() { |
||
| 419 | |||
| 420 | |||
| 421 | if( is_admin() && !$this->is_aui_screen()){ |
||
| 422 | // don't add wp-admin scripts if not requested to |
||
| 423 | }else{ |
||
| 424 | $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
||
| 425 | |||
| 426 | $rtl = is_rtl() ? '-rtl' : ''; |
||
| 427 | |||
| 428 | if($this->settings[$css_setting]){ |
||
| 429 | $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
||
| 430 | $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
||
| 431 | |||
| 432 | |||
| 433 | |||
| 434 | wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
||
| 435 | wp_enqueue_style( 'ayecode-ui' ); |
||
| 436 | |||
| 437 | |||
| 438 | // if ( is_admin() && !empty($_REQUEST['postType']) ) { |
||
| 439 | if ( is_admin() && !empty($_REQUEST['postType']) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { |
||
| 440 | $url = $this->url.'assets/css/ayecode-ui-fse.css'; |
||
| 441 | wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version ); |
||
| 442 | wp_enqueue_style( 'ayecode-ui-fse' ); |
||
| 443 | } |
||
| 444 | |||
| 445 | |||
| 446 | // flatpickr |
||
| 447 | wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->version ); |
||
| 448 | |||
| 449 | // fix some wp-admin issues |
||
| 450 | if(is_admin()){ |
||
| 451 | $custom_css = " |
||
| 452 | body{ |
||
| 453 | background-color: #f1f1f1; |
||
| 454 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
||
| 455 | font-size:13px; |
||
| 456 | } |
||
| 457 | a { |
||
| 458 | color: #0073aa; |
||
| 459 | text-decoration: underline; |
||
| 460 | } |
||
| 461 | label { |
||
| 462 | display: initial; |
||
| 463 | margin-bottom: 0; |
||
| 464 | } |
||
| 465 | input, select { |
||
| 466 | margin: 1px; |
||
| 467 | line-height: initial; |
||
| 468 | } |
||
| 469 | th, td, div, h2 { |
||
| 470 | box-sizing: content-box; |
||
| 471 | } |
||
| 472 | p { |
||
| 473 | font-size: 13px; |
||
| 474 | line-height: 1.5; |
||
| 475 | margin: 1em 0; |
||
| 476 | } |
||
| 477 | h1, h2, h3, h4, h5, h6 { |
||
| 478 | display: block; |
||
| 479 | font-weight: 600; |
||
| 480 | } |
||
| 481 | h2,h3 { |
||
| 482 | font-size: 1.3em; |
||
| 483 | margin: 1em 0 |
||
| 484 | } |
||
| 485 | .blocks-widgets-container .bsui *{ |
||
| 486 | box-sizing: border-box; |
||
| 487 | } |
||
| 488 | .bs-tooltip-top .arrow{ |
||
| 489 | margin-left:0px; |
||
| 490 | } |
||
| 491 | |||
| 492 | .custom-switch input[type=checkbox]{ |
||
| 493 | display:none; |
||
| 494 | } |
||
| 495 | "; |
||
| 496 | |||
| 497 | // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
||
| 498 | $custom_css .= " |
||
| 499 | .edit-post-sidebar input[type=color].components-text-control__input{ |
||
| 500 | padding: 0; |
||
| 501 | } |
||
| 502 | "; |
||
| 503 | wp_add_inline_style( 'ayecode-ui', $custom_css ); |
||
| 504 | } |
||
| 505 | |||
| 506 | // custom changes |
||
| 507 | wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
||
| 508 | |||
| 509 | } |
||
| 510 | } |
||
| 511 | |||
| 512 | |||
| 513 | } |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get inline script used if bootstrap enqueued |
||
| 517 | * |
||
| 518 | * If this remains small then its best to use this than to add another JS file. |
||
| 519 | */ |
||
| 520 | public function inline_script() { |
||
| 521 | // Flatpickr calendar locale |
||
| 522 | $flatpickr_locale = self::flatpickr_locale(); |
||
| 523 | |||
| 524 | ob_start(); |
||
| 525 | ?> |
||
| 526 | <script> |
||
| 527 | /** |
||
| 528 | * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ). |
||
| 529 | * |
||
| 530 | * Simply add the class `greedy` to any <nav> menu and it will do the rest. |
||
| 531 | * Licensed under the MIT license - http://opensource.org/licenses/MIT |
||
| 532 | * @ver 0.0.1 |
||
| 533 | */ |
||
| 534 | function aui_init_greedy_nav(){ |
||
| 535 | jQuery('nav.greedy').each(function(i, obj) { |
||
| 536 | |||
| 537 | // Check if already initialized, if so continue. |
||
| 538 | if(jQuery(this).hasClass("being-greedy")){return true;} |
||
| 539 | |||
| 540 | // Make sure its always expanded |
||
| 541 | jQuery(this).addClass('navbar-expand'); |
||
| 542 | |||
| 543 | // vars |
||
| 544 | var $vlinks = ''; |
||
| 545 | var $dDownClass = ''; |
||
| 546 | if(jQuery(this).find('.navbar-nav').length){ |
||
| 547 | if(jQuery(this).find('.navbar-nav').hasClass("being-greedy")){return true;} |
||
| 548 | $vlinks = jQuery(this).find('.navbar-nav').addClass("being-greedy w-100").removeClass('overflow-hidden'); |
||
| 549 | }else if(jQuery(this).find('.nav').length){ |
||
| 550 | if(jQuery(this).find('.nav').hasClass("being-greedy")){return true;} |
||
| 551 | $vlinks = jQuery(this).find('.nav').addClass("being-greedy w-100").removeClass('overflow-hidden'); |
||
| 552 | $dDownClass = ' mt-2 '; |
||
| 553 | }else{ |
||
| 554 | return false; |
||
| 555 | } |
||
| 556 | |||
| 557 | jQuery($vlinks).append('<li class="nav-item list-unstyled ml-auto greedy-btn d-none dropdown ">' + |
||
| 558 | '<a href="javascript:void(0)" data-toggle="dropdown" class="nav-link"><i class="fas fa-ellipsis-h"></i> <span class="greedy-count badge badge-dark badge-pill"></span></a>' + |
||
| 559 | '<ul class="greedy-links dropdown-menu dropdown-menu-right '+$dDownClass+'"></ul>' + |
||
| 560 | '</li>'); |
||
| 561 | |||
| 562 | var $hlinks = jQuery(this).find('.greedy-links'); |
||
| 563 | var $btn = jQuery(this).find('.greedy-btn'); |
||
| 564 | |||
| 565 | var numOfItems = 0; |
||
| 566 | var totalSpace = 0; |
||
| 567 | var closingTime = 1000; |
||
| 568 | var breakWidths = []; |
||
| 569 | |||
| 570 | // Get initial state |
||
| 571 | $vlinks.children().outerWidth(function(i, w) { |
||
| 572 | totalSpace += w; |
||
| 573 | numOfItems += 1; |
||
| 574 | breakWidths.push(totalSpace); |
||
| 575 | }); |
||
| 576 | |||
| 577 | var availableSpace, numOfVisibleItems, requiredSpace, buttonSpace ,timer; |
||
| 578 | |||
| 579 | /* |
||
| 580 | The check function. |
||
| 581 | */ |
||
| 582 | function check() { |
||
| 583 | |||
| 584 | // Get instant state |
||
| 585 | buttonSpace = $btn.width(); |
||
| 586 | availableSpace = $vlinks.width() - 10; |
||
| 587 | numOfVisibleItems = $vlinks.children().length; |
||
| 588 | requiredSpace = breakWidths[numOfVisibleItems - 1]; |
||
| 589 | |||
| 590 | // There is not enough space |
||
| 591 | if (numOfVisibleItems > 1 && requiredSpace > availableSpace) { |
||
| 592 | $vlinks.children().last().prev().prependTo($hlinks); |
||
| 593 | numOfVisibleItems -= 1; |
||
| 594 | check(); |
||
| 595 | // There is more than enough space |
||
| 596 | } else if (availableSpace > breakWidths[numOfVisibleItems]) { |
||
| 597 | $hlinks.children().first().insertBefore($btn); |
||
| 598 | numOfVisibleItems += 1; |
||
| 599 | check(); |
||
| 600 | } |
||
| 601 | // Update the button accordingly |
||
| 602 | jQuery($btn).find(".greedy-count").html( numOfItems - numOfVisibleItems); |
||
| 603 | if (numOfVisibleItems === numOfItems) { |
||
| 604 | $btn.addClass('d-none'); |
||
| 605 | } else $btn.removeClass('d-none'); |
||
| 606 | } |
||
| 607 | |||
| 608 | // Window listeners |
||
| 609 | jQuery(window).on("resize",function() { |
||
| 610 | check(); |
||
| 611 | }); |
||
| 612 | |||
| 613 | // do initial check |
||
| 614 | check(); |
||
| 615 | }); |
||
| 616 | } |
||
| 617 | |||
| 618 | function aui_select2_locale() { |
||
| 619 | var aui_select2_params = <?php echo self::select2_locale(); ?>; |
||
| 620 | |||
| 621 | return { |
||
| 622 | 'language': { |
||
| 623 | errorLoading: function() { |
||
| 624 | // Workaround for https://github.com/select2/select2/issues/4355 instead of i18n_ajax_error. |
||
| 625 | return aui_select2_params.i18n_searching; |
||
| 626 | }, |
||
| 627 | inputTooLong: function(args) { |
||
| 628 | var overChars = args.input.length - args.maximum; |
||
| 629 | if (1 === overChars) { |
||
| 630 | return aui_select2_params.i18n_input_too_long_1; |
||
| 631 | } |
||
| 632 | return aui_select2_params.i18n_input_too_long_n.replace('%item%', overChars); |
||
| 633 | }, |
||
| 634 | inputTooShort: function(args) { |
||
| 635 | var remainingChars = args.minimum - args.input.length; |
||
| 636 | if (1 === remainingChars) { |
||
| 637 | return aui_select2_params.i18n_input_too_short_1; |
||
| 638 | } |
||
| 639 | return aui_select2_params.i18n_input_too_short_n.replace('%item%', remainingChars); |
||
| 640 | }, |
||
| 641 | loadingMore: function() { |
||
| 642 | return aui_select2_params.i18n_load_more; |
||
| 643 | }, |
||
| 644 | maximumSelected: function(args) { |
||
| 645 | if (args.maximum === 1) { |
||
| 646 | return aui_select2_params.i18n_selection_too_long_1; |
||
| 647 | } |
||
| 648 | return aui_select2_params.i18n_selection_too_long_n.replace('%item%', args.maximum); |
||
| 649 | }, |
||
| 650 | noResults: function() { |
||
| 651 | return aui_select2_params.i18n_no_matches; |
||
| 652 | }, |
||
| 653 | searching: function() { |
||
| 654 | return aui_select2_params.i18n_searching; |
||
| 655 | } |
||
| 656 | } |
||
| 657 | }; |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Initiate Select2 items. |
||
| 662 | */ |
||
| 663 | function aui_init_select2(){ |
||
| 664 | var select2_args = jQuery.extend({}, aui_select2_locale()); |
||
| 665 | jQuery("select.aui-select2").each(function() { |
||
| 666 | if (!jQuery(this).hasClass("select2-hidden-accessible")) { |
||
| 667 | jQuery(this).select2(select2_args); |
||
| 668 | } |
||
| 669 | }); |
||
| 670 | } |
||
| 671 | |||
| 672 | /** |
||
| 673 | * A function to convert a time value to a "ago" time text. |
||
| 674 | * |
||
| 675 | * @param selector string The .class selector |
||
| 676 | */ |
||
| 677 | function aui_time_ago(selector) { |
||
| 678 | var aui_timeago_params = <?php echo self::timeago_locale(); ?>; |
||
| 679 | |||
| 680 | var templates = { |
||
| 681 | prefix: aui_timeago_params.prefix_ago, |
||
| 682 | suffix: aui_timeago_params.suffix_ago, |
||
| 683 | seconds: aui_timeago_params.seconds, |
||
| 684 | minute: aui_timeago_params.minute, |
||
| 685 | minutes: aui_timeago_params.minutes, |
||
| 686 | hour: aui_timeago_params.hour, |
||
| 687 | hours: aui_timeago_params.hours, |
||
| 688 | day: aui_timeago_params.day, |
||
| 689 | days: aui_timeago_params.days, |
||
| 690 | month: aui_timeago_params.month, |
||
| 691 | months: aui_timeago_params.months, |
||
| 692 | year: aui_timeago_params.year, |
||
| 693 | years: aui_timeago_params.years |
||
| 694 | }; |
||
| 695 | var template = function (t, n) { |
||
| 696 | return templates[t] && templates[t].replace(/%d/i, Math.abs(Math.round(n))); |
||
| 697 | }; |
||
| 698 | |||
| 699 | var timer = function (time) { |
||
| 700 | if (!time) |
||
| 701 | return; |
||
| 702 | time = time.replace(/\.\d+/, ""); // remove milliseconds |
||
| 703 | time = time.replace(/-/, "/").replace(/-/, "/"); |
||
| 704 | time = time.replace(/T/, " ").replace(/Z/, " UTC"); |
||
| 705 | time = time.replace(/([\+\-]\d\d)\:?(\d\d)/, " $1$2"); // -04:00 -> -0400 |
||
| 706 | time = new Date(time * 1000 || time); |
||
| 707 | |||
| 708 | var now = new Date(); |
||
| 709 | var seconds = ((now.getTime() - time) * .001) >> 0; |
||
| 710 | var minutes = seconds / 60; |
||
| 711 | var hours = minutes / 60; |
||
| 712 | var days = hours / 24; |
||
| 713 | var years = days / 365; |
||
| 714 | |||
| 715 | return templates.prefix + ( |
||
| 716 | seconds < 45 && template('seconds', seconds) || |
||
| 717 | seconds < 90 && template('minute', 1) || |
||
| 718 | minutes < 45 && template('minutes', minutes) || |
||
| 719 | minutes < 90 && template('hour', 1) || |
||
| 720 | hours < 24 && template('hours', hours) || |
||
| 721 | hours < 42 && template('day', 1) || |
||
| 722 | days < 30 && template('days', days) || |
||
| 723 | days < 45 && template('month', 1) || |
||
| 724 | days < 365 && template('months', days / 30) || |
||
| 725 | years < 1.5 && template('year', 1) || |
||
| 726 | template('years', years) |
||
| 727 | ) + templates.suffix; |
||
| 728 | }; |
||
| 729 | |||
| 730 | var elements = document.getElementsByClassName(selector); |
||
| 731 | if (selector && elements && elements.length) { |
||
| 732 | for (var i in elements) { |
||
| 733 | var $el = elements[i]; |
||
| 734 | if (typeof $el === 'object') { |
||
| 735 | $el.innerHTML = '<i class="far fa-clock"></i> ' + timer($el.getAttribute('title') || $el.getAttribute('datetime')); |
||
| 736 | } |
||
| 737 | } |
||
| 738 | } |
||
| 739 | |||
| 740 | // update time every minute |
||
| 741 | setTimeout(function() { |
||
| 742 | aui_time_ago(selector); |
||
| 743 | }, 60000); |
||
| 744 | |||
| 745 | } |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Initiate tooltips on the page. |
||
| 749 | */ |
||
| 750 | function aui_init_tooltips(){ |
||
| 751 | jQuery('[data-toggle="tooltip"]').tooltip(); |
||
| 752 | jQuery('[data-toggle="popover"]').popover(); |
||
| 753 | jQuery('[data-toggle="popover-html"]').popover({ |
||
| 754 | html: true |
||
| 755 | }); |
||
| 756 | |||
| 757 | // fix popover container compatibility |
||
| 758 | jQuery('[data-toggle="popover"],[data-toggle="popover-html"]').on('inserted.bs.popover', function () { |
||
| 759 | jQuery('body > .popover').wrapAll("<div class='bsui' />"); |
||
| 760 | }); |
||
| 761 | } |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Initiate flatpickrs on the page. |
||
| 765 | */ |
||
| 766 | $aui_doing_init_flatpickr = false; |
||
| 767 | function aui_init_flatpickr(){ |
||
| 768 | if ( typeof jQuery.fn.flatpickr === "function" && !$aui_doing_init_flatpickr) { |
||
| 769 | $aui_doing_init_flatpickr = true; |
||
| 770 | <?php if ( ! empty( $flatpickr_locale ) ) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?> |
||
| 771 | jQuery('input[data-aui-init="flatpickr"]:not(.flatpickr-input)').flatpickr(); |
||
| 772 | } |
||
| 773 | $aui_doing_init_flatpickr = false; |
||
| 774 | } |
||
| 775 | |||
| 776 | /** |
||
| 777 | * Initiate iconpicker on the page. |
||
| 778 | */ |
||
| 779 | $aui_doing_init_iconpicker = false; |
||
| 780 | function aui_init_iconpicker(){ |
||
| 781 | if ( typeof jQuery.fn.iconpicker === "function" && !$aui_doing_init_iconpicker) { |
||
| 782 | $aui_doing_init_iconpicker = true; |
||
| 783 | jQuery('input[data-aui-init="iconpicker"]:not(.iconpicker-input)').iconpicker(); |
||
| 784 | } |
||
| 785 | $aui_doing_init_iconpicker= false; |
||
| 786 | } |
||
| 787 | |||
| 788 | function aui_modal_iframe($title,$url,$footer,$dismissible,$class,$dialog_class,$body_class,responsive){ |
||
| 789 | if(!$body_class){$body_class = 'p-0';} |
||
| 790 | var wClass = 'text-center position-absolute w-100 text-dark overlay overlay-white p-0 m-0 d-none d-flex justify-content-center align-items-center'; |
||
| 791 | var $body = "", sClass = "w-100 p-0 m-0"; |
||
| 792 | if (responsive) { |
||
| 793 | $body += '<div class="embed-responsive embed-responsive-16by9">'; |
||
| 794 | wClass += ' h-100'; |
||
| 795 | sClass += ' embed-responsive-item'; |
||
| 796 | } else { |
||
| 797 | wClass += ' vh-100'; |
||
| 798 | sClass += ' vh-100'; |
||
| 799 | } |
||
| 800 | $body += '<div class="ac-preview-loading ' + wClass + '" style="left:0;top:0"><div class="spinner-border" role="status"></div></div>'; |
||
| 801 | $body += '<iframe id="embedModal-iframe" class="' + sClass + '" src="" width="100%" height="100%" frameborder="0" allowtransparency="true"></iframe>'; |
||
| 802 | if (responsive) { |
||
| 803 | $body += '</div>'; |
||
| 804 | } |
||
| 805 | |||
| 806 | $m = aui_modal($title,$body,$footer,$dismissible,$class,$dialog_class,$body_class); |
||
| 807 | jQuery( $m ).on( 'shown.bs.modal', function ( e ) { |
||
| 808 | iFrame = jQuery( '#embedModal-iframe') ; |
||
| 809 | |||
| 810 | jQuery('.ac-preview-loading').addClass('d-flex'); |
||
| 811 | iFrame.attr({ |
||
| 812 | src: $url |
||
| 813 | }); |
||
| 814 | |||
| 815 | //resize the iframe once loaded. |
||
| 816 | iFrame.load(function() { |
||
| 817 | jQuery('.ac-preview-loading').removeClass('d-flex'); |
||
| 818 | }); |
||
| 819 | }); |
||
| 820 | |||
| 821 | return $m; |
||
| 822 | |||
| 823 | } |
||
| 824 | |||
| 825 | function aui_modal($title,$body,$footer,$dismissible,$class,$dialog_class,$body_class) { |
||
| 826 | if(!$class){$class = '';} |
||
| 827 | if(!$dialog_class){$dialog_class = '';} |
||
| 828 | if(!$body){$body = '<div class="text-center"><div class="spinner-border" role="status"></div></div>';} |
||
| 829 | // remove it first |
||
| 830 | jQuery('.aui-modal').modal('hide').modal('dispose').remove(); |
||
| 831 | jQuery('.modal-backdrop').remove(); |
||
| 832 | |||
| 833 | var $modal = ''; |
||
| 834 | |||
| 835 | $modal += '<div class="modal aui-modal fade shadow bsui '+$class+'" tabindex="-1">'+ |
||
| 836 | '<div class="modal-dialog modal-dialog-centered '+$dialog_class+'">'+ |
||
| 837 | '<div class="modal-content border-0 shadow">'; |
||
| 838 | |||
| 839 | if($title) { |
||
| 840 | $modal += '<div class="modal-header">' + |
||
| 841 | '<h5 class="modal-title">' + $title + '</h5>'; |
||
| 842 | |||
| 843 | if ($dismissible) { |
||
| 844 | $modal += '<button type="button" class="close" data-dismiss="modal" aria-label="Close">' + |
||
| 845 | '<span aria-hidden="true">×</span>' + |
||
| 846 | '</button>'; |
||
| 847 | } |
||
| 848 | |||
| 849 | $modal += '</div>'; |
||
| 850 | } |
||
| 851 | $modal += '<div class="modal-body '+$body_class+'">'+ |
||
| 852 | $body+ |
||
| 853 | '</div>'; |
||
| 854 | |||
| 855 | if($footer){ |
||
| 856 | $modal += '<div class="modal-footer">'+ |
||
| 857 | $footer + |
||
| 858 | '</div>'; |
||
| 859 | } |
||
| 860 | |||
| 861 | $modal +='</div>'+ |
||
| 862 | '</div>'+ |
||
| 863 | '</div>'; |
||
| 864 | |||
| 865 | jQuery('body').append($modal); |
||
| 866 | |||
| 867 | return jQuery('.aui-modal').modal('hide').modal({ |
||
| 868 | //backdrop: 'static' |
||
| 869 | }); |
||
| 870 | } |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Show / hide fields depending on conditions. |
||
| 874 | */ |
||
| 875 | function aui_conditional_fields(form){ |
||
| 876 | jQuery(form).find(".aui-conditional-field").each(function () { |
||
| 877 | |||
| 878 | var $element_require = jQuery(this).data('element-require'); |
||
| 879 | |||
| 880 | if ($element_require) { |
||
| 881 | |||
| 882 | $element_require = $element_require.replace("'", "'"); // replace single quotes |
||
| 883 | $element_require = $element_require.replace(""", '"'); // replace double quotes |
||
| 884 | if (aui_check_form_condition($element_require,form)) { |
||
| 885 | jQuery(this).removeClass('d-none'); |
||
| 886 | } else { |
||
| 887 | jQuery(this).addClass('d-none'); |
||
| 888 | } |
||
| 889 | } |
||
| 890 | }); |
||
| 891 | } |
||
| 892 | |||
| 893 | /** |
||
| 894 | * Check form condition |
||
| 895 | */ |
||
| 896 | function aui_check_form_condition(condition,form) { |
||
| 897 | if (form) { |
||
| 898 | condition = condition.replace(/\(form\)/g, "('"+form+"')"); |
||
| 899 | } |
||
| 900 | return new Function("return " + condition+";")(); |
||
| 901 | } |
||
| 902 | |||
| 903 | /** |
||
| 904 | * A function to determine if a element is on screen. |
||
| 905 | */ |
||
| 906 | jQuery.fn.aui_isOnScreen = function(){ |
||
| 907 | |||
| 908 | var win = jQuery(window); |
||
| 909 | |||
| 910 | var viewport = { |
||
| 911 | top : win.scrollTop(), |
||
| 912 | left : win.scrollLeft() |
||
| 913 | }; |
||
| 914 | viewport.right = viewport.left + win.width(); |
||
| 915 | viewport.bottom = viewport.top + win.height(); |
||
| 916 | |||
| 917 | var bounds = this.offset(); |
||
| 918 | bounds.right = bounds.left + this.outerWidth(); |
||
| 919 | bounds.bottom = bounds.top + this.outerHeight(); |
||
| 920 | |||
| 921 | return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); |
||
| 922 | |||
| 923 | }; |
||
| 924 | |||
| 925 | /** |
||
| 926 | * Maybe show multiple carousel items if set to do so. |
||
| 927 | */ |
||
| 928 | function aui_carousel_maybe_show_multiple_items($carousel){ |
||
| 929 | var $items = {}; |
||
| 930 | var $item_count = 0; |
||
| 931 | |||
| 932 | // maybe backup |
||
| 933 | if(!jQuery($carousel).find('.carousel-inner-original').length){ |
||
| 934 | jQuery($carousel).append('<div class="carousel-inner-original d-none">'+jQuery($carousel).find('.carousel-inner').html()+'</div>'); |
||
| 935 | } |
||
| 936 | |||
| 937 | // Get the original items html |
||
| 938 | jQuery($carousel).find('.carousel-inner-original .carousel-item').each(function () { |
||
| 939 | $items[$item_count] = jQuery(this).html(); |
||
| 940 | $item_count++; |
||
| 941 | }); |
||
| 942 | |||
| 943 | // bail if no items |
||
| 944 | if(!$item_count){return;} |
||
| 945 | |||
| 946 | if(jQuery(window).width() <= 576){ |
||
| 947 | // maybe restore original |
||
| 948 | if(jQuery($carousel).find('.carousel-inner').hasClass('aui-multiple-items') && jQuery($carousel).find('.carousel-inner-original').length){ |
||
| 949 | jQuery($carousel).find('.carousel-inner').removeClass('aui-multiple-items').html(jQuery($carousel).find('.carousel-inner-original').html()); |
||
| 950 | jQuery($carousel).find(".carousel-indicators li").removeClass("d-none"); |
||
| 951 | } |
||
| 952 | |||
| 953 | }else{ |
||
| 954 | // new items |
||
| 955 | var $md_count = jQuery($carousel).data('limit_show'); |
||
| 956 | var $new_items = ''; |
||
| 957 | var $new_items_count = 0; |
||
| 958 | var $new_item_count = 0; |
||
| 959 | var $closed = true; |
||
| 960 | Object.keys($items).forEach(function(key,index) { |
||
| 961 | |||
| 962 | // close |
||
| 963 | if(index != 0 && Number.isInteger(index/$md_count) ){ |
||
| 964 | $new_items += '</div></div>'; |
||
| 965 | $closed = true; |
||
| 966 | } |
||
| 967 | |||
| 968 | // open |
||
| 969 | if(index == 0 || Number.isInteger(index/$md_count) ){ |
||
| 970 | $active = index == 0 ? 'active' : ''; |
||
| 971 | $new_items += '<div class="carousel-item '+$active+'"><div class="row m-0">'; |
||
| 972 | $closed = false; |
||
| 973 | $new_items_count++; |
||
| 974 | $new_item_count = 0; |
||
| 975 | } |
||
| 976 | |||
| 977 | // content |
||
| 978 | $new_items += '<div class="col pr-1 pl-0">'+$items[index]+'</div>'; |
||
| 979 | $new_item_count++; |
||
| 980 | |||
| 981 | |||
| 982 | }); |
||
| 983 | |||
| 984 | // close if not closed in the loop |
||
| 985 | if(!$closed){ |
||
| 986 | // check for spares |
||
| 987 | if($md_count-$new_item_count > 0){ |
||
| 988 | $placeholder_count = $md_count-$new_item_count; |
||
| 989 | while($placeholder_count > 0){ |
||
| 990 | $new_items += '<div class="col pr-1 pl-0"></div>'; |
||
| 991 | $placeholder_count--; |
||
| 992 | } |
||
| 993 | |||
| 994 | } |
||
| 995 | |||
| 996 | $new_items += '</div></div>'; |
||
| 997 | } |
||
| 998 | |||
| 999 | // insert the new items |
||
| 1000 | jQuery($carousel).find('.carousel-inner').addClass('aui-multiple-items').html($new_items); |
||
| 1001 | |||
| 1002 | // fix any lazyload images in the active slider |
||
| 1003 | jQuery($carousel).find('.carousel-item.active img').each(function () { |
||
| 1004 | // fix the srcset |
||
| 1005 | if(real_srcset = jQuery(this).attr("data-srcset")){ |
||
| 1006 | if(!jQuery(this).attr("srcset")) jQuery(this).attr("srcset",real_srcset); |
||
| 1007 | } |
||
| 1008 | // fix the src |
||
| 1009 | if(real_src = jQuery(this).attr("data-src")){ |
||
| 1010 | if(!jQuery(this).attr("srcset")) jQuery(this).attr("src",real_src); |
||
| 1011 | } |
||
| 1012 | }); |
||
| 1013 | |||
| 1014 | // maybe fix carousel indicators |
||
| 1015 | $hide_count = $new_items_count-1; |
||
| 1016 | jQuery($carousel).find(".carousel-indicators li:gt("+$hide_count+")").addClass("d-none"); |
||
| 1017 | } |
||
| 1018 | |||
| 1019 | // trigger a global action to say we have |
||
| 1020 | jQuery( window ).trigger( "aui_carousel_multiple" ); |
||
| 1021 | } |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Init Multiple item carousels. |
||
| 1025 | */ |
||
| 1026 | function aui_init_carousel_multiple_items(){ |
||
| 1027 | jQuery(window).on("resize",function(){ |
||
| 1028 | jQuery('.carousel-multiple-items').each(function () { |
||
| 1029 | aui_carousel_maybe_show_multiple_items(this); |
||
| 1030 | }); |
||
| 1031 | }); |
||
| 1032 | |||
| 1033 | // run now |
||
| 1034 | jQuery('.carousel-multiple-items').each(function () { |
||
| 1035 | aui_carousel_maybe_show_multiple_items(this); |
||
| 1036 | }); |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Allow navs to use multiple sub menus. |
||
| 1041 | */ |
||
| 1042 | function init_nav_sub_menus(){ |
||
| 1043 | |||
| 1044 | jQuery('.navbar-multi-sub-menus').each(function(i, obj) { |
||
| 1045 | // Check if already initialized, if so continue. |
||
| 1046 | if(jQuery(this).hasClass("has-sub-sub-menus")){return true;} |
||
| 1047 | |||
| 1048 | // Make sure its always expanded |
||
| 1049 | jQuery(this).addClass('has-sub-sub-menus'); |
||
| 1050 | |||
| 1051 | jQuery(this).find( '.dropdown-menu a.dropdown-toggle' ).on( 'click', function ( e ) { |
||
| 1052 | var $el = jQuery( this ); |
||
| 1053 | $el.toggleClass('active-dropdown'); |
||
| 1054 | var $parent = jQuery( this ).offsetParent( ".dropdown-menu" ); |
||
| 1055 | if ( !jQuery( this ).next().hasClass( 'show' ) ) { |
||
| 1056 | jQuery( this ).parents( '.dropdown-menu' ).first().find( '.show' ).removeClass( "show" ); |
||
| 1057 | } |
||
| 1058 | var $subMenu = jQuery( this ).next( ".dropdown-menu" ); |
||
| 1059 | $subMenu.toggleClass( 'show' ); |
||
| 1060 | |||
| 1061 | jQuery( this ).parent( "li" ).toggleClass( 'show' ); |
||
| 1062 | |||
| 1063 | jQuery( this ).parents( 'li.nav-item.dropdown.show' ).on( 'hidden.bs.dropdown', function ( e ) { |
||
| 1064 | jQuery( '.dropdown-menu .show' ).removeClass( "show" ); |
||
| 1065 | $el.removeClass('active-dropdown'); |
||
| 1066 | } ); |
||
| 1067 | |||
| 1068 | if ( !$parent.parent().hasClass( 'navbar-nav' ) ) { |
||
| 1069 | $el.next().addClass('position-relative border-top border-bottom'); |
||
| 1070 | } |
||
| 1071 | |||
| 1072 | return false; |
||
| 1073 | } ); |
||
| 1074 | |||
| 1075 | }); |
||
| 1076 | |||
| 1077 | } |
||
| 1078 | |||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Open a lightbox when an embed item is clicked. |
||
| 1082 | */ |
||
| 1083 | function aui_lightbox_embed($link,ele){ |
||
| 1084 | ele.preventDefault(); |
||
| 1085 | |||
| 1086 | // remove it first |
||
| 1087 | jQuery('.aui-carousel-modal').remove(); |
||
| 1088 | |||
| 1089 | var $modal = '<div class="modal fade aui-carousel-modal bsui" tabindex="-1" role="dialog" aria-labelledby="aui-modal-title" aria-hidden="true"><div class="modal-dialog modal-dialog-centered modal-xl mw-100"><div class="modal-content bg-transparent border-0"><div class="modal-header"><h5 class="modal-title" id="aui-modal-title"></h5></div><div class="modal-body text-center"><i class="fas fa-circle-notch fa-spin fa-3x"></i></div></div></div></div>'; |
||
| 1090 | jQuery('body').append($modal); |
||
| 1091 | |||
| 1092 | jQuery('.aui-carousel-modal').modal({ |
||
| 1093 | //backdrop: 'static' |
||
| 1094 | }); |
||
| 1095 | jQuery('.aui-carousel-modal').on('hidden.bs.modal', function (e) { |
||
| 1096 | jQuery("iframe").attr('src', ''); |
||
| 1097 | }); |
||
| 1098 | |||
| 1099 | $container = jQuery($link).closest('.aui-gallery'); |
||
| 1100 | |||
| 1101 | $clicked_href = jQuery($link).attr('href'); |
||
| 1102 | $images = []; |
||
| 1103 | $container.find('.aui-lightbox-image').each(function() { |
||
| 1104 | var a = this; |
||
| 1105 | var href = jQuery(a).attr('href'); |
||
| 1106 | if (href) { |
||
| 1107 | $images.push(href); |
||
| 1108 | } |
||
| 1109 | }); |
||
| 1110 | |||
| 1111 | if( $images.length ){ |
||
| 1112 | var $carousel = '<div id="aui-embed-slider-modal" class="carousel slide" >'; |
||
| 1113 | |||
| 1114 | // indicators |
||
| 1115 | if($images.length > 1){ |
||
| 1116 | $i = 0; |
||
| 1117 | $carousel += '<ol class="carousel-indicators position-fixed">'; |
||
| 1118 | $container.find('.aui-lightbox-image').each(function() { |
||
| 1119 | $active = $clicked_href == jQuery(this).attr('href') ? 'active' : ''; |
||
| 1120 | $carousel += '<li data-target="#aui-embed-slider-modal" data-slide-to="'+$i+'" class="'+$active+'"></li>'; |
||
| 1121 | $i++; |
||
| 1122 | |||
| 1123 | }); |
||
| 1124 | $carousel += '</ol>'; |
||
| 1125 | } |
||
| 1126 | |||
| 1127 | |||
| 1128 | |||
| 1129 | // items |
||
| 1130 | $i = 0; |
||
| 1131 | $carousel += '<div class="carousel-inner">'; |
||
| 1132 | $container.find('.aui-lightbox-image').each(function() { |
||
| 1133 | var a = this; |
||
| 1134 | |||
| 1135 | $active = $clicked_href == jQuery(this).attr('href') ? 'active' : ''; |
||
| 1136 | $carousel += '<div class="carousel-item '+ $active+'"><div>'; |
||
| 1137 | |||
| 1138 | |||
| 1139 | // image |
||
| 1140 | var css_height = window.innerWidth > window.innerHeight ? '90vh' : 'auto'; |
||
| 1141 | var img = jQuery(a).find('img').clone().removeClass().addClass('mx-auto d-block w-auto mw-100 rounded').css('max-height',css_height).get(0).outerHTML; |
||
| 1142 | $carousel += img; |
||
| 1143 | // captions |
||
| 1144 | if(jQuery(a).parent().find('.carousel-caption').length ){ |
||
| 1145 | $carousel += jQuery(a).parent().find('.carousel-caption').clone().removeClass('sr-only').get(0).outerHTML; |
||
| 1146 | }else if(jQuery(a).parent().find('.figure-caption').length ){ |
||
| 1147 | $carousel += jQuery(a).parent().find('.figure-caption').clone().removeClass('sr-only').addClass('carousel-caption').get(0).outerHTML; |
||
| 1148 | } |
||
| 1149 | $carousel += '</div></div>'; |
||
| 1150 | $i++; |
||
| 1151 | |||
| 1152 | }); |
||
| 1153 | $container.find('.aui-lightbox-iframe').each(function() { |
||
| 1154 | var a = this; |
||
| 1155 | |||
| 1156 | $active = $clicked_href == jQuery(this).attr('href') ? 'active' : ''; |
||
| 1157 | $carousel += '<div class="carousel-item '+ $active+'"><div class="modal-xl mx-auto embed-responsive embed-responsive-16by9">'; |
||
| 1158 | |||
| 1159 | |||
| 1160 | // iframe |
||
| 1161 | var css_height = window.innerWidth > window.innerHeight ? '95vh' : 'auto'; |
||
| 1162 | var url = jQuery(a).attr('href'); |
||
| 1163 | var iframe = '<iframe class="embed-responsive-item" style="height:'+css_height +'" src="'+url+'?rel=0&showinfo=0&modestbranding=1&autoplay=1" id="video" allow="autoplay"></iframe>'; |
||
| 1164 | var img = iframe ;//.css('height',css_height).get(0).outerHTML; |
||
| 1165 | $carousel += img; |
||
| 1166 | |||
| 1167 | $carousel += '</div></div>'; |
||
| 1168 | $i++; |
||
| 1169 | |||
| 1170 | }); |
||
| 1171 | $carousel += '</div>'; |
||
| 1172 | |||
| 1173 | |||
| 1174 | // next/prev indicators |
||
| 1175 | if($images.length > 1) { |
||
| 1176 | $carousel += '<a class="carousel-control-prev" href="#aui-embed-slider-modal" role="button" data-slide="prev">'; |
||
| 1177 | $carousel += '<span class="carousel-control-prev-icon" aria-hidden="true"></span>'; |
||
| 1178 | $carousel += ' <a class="carousel-control-next" href="#aui-embed-slider-modal" role="button" data-slide="next">'; |
||
| 1179 | $carousel += '<span class="carousel-control-next-icon" aria-hidden="true"></span>'; |
||
| 1180 | $carousel += '</a>'; |
||
| 1181 | } |
||
| 1182 | |||
| 1183 | |||
| 1184 | $carousel += '</div>'; |
||
| 1185 | |||
| 1186 | var $close = '<button type="button" class="close text-white text-right position-fixed" style="font-size: 2.5em;right: 20px;top: 10px; z-index: 1055;" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>'; |
||
| 1187 | |||
| 1188 | jQuery('.aui-carousel-modal .modal-content').html($carousel).prepend($close); |
||
| 1189 | |||
| 1190 | // enable ajax load |
||
| 1191 | //gd_init_carousel_ajax(); |
||
| 1192 | } |
||
| 1193 | |||
| 1194 | } |
||
| 1195 | |||
| 1196 | /** |
||
| 1197 | * Init lightbox embed. |
||
| 1198 | */ |
||
| 1199 | function aui_init_lightbox_embed(){ |
||
| 1200 | // Open a lightbox for embeded items |
||
| 1201 | jQuery('.aui-lightbox-image, .aui-lightbox-iframe').off('click').on("click",function(ele) { |
||
| 1202 | aui_lightbox_embed(this,ele); |
||
| 1203 | }); |
||
| 1204 | } |
||
| 1205 | |||
| 1206 | /** |
||
| 1207 | * Init modal iframe. |
||
| 1208 | */ |
||
| 1209 | function aui_init_modal_iframe() { |
||
| 1210 | jQuery('.aui-has-embed, [data-aui-embed="iframe"]').each(function(e){ |
||
| 1211 | if (!jQuery(this).hasClass('aui-modal-iframed') && jQuery(this).data('embed-url')) { |
||
| 1212 | jQuery(this).addClass('aui-modal-iframed'); |
||
| 1213 | |||
| 1214 | jQuery(this).on("click",function(e1) { |
||
| 1215 | aui_modal_iframe('',jQuery(this).data('embed-url'),'',true,'','modal-lg','aui-modal-iframe p-0',true); |
||
| 1216 | return false; |
||
| 1217 | }); |
||
| 1218 | } |
||
| 1219 | }); |
||
| 1220 | } |
||
| 1221 | |||
| 1222 | /** |
||
| 1223 | * Show a toast. |
||
| 1224 | */ |
||
| 1225 | $aui_doing_toast = false; |
||
| 1226 | function aui_toast($id,$type,$title,$title_small,$body,$time,$can_close){ |
||
| 1227 | |||
| 1228 | if($aui_doing_toast){setTimeout(function(){ |
||
| 1229 | aui_toast($id,$type,$title,$title_small,$body,$time,$can_close); |
||
| 1230 | }, 500); return;} |
||
| 1231 | |||
| 1232 | $aui_doing_toast = true; |
||
| 1233 | |||
| 1234 | if($can_close == null){$can_close = false;} |
||
| 1235 | if($time == '' || $time == null ){$time = 3000;} |
||
| 1236 | |||
| 1237 | // if already setup then just show |
||
| 1238 | if(document.getElementById($id)){ |
||
| 1239 | jQuery('#'+$id).toast('show'); |
||
| 1240 | setTimeout(function(){ $aui_doing_toast = false; }, 500); |
||
| 1241 | return; |
||
| 1242 | } |
||
| 1243 | |||
| 1244 | var uniqid = Date.now(); |
||
| 1245 | if($id){ |
||
| 1246 | uniqid = $id; |
||
| 1247 | } |
||
| 1248 | |||
| 1249 | $op = ""; |
||
| 1250 | $tClass = ''; |
||
| 1251 | $thClass = ''; |
||
| 1252 | $icon = ""; |
||
| 1253 | |||
| 1254 | if ($type == 'success') { |
||
| 1255 | $op = "opacity:.92;"; |
||
| 1256 | $tClass = 'alert alert-success'; |
||
| 1257 | $thClass = 'bg-transparent border-0 alert-success'; |
||
| 1258 | $icon = "<div class='h5 m-0 p-0'><i class='fas fa-check-circle mr-2'></i></div>"; |
||
| 1259 | } else if ($type == 'error' || $type == 'danger') { |
||
| 1260 | $op = "opacity:.92;"; |
||
| 1261 | $tClass = 'alert alert-danger'; |
||
| 1262 | $thClass = 'bg-transparent border-0 alert-danger'; |
||
| 1263 | $icon = "<div class='h5 m-0 p-0'><i class='far fa-times-circle mr-2'></i></div>"; |
||
| 1264 | } else if ($type == 'info') { |
||
| 1265 | $op = "opacity:.92;"; |
||
| 1266 | $tClass = 'alert alert-info'; |
||
| 1267 | $thClass = 'bg-transparent border-0 alert-info'; |
||
| 1268 | $icon = "<div class='h5 m-0 p-0'><i class='fas fa-info-circle mr-2'></i></div>"; |
||
| 1269 | } else if ($type == 'warning') { |
||
| 1270 | $op = "opacity:.92;"; |
||
| 1271 | $tClass = 'alert alert-warning'; |
||
| 1272 | $thClass = 'bg-transparent border-0 alert-warning'; |
||
| 1273 | $icon = "<div class='h5 m-0 p-0'><i class='fas fa-exclamation-triangle mr-2'></i></div>"; |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | |||
| 1277 | // add container if not exist |
||
| 1278 | if(!document.getElementById("aui-toasts")){ |
||
| 1279 | jQuery('body').append('<div class="bsui" id="aui-toasts"><div class="position-fixed aui-toast-bottom-right pr-3 mb-1" style="z-index: 500000;right: 0;bottom: 0;'+$op+'"></div></div>'); |
||
| 1280 | } |
||
| 1281 | |||
| 1282 | $toast = '<div id="'+uniqid+'" class="toast fade hide shadow hover-shadow '+$tClass+'" style="" role="alert" aria-live="assertive" aria-atomic="true" data-delay="'+$time+'">'; |
||
| 1283 | if($type || $title || $title_small){ |
||
| 1284 | $toast += '<div class="toast-header '+$thClass+'">'; |
||
| 1285 | if($icon ){$toast += $icon;} |
||
| 1286 | if($title){$toast += '<strong class="mr-auto">'+$title+'</strong>';} |
||
| 1287 | if($title_small){$toast += '<small>'+$title_small+'</small>';} |
||
| 1288 | if($can_close){$toast += '<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close"><span aria-hidden="true">×</span></button>';} |
||
| 1289 | $toast += '</div>'; |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | if($body){ |
||
| 1293 | $toast += '<div class="toast-body">'+$body+'</div>'; |
||
| 1294 | } |
||
| 1295 | |||
| 1296 | $toast += '</div>'; |
||
| 1297 | |||
| 1298 | jQuery('.aui-toast-bottom-right').prepend($toast); |
||
| 1299 | jQuery('#'+uniqid).toast('show'); |
||
| 1300 | setTimeout(function(){ $aui_doing_toast = false; }, 500); |
||
| 1301 | } |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Animate a number. |
||
| 1305 | */ |
||
| 1306 | function aui_init_counters(){ |
||
| 1307 | |||
| 1308 | const animNum = (EL) => { |
||
| 1309 | |||
| 1310 | if (EL._isAnimated) return; // Animate only once! |
||
| 1311 | EL._isAnimated = true; |
||
| 1312 | |||
| 1313 | let end = EL.dataset.auiend; |
||
| 1314 | let start = EL.dataset.auistart; |
||
| 1315 | let duration = EL.dataset.auiduration ? EL.dataset.auiduration : 2000; |
||
| 1316 | let seperator = EL.dataset.auisep ? EL.dataset.auisep: ''; |
||
| 1317 | |||
| 1318 | jQuery(EL).prop('Counter', start).animate({ |
||
| 1319 | Counter: end |
||
| 1320 | }, { |
||
| 1321 | duration: Math.abs(duration), |
||
| 1322 | easing: 'swing', |
||
| 1323 | step: function(now) { |
||
| 1324 | const text = seperator ? (Math.ceil(now)).toLocaleString('en-US') : Math.ceil(now); |
||
| 1325 | const html = seperator ? text.split(",").map(n => `<span class="count">${n}</span>`).join(",") : text; |
||
| 1326 | if(seperator && seperator!=','){ |
||
| 1327 | html.replace(',',seperator); |
||
| 1328 | } |
||
| 1329 | jQuery(this).html(html); |
||
| 1330 | } |
||
| 1331 | }); |
||
| 1332 | }; |
||
| 1333 | |||
| 1334 | const inViewport = (entries, observer) => { |
||
| 1335 | // alert(1); |
||
| 1336 | entries.forEach(entry => { |
||
| 1337 | if (entry.isIntersecting) animNum(entry.target); |
||
| 1338 | }); |
||
| 1339 | }; |
||
| 1340 | |||
| 1341 | jQuery("[data-auicounter]").each((i, EL) => { |
||
| 1342 | const observer = new IntersectionObserver(inViewport); |
||
| 1343 | observer.observe(EL); |
||
| 1344 | }); |
||
| 1345 | } |
||
| 1346 | |||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Initiate all AUI JS. |
||
| 1350 | */ |
||
| 1351 | function aui_init(){ |
||
| 1352 | |||
| 1353 | // init counters |
||
| 1354 | aui_init_counters(); |
||
| 1355 | |||
| 1356 | // nav menu submenus |
||
| 1357 | init_nav_sub_menus(); |
||
| 1358 | |||
| 1359 | // init tooltips |
||
| 1360 | aui_init_tooltips(); |
||
| 1361 | |||
| 1362 | // init select2 |
||
| 1363 | aui_init_select2(); |
||
| 1364 | |||
| 1365 | // init flatpickr |
||
| 1366 | aui_init_flatpickr(); |
||
| 1367 | |||
| 1368 | // init iconpicker |
||
| 1369 | aui_init_iconpicker(); |
||
| 1370 | |||
| 1371 | // init Greedy nav |
||
| 1372 | aui_init_greedy_nav(); |
||
| 1373 | |||
| 1374 | // Set times to time ago |
||
| 1375 | aui_time_ago('timeago'); |
||
| 1376 | |||
| 1377 | // init multiple item carousels |
||
| 1378 | aui_init_carousel_multiple_items(); |
||
| 1379 | |||
| 1380 | // init lightbox embeds |
||
| 1381 | aui_init_lightbox_embed(); |
||
| 1382 | |||
| 1383 | /* Init modal iframe */ |
||
| 1384 | aui_init_modal_iframe(); |
||
| 1385 | } |
||
| 1386 | |||
| 1387 | // run on window loaded |
||
| 1388 | jQuery(window).on("load",function() { |
||
| 1389 | aui_init(); |
||
| 1390 | }); |
||
| 1391 | |||
| 1392 | /* Fix modal background scroll on iOS mobile device */ |
||
| 1393 | jQuery(function($) { |
||
| 1394 | var ua = navigator.userAgent.toLowerCase(); |
||
| 1395 | var isiOS = ua.match(/(iphone|ipod|ipad)/); |
||
| 1396 | if (isiOS) { |
||
| 1397 | var pS = 0; pM = parseFloat($('body').css('marginTop')); |
||
| 1398 | |||
| 1399 | $(document).on('show.bs.modal', function() { |
||
| 1400 | pS = window.scrollY; |
||
| 1401 | $('body').css({ |
||
| 1402 | marginTop: -pS, |
||
| 1403 | overflow: 'hidden', |
||
| 1404 | position: 'fixed', |
||
| 1405 | }); |
||
| 1406 | }).on('hidden.bs.modal', function() { |
||
| 1407 | $('body').css({ |
||
| 1408 | marginTop: pM, |
||
| 1409 | overflow: 'visible', |
||
| 1410 | position: 'inherit', |
||
| 1411 | }); |
||
| 1412 | window.scrollTo(0, pS); |
||
| 1413 | }); |
||
| 1414 | } |
||
| 1415 | }); |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Show a "confirm" dialog to the user (using jQuery UI's dialog) |
||
| 1419 | * |
||
| 1420 | * @param {string} message The message to display to the user |
||
| 1421 | * @param {string} okButtonText OPTIONAL - The OK button text, defaults to "Yes" |
||
| 1422 | * @param {string} cancelButtonText OPTIONAL - The Cancel button text, defaults to "No" |
||
| 1423 | * @returns {Q.Promise<boolean>} A promise of a boolean value |
||
| 1424 | */ |
||
| 1425 | var aui_confirm = function (message, okButtonText, cancelButtonText, isDelete, large ) { |
||
| 1426 | okButtonText = okButtonText || 'Yes'; |
||
| 1427 | cancelButtonText = cancelButtonText || 'Cancel'; |
||
| 1428 | message = message || 'Are you sure?'; |
||
| 1429 | sizeClass = large ? '' : 'modal-sm'; |
||
| 1430 | btnClass = isDelete ? 'btn-danger' : 'btn-primary'; |
||
| 1431 | |||
| 1432 | deferred = jQuery.Deferred(); |
||
| 1433 | var $body = ""; |
||
| 1434 | $body += "<h3 class='h4 py-3 text-center text-dark'>"+message+"</h3>"; |
||
| 1435 | $body += "<div class='d-flex'>"; |
||
| 1436 | $body += "<button class='btn btn-outline-secondary w-50 btn-round' data-dismiss='modal' onclick='deferred.resolve(false);'>"+cancelButtonText+"</button>"; |
||
| 1437 | $body += "<button class='btn "+btnClass+" ml-2 w-50 btn-round' data-dismiss='modal' onclick='deferred.resolve(true);'>"+okButtonText+"</button>"; |
||
| 1438 | $body += "</div>"; |
||
| 1439 | $modal = aui_modal('',$body,'',false,'',sizeClass); |
||
| 1440 | |||
| 1441 | return deferred.promise(); |
||
| 1442 | }; |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Add a window scrolled data element. |
||
| 1446 | */ |
||
| 1447 | window.onscroll = function () { |
||
| 1448 | aui_set_data_scroll() |
||
| 1449 | }; |
||
| 1450 | |||
| 1451 | /** |
||
| 1452 | * Set scroll data element. |
||
| 1453 | */ |
||
| 1454 | function aui_set_data_scroll(){ |
||
| 1455 | document.documentElement.dataset.scroll = window.scrollY; |
||
| 1456 | } |
||
| 1457 | |||
| 1458 | // call data scroll function ASAP. |
||
| 1459 | aui_set_data_scroll(); |
||
| 1460 | |||
| 1461 | <?php |
||
| 1462 | // FSE tweaks. |
||
| 1463 | if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
||
| 1464 | function aui_fse_set_data_scroll() { |
||
| 1465 | console.log('init scroll'); |
||
| 1466 | let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas"); |
||
| 1467 | if( Iframe[0] === undefined ){ return; } |
||
| 1468 | let iframe_doc = Iframe[0].contentWindow ? Iframe[0].contentWindow.document : Iframe[0].contentDocument; |
||
| 1469 | Iframe[0].contentWindow.onscroll = function () { |
||
| 1470 | iframe_doc.documentElement.dataset.scroll = Iframe[0].contentWindow.scrollY; |
||
| 1471 | }; |
||
| 1472 | } |
||
| 1473 | |||
| 1474 | setTimeout(function(){ |
||
| 1475 | aui_fse_set_data_scroll(); |
||
| 1476 | }, 3000); |
||
| 1477 | |||
| 1478 | // fire when URL changes also. |
||
| 1479 | let FSElastUrl = location.href; |
||
| 1480 | new MutationObserver(() => { |
||
| 1481 | const url = location.href; |
||
| 1482 | if (url !== FSElastUrl) { |
||
| 1483 | FSElastUrl = url; |
||
| 1484 | aui_fse_set_data_scroll(); |
||
| 1485 | // fire a second time incase of load delays. |
||
| 1486 | setTimeout(function(){ |
||
| 1487 | aui_fse_set_data_scroll(); |
||
| 1488 | }, 2000); |
||
| 1489 | } |
||
| 1490 | }).observe(document, {subtree: true, childList: true}); |
||
| 1491 | <?php } ?> |
||
| 1492 | |||
| 1493 | |||
| 1494 | </script> |
||
| 1495 | <?php |
||
| 1496 | $output = ob_get_clean(); |
||
| 1497 | |||
| 1498 | |||
| 1499 | |||
| 1500 | /* |
||
| 1501 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
| 1502 | */ |
||
| 1503 | return str_replace( array( |
||
| 1504 | '<script>', |
||
| 1505 | '</script>' |
||
| 1506 | ), '', self::minify_js($output) ); |
||
| 1507 | } |
||
| 1508 | |||
| 1509 | |||
| 1510 | /** |
||
| 1511 | * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
||
| 1512 | * |
||
| 1513 | * @TODO we may need this when other conflicts arrise. |
||
| 1514 | * @return mixed |
||
| 1515 | */ |
||
| 1516 | public static function bs3_compat_js() { |
||
| 1517 | ob_start(); |
||
| 1518 | ?> |
||
| 1519 | <script> |
||
| 1520 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
||
| 1521 | /* With Avada builder */ |
||
| 1522 | |||
| 1523 | <?php } ?> |
||
| 1524 | </script> |
||
| 1525 | <?php |
||
| 1526 | return str_replace( array( |
||
| 1527 | '<script>', |
||
| 1528 | '</script>' |
||
| 1529 | ), '', ob_get_clean()); |
||
| 1530 | } |
||
| 1531 | |||
| 1532 | /** |
||
| 1533 | * Get inline script used if bootstrap file browser enqueued. |
||
| 1534 | * |
||
| 1535 | * If this remains small then its best to use this than to add another JS file. |
||
| 1536 | */ |
||
| 1537 | public function inline_script_file_browser(){ |
||
| 1538 | ob_start(); |
||
| 1539 | ?> |
||
| 1540 | <script> |
||
| 1541 | // run on doc ready |
||
| 1542 | jQuery(document).ready(function () { |
||
| 1543 | bsCustomFileInput.init(); |
||
| 1544 | }); |
||
| 1545 | </script> |
||
| 1546 | <?php |
||
| 1547 | $output = ob_get_clean(); |
||
| 1548 | |||
| 1549 | /* |
||
| 1550 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
| 1551 | */ |
||
| 1552 | return str_replace( array( |
||
| 1553 | '<script>', |
||
| 1554 | '</script>' |
||
| 1555 | ), '', $output ); |
||
| 1556 | } |
||
| 1557 | |||
| 1558 | /** |
||
| 1559 | * Adds the Font Awesome JS. |
||
| 1560 | */ |
||
| 1561 | public function enqueue_scripts() { |
||
| 1562 | |||
| 1563 | if( is_admin() && !$this->is_aui_screen()){ |
||
| 1564 | // don't add wp-admin scripts if not requested to |
||
| 1565 | }else { |
||
| 1566 | |||
| 1567 | $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
||
| 1568 | |||
| 1569 | // select2 |
||
| 1570 | wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
||
| 1571 | |||
| 1572 | // flatpickr |
||
| 1573 | wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version ); |
||
| 1574 | |||
| 1575 | // flatpickr |
||
| 1576 | wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version ); |
||
| 1577 | |||
| 1578 | // Bootstrap file browser |
||
| 1579 | wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
||
| 1580 | wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
||
| 1581 | |||
| 1582 | $load_inline = false; |
||
| 1583 | |||
| 1584 | if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
||
| 1585 | // Bootstrap bundle |
||
| 1586 | $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
||
| 1587 | wp_register_script( 'bootstrap-js-bundle', $url, array( |
||
| 1588 | 'select2', |
||
| 1589 | 'jquery' |
||
| 1590 | ), $this->version, $this->is_bs3_compat() ); |
||
| 1591 | // if in admin then add to footer for compatibility. |
||
| 1592 | is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
||
| 1593 | $script = $this->inline_script(); |
||
| 1594 | wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
||
| 1595 | } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
||
| 1596 | $url = $this->url . 'assets/js/popper.min.js'; |
||
| 1597 | wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version ); |
||
| 1598 | wp_enqueue_script( 'bootstrap-js-popper' ); |
||
| 1599 | $load_inline = true; |
||
| 1600 | } else { |
||
| 1601 | $load_inline = true; |
||
| 1602 | } |
||
| 1603 | |||
| 1604 | // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
||
| 1605 | if ( $load_inline ) { |
||
| 1606 | wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
||
| 1607 | wp_enqueue_script( 'bootstrap-dummy' ); |
||
| 1608 | $script = $this->inline_script(); |
||
| 1609 | wp_add_inline_script( 'bootstrap-dummy', $script ); |
||
| 1610 | } |
||
| 1611 | } |
||
| 1612 | |||
| 1613 | } |
||
| 1614 | |||
| 1615 | /** |
||
| 1616 | * Enqueue flatpickr if called. |
||
| 1617 | */ |
||
| 1618 | public function enqueue_flatpickr(){ |
||
| 1619 | wp_enqueue_style( 'flatpickr' ); |
||
| 1620 | wp_enqueue_script( 'flatpickr' ); |
||
| 1621 | } |
||
| 1622 | |||
| 1623 | /** |
||
| 1624 | * Enqueue iconpicker if called. |
||
| 1625 | */ |
||
| 1626 | public function enqueue_iconpicker(){ |
||
| 1627 | wp_enqueue_style( 'iconpicker' ); |
||
| 1628 | wp_enqueue_script( 'iconpicker' ); |
||
| 1629 | } |
||
| 1630 | |||
| 1631 | /** |
||
| 1632 | * Get the url path to the current folder. |
||
| 1633 | * |
||
| 1634 | * @return string |
||
| 1635 | */ |
||
| 1636 | public function get_url() { |
||
| 1637 | $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
||
| 1638 | $content_url = untrailingslashit( WP_CONTENT_URL ); |
||
| 1639 | |||
| 1640 | // Replace http:// to https://. |
||
| 1641 | if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
||
| 1642 | $content_url = str_replace( 'http://', 'https://', $content_url ); |
||
| 1643 | } |
||
| 1644 | |||
| 1645 | // Check if we are inside a plugin |
||
| 1646 | $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
||
| 1647 | $url = str_replace( $content_dir, $content_url, $file_dir ); |
||
| 1648 | |||
| 1649 | return trailingslashit( $url ); |
||
| 1650 | } |
||
| 1651 | |||
| 1652 | /** |
||
| 1653 | * Get the url path to the current folder. |
||
| 1654 | * |
||
| 1655 | * @return string |
||
| 1656 | */ |
||
| 1657 | public function get_url_old() { |
||
| 1658 | |||
| 1659 | $url = ''; |
||
| 1660 | // check if we are inside a plugin |
||
| 1661 | $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
||
| 1662 | |||
| 1663 | // add check in-case user has changed wp-content dir name. |
||
| 1664 | $wp_content_folder_name = basename(WP_CONTENT_DIR); |
||
| 1665 | $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
||
| 1666 | $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
||
| 1667 | |||
| 1668 | if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
||
| 1669 | $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
||
| 1670 | } |
||
| 1671 | |||
| 1672 | return $url; |
||
| 1673 | } |
||
| 1674 | |||
| 1675 | /** |
||
| 1676 | * Register the database settings with WordPress. |
||
| 1677 | */ |
||
| 1678 | public function register_settings() { |
||
| 1679 | register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
||
| 1680 | } |
||
| 1681 | |||
| 1682 | /** |
||
| 1683 | * Add the WordPress settings menu item. |
||
| 1684 | * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
||
| 1685 | */ |
||
| 1686 | public function menu_item() { |
||
| 1687 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
||
| 1688 | call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
||
| 1689 | $this, |
||
| 1690 | 'settings_page' |
||
| 1691 | ) ); |
||
| 1692 | } |
||
| 1693 | |||
| 1694 | /** |
||
| 1695 | * Get a list of themes and their default JS settings. |
||
| 1696 | * |
||
| 1697 | * @return array |
||
| 1698 | */ |
||
| 1699 | public function theme_js_settings(){ |
||
| 1700 | return array( |
||
| 1701 | 'ayetheme' => 'popper', |
||
| 1702 | 'listimia' => 'required', |
||
| 1703 | 'listimia_backend' => 'core-popper', |
||
| 1704 | //'avada' => 'required', // removed as we now add compatibility |
||
| 1705 | ); |
||
| 1706 | } |
||
| 1707 | |||
| 1708 | /** |
||
| 1709 | * Get the current Font Awesome output settings. |
||
| 1710 | * |
||
| 1711 | * @return array The array of settings. |
||
| 1712 | */ |
||
| 1713 | public function get_settings() { |
||
| 1714 | |||
| 1715 | $db_settings = get_option( 'ayecode-ui-settings' ); |
||
| 1716 | $js_default = 'core-popper'; |
||
| 1717 | $js_default_backend = $js_default; |
||
| 1718 | |||
| 1719 | // maybe set defaults (if no settings set) |
||
| 1720 | if(empty($db_settings)){ |
||
| 1721 | $active_theme = strtolower( get_template() ); // active parent theme. |
||
| 1722 | $theme_js_settings = self::theme_js_settings(); |
||
| 1723 | if(isset($theme_js_settings[$active_theme])){ |
||
| 1724 | $js_default = $theme_js_settings[$active_theme]; |
||
| 1725 | $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
||
| 1726 | } |
||
| 1727 | } |
||
| 1728 | |||
| 1729 | /** |
||
| 1730 | * Filter the default settings. |
||
| 1731 | */ |
||
| 1732 | $defaults = apply_filters( 'ayecode-ui-default-settings', array( |
||
| 1733 | 'css' => 'compatibility', // core, compatibility |
||
| 1734 | 'js' => $js_default, // js to load, core-popper, popper |
||
| 1735 | 'html_font_size' => '16', // js to load, core-popper, popper |
||
| 1736 | 'css_backend' => 'compatibility', // core, compatibility |
||
| 1737 | 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
||
| 1738 | 'disable_admin' => '', // URL snippets to disable loading on admin |
||
| 1739 | ), $db_settings ); |
||
| 1740 | |||
| 1741 | $settings = wp_parse_args( $db_settings, $defaults ); |
||
| 1742 | |||
| 1743 | /** |
||
| 1744 | * Filter the Bootstrap settings. |
||
| 1745 | * |
||
| 1746 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
||
| 1747 | */ |
||
| 1748 | return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
||
| 1749 | } |
||
| 1750 | |||
| 1751 | |||
| 1752 | /** |
||
| 1753 | * The settings page html output. |
||
| 1754 | */ |
||
| 1755 | public function settings_page() { |
||
| 1756 | if ( ! current_user_can( 'manage_options' ) ) { |
||
| 1757 | wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
||
| 1758 | } |
||
| 1759 | ?> |
||
| 1760 | <div class="wrap"> |
||
| 1761 | <h1><?php echo $this->name; ?></h1> |
||
| 1762 | <p><?php echo apply_filters( 'ayecode-ui-settings-message', __("Here you can adjust settings if you are having compatibility issues.",'aui') );?></p> |
||
| 1763 | <form method="post" action="options.php"> |
||
| 1764 | <?php |
||
| 1765 | settings_fields( 'ayecode-ui-settings' ); |
||
| 1766 | do_settings_sections( 'ayecode-ui-settings' ); |
||
| 1767 | ?> |
||
| 1768 | |||
| 1769 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
||
| 1770 | <table class="form-table wpbs-table-settings"> |
||
| 1771 | <tr valign="top"> |
||
| 1772 | <th scope="row"><label |
||
| 1773 | for="wpbs-css"><?php _e( 'Load CSS', 'aui' ); ?></label></th> |
||
| 1774 | <td> |
||
| 1775 | <select name="ayecode-ui-settings[css]" id="wpbs-css"> |
||
| 1776 | <option value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'aui' ); ?></option> |
||
| 1777 | <option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option> |
||
| 1778 | <option value="" <?php selected( $this->settings['css'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option> |
||
| 1779 | </select> |
||
| 1780 | </td> |
||
| 1781 | </tr> |
||
| 1782 | |||
| 1783 | <tr valign="top"> |
||
| 1784 | <th scope="row"><label |
||
| 1785 | for="wpbs-js"><?php _e( 'Load JS', 'aui' ); ?></label></th> |
||
| 1786 | <td> |
||
| 1787 | <select name="ayecode-ui-settings[js]" id="wpbs-js"> |
||
| 1788 | <option value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option> |
||
| 1789 | <option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option> |
||
| 1790 | <option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option> |
||
| 1791 | <option value="" <?php selected( $this->settings['js'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option> |
||
| 1792 | </select> |
||
| 1793 | </td> |
||
| 1794 | </tr> |
||
| 1795 | |||
| 1796 | <tr valign="top"> |
||
| 1797 | <th scope="row"><label |
||
| 1798 | for="wpbs-font_size"><?php _e( 'HTML Font Size (px)', 'aui' ); ?></label></th> |
||
| 1799 | <td> |
||
| 1800 | <input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint( $this->settings['html_font_size']); ?>" placeholder="16" /> |
||
| 1801 | <p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.",'aui');?></p> |
||
| 1802 | </td> |
||
| 1803 | </tr> |
||
| 1804 | |||
| 1805 | </table> |
||
| 1806 | |||
| 1807 | <h2><?php _e( 'Backend', 'aui' ); ?> (wp-admin)</h2> |
||
| 1808 | <table class="form-table wpbs-table-settings"> |
||
| 1809 | <tr valign="top"> |
||
| 1810 | <th scope="row"><label |
||
| 1811 | for="wpbs-css-admin"><?php _e( 'Load CSS', 'aui' ); ?></label></th> |
||
| 1812 | <td> |
||
| 1813 | <select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin"> |
||
| 1814 | <option value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'aui' ); ?></option> |
||
| 1815 | <option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option> |
||
| 1816 | <option value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option> |
||
| 1817 | </select> |
||
| 1818 | </td> |
||
| 1819 | </tr> |
||
| 1820 | |||
| 1821 | <tr valign="top"> |
||
| 1822 | <th scope="row"><label |
||
| 1823 | for="wpbs-js-admin"><?php _e( 'Load JS', 'aui' ); ?></label></th> |
||
| 1824 | <td> |
||
| 1825 | <select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin"> |
||
| 1826 | <option value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option> |
||
| 1827 | <option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option> |
||
| 1828 | <option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option> |
||
| 1829 | <option value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option> |
||
| 1830 | </select> |
||
| 1831 | </td> |
||
| 1832 | </tr> |
||
| 1833 | |||
| 1834 | <tr valign="top"> |
||
| 1835 | <th scope="row"><label |
||
| 1836 | for="wpbs-disable-admin"><?php _e( 'Disable load on URL', 'aui' ); ?></label></th> |
||
| 1837 | <td> |
||
| 1838 | <p><?php _e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'aui' ); ?></p> |
||
| 1839 | <textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php action=go"><?php echo $this->settings['disable_admin'];?></textarea> |
||
| 1840 | |||
| 1841 | </td> |
||
| 1842 | </tr> |
||
| 1843 | |||
| 1844 | </table> |
||
| 1845 | |||
| 1846 | <?php |
||
| 1847 | submit_button(); |
||
| 1848 | ?> |
||
| 1849 | </form> |
||
| 1850 | |||
| 1851 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
||
| 1852 | </div> |
||
| 1853 | |||
| 1854 | <?php |
||
| 1855 | } |
||
| 1856 | |||
| 1857 | public function customizer_settings($wp_customize){ |
||
| 1858 | $wp_customize->add_section('aui_settings', array( |
||
| 1859 | 'title' => __('AyeCode UI','aui'), |
||
| 1860 | 'priority' => 120, |
||
| 1861 | )); |
||
| 1862 | |||
| 1863 | // ============================= |
||
| 1864 | // = Color Picker = |
||
| 1865 | // ============================= |
||
| 1866 | $wp_customize->add_setting('aui_options[color_primary]', array( |
||
| 1867 | 'default' => AUI_PRIMARY_COLOR, |
||
| 1868 | 'sanitize_callback' => 'sanitize_hex_color', |
||
| 1869 | 'capability' => 'edit_theme_options', |
||
| 1870 | 'type' => 'option', |
||
| 1871 | 'transport' => 'refresh', |
||
| 1872 | )); |
||
| 1873 | $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
||
| 1874 | 'label' => __('Primary Color','aui'), |
||
| 1875 | 'section' => 'aui_settings', |
||
| 1876 | 'settings' => 'aui_options[color_primary]', |
||
| 1877 | ))); |
||
| 1878 | |||
| 1879 | $wp_customize->add_setting('aui_options[color_secondary]', array( |
||
| 1880 | 'default' => '#6c757d', |
||
| 1881 | 'sanitize_callback' => 'sanitize_hex_color', |
||
| 1882 | 'capability' => 'edit_theme_options', |
||
| 1883 | 'type' => 'option', |
||
| 1884 | 'transport' => 'refresh', |
||
| 1885 | )); |
||
| 1886 | $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
||
| 1887 | 'label' => __('Secondary Color','aui'), |
||
| 1888 | 'section' => 'aui_settings', |
||
| 1889 | 'settings' => 'aui_options[color_secondary]', |
||
| 1890 | ))); |
||
| 1891 | } |
||
| 1892 | |||
| 1893 | /** |
||
| 1894 | * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
||
| 1895 | * |
||
| 1896 | * @return mixed |
||
| 1897 | */ |
||
| 1898 | public static function bs3_compat_css() { |
||
| 1933 | } |
||
| 1934 | |||
| 1935 | |||
| 1936 | public static function custom_css($compatibility = true) { |
||
| 1937 | $colors = array(); |
||
| 1938 | if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
||
| 1939 | |||
| 1940 | $setting = wp_get_global_settings(); |
||
| 1941 | if(!empty($setting['color']['palette']['theme'])){ |
||
| 1942 | foreach($setting['color']['palette']['theme'] as $color){ |
||
| 1943 | $colors[$color['slug']] = esc_attr($color['color']); |
||
| 1944 | } |
||
| 1945 | } |
||
| 1946 | |||
| 1947 | if(!empty($setting['color']['palette']['custom'])){ |
||
| 1948 | foreach($setting['color']['palette']['custom'] as $color){ |
||
| 1949 | $colors[$color['slug']] = esc_attr($color['color']); |
||
| 1950 | } |
||
| 1951 | } |
||
| 1952 | }else{ |
||
| 1953 | $settings = get_option('aui_options'); |
||
| 1954 | $colors = array( |
||
| 1955 | 'primary' => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR, |
||
| 1956 | 'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR |
||
| 1957 | ); |
||
| 1958 | } |
||
| 1959 | |||
| 1960 | ob_start(); |
||
| 1961 | |||
| 1962 | ?> |
||
| 1963 | <style> |
||
| 1964 | <?php |
||
| 1965 | |||
| 1966 | // BS v3 compat |
||
| 1967 | if( self::is_bs3_compat() ){ |
||
| 1968 | echo self::bs3_compat_css(); |
||
| 1969 | } |
||
| 1970 | |||
| 1971 | if(!empty($colors)){ |
||
| 1972 | $d_colors = self::get_colors(true); |
||
| 1973 | //print_r($d_colors );exit; |
||
| 1974 | // print_r($colors );exit; |
||
| 1975 | $is_fse = !empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'; |
||
| 1976 | foreach($colors as $key => $color ){ |
||
| 1977 | if((empty( $d_colors[$key]) || $d_colors[$key] != $color) || $is_fse ) { |
||
| 1978 | $var = $is_fse ? "var(--wp--preset--color--$key)" : $color; |
||
| 1979 | $compat = $is_fse ? '.editor-styles-wrapper' : $compatibility; |
||
| 1980 | echo self::css_overwrite($key,$var,$compat); |
||
| 1981 | } |
||
| 1982 | } |
||
| 1983 | // exit; |
||
| 1984 | } |
||
| 1985 | |||
| 1986 | // Set admin bar z-index lower when modal is open. |
||
| 1987 | echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}'; |
||
| 1988 | |||
| 1989 | if(is_admin()){ |
||
| 1990 | echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}'; |
||
| 1991 | } |
||
| 1992 | ?> |
||
| 1993 | </style> |
||
| 1994 | <?php |
||
| 1995 | |||
| 1996 | |||
| 1997 | /* |
||
| 1998 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
||
| 1999 | */ |
||
| 2000 | return str_replace( array( |
||
| 2001 | '<style>', |
||
| 2002 | '</style>' |
||
| 2003 | ), '', self::minify_css( ob_get_clean() ) ); |
||
| 2004 | } |
||
| 2005 | |||
| 2006 | |||
| 2007 | |||
| 2008 | /** |
||
| 2009 | * Check if we should add booststrap 3 compatibility changes. |
||
| 2010 | * |
||
| 2011 | * @return bool |
||
| 2012 | */ |
||
| 2013 | public static function is_bs3_compat(){ |
||
| 2014 | return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
||
| 2015 | } |
||
| 2016 | |||
| 2017 | /** |
||
| 2018 | * Build the CSS to overwrite a bootstrap color variable. |
||
| 2019 | * |
||
| 2020 | * @param $type |
||
| 2021 | * @param $color_code |
||
| 2022 | * @param $compatibility |
||
| 2023 | * |
||
| 2024 | * @return string |
||
| 2025 | */ |
||
| 2026 | public static function css_overwrite($type,$color_code,$compatibility){ |
||
| 2027 | |||
| 2028 | $is_var = false; |
||
| 2029 | if(!$color_code){return '';} |
||
| 2030 | if(!sanitize_hex_color($color_code)){ |
||
| 2031 | $color_code = esc_attr($color_code); |
||
| 2032 | $is_var = true; |
||
| 2033 | // echo '###1'.$color_code;//exit; |
||
| 2034 | } |
||
| 2035 | if(!$color_code){return '';} |
||
| 2036 | |||
| 2037 | if($compatibility===true || $compatibility===1){ |
||
| 2038 | $compatibility = '.bsui'; |
||
| 2039 | }elseif(!$compatibility){ |
||
| 2040 | $compatibility = ''; |
||
| 2041 | }else{ |
||
| 2042 | $compatibility = esc_attr($compatibility); |
||
| 2043 | } |
||
| 2044 | |||
| 2045 | // echo '####'.$color_code;exit; |
||
| 2046 | |||
| 2047 | $type = sanitize_html_class($type); |
||
| 2048 | |||
| 2049 | /** |
||
| 2050 | * c = color, b = background color, o = border-color, f = fill |
||
| 2051 | */ |
||
| 2052 | $selectors = array( |
||
| 2053 | ".btn-{$type}" => array( 'b', 'o' ), |
||
| 2054 | ".btn-{$type}.disabled" => array( 'b', 'o' ), |
||
| 2055 | ".btn-{$type}:disabled" => array( 'b', 'o' ), |
||
| 2056 | ".btn-outline-{$type}" => array( 'c', 'o' ), |
||
| 2057 | ".btn-outline-{$type}:hover" => array( 'b', 'o' ), |
||
| 2058 | ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ), |
||
| 2059 | ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ), |
||
| 2060 | ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ), |
||
| 2061 | ".badge-{$type}" => array( 'b' ), |
||
| 2062 | ".alert-{$type}" => array( 'b', 'o' ), |
||
| 2063 | ".bg-{$type}" => array( 'b', 'f' ), |
||
| 2064 | ".btn-link.btn-{$type}" => array( 'c' ), |
||
| 2065 | ); |
||
| 2066 | |||
| 2067 | if ( $type == 'primary' ) { |
||
| 2068 | $selectors = $selectors + array( |
||
| 2069 | 'a' => array( 'c' ), |
||
| 2070 | '.btn-link' => array( 'c' ), |
||
| 2071 | '.dropdown-item.active' => array( 'b' ), |
||
| 2072 | '.custom-control-input:checked~.custom-control-label::before' => array( |
||
| 2073 | 'b', |
||
| 2074 | 'o' |
||
| 2075 | ), |
||
| 2076 | '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array( |
||
| 2077 | 'b', |
||
| 2078 | 'o' |
||
| 2079 | ), |
||
| 2080 | '.nav-pills .nav-link.active' => array( 'b' ), |
||
| 2081 | '.nav-pills .show>.nav-link' => array( 'b' ), |
||
| 2082 | '.page-link' => array( 'c' ), |
||
| 2083 | '.page-item.active .page-link' => array( |
||
| 2084 | 'b', |
||
| 2085 | 'o' |
||
| 2086 | ), |
||
| 2087 | '.progress-bar' => array( 'b' ), |
||
| 2088 | '.list-group-item.active' => array( |
||
| 2089 | 'b', |
||
| 2090 | 'o' |
||
| 2091 | ), |
||
| 2092 | '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ), |
||
| 2093 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
||
| 2094 | // '.custom-range::-moz-range-thumb' => array('b'), |
||
| 2095 | // '.custom-range::-ms-thumb' => array('b'), |
||
| 2096 | ); |
||
| 2097 | } |
||
| 2098 | |||
| 2099 | $important_selectors = array( |
||
| 2100 | ".bg-{$type}" => array('b','f'), |
||
| 2101 | ".border-{$type}" => array('o'), |
||
| 2102 | ".text-{$type}" => array('c'), |
||
| 2103 | ); |
||
| 2104 | |||
| 2105 | $color = array(); |
||
| 2106 | $color_i = array(); |
||
| 2107 | $background = array(); |
||
| 2108 | $background_i = array(); |
||
| 2109 | $border = array(); |
||
| 2110 | $border_i = array(); |
||
| 2111 | $fill = array(); |
||
| 2112 | $fill_i = array(); |
||
| 2113 | |||
| 2114 | $output = ''; |
||
| 2115 | |||
| 2116 | // build rules into each type |
||
| 2117 | foreach($selectors as $selector => $types){ |
||
| 2118 | $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
||
| 2119 | $types = array_combine($types,$types); |
||
| 2120 | if(isset($types['c'])){$color[] = $selector;} |
||
| 2121 | if(isset($types['b'])){$background[] = $selector;} |
||
| 2122 | if(isset($types['o'])){$border[] = $selector;} |
||
| 2123 | if(isset($types['f'])){$fill[] = $selector;} |
||
| 2124 | } |
||
| 2125 | |||
| 2126 | // build rules into each type |
||
| 2127 | foreach($important_selectors as $selector => $types){ |
||
| 2128 | $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
||
| 2129 | $types = array_combine($types,$types); |
||
| 2130 | if(isset($types['c'])){$color_i[] = $selector;} |
||
| 2131 | if(isset($types['b'])){$background_i[] = $selector;} |
||
| 2132 | if(isset($types['o'])){$border_i[] = $selector;} |
||
| 2133 | if(isset($types['f'])){$fill_i[] = $selector;} |
||
| 2134 | } |
||
| 2135 | |||
| 2136 | // add any color rules |
||
| 2137 | if(!empty($color)){ |
||
| 2138 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
| 2139 | } |
||
| 2140 | if(!empty($color_i)){ |
||
| 2141 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
| 2142 | } |
||
| 2143 | |||
| 2144 | // add any background color rules |
||
| 2145 | if(!empty($background)){ |
||
| 2146 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
| 2147 | } |
||
| 2148 | if(!empty($background_i)){ |
||
| 2149 | $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
| 2150 | } |
||
| 2151 | |||
| 2152 | // add any border color rules |
||
| 2153 | if(!empty($border)){ |
||
| 2154 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
| 2155 | } |
||
| 2156 | if(!empty($border_i)){ |
||
| 2157 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
| 2158 | } |
||
| 2159 | |||
| 2160 | // add any fill color rules |
||
| 2161 | if(!empty($fill)){ |
||
| 2162 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
| 2163 | } |
||
| 2164 | if(!empty($fill_i)){ |
||
| 2165 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
| 2166 | } |
||
| 2167 | |||
| 2168 | |||
| 2169 | $prefix = $compatibility ? $compatibility . " " : ""; |
||
| 2170 | |||
| 2171 | $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : ''; |
||
| 2172 | // darken |
||
| 2173 | $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075"); |
||
| 2174 | $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10"); |
||
| 2175 | $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125"); |
||
| 2176 | |||
| 2177 | // lighten |
||
| 2178 | $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25"); |
||
| 2179 | |||
| 2180 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
| 2181 | $op_25 = $color_code."40"; // 25% opacity |
||
| 2182 | |||
| 2183 | |||
| 2184 | // button states |
||
| 2185 | $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : ''; |
||
| 2186 | $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
| 2187 | // $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000; border-color: #000;} "; |
||
| 2188 | $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2189 | $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
| 2190 | $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2191 | |||
| 2192 | if ( $type == 'primary' ) { |
||
| 2193 | // dropdown's |
||
| 2194 | $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
||
| 2195 | |||
| 2196 | // input states |
||
| 2197 | $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2198 | |||
| 2199 | // page link |
||
| 2200 | $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2201 | } |
||
| 2202 | |||
| 2203 | return $output; |
||
| 2204 | } |
||
| 2205 | |||
| 2206 | /** |
||
| 2207 | * |
||
| 2208 | * @deprecated 0.1.76 Use css_overwrite() |
||
| 2209 | * |
||
| 2210 | * @param $color_code |
||
| 2211 | * @param $compatibility |
||
| 2212 | * @param $use_variable |
||
| 2213 | * |
||
| 2214 | * @return string |
||
| 2215 | */ |
||
| 2216 | public static function css_primary($color_code,$compatibility, $use_variable = false){ |
||
| 2217 | |||
| 2218 | if(!$use_variable){ |
||
| 2219 | $color_code = sanitize_hex_color($color_code); |
||
| 2220 | if(!$color_code){return '';} |
||
| 2221 | } |
||
| 2222 | |||
| 2223 | /** |
||
| 2224 | * c = color, b = background color, o = border-color, f = fill |
||
| 2225 | */ |
||
| 2226 | $selectors = array( |
||
| 2227 | 'a' => array('c'), |
||
| 2228 | '.btn-primary' => array('b','o'), |
||
| 2229 | '.btn-primary.disabled' => array('b','o'), |
||
| 2230 | '.btn-primary:disabled' => array('b','o'), |
||
| 2231 | '.btn-outline-primary' => array('c','o'), |
||
| 2232 | '.btn-outline-primary:hover' => array('b','o'), |
||
| 2233 | '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
||
| 2234 | '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
||
| 2235 | '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
||
| 2236 | '.btn-link' => array('c'), |
||
| 2237 | '.dropdown-item.active' => array('b'), |
||
| 2238 | '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
||
| 2239 | '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
||
| 2240 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
||
| 2241 | // '.custom-range::-moz-range-thumb' => array('b'), |
||
| 2242 | // '.custom-range::-ms-thumb' => array('b'), |
||
| 2243 | '.nav-pills .nav-link.active' => array('b'), |
||
| 2244 | '.nav-pills .show>.nav-link' => array('b'), |
||
| 2245 | '.page-link' => array('c'), |
||
| 2246 | '.page-item.active .page-link' => array('b','o'), |
||
| 2247 | '.badge-primary' => array('b'), |
||
| 2248 | '.alert-primary' => array('b','o'), |
||
| 2249 | '.progress-bar' => array('b'), |
||
| 2250 | '.list-group-item.active' => array('b','o'), |
||
| 2251 | '.bg-primary' => array('b','f'), |
||
| 2252 | '.btn-link.btn-primary' => array('c'), |
||
| 2253 | '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
||
| 2254 | ); |
||
| 2255 | |||
| 2256 | $important_selectors = array( |
||
| 2257 | '.bg-primary' => array('b','f'), |
||
| 2258 | '.border-primary' => array('o'), |
||
| 2259 | '.text-primary' => array('c'), |
||
| 2260 | ); |
||
| 2261 | |||
| 2262 | $color = array(); |
||
| 2263 | $color_i = array(); |
||
| 2264 | $background = array(); |
||
| 2265 | $background_i = array(); |
||
| 2266 | $border = array(); |
||
| 2267 | $border_i = array(); |
||
| 2268 | $fill = array(); |
||
| 2269 | $fill_i = array(); |
||
| 2270 | |||
| 2271 | $output = ''; |
||
| 2272 | |||
| 2273 | // build rules into each type |
||
| 2274 | foreach($selectors as $selector => $types){ |
||
| 2275 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
| 2276 | $types = array_combine($types,$types); |
||
| 2277 | if(isset($types['c'])){$color[] = $selector;} |
||
| 2278 | if(isset($types['b'])){$background[] = $selector;} |
||
| 2279 | if(isset($types['o'])){$border[] = $selector;} |
||
| 2280 | if(isset($types['f'])){$fill[] = $selector;} |
||
| 2281 | } |
||
| 2282 | |||
| 2283 | // build rules into each type |
||
| 2284 | foreach($important_selectors as $selector => $types){ |
||
| 2285 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
| 2286 | $types = array_combine($types,$types); |
||
| 2287 | if(isset($types['c'])){$color_i[] = $selector;} |
||
| 2288 | if(isset($types['b'])){$background_i[] = $selector;} |
||
| 2289 | if(isset($types['o'])){$border_i[] = $selector;} |
||
| 2290 | if(isset($types['f'])){$fill_i[] = $selector;} |
||
| 2291 | } |
||
| 2292 | |||
| 2293 | // add any color rules |
||
| 2294 | if(!empty($color)){ |
||
| 2295 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
| 2296 | } |
||
| 2297 | if(!empty($color_i)){ |
||
| 2298 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
| 2299 | } |
||
| 2300 | |||
| 2301 | // add any background color rules |
||
| 2302 | if(!empty($background)){ |
||
| 2303 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
| 2304 | } |
||
| 2305 | if(!empty($background_i)){ |
||
| 2306 | $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
| 2307 | } |
||
| 2308 | |||
| 2309 | // add any border color rules |
||
| 2310 | if(!empty($border)){ |
||
| 2311 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
| 2312 | } |
||
| 2313 | if(!empty($border_i)){ |
||
| 2314 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
| 2315 | } |
||
| 2316 | |||
| 2317 | // add any fill color rules |
||
| 2318 | if(!empty($fill)){ |
||
| 2319 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
| 2320 | } |
||
| 2321 | if(!empty($fill_i)){ |
||
| 2322 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
| 2323 | } |
||
| 2324 | |||
| 2325 | |||
| 2326 | $prefix = $compatibility ? ".bsui " : ""; |
||
| 2327 | |||
| 2328 | // darken |
||
| 2329 | $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
||
| 2330 | $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
||
| 2331 | $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
||
| 2332 | |||
| 2333 | // lighten |
||
| 2334 | $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
||
| 2335 | |||
| 2336 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
| 2337 | $op_25 = $color_code."40"; // 25% opacity |
||
| 2338 | |||
| 2339 | |||
| 2340 | // button states |
||
| 2341 | $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
| 2342 | $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2343 | $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
| 2344 | $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2345 | |||
| 2346 | |||
| 2347 | // dropdown's |
||
| 2348 | $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
||
| 2349 | |||
| 2350 | |||
| 2351 | // input states |
||
| 2352 | $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2353 | |||
| 2354 | // page link |
||
| 2355 | $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2356 | |||
| 2357 | return $output; |
||
| 2358 | } |
||
| 2359 | |||
| 2360 | /** |
||
| 2361 | * |
||
| 2362 | * @deprecated 0.1.76 Use css_overwrite() |
||
| 2363 | * |
||
| 2364 | * @param $color_code |
||
| 2365 | * @param $compatibility |
||
| 2366 | * |
||
| 2367 | * @return string |
||
| 2368 | */ |
||
| 2369 | public static function css_secondary($color_code,$compatibility){; |
||
| 2370 | $color_code = sanitize_hex_color($color_code); |
||
| 2371 | if(!$color_code){return '';} |
||
| 2372 | /** |
||
| 2373 | * c = color, b = background color, o = border-color, f = fill |
||
| 2374 | */ |
||
| 2375 | $selectors = array( |
||
| 2376 | '.btn-secondary' => array('b','o'), |
||
| 2377 | '.btn-secondary.disabled' => array('b','o'), |
||
| 2378 | '.btn-secondary:disabled' => array('b','o'), |
||
| 2379 | '.btn-outline-secondary' => array('c','o'), |
||
| 2380 | '.btn-outline-secondary:hover' => array('b','o'), |
||
| 2381 | '.btn-outline-secondary.disabled' => array('c'), |
||
| 2382 | '.btn-outline-secondary:disabled' => array('c'), |
||
| 2383 | '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
||
| 2384 | '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
||
| 2385 | '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
||
| 2386 | '.badge-secondary' => array('b'), |
||
| 2387 | '.alert-secondary' => array('b','o'), |
||
| 2388 | '.btn-link.btn-secondary' => array('c'), |
||
| 2389 | ); |
||
| 2390 | |||
| 2391 | $important_selectors = array( |
||
| 2392 | '.bg-secondary' => array('b','f'), |
||
| 2393 | '.border-secondary' => array('o'), |
||
| 2394 | '.text-secondary' => array('c'), |
||
| 2395 | ); |
||
| 2396 | |||
| 2397 | $color = array(); |
||
| 2398 | $color_i = array(); |
||
| 2399 | $background = array(); |
||
| 2400 | $background_i = array(); |
||
| 2401 | $border = array(); |
||
| 2402 | $border_i = array(); |
||
| 2403 | $fill = array(); |
||
| 2404 | $fill_i = array(); |
||
| 2405 | |||
| 2406 | $output = ''; |
||
| 2407 | |||
| 2408 | // build rules into each type |
||
| 2409 | foreach($selectors as $selector => $types){ |
||
| 2410 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
| 2411 | $types = array_combine($types,$types); |
||
| 2412 | if(isset($types['c'])){$color[] = $selector;} |
||
| 2413 | if(isset($types['b'])){$background[] = $selector;} |
||
| 2414 | if(isset($types['o'])){$border[] = $selector;} |
||
| 2415 | if(isset($types['f'])){$fill[] = $selector;} |
||
| 2416 | } |
||
| 2417 | |||
| 2418 | // build rules into each type |
||
| 2419 | foreach($important_selectors as $selector => $types){ |
||
| 2420 | $selector = $compatibility ? ".bsui ".$selector : $selector; |
||
| 2421 | $types = array_combine($types,$types); |
||
| 2422 | if(isset($types['c'])){$color_i[] = $selector;} |
||
| 2423 | if(isset($types['b'])){$background_i[] = $selector;} |
||
| 2424 | if(isset($types['o'])){$border_i[] = $selector;} |
||
| 2425 | if(isset($types['f'])){$fill_i[] = $selector;} |
||
| 2426 | } |
||
| 2427 | |||
| 2428 | // add any color rules |
||
| 2429 | if(!empty($color)){ |
||
| 2430 | $output .= implode(",",$color) . "{color: $color_code;} "; |
||
| 2431 | } |
||
| 2432 | if(!empty($color_i)){ |
||
| 2433 | $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
||
| 2434 | } |
||
| 2435 | |||
| 2436 | // add any background color rules |
||
| 2437 | if(!empty($background)){ |
||
| 2438 | $output .= implode(",",$background) . "{background-color: $color_code;} "; |
||
| 2439 | } |
||
| 2440 | if(!empty($background_i)){ |
||
| 2441 | $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
||
| 2442 | } |
||
| 2443 | |||
| 2444 | // add any border color rules |
||
| 2445 | if(!empty($border)){ |
||
| 2446 | $output .= implode(",",$border) . "{border-color: $color_code;} "; |
||
| 2447 | } |
||
| 2448 | if(!empty($border_i)){ |
||
| 2449 | $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
||
| 2450 | } |
||
| 2451 | |||
| 2452 | // add any fill color rules |
||
| 2453 | if(!empty($fill)){ |
||
| 2454 | $output .= implode(",",$fill) . "{fill: $color_code;} "; |
||
| 2455 | } |
||
| 2456 | if(!empty($fill_i)){ |
||
| 2457 | $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
||
| 2458 | } |
||
| 2459 | |||
| 2460 | |||
| 2461 | $prefix = $compatibility ? ".bsui " : ""; |
||
| 2462 | |||
| 2463 | // darken |
||
| 2464 | $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
||
| 2465 | $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
||
| 2466 | $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
||
| 2467 | |||
| 2468 | // lighten |
||
| 2469 | $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
||
| 2470 | |||
| 2471 | // opacity see https://css-tricks.com/8-digit-hex-codes/ |
||
| 2472 | $op_25 = $color_code."40"; // 25% opacity |
||
| 2473 | |||
| 2474 | |||
| 2475 | // button states |
||
| 2476 | $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
||
| 2477 | $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2478 | $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
||
| 2479 | $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
||
| 2480 | |||
| 2481 | |||
| 2482 | return $output; |
||
| 2483 | } |
||
| 2484 | |||
| 2485 | /** |
||
| 2486 | * Increases or decreases the brightness of a color by a percentage of the current brightness. |
||
| 2487 | * |
||
| 2488 | * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
||
| 2489 | * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
||
| 2490 | * |
||
| 2491 | * @return string |
||
| 2492 | */ |
||
| 2493 | public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
||
| 2494 | $hexCode = ltrim($hexCode, '#'); |
||
| 2495 | |||
| 2496 | if (strlen($hexCode) == 3) { |
||
| 2497 | $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
||
| 2498 | } |
||
| 2499 | |||
| 2500 | $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
||
| 2501 | |||
| 2502 | foreach ($hexCode as & $color) { |
||
| 2503 | $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
||
| 2504 | $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
||
| 2505 | |||
| 2506 | $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
||
| 2507 | } |
||
| 2508 | |||
| 2509 | return '#' . implode($hexCode); |
||
| 2510 | } |
||
| 2511 | |||
| 2512 | /** |
||
| 2513 | * Check if we should display examples. |
||
| 2514 | */ |
||
| 2515 | public function maybe_show_examples(){ |
||
| 2516 | if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
||
| 2517 | echo "<head>"; |
||
| 2518 | wp_head(); |
||
| 2519 | echo "</head>"; |
||
| 2520 | echo "<body>"; |
||
| 2521 | echo $this->get_examples(); |
||
| 2522 | echo "</body>"; |
||
| 2523 | exit; |
||
| 2524 | } |
||
| 2525 | } |
||
| 2526 | |||
| 2527 | /** |
||
| 2528 | * Get developer examples. |
||
| 2529 | * |
||
| 2530 | * @return string |
||
| 2531 | */ |
||
| 2532 | public function get_examples(){ |
||
| 2533 | $output = ''; |
||
| 2534 | |||
| 2535 | |||
| 2536 | // open form |
||
| 2537 | $output .= "<form class='p-5 m-5 border rounded'>"; |
||
| 2538 | |||
| 2539 | // input example |
||
| 2540 | $output .= aui()->input(array( |
||
| 2541 | 'type' => 'text', |
||
| 2542 | 'id' => 'text-example', |
||
| 2543 | 'name' => 'text-example', |
||
| 2544 | 'placeholder' => 'text placeholder', |
||
| 2545 | 'title' => 'Text input example', |
||
| 2546 | 'value' => '', |
||
| 2547 | 'required' => false, |
||
| 2548 | 'help_text' => 'help text', |
||
| 2549 | 'label' => 'Text input example label' |
||
| 2550 | )); |
||
| 2551 | |||
| 2552 | // input example |
||
| 2553 | $output .= aui()->input(array( |
||
| 2554 | 'type' => 'url', |
||
| 2555 | 'id' => 'text-example2', |
||
| 2556 | 'name' => 'text-example', |
||
| 2557 | 'placeholder' => 'url placeholder', |
||
| 2558 | 'title' => 'Text input example', |
||
| 2559 | 'value' => '', |
||
| 2560 | 'required' => false, |
||
| 2561 | 'help_text' => 'help text', |
||
| 2562 | 'label' => 'Text input example label' |
||
| 2563 | )); |
||
| 2564 | |||
| 2565 | // checkbox example |
||
| 2566 | $output .= aui()->input(array( |
||
| 2567 | 'type' => 'checkbox', |
||
| 2568 | 'id' => 'checkbox-example', |
||
| 2569 | 'name' => 'checkbox-example', |
||
| 2570 | 'placeholder' => 'checkbox-example', |
||
| 2571 | 'title' => 'Checkbox example', |
||
| 2572 | 'value' => '1', |
||
| 2573 | 'checked' => true, |
||
| 2574 | 'required' => false, |
||
| 2575 | 'help_text' => 'help text', |
||
| 2576 | 'label' => 'Checkbox checked' |
||
| 2577 | )); |
||
| 2578 | |||
| 2579 | // checkbox example |
||
| 2580 | $output .= aui()->input(array( |
||
| 2581 | 'type' => 'checkbox', |
||
| 2582 | 'id' => 'checkbox-example2', |
||
| 2583 | 'name' => 'checkbox-example2', |
||
| 2584 | 'placeholder' => 'checkbox-example', |
||
| 2585 | 'title' => 'Checkbox example', |
||
| 2586 | 'value' => '1', |
||
| 2587 | 'checked' => false, |
||
| 2588 | 'required' => false, |
||
| 2589 | 'help_text' => 'help text', |
||
| 2590 | 'label' => 'Checkbox un-checked' |
||
| 2591 | )); |
||
| 2592 | |||
| 2593 | // switch example |
||
| 2594 | $output .= aui()->input(array( |
||
| 2595 | 'type' => 'checkbox', |
||
| 2596 | 'id' => 'switch-example', |
||
| 2597 | 'name' => 'switch-example', |
||
| 2598 | 'placeholder' => 'checkbox-example', |
||
| 2599 | 'title' => 'Switch example', |
||
| 2600 | 'value' => '1', |
||
| 2601 | 'checked' => true, |
||
| 2602 | 'switch' => true, |
||
| 2603 | 'required' => false, |
||
| 2604 | 'help_text' => 'help text', |
||
| 2605 | 'label' => 'Switch on' |
||
| 2606 | )); |
||
| 2607 | |||
| 2608 | // switch example |
||
| 2609 | $output .= aui()->input(array( |
||
| 2610 | 'type' => 'checkbox', |
||
| 2611 | 'id' => 'switch-example2', |
||
| 2612 | 'name' => 'switch-example2', |
||
| 2613 | 'placeholder' => 'checkbox-example', |
||
| 2614 | 'title' => 'Switch example', |
||
| 2615 | 'value' => '1', |
||
| 2616 | 'checked' => false, |
||
| 2617 | 'switch' => true, |
||
| 2618 | 'required' => false, |
||
| 2619 | 'help_text' => 'help text', |
||
| 2620 | 'label' => 'Switch off' |
||
| 2621 | )); |
||
| 2622 | |||
| 2623 | // close form |
||
| 2624 | $output .= "</form>"; |
||
| 2625 | |||
| 2626 | return $output; |
||
| 2627 | } |
||
| 2628 | |||
| 2629 | /** |
||
| 2630 | * Calendar params. |
||
| 2631 | * |
||
| 2632 | * @since 0.1.44 |
||
| 2633 | * |
||
| 2634 | * @return array Calendar params. |
||
| 2635 | */ |
||
| 2636 | public static function calendar_params() { |
||
| 2637 | $params = array( |
||
| 2638 | 'month_long_1' => __( 'January', 'aui' ), |
||
| 2639 | 'month_long_2' => __( 'February', 'aui' ), |
||
| 2640 | 'month_long_3' => __( 'March', 'aui' ), |
||
| 2641 | 'month_long_4' => __( 'April', 'aui' ), |
||
| 2642 | 'month_long_5' => __( 'May', 'aui' ), |
||
| 2643 | 'month_long_6' => __( 'June', 'aui' ), |
||
| 2644 | 'month_long_7' => __( 'July', 'aui' ), |
||
| 2645 | 'month_long_8' => __( 'August', 'aui' ), |
||
| 2646 | 'month_long_9' => __( 'September', 'aui' ), |
||
| 2647 | 'month_long_10' => __( 'October', 'aui' ), |
||
| 2648 | 'month_long_11' => __( 'November', 'aui' ), |
||
| 2649 | 'month_long_12' => __( 'December', 'aui' ), |
||
| 2650 | 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
||
| 2651 | 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
||
| 2652 | 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
||
| 2653 | 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
||
| 2654 | 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
||
| 2655 | 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
||
| 2656 | 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
||
| 2657 | 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
||
| 2658 | 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
||
| 2659 | 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
||
| 2660 | 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
||
| 2661 | 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
||
| 2662 | 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
||
| 2663 | 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
||
| 2664 | 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
||
| 2665 | 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
||
| 2666 | 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
||
| 2667 | 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
||
| 2668 | 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
||
| 2669 | 'day_s2_1' => __( 'Su', 'aui' ), |
||
| 2670 | 'day_s2_2' => __( 'Mo', 'aui' ), |
||
| 2671 | 'day_s2_3' => __( 'Tu', 'aui' ), |
||
| 2672 | 'day_s2_4' => __( 'We', 'aui' ), |
||
| 2673 | 'day_s2_5' => __( 'Th', 'aui' ), |
||
| 2674 | 'day_s2_6' => __( 'Fr', 'aui' ), |
||
| 2675 | 'day_s2_7' => __( 'Sa', 'aui' ), |
||
| 2676 | 'day_s3_1' => __( 'Sun', 'aui' ), |
||
| 2677 | 'day_s3_2' => __( 'Mon', 'aui' ), |
||
| 2678 | 'day_s3_3' => __( 'Tue', 'aui' ), |
||
| 2679 | 'day_s3_4' => __( 'Wed', 'aui' ), |
||
| 2680 | 'day_s3_5' => __( 'Thu', 'aui' ), |
||
| 2681 | 'day_s3_6' => __( 'Fri', 'aui' ), |
||
| 2682 | 'day_s3_7' => __( 'Sat', 'aui' ), |
||
| 2683 | 'day_s5_1' => __( 'Sunday', 'aui' ), |
||
| 2684 | 'day_s5_2' => __( 'Monday', 'aui' ), |
||
| 2685 | 'day_s5_3' => __( 'Tuesday', 'aui' ), |
||
| 2686 | 'day_s5_4' => __( 'Wednesday', 'aui' ), |
||
| 2687 | 'day_s5_5' => __( 'Thursday', 'aui' ), |
||
| 2688 | 'day_s5_6' => __( 'Friday', 'aui' ), |
||
| 2689 | 'day_s5_7' => __( 'Saturday', 'aui' ), |
||
| 2690 | 'am_lower' => __( 'am', 'aui' ), |
||
| 2691 | 'pm_lower' => __( 'pm', 'aui' ), |
||
| 2692 | 'am_upper' => __( 'AM', 'aui' ), |
||
| 2693 | 'pm_upper' => __( 'PM', 'aui' ), |
||
| 2694 | 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
||
| 2695 | 'time_24hr' => false, |
||
| 2696 | 'year' => __( 'Year', 'aui' ), |
||
| 2697 | 'hour' => __( 'Hour', 'aui' ), |
||
| 2698 | 'minute' => __( 'Minute', 'aui' ), |
||
| 2699 | 'weekAbbreviation' => __( 'Wk', 'aui' ), |
||
| 2700 | 'rangeSeparator' => __( ' to ', 'aui' ), |
||
| 2701 | 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
||
| 2702 | 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
||
| 2703 | ); |
||
| 2704 | |||
| 2705 | return apply_filters( 'ayecode_ui_calendar_params', $params ); |
||
| 2706 | } |
||
| 2707 | |||
| 2708 | /** |
||
| 2709 | * Flatpickr calendar localize. |
||
| 2710 | * |
||
| 2711 | * @since 0.1.44 |
||
| 2712 | * |
||
| 2713 | * @return string Calendar locale. |
||
| 2714 | */ |
||
| 2715 | public static function flatpickr_locale() { |
||
| 2716 | $params = self::calendar_params(); |
||
| 2717 | |||
| 2718 | if ( is_string( $params ) ) { |
||
| 2719 | $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
||
| 2720 | } else { |
||
| 2721 | foreach ( (array) $params as $key => $value ) { |
||
| 2722 | if ( ! is_scalar( $value ) ) { |
||
| 2723 | continue; |
||
| 2724 | } |
||
| 2725 | |||
| 2726 | $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
||
| 2727 | } |
||
| 2728 | } |
||
| 2729 | |||
| 2730 | $day_s3 = array(); |
||
| 2731 | $day_s5 = array(); |
||
| 2732 | |||
| 2733 | for ( $i = 1; $i <= 7; $i ++ ) { |
||
| 2734 | $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
||
| 2735 | $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
||
| 2736 | } |
||
| 2737 | |||
| 2738 | $month_s = array(); |
||
| 2739 | $month_long = array(); |
||
| 2740 | |||
| 2741 | for ( $i = 1; $i <= 12; $i ++ ) { |
||
| 2742 | $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
||
| 2743 | $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
||
| 2744 | } |
||
| 2745 | |||
| 2746 | ob_start(); |
||
| 2747 | if ( 0 ) { ?><script><?php } ?> |
||
| 2748 | { |
||
| 2749 | weekdays: { |
||
| 2750 | shorthand: ['<?php echo implode( "','", $day_s3 ); ?>'], |
||
| 2751 | longhand: ['<?php echo implode( "','", $day_s5 ); ?>'], |
||
| 2752 | }, |
||
| 2753 | months: { |
||
| 2754 | shorthand: ['<?php echo implode( "','", $month_s ); ?>'], |
||
| 2755 | longhand: ['<?php echo implode( "','", $month_long ); ?>'], |
||
| 2756 | }, |
||
| 2757 | daysInMonth: [31,28,31,30,31,30,31,31,30,31,30,31], |
||
| 2758 | firstDayOfWeek: <?php echo (int) $params[ 'firstDayOfWeek' ]; ?>, |
||
| 2759 | ordinal: function (nth) { |
||
| 2760 | var s = nth % 100; |
||
| 2761 | if (s > 3 && s < 21) |
||
| 2762 | return "th"; |
||
| 2763 | switch (s % 10) { |
||
| 2764 | case 1: |
||
| 2765 | return "st"; |
||
| 2766 | case 2: |
||
| 2767 | return "nd"; |
||
| 2768 | case 3: |
||
| 2769 | return "rd"; |
||
| 2770 | default: |
||
| 2771 | return "th"; |
||
| 2772 | } |
||
| 2773 | }, |
||
| 2774 | rangeSeparator: '<?php echo addslashes( $params[ 'rangeSeparator' ] ); ?>', |
||
| 2775 | weekAbbreviation: '<?php echo addslashes( $params[ 'weekAbbreviation' ] ); ?>', |
||
| 2776 | scrollTitle: '<?php echo addslashes( $params[ 'scrollTitle' ] ); ?>', |
||
| 2777 | toggleTitle: '<?php echo addslashes( $params[ 'toggleTitle' ] ); ?>', |
||
| 2778 | amPM: ['<?php echo addslashes( $params[ 'am_upper' ] ); ?>','<?php echo addslashes( $params[ 'pm_upper' ] ); ?>'], |
||
| 2779 | yearAriaLabel: '<?php echo addslashes( $params[ 'year' ] ); ?>', |
||
| 2780 | hourAriaLabel: '<?php echo addslashes( $params[ 'hour' ] ); ?>', |
||
| 2781 | minuteAriaLabel: '<?php echo addslashes( $params[ 'minute' ] ); ?>', |
||
| 2782 | time_24hr: <?php echo ( $params[ 'time_24hr' ] ? 'true' : 'false' ) ; ?> |
||
| 2783 | } |
||
| 2784 | <?php if ( 0 ) { ?></script><?php } ?> |
||
| 2785 | <?php |
||
| 2786 | $locale = ob_get_clean(); |
||
| 2787 | |||
| 2788 | return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
||
| 2789 | } |
||
| 2790 | |||
| 2791 | /** |
||
| 2792 | * Select2 JS params. |
||
| 2793 | * |
||
| 2794 | * @since 0.1.44 |
||
| 2795 | * |
||
| 2796 | * @return array Select2 JS params. |
||
| 2797 | */ |
||
| 2798 | public static function select2_params() { |
||
| 2814 | } |
||
| 2815 | |||
| 2816 | /** |
||
| 2817 | * Select2 JS localize. |
||
| 2818 | * |
||
| 2819 | * @since 0.1.44 |
||
| 2820 | * |
||
| 2821 | * @return string Select2 JS locale. |
||
| 2822 | */ |
||
| 2823 | public static function select2_locale() { |
||
| 2824 | $params = self::select2_params(); |
||
| 2825 | |||
| 2826 | foreach ( (array) $params as $key => $value ) { |
||
| 2827 | if ( ! is_scalar( $value ) ) { |
||
| 2828 | continue; |
||
| 2829 | } |
||
| 2830 | |||
| 2831 | $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
||
| 2832 | } |
||
| 2833 | |||
| 2834 | $locale = json_encode( $params ); |
||
| 2835 | |||
| 2836 | return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
||
| 2837 | } |
||
| 2838 | |||
| 2839 | /** |
||
| 2840 | * Time ago JS localize. |
||
| 2841 | * |
||
| 2842 | * @since 0.1.47 |
||
| 2843 | * |
||
| 2844 | * @return string Time ago JS locale. |
||
| 2845 | */ |
||
| 2846 | public static function timeago_locale() { |
||
| 2847 | $params = array( |
||
| 2848 | 'prefix_ago' => '', |
||
| 2849 | 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
||
| 2850 | 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
||
| 2851 | 'suffix_after' => '', |
||
| 2852 | 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
||
| 2853 | 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
||
| 2854 | 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
||
| 2855 | 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
||
| 2856 | 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
||
| 2857 | 'day' => _x( 'a day', 'time ago', 'aui' ), |
||
| 2858 | 'days' => _x( '%d days', 'time ago', 'aui' ), |
||
| 2859 | 'month' => _x( 'about a month', 'time ago', 'aui' ), |
||
| 2860 | 'months' => _x( '%d months', 'time ago', 'aui' ), |
||
| 2861 | 'year' => _x( 'about a year', 'time ago', 'aui' ), |
||
| 2862 | 'years' => _x( '%d years', 'time ago', 'aui' ), |
||
| 2863 | ); |
||
| 2864 | |||
| 2865 | $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
||
| 2866 | |||
| 2867 | foreach ( (array) $params as $key => $value ) { |
||
| 2868 | if ( ! is_scalar( $value ) ) { |
||
| 2869 | continue; |
||
| 2870 | } |
||
| 2871 | |||
| 2872 | $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
||
| 2873 | } |
||
| 2874 | |||
| 2875 | $locale = json_encode( $params ); |
||
| 2876 | |||
| 2877 | return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
||
| 2878 | } |
||
| 2879 | |||
| 2880 | /** |
||
| 2881 | * JavaScript Minifier |
||
| 2882 | * |
||
| 2883 | * @param $input |
||
| 2884 | * |
||
| 2885 | * @return mixed |
||
| 2886 | */ |
||
| 2887 | public static function minify_js($input) { |
||
| 2888 | if(trim($input) === "") return $input; |
||
| 2889 | return preg_replace( |
||
| 2890 | array( |
||
| 2891 | // Remove comment(s) |
||
| 2892 | '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
||
| 2893 | // Remove white-space(s) outside the string and regex |
||
| 2894 | '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
||
| 2895 | // Remove the last semicolon |
||
| 2896 | '#;+\}#', |
||
| 2897 | // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
||
| 2898 | '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
||
| 2899 | // --ibid. From `foo['bar']` to `foo.bar` |
||
| 2900 | '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
||
| 2901 | ), |
||
| 2902 | array( |
||
| 2903 | '$1', |
||
| 2904 | '$1$2', |
||
| 2905 | '}', |
||
| 2906 | '$1$3', |
||
| 2907 | '$1.$3' |
||
| 2908 | ), |
||
| 2909 | $input); |
||
| 2910 | } |
||
| 2911 | |||
| 2912 | /** |
||
| 2913 | * Minify CSS |
||
| 2914 | * |
||
| 2915 | * @param $input |
||
| 2916 | * |
||
| 2917 | * @return mixed |
||
| 2918 | */ |
||
| 2919 | public static function minify_css($input) { |
||
| 2959 | } |
||
| 2960 | |||
| 2961 | /** |
||
| 2962 | * Get the conditional fields JavaScript. |
||
| 2963 | * |
||
| 2964 | * @return mixed |
||
| 2965 | */ |
||
| 2966 | public function conditional_fields_js() { |
||
| 3474 | } |
||
| 3475 | } |
||
| 3476 | |||
| 3477 | /** |
||
| 3478 | * Run the class if found. |
||
| 3479 | */ |
||
| 3480 | AyeCode_UI_Settings::instance(); |
||
| 3481 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.