PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/load-more-products-for-woocommerce/berocket/templates/conditions.php

https://bitbucket.org/hcdesenvolvimentos/abracei_loja
PHP | 271 lines | 270 code | 1 blank | 0 comment | 14 complexity | b6548019355694e1fc1efc212c86a0bf MD5 | raw file
Possible License(s): Apache-2.0, MIT, GPL-2.0
  1. <?php
  2. $name_for_condition = $name;
  3. if( ! empty($additional['hook_name']) ) {
  4. $hook_name = $additional['hook_name'];
  5. } else {
  6. return false;
  7. }
  8. echo '<div class="submitbox" id="submitpost">';
  9. $condition_types = apply_filters($hook_name.'_types', array());
  10. ?>
  11. <div class="">
  12. <div class="br_condition_example" style="display:none;">
  13. <div class="br_cond_select" data-current="1">
  14. <span>
  15. <select class="br_cond_type">
  16. <?php
  17. foreach($condition_types as $condition_type_slug => $condition_type_name) {
  18. echo '<option value="', $condition_type_slug, '">', $condition_type_name, '</option>';
  19. }
  20. ?>
  21. </select>
  22. </span>
  23. <span class="button berocket_remove_condition"><i class="fa fa-minus"></i></span>
  24. <div class="br_current_cond">
  25. </div>
  26. </div>
  27. <span class="button berocket_add_condition"><i class="fa fa-plus"></i></span>
  28. <span class="button br_remove_group"><i class="fa fa-minus"></i></span>
  29. </div>
  30. <div class="br_cond_example" style="display:none;">
  31. <?php
  32. foreach($condition_types as $condition_type_slug => $condition_type_name) {
  33. $condition_html = apply_filters($hook_name . '_type_' . $condition_type_slug, '', '%name%[%id%][%current_id%]', array());
  34. if( ! empty($condition_html) ) {
  35. echo '<div class="br_cond br_cond_', $condition_type_slug, '">
  36. ', $condition_html, '
  37. <input type="hidden" name="%name%[%id%][%current_id%][type]" value="', $condition_type_slug, '">
  38. </div>';
  39. }
  40. }
  41. ?>
  42. </div>
  43. <div class="br_conditions">
  44. <?php
  45. $last_id = 0;
  46. foreach($value as $id => $data) {
  47. $current_id = 1;
  48. ob_start();
  49. foreach($data as $current => $conditions) {
  50. if( $current > $current_id ) {
  51. $current_id = $current;
  52. }
  53. ?>
  54. <div class="br_cond_select" data-current="<?php echo $current; ?>">
  55. <span>
  56. <select class="br_cond_type">
  57. <?php
  58. foreach($condition_types as $condition_type_slug => $condition_type_name) {
  59. echo '<option value="', $condition_type_slug, '"', ( isset($conditions['type']) && $conditions['type'] == $condition_type_slug ? ' selected' : '' ) , '>', $condition_type_name, '</option>';
  60. }
  61. ?>
  62. </select>
  63. </span>
  64. <span class="button berocket_remove_condition"><i class="fa fa-minus"></i></span>
  65. <div class="br_current_cond">
  66. </div>
  67. <?php
  68. $condition_html = apply_filters($hook_name . '_type_' . $conditions['type'], '', $name_for_condition . '[' . $id . '][' . $current . ']', $conditions);
  69. if( ! empty($condition_html) ) {
  70. echo '<div class="br_cond br_cond_', $conditions['type'], '">
  71. ', $condition_html, '
  72. <input type="hidden" name="' . $name_for_condition . '[' . $id . '][' . $current . '][type]" value="', $conditions['type'], '">
  73. </div>';
  74. }
  75. ?>
  76. </div>
  77. <?php
  78. }
  79. ?>
  80. <span class="button berocket_add_condition"><i class="fa fa-plus"></i></span>
  81. <span class="button br_remove_group"><i class="fa fa-minus"></i></span>
  82. <?php
  83. $html = ob_get_clean();
  84. echo '<div class="br_html_condition" data-id="'.$id.'" data-current="'.$current_id.'">';
  85. echo $html;
  86. echo '</div>';
  87. if( $id > $last_id ) {
  88. $last_id = $id;
  89. }
  90. }
  91. $last_id++;
  92. ?>
  93. <span class="button br_add_group"><i class="fa fa-plus"></i></span>
  94. </div>
  95. <script>
  96. var last_id = <?php echo $last_id; ?>;
  97. var condition_name = '<?php echo $name_for_condition; ?>';
  98. var $html = jQuery('.br_condition_example').html();
  99. $html = '<div class="br_cond_one">'+$html+'</div>';
  100. jQuery(document).on('change', '.br_cond_type', function(event) {
  101. var $parent = jQuery(this).parents('.br_cond_select');
  102. $parent.find('.br_cond').remove();
  103. var id = $parent.parents('.br_html_condition');
  104. var current_id = $parent.data('current');
  105. id = id.data('id');
  106. var html_need = jQuery('.br_cond_example .br_cond_'+jQuery(this).val()).get(0);
  107. html_need = html_need.outerHTML;
  108. html_need = html_need.replace(/%id%/g, id);
  109. html_need = html_need.replace(/%current_id%/g, current_id);
  110. html_need = html_need.replace(/%name%/g, condition_name);
  111. console.log(html_need);
  112. $parent.find('.br_current_cond').html(html_need);
  113. });
  114. jQuery(document).on('click', '.berocket_add_condition', function() {
  115. var id = jQuery(this).parents('.br_html_condition');
  116. var current_id = id.data('current');
  117. current_id = current_id + 1;
  118. id.data('current', current_id);
  119. id = id.data('id');
  120. var $html = jQuery('.br_condition_example .br_cond_select').html();
  121. $html = '<div class="br_cond_select" data-current="'+current_id+'">'+$html+'</div>';
  122. $html = $html.replace('%id%', id);
  123. jQuery(this).before($html);
  124. $parent = jQuery(this).prev();
  125. $parent.find('.br_cond_type').trigger('change');
  126. });
  127. jQuery(document).on('click', '.berocket_remove_condition', function() {
  128. $parent = jQuery(this).parents('.br_cond_select');
  129. $parent.remove();
  130. });
  131. jQuery(document).on('click', '.br_add_group', function() {
  132. last_id++;
  133. var html = $html.replace( '%id%', last_id );
  134. var html = '<div class="br_html_condition" data-id="'+last_id+'" data-current="1">'+html+'</div>';
  135. jQuery(this).before(html);
  136. $parent = jQuery(this).prev();
  137. $parent.find('.br_cond_type').trigger('change');
  138. });
  139. jQuery(document).on('click', '.br_remove_group', function() {
  140. $parent = jQuery(this).parents('.br_html_condition');
  141. $parent.remove();
  142. });
  143. jQuery(document).on('change', '.br_cond_attr_select', function() {
  144. var $attr_block = jQuery(this).parents('.br_cond_attribute');
  145. $attr_block.find('.br_attr_values').hide();
  146. $attr_block.find('.br_attr_value_'+jQuery(this).val()).show();
  147. });
  148. jQuery(document).on('change', '.price_from', function() {
  149. var val_price_from = jQuery(this).val();
  150. var val_price_to = jQuery(this).parents('.br_cond').first().find('.price_to').val();
  151. price_from = parseFloat(val_price_from);
  152. price_to = parseFloat(val_price_to);
  153. price_to_int = parseInt(val_price_to);
  154. if( val_price_from == '' ) {
  155. jQuery(this).val(0);
  156. price_from = 0;
  157. }
  158. if( price_from > price_to ) {
  159. jQuery(this).val(price_to_int);
  160. }
  161. });
  162. jQuery(document).on('change', '.price_to', function() {
  163. var val_price_from = jQuery(this).parents('.br_cond').first().find('.price_from').val();
  164. var val_price_to = jQuery(this).val();
  165. price_from = parseFloat(val_price_from);
  166. price_from_int = parseInt(val_price_from);
  167. price_to = parseFloat(val_price_to);
  168. if( val_price_to == '' ) {
  169. jQuery(this).val(0);
  170. price_to = 0;
  171. }
  172. if( price_from > price_to ) {
  173. jQuery(this).val(price_from_int);
  174. }
  175. });
  176. </script>
  177. <style>
  178. .br_conditions .br_html_condition {
  179. margin-top: 40px;
  180. }
  181. .br_conditions .br_html_condition:first-child {
  182. margin-top: 0;
  183. }
  184. .br_conditions .br_html_condition:before {
  185. content: "OR";
  186. display: block;
  187. position: absolute;
  188. top: -30px;
  189. font-size: 30px;
  190. }
  191. .br_conditions .br_html_condition:first-child:before {
  192. display: none;
  193. }
  194. .br_html_condition .br_cond_select {
  195. margin-top: 40px;
  196. position: relative;
  197. }
  198. .br_html_condition .br_cond_select:first-child {
  199. margin-top: 0;
  200. }
  201. .br_html_condition .br_cond_select:before {
  202. content: "AND";
  203. display: block;
  204. position: absolute;
  205. top: -30px;
  206. font-size: 30px;
  207. }
  208. .br_html_condition .br_cond_select:first-child:before {
  209. display: none;
  210. }
  211. .br_html_condition .br_cond_one .br_cond_select:first-child .berocket_remove_condition {
  212. display: none;
  213. }
  214. .br_html_condition {
  215. border: 1px solid #999;
  216. background-color: #fafafa;
  217. padding: 0.5em;
  218. margin-bottom: 1em;
  219. position: relative;
  220. }
  221. .br_html_condition .br_remove_group {
  222. position: absolute!important;
  223. top:-10px;
  224. right: -10px;
  225. }
  226. .br_cond_select {
  227. padding-bottom: 1em;
  228. }
  229. .br_cond_select {
  230. border: 1px solid #999;
  231. padding: 0.5em;
  232. margin-bottom: 0.5em;
  233. background-color: #eee;
  234. }
  235. .br_framework_settings .button.berocket_remove_condition,
  236. .br_framework_settings .button.berocket_add_condition,
  237. .br_framework_settings .button.br_remove_group,
  238. .br_framework_settings .button.br_add_group {
  239. padding: 0 10px;
  240. margin: 0;
  241. width: initial;
  242. min-width: initial;
  243. }
  244. .berocket_label_preview_wrap {
  245. display: inline-block;
  246. width: 240px;
  247. padding: 20px;
  248. background: white;
  249. position: fixed;
  250. top: 100%;
  251. margin-top: -320px;
  252. min-height: 320px;
  253. right: 20px;
  254. box-sizing: border-box;
  255. }
  256. .berocket_label_preview_wrap .berocket_label_preview {
  257. position: relative;
  258. }
  259. .berocket_label_preview_wrap .berocket_product_image {
  260. display: block;
  261. width: 200px;
  262. }
  263. @media screen and (max-width: 850px) {
  264. .berocket_label_preview_wrap {
  265. position: relative;
  266. }
  267. }
  268. </style>
  269. </div>
  270. </div>