PageRenderTime 61ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/Ultimate_VC_Addons/params/Ultimate_Gradient.php

https://bitbucket.org/youresolutions/sheffieldcareservices.yes1.co.uk
PHP | 243 lines | 205 code | 34 blank | 4 comment | 28 complexity | 208629e6d7f91036269180703ce4911d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, MIT, Apache-2.0
  1. <?php
  2. if(!class_exists('Ultimate_Gradient_Param'))
  3. {
  4. class Ultimate_Gradient_Param
  5. {
  6. function __construct()
  7. {
  8. if(defined('WPB_VC_VERSION') && version_compare(WPB_VC_VERSION, 4.8) >= 0) {
  9. if(function_exists('vc_add_shortcode_param'))
  10. {
  11. vc_add_shortcode_param('gradient' , array(&$this, 'gradient_picker' ) );
  12. }
  13. }
  14. else {
  15. if(function_exists('add_shortcode_param'))
  16. {
  17. add_shortcode_param('gradient' , array(&$this, 'gradient_picker' ) );
  18. }
  19. }
  20. }
  21. function gradient_picker($settings, $value)
  22. {
  23. $dependency = '';
  24. $param_name = isset($settings['param_name']) ? $settings['param_name'] : '';
  25. $type = isset($settings['type']) ? $settings['type'] : '';
  26. $color1 = isset($settings['color1']) ? $settings['color1'] : ' ';
  27. $color2 = isset($settings['color2']) ? $settings['color2'] : ' ';
  28. $class = isset($settings['class']) ? $settings['class'] : '';
  29. $dependency_element = $settings['dependency']['element'];
  30. $dependency_value = $settings['dependency']['value'];
  31. $dependency_value_json = json_encode($dependency_value);
  32. $uni = uniqid();
  33. $output = '<div class="vc_ug_control" data-uniqid="'.esc_attr( $uni ).'" data-color1="'.esc_attr( $color1 ).'" data-color2="'.esc_attr( $color2 ).'">';
  34. //$output .= '<div class="wpb_element_label" style="margin-top: 10px;">'.__('Gradient Type','upb_parallax').'</div>
  35. $output .= '<select id="grad_type'.esc_attr( $uni ).'" class="grad_type" data-uniqid="'.esc_attr( $uni ).'">
  36. <option value="vertical">'.__('Vertical','ultimate_vc').'</option>
  37. <option value="horizontal">'.__('Horizontal','ultimate_vc').'</option>
  38. <option value="custom">'.__('Custom','ultimate_vc').'</option>
  39. </select>
  40. <div id="grad_type_custom_wrapper'.esc_attr( $uni ).'" class="grad_type_custom_wrapper" style="display:none;"><input type="number" id="grad_type_custom'.esc_attr( $uni ).'" placeholder="45" data-uniqid="'.esc_attr( $uni ).'" class="grad_custom" style="width: 200px; margin-bottom: 10px;"/> deg</div>';
  41. $output .= '<div class="wpb_element_label" style="margin-top: 10px;">'.__('Choose Colors','ultimate_vc').'</div>';
  42. $output .= '<div class="grad_hold" id="grad_hold'.esc_attr( $uni ).'"></div>';
  43. $output .= '<div class="grad_trgt" id="grad_target'.esc_attr( $uni ).'"></div>';
  44. $output .= '<input id="grad_val'.esc_attr( $uni ).'" class="wpb_vc_param_value ' . esc_attr( $param_name ) . ' ' . esc_attr( $type ) . ' ' . esc_attr( $class ) . ' vc_ug_gradient" name="' . esc_attr( $param_name ) . '" style="display:none" value="'.esc_attr( $value ).'" '.$dependency.'/></div>';
  45. ?>
  46. <script type="text/javascript">
  47. jQuery(document).ready(function(){
  48. var dependency_element = '<?php echo $dependency_element ?>';
  49. var dependency_values = jQuery.parseJSON('<?php echo $dependency_value_json ?>');
  50. var dependency_values_array = jQuery.map(dependency_values, function(el) { return el; });
  51. var get_depend_value = jQuery('.'+dependency_element).val();
  52. jQuery('.grad_type').change(function(){
  53. var uni = jQuery(this).data('uniqid');
  54. var hid = "#grad_hold"+uni;
  55. var did = "#grad_target"+uni;
  56. var cid = "#grad_type_custom"+uni;
  57. var tid = "#grad_val"+uni;
  58. var cid_wrapper = "#grad_type_custom_wrapper"+uni;
  59. var orientation = jQuery(this).children('option:selected').val();
  60. if(orientation == 'custom')
  61. {
  62. jQuery(cid_wrapper).show();
  63. }
  64. else
  65. {
  66. jQuery(cid_wrapper).hide();
  67. if(orientation == 'vertical')
  68. var ori = 'top';
  69. else
  70. var ori = 'left';
  71. jQuery(hid).data('ClassyGradient').setOrientation(ori);
  72. var newCSS = jQuery(hid).data('ClassyGradient').getCSS();
  73. jQuery(tid).val(newCSS);
  74. }
  75. });
  76. jQuery('.grad_custom').on('keyup',function() {
  77. var uni = jQuery(this).data('uniqid');
  78. var hid = "#grad_hold"+uni;
  79. var gid = "#grad_type"+uni;
  80. var tid = "#grad_val"+uni;
  81. var orientation = jQuery(this).val()+'deg';
  82. jQuery(hid).data('ClassyGradient').setOrientation(orientation);
  83. var newCSS = jQuery(hid).data('ClassyGradient').getCSS();
  84. jQuery(tid).val(newCSS);
  85. });
  86. function gradient_pre_defined(dependency_element, dependency_values_array){
  87. jQuery('.vc_ug_control').each(function(){
  88. var uni = jQuery(this).data('uniqid');
  89. var hid = "#grad_hold"+uni;
  90. var did = "#grad_target"+uni;
  91. var tid = "#grad_val"+uni;
  92. var oid = "#grad_type"+uni;
  93. var cid = "#grad_type_custom"+uni;
  94. var cid_wrapper = "#grad_type_custom_wrapper"+uni;
  95. var orientation = jQuery(oid).children('option:selected').val();
  96. var prev_col = jQuery(tid).val();
  97. var is_custom = 'false';
  98. if(prev_col!='')
  99. {
  100. if(prev_col.indexOf('-webkit-linear-gradient(top,') != -1)
  101. {
  102. var p_l = prev_col.indexOf('-webkit-linear-gradient(top,');
  103. prev_col = prev_col.substring(p_l+28);
  104. p_l = prev_col.indexOf(');');
  105. prev_col = prev_col.substring(0,p_l);
  106. orientation = 'vertical';
  107. }
  108. else if(prev_col.indexOf('-webkit-linear-gradient(left,') != -1)
  109. {
  110. var p_l = prev_col.indexOf('-webkit-linear-gradient(left,');
  111. prev_col = prev_col.substring(p_l+29);
  112. p_l = prev_col.indexOf(');');
  113. prev_col = prev_col.substring(0,p_l);
  114. orientation = 'horizontal';
  115. }
  116. else
  117. {
  118. var p_l = prev_col.indexOf('-webkit-linear-gradient(');
  119. var subStr = prev_col.match("-webkit-linear-gradient((.*));background: -o");
  120. var prev_col = subStr[1].replace(/\(|\)/g, '');
  121. var temp_col = prev_col;
  122. var t_l = temp_col.indexOf('deg');
  123. var deg = temp_col.substring(0,t_l);
  124. prev_col = prev_col.substring(t_l+4, prev_col.length);
  125. jQuery(cid).val(deg);
  126. jQuery(cid_wrapper).show();
  127. orientation = 'custom';
  128. is_custom = 'true';
  129. }
  130. }
  131. else
  132. {
  133. prev_col ="#e3e3e3 0%";
  134. }
  135. jQuery(oid).children('option').each(function(i,opt){
  136. if(opt.value == orientation)
  137. jQuery(this).attr('selected',true);
  138. });
  139. if(is_custom == 'true')
  140. orientation = deg+'deg';
  141. else
  142. {
  143. if(orientation == 'vertical')
  144. orientation = 'top';
  145. else
  146. orientation = 'left';
  147. }
  148. jQuery(hid).ClassyGradient({
  149. width:350,
  150. height:25,
  151. orientation : orientation,
  152. target:did,
  153. gradient: prev_col,
  154. onChange: function(stringGradient,cssGradient) {
  155. var depend = uvc_gradient_verfiy_depedant(dependency_element, dependency_values_array);
  156. cssGradient = cssGradient.replace('url(data:image/svg+xml;base64,','');
  157. var e_pos = cssGradient.indexOf(';');
  158. cssGradient = cssGradient.substring(e_pos+1);
  159. if(jQuery(tid).parents('.wpb_el_type_gradient').css('display')=='none'){
  160. //jQuery(tid).val('');
  161. cssGradient='';
  162. }
  163. if(depend)
  164. jQuery(tid).val(cssGradient);
  165. else
  166. jQuery(tid).val('');
  167. },
  168. onInit: function(cssGradient){
  169. //console.log(jQuery(tid).val())
  170. //check_for_orientation();
  171. }
  172. });
  173. jQuery('.colorpicker').css('z-index','999999');
  174. })
  175. }
  176. if(jQuery.inArray( get_depend_value, dependency_values_array ) !== -1)
  177. var depend = true;
  178. else
  179. var depend = false;
  180. gradient_pre_defined(dependency_element, dependency_values_array);
  181. jQuery('.'+dependency_element).on('change',function(){
  182. var depend = uvc_gradient_verfiy_depedant(dependency_element, dependency_values_array);
  183. jQuery('.vc_ug_control').each(function(){
  184. var uni = jQuery(this).data('uniqid');
  185. var tid = "#grad_val"+uni;
  186. if(depend === false)
  187. jQuery(tid).val('');
  188. else
  189. gradient_pre_defined(dependency_element, dependency_values_array);
  190. });
  191. });
  192. function uvc_gradient_verfiy_depedant(dependency_element, dependency_values_array) {
  193. var get_depend_value = jQuery('.'+dependency_element).val();
  194. if(jQuery.inArray( get_depend_value, dependency_values_array ) !== -1)
  195. return true;
  196. else
  197. return false;
  198. }
  199. })
  200. </script>
  201. <?php
  202. return $output;
  203. }
  204. }
  205. }
  206. if(class_exists('Ultimate_Gradient_Param'))
  207. {
  208. $Ultimate_Gradient_Param = new Ultimate_Gradient_Param();
  209. }