widget-options
/
includes
/
widgets
/
gutenberg
/
src
/
attributes
/
components
/
option-tabs
/
devices.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
devices.js
245 lines
| 1 | const { __ } = wp.i18n; |
| 2 | import { TabPanel } from "@wordpress/components"; |
| 3 | |
| 4 | const onSelect = (tabName) => {}; |
| 5 | |
| 6 | const DevicesTabPanel = (props) => { |
| 7 | let desktop = ""; |
| 8 | let tablet = ""; |
| 9 | let mobile = ""; |
| 10 | let options_role = ""; |
| 11 | |
| 12 | const handleInputChangeDeviceHideShow = (event) => { |
| 13 | let _attribute = { ...props.extended_widget_opts }; |
| 14 | if ( |
| 15 | _attribute["devices"] == undefined || |
| 16 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 17 | ) { |
| 18 | _attribute["devices"] = {}; |
| 19 | } |
| 20 | |
| 21 | _attribute["devices"]["options"] = event.target.value; |
| 22 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 23 | }; |
| 24 | |
| 25 | const handleInputChangeDeviceDesktop = (event) => { |
| 26 | let _attribute = { ...props.extended_widget_opts }; |
| 27 | if ( |
| 28 | _attribute["devices"] == undefined || |
| 29 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 30 | ) { |
| 31 | _attribute["devices"] = {}; |
| 32 | } |
| 33 | |
| 34 | _attribute["devices"]["desktop"] = event.target.value; |
| 35 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 36 | }; |
| 37 | |
| 38 | const handleInputChangeDeviceDesktopCheckbox = (event) => { |
| 39 | let _attribute = { ...props.extended_widget_opts }; |
| 40 | if ( |
| 41 | _attribute["devices"] == undefined || |
| 42 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 43 | ) { |
| 44 | _attribute["devices"] = {}; |
| 45 | } |
| 46 | |
| 47 | if (event.target.checked) { |
| 48 | _attribute["devices"]["desktop"] = 1; |
| 49 | } else { |
| 50 | delete _attribute["devices"]["desktop"]; |
| 51 | } |
| 52 | |
| 53 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 54 | }; |
| 55 | |
| 56 | const handleInputChangeDeviceTablet = (event) => { |
| 57 | let _attribute = { ...props.extended_widget_opts }; |
| 58 | if ( |
| 59 | _attribute["devices"] == undefined || |
| 60 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 61 | ) { |
| 62 | _attribute["devices"] = {}; |
| 63 | } |
| 64 | |
| 65 | _attribute["devices"]["tablet"] = event.target.value; |
| 66 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 67 | }; |
| 68 | |
| 69 | const handleInputChangeDeviceTabletCheckbox = (event) => { |
| 70 | let _attribute = { ...props.extended_widget_opts }; |
| 71 | if ( |
| 72 | _attribute["devices"] == undefined || |
| 73 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 74 | ) { |
| 75 | _attribute["devices"] = {}; |
| 76 | } |
| 77 | |
| 78 | if (event.target.checked) { |
| 79 | _attribute["devices"]["tablet"] = 1; |
| 80 | } else { |
| 81 | delete _attribute["devices"]["tablet"]; |
| 82 | } |
| 83 | |
| 84 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 85 | }; |
| 86 | |
| 87 | const handleInputChangeDeviceMobile = (event) => { |
| 88 | let _attribute = { ...props.extended_widget_opts }; |
| 89 | if ( |
| 90 | _attribute["devices"] == undefined || |
| 91 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 92 | ) { |
| 93 | _attribute["devices"] = {}; |
| 94 | } |
| 95 | |
| 96 | _attribute["devices"]["mobile"] = event.target.value; |
| 97 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 98 | }; |
| 99 | |
| 100 | const handleInputChangeDeviceMobileCheckbox = (event) => { |
| 101 | let _attribute = { ...props.extended_widget_opts }; |
| 102 | if ( |
| 103 | _attribute["devices"] == undefined || |
| 104 | (_attribute["devices"] != undefined && _attribute["devices"].length == 0) |
| 105 | ) { |
| 106 | _attribute["devices"] = {}; |
| 107 | } |
| 108 | |
| 109 | if (event.target.checked) { |
| 110 | _attribute["devices"]["mobile"] = 1; |
| 111 | } else { |
| 112 | delete _attribute["devices"]["mobile"]; |
| 113 | } |
| 114 | |
| 115 | props.onUpdateDynamicAttribute(_attribute, props.widgetId); |
| 116 | }; |
| 117 | |
| 118 | return ( |
| 119 | <div |
| 120 | id={"extended-widget-opts-tab-" + props.widgetId + "-devices"} |
| 121 | className="extended-widget-opts-tabcontent extended-widget-opts-tabcontent-devices" |
| 122 | style={{ "margin-left": "16px" }} |
| 123 | > |
| 124 | <p style={{ "margin-top": "10px" }}> |
| 125 | <strong>{__("Hide/Show")}</strong> |
| 126 | <select |
| 127 | class="widefat" |
| 128 | name={"extended_widget_opts[devices][options]"} |
| 129 | onChange={handleInputChangeDeviceHideShow} |
| 130 | value={ |
| 131 | props.extended_widget_opts["devices"] != undefined |
| 132 | ? props.extended_widget_opts["devices"]["options"] |
| 133 | : "" |
| 134 | } |
| 135 | > |
| 136 | <option value="hide">{__("Hide on checked devices")}</option> |
| 137 | <option value="show">{__("Show on checked devices")}</option> |
| 138 | </select> |
| 139 | </p> |
| 140 | |
| 141 | <table class="form-table"> |
| 142 | <tbody> |
| 143 | <tr valign="top"> |
| 144 | <td scope="row"> |
| 145 | <strong>{__("Devices")}</strong> |
| 146 | </td> |
| 147 | <td> </td> |
| 148 | </tr> |
| 149 | <tr valign="top"> |
| 150 | <td scope="row"> |
| 151 | <span class="dashicons dashicons-desktop"></span>{" "} |
| 152 | <label |
| 153 | for={ |
| 154 | "extended_widget_opts-" + props.widgetId + "-devices-desktop" |
| 155 | } |
| 156 | > |
| 157 | {__("Desktop")} |
| 158 | </label> |
| 159 | </td> |
| 160 | <td> |
| 161 | <input |
| 162 | type="checkbox" |
| 163 | name={"extended_widget_opts[devices][desktop]"} |
| 164 | value="1" |
| 165 | id={ |
| 166 | "extended_widget_opts-" + props.widgetId + "-devices-desktop" |
| 167 | } |
| 168 | onChange={handleInputChangeDeviceDesktopCheckbox} |
| 169 | checked={ |
| 170 | props.extended_widget_opts["devices"] != undefined && |
| 171 | props.extended_widget_opts["devices"]["desktop"] == 1 |
| 172 | ? true |
| 173 | : false |
| 174 | } |
| 175 | /> |
| 176 | </td> |
| 177 | </tr> |
| 178 | <tr valign="top"> |
| 179 | <td scope="row"> |
| 180 | <span class="dashicons dashicons-tablet"></span>{" "} |
| 181 | <label |
| 182 | for={ |
| 183 | "extended_widget_opts-" + props.widgetId + "-devices-table" |
| 184 | } |
| 185 | > |
| 186 | {__("Tablet")} |
| 187 | </label> |
| 188 | </td> |
| 189 | <td> |
| 190 | <input |
| 191 | type="checkbox" |
| 192 | name={"extended_widget_opts[devices][tablet]"} |
| 193 | value="1" |
| 194 | id={"extended_widget_opts-" + props.widgetId + "-devices-table"} |
| 195 | onChange={handleInputChangeDeviceTabletCheckbox} |
| 196 | checked={ |
| 197 | props.extended_widget_opts["devices"] != undefined && |
| 198 | props.extended_widget_opts["devices"]["tablet"] == 1 |
| 199 | ? true |
| 200 | : false |
| 201 | } |
| 202 | /> |
| 203 | </td> |
| 204 | </tr> |
| 205 | <tr valign="top"> |
| 206 | <td scope="row"> |
| 207 | <span class="dashicons dashicons-smartphone"></span>{" "} |
| 208 | <label |
| 209 | for={ |
| 210 | "extended_widget_opts-" + props.widgetId + "-devices-mobile" |
| 211 | } |
| 212 | > |
| 213 | {__("Mobile")} |
| 214 | </label> |
| 215 | </td> |
| 216 | <td> |
| 217 | <input |
| 218 | type="checkbox" |
| 219 | name={ |
| 220 | "extended_widget_opts-" + |
| 221 | props.widgetId + |
| 222 | "[extended_widget_opts][devices][mobile]" |
| 223 | } |
| 224 | value="1" |
| 225 | id={ |
| 226 | "extended_widget_opts-" + props.widgetId + "-devices-mobile" |
| 227 | } |
| 228 | onChange={handleInputChangeDeviceMobileCheckbox} |
| 229 | checked={ |
| 230 | props.extended_widget_opts["devices"] != undefined && |
| 231 | props.extended_widget_opts["devices"]["mobile"] == 1 |
| 232 | ? true |
| 233 | : false |
| 234 | } |
| 235 | /> |
| 236 | </td> |
| 237 | </tr> |
| 238 | </tbody> |
| 239 | </table> |
| 240 | </div> |
| 241 | ); |
| 242 | }; |
| 243 | |
| 244 | export default DevicesTabPanel; |
| 245 |