widget-options
/
includes
/
widgets
/
gutenberg
/
src
/
attributes
/
components
/
option-tabs
/
behavior.js
widget-options
/
includes
/
widgets
/
gutenberg
/
src
/
attributes
/
components
/
option-tabs
Last commit date
alignment.js
1 year ago
animation.js
1 year ago
behavior.js
1 year ago
columns.js
1 year ago
days-dates.js
1 year ago
devices.js
1 year ago
roles.js
1 year ago
settings.js
1 year ago
styling.js
1 year ago
visibility.js
1 year ago
behavior.js
595 lines
| 1 | import { __ } from "@wordpress/i18n"; |
| 2 | import { TabPanel } from "@wordpress/components"; |
| 3 | import React from "react"; |
| 4 | |
| 5 | const { PanelBody } = wp.components; |
| 6 | |
| 7 | const onSelect = (tabName) => {}; |
| 8 | |
| 9 | const BehaviorTabPanel = (props) => { |
| 10 | const validLicense = true; |
| 11 | let validLicenseClass = props.validLicense ? "" : "disabled-section"; |
| 12 | let widget_options = { ...props.widgetopts_get_settings }; |
| 13 | let selected = ""; |
| 14 | let options_values = ""; |
| 15 | let desktop_clear = ""; |
| 16 | let tablet_clear = ""; |
| 17 | let types = []; |
| 18 | let options_role = ""; |
| 19 | let roles = []; |
| 20 | let miscs = []; |
| 21 | let key = ""; |
| 22 | let value = ""; |
| 23 | let misc_values = []; |
| 24 | let taxonomies = []; |
| 25 | let terms_values = []; |
| 26 | let taxLoop = []; |
| 27 | let tax_values = []; |
| 28 | let args = []; |
| 29 | let authors = []; |
| 30 | let options_author_pages = 0; |
| 31 | let fields = []; |
| 32 | let acf_values = ""; |
| 33 | let pages_values; |
| 34 | const liMisc = React.useRef(null); |
| 35 | const liClass = React.useRef(null); |
| 36 | const liAnimation = React.useRef(null); |
| 37 | const liLogic = React.useRef(null); |
| 38 | let check = ""; |
| 39 | let fixed = ""; |
| 40 | let link = ""; |
| 41 | let target = ""; |
| 42 | let nofollow = ""; |
| 43 | let is_url = ""; |
| 44 | let urls = ""; |
| 45 | let id = ""; |
| 46 | let classes_data = ""; |
| 47 | let predefined = []; |
| 48 | let animation = ""; |
| 49 | let event = ""; |
| 50 | let speed = ""; |
| 51 | let offset = ""; |
| 52 | let hidden = ""; |
| 53 | let link_title = ""; |
| 54 | let http = ""; |
| 55 | let nocache = ""; |
| 56 | let logic = ""; |
| 57 | |
| 58 | let _animation_array = { |
| 59 | "Attention Seekers": [ |
| 60 | "bounce", |
| 61 | "flash", |
| 62 | "pulse", |
| 63 | "rubberBand", |
| 64 | "shake", |
| 65 | "swing", |
| 66 | "tada", |
| 67 | "wobble", |
| 68 | "jello", |
| 69 | ], |
| 70 | "Bouncing Entrances": [ |
| 71 | "bounceIn", |
| 72 | "bounceInDown", |
| 73 | "bounceInLeft", |
| 74 | "bounceInRight", |
| 75 | "bounceInUp", |
| 76 | ], |
| 77 | |
| 78 | "Fading Entrances": [ |
| 79 | "fadeIn", |
| 80 | "fadeInDown", |
| 81 | "fadeInDownBig", |
| 82 | "fadeInLeft", |
| 83 | "fadeInLeftBig", |
| 84 | "fadeInRight", |
| 85 | "fadeInRightBig", |
| 86 | "fadeInUp", |
| 87 | "fadeInUpBig", |
| 88 | ], |
| 89 | Flippers: ["flip", "flipInX", "flipInY", "flipOutX", "flipOutY"], |
| 90 | Lightspeed: ["lightSpeedIn", "lightSpeedOut"], |
| 91 | |
| 92 | "Rotating Entrances": [ |
| 93 | "rotateIn", |
| 94 | "rotateInDownLeft", |
| 95 | "rotateInDownRight", |
| 96 | "rotateInUpLeft", |
| 97 | "rotateInUpRight", |
| 98 | ], |
| 99 | "Sliding Entrances": [ |
| 100 | "slideInUp", |
| 101 | "slideInDown", |
| 102 | "slideInLeft", |
| 103 | "slideInRight", |
| 104 | ], |
| 105 | "Zoom Entrances": [ |
| 106 | "zoomIn", |
| 107 | "zoomInDown", |
| 108 | "zoomInLeft", |
| 109 | "zoomInRight", |
| 110 | "zoomInUp", |
| 111 | ], |
| 112 | Specials: ["hinge", "rollIn"], |
| 113 | }; |
| 114 | |
| 115 | let animation_array = [...Object.entries(_animation_array)]; |
| 116 | |
| 117 | const handleInputChange = (event, key1, key2) => { |
| 118 | let _attribute = { ...props.extended_widget_opts }; |
| 119 | if ( |
| 120 | _attribute[key1] == undefined || |
| 121 | (_attribute[key1] != undefined && _attribute[key1].length == 0) |
| 122 | ) { |
| 123 | _attribute[key1] = {}; |
| 124 | } |
| 125 | |
| 126 | _attribute[key1][key2] = event.target.value; |
| 127 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 128 | }; |
| 129 | |
| 130 | const handleInputChangeCheckbox = (event, key1, key2) => { |
| 131 | let _attribute = { ...props.extended_widget_opts }; |
| 132 | if ( |
| 133 | _attribute[key1] == undefined || |
| 134 | (_attribute[key1] != undefined && _attribute[key1].length == 0) |
| 135 | ) { |
| 136 | _attribute[key1] = {}; |
| 137 | } |
| 138 | |
| 139 | if (event.target.checked) { |
| 140 | _attribute[key1][key2] = 1; |
| 141 | } else { |
| 142 | delete _attribute[key1][key2]; |
| 143 | } |
| 144 | |
| 145 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 146 | }; |
| 147 | |
| 148 | const checkLicense = (isLicenseValid) => { |
| 149 | if (isLicenseValid) { |
| 150 | return ""; |
| 151 | } else { |
| 152 | return ( |
| 153 | <div className="extended-widget-opts-demo-warning"> |
| 154 | <p className="widgetopts-unlock-features"> |
| 155 | <span className="dashicons dashicons-lock"></span> |
| 156 | <br /> |
| 157 | Unlock all Features |
| 158 | <br /> |
| 159 | <a |
| 160 | href="https://widget-options.com/?utm_source=wordpressadmin&utm_medium=widgettabs&utm_campaign=widgetoptsprotab" |
| 161 | className="button-primary" |
| 162 | target="_blank" |
| 163 | > |
| 164 | Learn More |
| 165 | </a> |
| 166 | </p> |
| 167 | </div> |
| 168 | ); |
| 169 | } |
| 170 | }; |
| 171 | |
| 172 | const checkSelectedRoles = (rolesSelected, role, roleName, roleInfo) => { |
| 173 | if ( |
| 174 | (rolesSelected != undefined && |
| 175 | rolesSelected != null && |
| 176 | rolesSelected != "") || |
| 177 | (role[roleName] != undefined && |
| 178 | role[roleName] != "" && |
| 179 | role[roleName] != null) |
| 180 | ) { |
| 181 | return ( |
| 182 | <option value={roleName} selected="selected"> |
| 183 | {roleInfo["name"]} |
| 184 | </option> |
| 185 | ); |
| 186 | } else { |
| 187 | return ""; |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | const clickTabs = (el, tabName) => { |
| 192 | Array.from( |
| 193 | document.querySelectorAll(".extended-widget-opts-settings-tab-settings") |
| 194 | ).forEach((ele) => ele.classList.remove("ui-tabs-active")); |
| 195 | |
| 196 | Array.from( |
| 197 | document.querySelectorAll( |
| 198 | ".extended-widget-opts-inside-tabs .extended-widget-opts-settings-tabcontent-2" |
| 199 | ) |
| 200 | ).forEach((ele) => (ele.style.display = "none")); |
| 201 | |
| 202 | document.getElementById( |
| 203 | "extended-widget-opts-settings-tab-" + props.widgetId + "-" + tabName |
| 204 | ).style.display = "block"; |
| 205 | |
| 206 | el.current.classList.add("ui-tabs-active"); |
| 207 | }; |
| 208 | |
| 209 | return ( |
| 210 | <div |
| 211 | id={"extended-widget-opts-tab-" + props.widgetId + "-class"} |
| 212 | className="extended-widget-opts-tabcontent extended-widget-opts-tabcontent-class" |
| 213 | style={{ width: "100%" }} |
| 214 | > |
| 215 | <div className="extended-widget-opts-settings-tabs extended-widget-opts-inside-tabs"> |
| 216 | <input |
| 217 | type="hidden" |
| 218 | id="extended-widget-opts-styling-selectedtab" |
| 219 | value={selected} |
| 220 | name={"extended_widget_opts[class][selected]"} |
| 221 | /> |
| 222 | |
| 223 | <div className="extended-widget-opts-clearfix"></div> |
| 224 | |
| 225 | {props.editor == "widget" ? ( |
| 226 | <> |
| 227 | <PanelBody |
| 228 | title={__("Fixed Widget")} |
| 229 | className="margin-x-minus-16" |
| 230 | initialOpen={true} |
| 231 | > |
| 232 | <div |
| 233 | id={ |
| 234 | "extended-widget-opts-settings-tab-" + |
| 235 | props.widgetId + |
| 236 | "-title" |
| 237 | } |
| 238 | className="extended-widget-opts-settings-tabcontent-2 extended-widget-opts-settings-tabcontent extended-widget-opts-inner-tabcontent" |
| 239 | style={{ display: "block" }} |
| 240 | > |
| 241 | <div className="widget-opts-title"> |
| 242 | <div |
| 243 | class={ |
| 244 | "widgetopts-widget-opts-wrapper " + validLicenseClass |
| 245 | } |
| 246 | > |
| 247 | {checkLicense(props.validLicense)} |
| 248 | |
| 249 | <div class="widgetopts-fixed-widget-opts"> |
| 250 | <p class="widgetopts-subtitle">{__("Fixed Widget")}</p> |
| 251 | <p> |
| 252 | <input |
| 253 | type="checkbox" |
| 254 | name={"extended_widget_opts[class][fixed]"} |
| 255 | id={"opts-class-fixed-" + props.widgetId} |
| 256 | value="1" |
| 257 | /> |
| 258 | <label for={"opts-class-fixed-" + props.widgetId}> |
| 259 | {__("Check to fixed widget on scroll")} |
| 260 | </label> |
| 261 | </p> |
| 262 | </div> |
| 263 | |
| 264 | <div class="widgetopts-cache-widget-opts"> |
| 265 | <p class="widgetopts-subtitle">{__("Widget Cache")}</p> |
| 266 | <p> |
| 267 | <input |
| 268 | type="checkbox" |
| 269 | name={"extended_widget_opts[class][nocache]"} |
| 270 | id={"opts-class-cache-" + props.widgetId} |
| 271 | value="1" |
| 272 | /> |
| 273 | <label for={"opts-class-cache-" + props.widgetId}> |
| 274 | {__("Do not cache this widget")} |
| 275 | </label> |
| 276 | </p> |
| 277 | </div> |
| 278 | </div> |
| 279 | </div> |
| 280 | </div> |
| 281 | </PanelBody> |
| 282 | |
| 283 | <PanelBody |
| 284 | title={__("Link Widget")} |
| 285 | className="margin-x-minus-16" |
| 286 | initialOpen={false} |
| 287 | > |
| 288 | <div |
| 289 | id={ |
| 290 | "extended-widget-opts-settings-tab-" + |
| 291 | props.widgetId + |
| 292 | "-title" |
| 293 | } |
| 294 | className="extended-widget-opts-settings-tabcontent-2 extended-widget-opts-settings-tabcontent extended-widget-opts-inner-tabcontent" |
| 295 | style={{ display: "block" }} |
| 296 | > |
| 297 | <div className="widget-opts-title"> |
| 298 | <div |
| 299 | class={ |
| 300 | "widgetopts-widget-opts-wrapper " + validLicenseClass |
| 301 | } |
| 302 | > |
| 303 | {checkLicense(props.validLicense)} |
| 304 | |
| 305 | <div class="widgetopts-links-widget-opts"> |
| 306 | <p class="widgetopts-subtitle">{__("Link Widget")}</p> |
| 307 | <table class="form-table"> |
| 308 | <tbody> |
| 309 | <tr valign="top"> |
| 310 | <td scope="row" style={{ padding: "15px 3px" }}> |
| 311 | <strong>{__("Link:")}</strong> |
| 312 | </td> |
| 313 | <td style={{ padding: "15px 3px" }}> |
| 314 | <input |
| 315 | type="text" |
| 316 | class="widefat" |
| 317 | name={"extended_widget_opts[class][link]"} |
| 318 | value={""} |
| 319 | /> |
| 320 | </td> |
| 321 | </tr> |
| 322 | <tr valign="top"> |
| 323 | <td scope="row" style={{ padding: "15px 3px" }}> |
| 324 | |
| 325 | </td> |
| 326 | <td style={{ padding: "15px 3px" }}> |
| 327 | <input |
| 328 | type="checkbox" |
| 329 | id={"opts-class-target-" + props.widgetId} |
| 330 | name={"extended_widget_opts[class][target]"} |
| 331 | value="1" |
| 332 | /> |
| 333 | <label |
| 334 | class="opts-label-small" |
| 335 | for={"opts-class-target-" + props.widgetId} |
| 336 | > |
| 337 | {__("Open to new tab")} |
| 338 | </label> |
| 339 | </td> |
| 340 | </tr> |
| 341 | <tr valign="top"> |
| 342 | <td scope="row" style={{ padding: "15px 3px" }}> |
| 343 | |
| 344 | </td> |
| 345 | <td style={{ padding: "15px 3px" }}> |
| 346 | <input |
| 347 | type="checkbox" |
| 348 | id={"opts-class-nofollow-" + props.widgetId} |
| 349 | name={"extended_widget_opts[class][nofollow]"} |
| 350 | value="1" |
| 351 | /> |
| 352 | <label |
| 353 | class="opts-label-small" |
| 354 | for={"opts-class-nofollow-" + props.widgetId} |
| 355 | > |
| 356 | {__('rel="nofollow"')} |
| 357 | </label> |
| 358 | </td> |
| 359 | </tr> |
| 360 | <tr valign="top"> |
| 361 | <td scope="row" style={{ padding: "15px 3px" }}> |
| 362 | |
| 363 | </td> |
| 364 | <td style={{ padding: "15px 3px" }}> |
| 365 | <input |
| 366 | type="checkbox" |
| 367 | id={"opts-class-totitle-" + props.widgetId} |
| 368 | name={"extended_widget_opts[class][link_title]"} |
| 369 | value="1" |
| 370 | /> |
| 371 | <label |
| 372 | class="opts-label-small" |
| 373 | for={"opts-class-totitle-" + props.widgetId} |
| 374 | > |
| 375 | {__("Apply to title only")} |
| 376 | </label> |
| 377 | </td> |
| 378 | </tr> |
| 379 | <tr valign="top"> |
| 380 | <td scope="row" style={{ padding: "15px 3px" }}> |
| 381 | |
| 382 | </td> |
| 383 | <td style={{ padding: "15px 3px" }}> |
| 384 | <input |
| 385 | type="checkbox" |
| 386 | id={"opts-class-http-" + props.widgetId} |
| 387 | name={"extended_widget_opts[class][http]"} |
| 388 | value="1" |
| 389 | /> |
| 390 | <label |
| 391 | class="opts-label-small" |
| 392 | for={"opts-class-http-" + props.widgetId} |
| 393 | > |
| 394 | {__("Do not add http")} |
| 395 | </label> |
| 396 | </td> |
| 397 | </tr> |
| 398 | </tbody> |
| 399 | </table> |
| 400 | </div> |
| 401 | </div> |
| 402 | </div> |
| 403 | </div> |
| 404 | </PanelBody> |
| 405 | </> |
| 406 | ) : ( |
| 407 | "" |
| 408 | )} |
| 409 | |
| 410 | {"activate" == widget_options["classes"] ? ( |
| 411 | <PanelBody |
| 412 | title={__("Class & ID")} |
| 413 | className="margin-x-minus-16" |
| 414 | initialOpen={false} |
| 415 | > |
| 416 | <div |
| 417 | id={ |
| 418 | "extended-widget-opts-settings-tab-" + props.widgetId + "-class" |
| 419 | } |
| 420 | class="extended-widget-opts-settings-tabcontent-2 extended-widget-opts-settings-tabcontent extended-widget-opts-inner-tabcontent" |
| 421 | > |
| 422 | <div class="widget-opts-class"> |
| 423 | <table class="form-table"> |
| 424 | <tbody> |
| 425 | {widget_options["settings"]["classes"] != undefined && |
| 426 | widget_options["settings"]["classes"]["id"] != undefined && |
| 427 | "1" == widget_options["settings"]["classes"]["id"] ? ( |
| 428 | <tr valign="top" class="widgetopts_id_fld"> |
| 429 | <td scope="row"> |
| 430 | <strong>{__("Widget CSS ID:")}</strong> |
| 431 | <br /> |
| 432 | <input |
| 433 | type="text" |
| 434 | id={"opts-class-id-" + props.widgetId} |
| 435 | class="widefat" |
| 436 | name={"extended_widget_opts[class][id]"} |
| 437 | onChange={(event) => |
| 438 | handleInputChange(event, "class", "id") |
| 439 | } |
| 440 | value={ |
| 441 | props.extended_widget_opts["class"] != undefined |
| 442 | ? props.extended_widget_opts["class"]["id"] |
| 443 | : "" |
| 444 | } |
| 445 | /> |
| 446 | </td> |
| 447 | </tr> |
| 448 | ) : ( |
| 449 | "" |
| 450 | )} |
| 451 | |
| 452 | {widget_options["settings"]["classes"] != undefined || |
| 453 | (widget_options["settings"]["classes"] != undefined && |
| 454 | widget_options["settings"]["classes"]["type"] != |
| 455 | undefined && |
| 456 | widget_options["settings"]["classes"]["type"] != "hide" && |
| 457 | widget_options["settings"]["classes"]["type"] != |
| 458 | "predefined") ? ( |
| 459 | <tr valign="top"> |
| 460 | <td scope="row"> |
| 461 | <strong>{__("Widget CSS Classes:")}</strong> |
| 462 | <br /> |
| 463 | <input |
| 464 | type="text" |
| 465 | id={"opts-class-classes-" + props.widgetId} |
| 466 | class="widefat" |
| 467 | name={"extended_widget_opts[class][classes]"} |
| 468 | onChange={(event) => |
| 469 | handleInputChange(event, "class", "classes") |
| 470 | } |
| 471 | value={ |
| 472 | props.extended_widget_opts["class"] != undefined |
| 473 | ? props.extended_widget_opts["class"]["classes"] |
| 474 | : "" |
| 475 | } |
| 476 | /> |
| 477 | <small> |
| 478 | <em>{__("Separate each class with space.")}</em> |
| 479 | </small> |
| 480 | </td> |
| 481 | </tr> |
| 482 | ) : ( |
| 483 | "" |
| 484 | )} |
| 485 | {widget_options["settings"]["classes"] != undefined || |
| 486 | (widget_options["settings"]["classes"] != undefined && |
| 487 | widget_options["settings"]["classes"]["type"] != |
| 488 | undefined && |
| 489 | widget_options["settings"]["classes"]["type"] != "hide" && |
| 490 | widget_options["settings"]["classes"]["type"] != "text") |
| 491 | ? predefined != undefined && |
| 492 | Array.isArray(predefined) && |
| 493 | predefined.length > 0 |
| 494 | ? (function (_predefined, _args) { |
| 495 | let predef = _predefined.filter( |
| 496 | (value, index, array) => |
| 497 | array.indexOf(value) === index |
| 498 | ); |
| 499 | return ( |
| 500 | <tr valign="top"> |
| 501 | <td scope="row"> |
| 502 | <strong> |
| 503 | {__("Available Widget Classes:")} |
| 504 | </strong> |
| 505 | <br /> |
| 506 | <div |
| 507 | class="extended-widget-opts-class-lists" |
| 508 | style={{ |
| 509 | maxHeight: "230px", |
| 510 | padding: "5px", |
| 511 | overflow: "auto", |
| 512 | }} |
| 513 | > |
| 514 | {predef.map(function (value, key) { |
| 515 | let checked = ""; |
| 516 | if ( |
| 517 | _args["params"]["class"][ |
| 518 | "predefined" |
| 519 | ] != undefined && |
| 520 | Array.isArray( |
| 521 | _args["params"]["class"]["predefined"] |
| 522 | ) && |
| 523 | _args["params"]["class"][ |
| 524 | "predefined" |
| 525 | ].includes(value) |
| 526 | ) { |
| 527 | checked = 'checked="checked"'; |
| 528 | } |
| 529 | |
| 530 | return ( |
| 531 | <p> |
| 532 | <input |
| 533 | type="checkbox" |
| 534 | name={ |
| 535 | "extended_widget_opts[class][predefined][]" |
| 536 | } |
| 537 | id={ |
| 538 | props.widgetId + |
| 539 | "-opts-class-" + |
| 540 | key |
| 541 | } |
| 542 | // onChange={(event) => |
| 543 | // handleInputChange(event, "class", "predefined") |
| 544 | // } |
| 545 | // value={ |
| 546 | // props.extended_widget_opts["class"] != undefined |
| 547 | // ? props.extended_widget_opts["class"]["classes"] |
| 548 | // : "" |
| 549 | // } |
| 550 | /> |
| 551 | <label |
| 552 | for={ |
| 553 | props.widgetId + |
| 554 | "-opts-class-" + |
| 555 | key |
| 556 | } |
| 557 | > |
| 558 | {value} |
| 559 | </label> |
| 560 | </p> |
| 561 | ); |
| 562 | })} |
| 563 | </div> |
| 564 | </td> |
| 565 | </tr> |
| 566 | ); |
| 567 | })(predefined, args) |
| 568 | : "" |
| 569 | : ""} |
| 570 | </tbody> |
| 571 | </table> |
| 572 | </div> |
| 573 | </div> |
| 574 | </PanelBody> |
| 575 | ) : ( |
| 576 | "" |
| 577 | )} |
| 578 | </div> |
| 579 | |
| 580 | <style> |
| 581 | {` |
| 582 | .extended-widget-opts-inside-tabs .ui-tabs-nav li.extended-widget-opts-settings-tab-settings a { |
| 583 | padding: 6px 4px !important; |
| 584 | } |
| 585 | .extended-widget-opts-tabs .ui-tabs-nav li.extended-widget-opts-settings-tab-settings.ui-tabs-active a { |
| 586 | padding-bottom: 9px !important; |
| 587 | } |
| 588 | `} |
| 589 | </style> |
| 590 | </div> |
| 591 | ); |
| 592 | }; |
| 593 | |
| 594 | export default BehaviorTabPanel; |
| 595 |