PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/revslider/js/settings.js

https://gitlab.com/thisishayat/itv-2016
JavaScript | 346 lines | 224 code | 88 blank | 34 comment | 52 complexity | 95f8f42a3730ae540c12d65d787c48c0 MD5 | raw file
  1. var UniteSettingsRev = new function(){
  2. var arrControls = {};
  3. var colorPicker;
  4. var t=this;
  5. this.getSettingsObject = function(formID){
  6. var obj = new Object();
  7. var form = document.getElementById(formID);
  8. var name,value,type,flagUpdate;
  9. //enabling all form items connected to mx
  10. var len = form.elements.length;
  11. for(var i=0; i<len; i++){
  12. var element = form.elements[i];
  13. if(element.name == "##NAME##[]") continue; //ignore dummy from multi text
  14. name = element.name;
  15. value = element.value;
  16. type = element.type;
  17. if(jQuery(element).hasClass("wp-editor-area"))
  18. type = "editor";
  19. //trace(name + " " + type);
  20. flagUpdate = true;
  21. switch(type){
  22. case "checkbox":
  23. value = form.elements[i].checked;
  24. break;
  25. case "radio":
  26. if(form.elements[i].checked == false)
  27. flagUpdate = false;
  28. break;
  29. case "editor":
  30. value = tinyMCE.get(name).getContent();
  31. break;
  32. case "select-multiple":
  33. value = jQuery(element).val();
  34. if(value)
  35. value = value.toString();
  36. break;
  37. }
  38. if(flagUpdate == true && name != undefined){
  39. if(name.indexOf('[]') > -1){
  40. name = name.replace('[]', '');
  41. if(typeof obj[name] !== 'object') obj[name] = [];
  42. obj[name][Object.keys(obj[name]).length] = value;
  43. }else{
  44. obj[name] = value;
  45. }
  46. }
  47. }
  48. return(obj);
  49. }
  50. /**
  51. * on selects change - impiment the hide/show, enabled/disables functionality
  52. */
  53. var onSettingChange = function(){
  54. var controlValue = this.value.toLowerCase();
  55. var controlName = this.name;
  56. if(!arrControls[this.name]) return(false);
  57. jQuery(arrControls[this.name]).each(function(){
  58. var childInput = document.getElementById(this.name);
  59. var childRow = document.getElementById(this.name + "_row");
  60. var value = this.value.toLowerCase();
  61. var isChildRadio = (childInput && childInput.tagName == "SPAN" && jQuery(childInput).hasClass("radio_wrapper"));
  62. switch(this.type){
  63. case "enable":
  64. case "disable":
  65. if(childInput){ //disable
  66. if(this.type == "enable" && controlValue != this.value || this.type == "disable" && controlValue == this.value){
  67. childRow.className = "disabled";
  68. if(childInput){
  69. childInput.disabled = true;
  70. childInput.style.color = "";
  71. }
  72. if(isChildRadio)
  73. jQuery(childInput).children("input").prop("disabled","disabled").addClass("disabled");
  74. }
  75. else{ //enable
  76. childRow.className = "";
  77. if(childInput)
  78. childInput.disabled = false;
  79. if(isChildRadio)
  80. jQuery(childInput).children("input").prop("disabled","").removeClass("disabled");
  81. //color the input again
  82. if(jQuery(childInput).hasClass("inputColorPicker")) g_picker.linkTo(childInput);
  83. }
  84. }
  85. break;
  86. case "show":
  87. if(controlValue == this.value) jQuery(childRow).show();
  88. else jQuery(childRow).hide();
  89. break;
  90. case "hide":
  91. if(controlValue == this.value) jQuery(childRow).hide();
  92. else jQuery(childRow).show();
  93. break;
  94. }
  95. });
  96. }
  97. /**
  98. * combine controls to one object, and init control events.
  99. */
  100. var initControls = function(){
  101. //combine controls
  102. for(key in g_settingsObj){
  103. var obj = g_settingsObj[key];
  104. for(controlKey in obj.controls){
  105. arrControls[controlKey] = obj.controls[controlKey];
  106. }
  107. }
  108. //init events
  109. jQuery(".settings_wrapper select").change(onSettingChange);
  110. jQuery(".settings_wrapper input[type='radio']").change(onSettingChange);
  111. }
  112. //init color picker
  113. var initColorPicker = function(){
  114. var colorPickerWrapper = jQuery('#divColorPicker');
  115. colorPicker = jQuery.farbtastic('#divColorPicker');
  116. jQuery(".inputColorPicker").focus(function(){
  117. colorPicker.linkTo(this);
  118. colorPickerWrapper.show();
  119. var input = jQuery(this);
  120. var offset = input.offset();
  121. var offsetView = jQuery("#viewWrapper").offset();
  122. colorPickerWrapper.css({
  123. "left":offset.left + input.width()+20-offsetView.left,
  124. "top":offset.top - colorPickerWrapper.height() + 100-offsetView.top
  125. });
  126. if (jQuery(input.data('linkto'))) {
  127. var oldval = jQuery(this).val();
  128. jQuery(this).data('int',setInterval(function() {
  129. if(input.val() != oldval){
  130. oldval = input.val();
  131. jQuery('#css_preview').css(input.data('linkto'), oldval);
  132. jQuery('input[name="css_'+input.data('linkto')+'"]').val(oldval);
  133. }
  134. } ,200));
  135. }
  136. }).blur(function() {
  137. clearInterval(jQuery(this).data('int'));
  138. }).click(function(){
  139. return(false); //prevent body click
  140. }).change(function(){
  141. colorPicker.linkTo(this);
  142. colorPicker.setColor(jQuery(this).val());
  143. });
  144. colorPickerWrapper.click(function(){
  145. return(false); //prevent body click
  146. });
  147. jQuery("body").click(function(){
  148. colorPickerWrapper.hide();
  149. });
  150. }
  151. /**
  152. * close all accordion items
  153. */
  154. var closeAllAccordionItems = function(formID){
  155. jQuery("#"+formID+" .unite-postbox .inside").slideUp("fast");
  156. jQuery("#"+formID+" .unite-postbox h3").addClass("box_closed");
  157. }
  158. /**
  159. * init side settings accordion - started from php
  160. */
  161. t.initAccordion = function(formID){
  162. var classClosed = "box_closed";
  163. jQuery("#"+formID+" .unite-postbox h3").click(function(){
  164. var handle = jQuery(this);
  165. //open
  166. if(handle.hasClass(classClosed)){
  167. closeAllAccordionItems(formID);
  168. handle.removeClass(classClosed).siblings(".inside").slideDown("fast");
  169. }else{ //close
  170. handle.addClass(classClosed).siblings(".inside").slideUp("fast");
  171. }
  172. });
  173. }
  174. /**
  175. * image search
  176. */
  177. var initImageSearch = function(){
  178. jQuery(".button-image-select").click(function(){
  179. var settingID = this.id.replace("_button","");
  180. UniteAdminRev.openAddImageDialog("Choose Image",function(urlImage, imageID){
  181. //update input:
  182. jQuery("#"+settingID).val(urlImage);
  183. //update preview image:
  184. var urlShowImage = UniteAdminRev.getUrlShowImage(imageID,100,70,true);
  185. jQuery("#" + settingID + "_button_preview").html('<div style="width:100px;height:70px;background:url(\''+urlShowImage+'\'); background-position:center center; background-size:cover;"></div>');
  186. });
  187. });
  188. jQuery(".button-image-remove").click(function(){
  189. var settingID = this.id.replace("_button_remove","");
  190. jQuery("#"+settingID).val('');
  191. jQuery("#" + settingID + "_button_preview").html('');
  192. });
  193. jQuery(".button-image-select-video").click(function(){
  194. UniteAdminRev.openAddImageDialog("Choose Image",function(urlImage, imageID){
  195. //update input:
  196. jQuery("#input_video_preview").val(urlImage);
  197. //update preview image:
  198. var urlShowImage = UniteAdminRev.getUrlShowImage(imageID,200,150,true);
  199. jQuery("#video-thumbnail-preview").attr('src', urlShowImage);
  200. });
  201. });
  202. jQuery(".button-image-remove-video").click(function(){
  203. jQuery("#input_video_preview").val('');
  204. if(jQuery('#video_block_vimeo').css('display') != 'none')
  205. jQuery("#button_vimeo_search").trigger("click");
  206. if(jQuery('#video_block_youtube').css('display') != 'none')
  207. jQuery("#button_youtube_search").trigger("click");
  208. });
  209. }
  210. /**
  211. * init the settings function, set the tootips on sidebars.
  212. */
  213. var init = function(){
  214. //init tipsy
  215. jQuery(".list_settings li .setting_text").tipsy({
  216. gravity:"e",
  217. delayIn: 70
  218. });
  219. jQuery(".tipsy_enabled_top").tipsy({
  220. gravity:"s",
  221. delayIn: 70
  222. });
  223. jQuery(".button-primary").tipsy({
  224. gravity:"s",
  225. delayIn: 70
  226. });
  227. //init controls
  228. initControls();
  229. initColorPicker();
  230. initImageSearch();
  231. //init checklist
  232. jQuery(".settings_wrapper .input_checklist").each(function(){
  233. var select = jQuery(this);
  234. var ominWidth = select.data("minwidth");
  235. if (ominWidth==undefined) ominWidth="none"
  236. select.dropdownchecklist({
  237. zIndex:1000,
  238. minWidth:ominWidth,
  239. onItemClick: function(checkbox,selector) {
  240. for (var i=0;i<20;i++)
  241. if (checkbox.val()=="notselectable"+i) {
  242. //console.log(checkbox.val());
  243. checkbox.attr("checked",false);
  244. }
  245. }
  246. });
  247. select.parent().find('input').each(function() {
  248. var option = jQuery(this);
  249. for (var i=0;i<20;i++)
  250. if (option.val()=="notselectable"+i) option.parent().addClass("dropdowntitleoption");
  251. })
  252. });
  253. }
  254. //call "constructor"
  255. jQuery(document).ready(function(){
  256. init();
  257. });
  258. } // UniteSettings class end