customizer-preview.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. 'use strict';
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. var _helpers = require('./helpers');
  7. var general = function general(api, $) {
  8. 'use strict';
  9. api('vamtam_theme[show-splash-screen]', function (value) {
  10. value.bind(function (to) {
  11. if (+to) {
  12. $('body').triggerHandler('vamtam-preview-splash-screen');
  13. }
  14. });
  15. });
  16. api('vamtam_theme[splash-screen-logo]', function (value) {
  17. value.bind(function (to) {
  18. var wrapper = $('.vamtam-splash-screen-progress-wrapper');
  19. var current_image = wrapper.find('> img');
  20. if (current_image.length === 0) {
  21. current_image = $('<img />');
  22. wrapper.prepend(current_image);
  23. }
  24. current_image.attr('src', to);
  25. $('body').triggerHandler('vamtam-preview-splash-screen');
  26. });
  27. });
  28. api('vamtam_theme[show-scroll-to-top]', function (value) {
  29. value.bind(function (to) {
  30. (0, _helpers.toggle)($('#scroll-to-top'), to);
  31. });
  32. });
  33. api('vamtam_theme[show-related-posts]', function (value) {
  34. value.bind(function (to) {
  35. (0, _helpers.toggle)($('.vamtam-related-content.related-posts'), to);
  36. });
  37. });
  38. api('vamtam_theme[related-posts-title]', function (value) {
  39. value.bind(function (to) {
  40. $('.related-posts .related-content-title').html(to);
  41. });
  42. });
  43. api('vamtam_theme[show-single-post-image]', function (value) {
  44. value.bind(function (to) {
  45. (0, _helpers.toggle)($('.single-post > .post-media-image'), to);
  46. });
  47. });
  48. api('vamtam_theme[post-meta]', function (value) {
  49. value.bind(function (to) {
  50. for (var type in to) {
  51. (0, _helpers.toggle)($('.vamtam-meta-' + type), +to[type]);
  52. }
  53. });
  54. });
  55. api('vamtam_theme[show-related-portfolios]', function (value) {
  56. value.bind(function (to) {
  57. (0, _helpers.toggle)($('.vamtam-related-content.related-portfolios'), to);
  58. });
  59. });
  60. api('vamtam_theme[related-portfolios-title]', function (value) {
  61. value.bind(function (to) {
  62. $('.related-portfolios .related-content-title').html(to);
  63. });
  64. });
  65. }; /* jshint esnext:true */
  66. exports.default = general;
  67. },{"./helpers":2}],2:[function(require,module,exports){
  68. 'use strict';
  69. Object.defineProperty(exports, "__esModule", {
  70. value: true
  71. });
  72. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  73. /* jshint esnext:true */
  74. var toggle = function toggle(el, visibility) {
  75. 'use strict';
  76. if (+visibility) {
  77. el.show();
  78. } else {
  79. el.hide();
  80. }
  81. };
  82. function isNumeric(n) {
  83. return !isNaN(parseFloat(n)) && isFinite(n);
  84. }
  85. /**
  86. * Converts an RGB color value to HSL. Conversion formula
  87. * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
  88. * Assumes r, g, and b are contained in the set [0, 255] and
  89. * returns h, s, and l for use with the hsl() notation in CSS
  90. *
  91. * @param Number r The red color value
  92. * @param Number g The green color value
  93. * @param Number b The blue color value
  94. * @return Array The HSL representation
  95. */
  96. function rgbToHsl(r, g, b) {
  97. r /= 255, g /= 255, b /= 255;
  98. var max = Math.max(r, g, b),
  99. min = Math.min(r, g, b);
  100. var h = void 0,
  101. s = void 0,
  102. l = (max + min) / 2;
  103. if (max == min) {
  104. h = s = 0; // achromatic
  105. } else {
  106. var d = max - min;
  107. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  108. switch (max) {
  109. case r:
  110. h = (g - b) / d + (g < b ? 6 : 0);break;
  111. case g:
  112. h = (b - r) / d + 2;break;
  113. case b:
  114. h = (r - g) / d + 4;break;
  115. }
  116. h /= 6;
  117. }
  118. return [h * 360, s * 100, l * 100];
  119. }
  120. function hexToRgb(hex) {
  121. // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
  122. var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
  123. hex = hex.replace(shorthandRegex, function (m, r, g, b) {
  124. return r + r + g + g + b + b;
  125. });
  126. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  127. return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : null;
  128. }
  129. function hexToHsl(hex) {
  130. return rgbToHsl.apply(undefined, _toConsumableArray(hexToRgb(hex)));
  131. }
  132. exports.toggle = toggle;
  133. exports.isNumeric = isNumeric;
  134. exports.rgbToHsl = rgbToHsl;
  135. exports.hexToRgb = hexToRgb;
  136. exports.hexToHsl = hexToHsl;
  137. },{}],3:[function(require,module,exports){
  138. 'use strict';
  139. Object.defineProperty(exports, "__esModule", {
  140. value: true
  141. });
  142. var _helpers = require('./helpers');
  143. var layout = function layout(api, $) {
  144. 'use strict';
  145. api('vamtam_theme[full-width-header]', function (value) {
  146. value.bind(function (to) {
  147. $('.header-maybe-limit-wrapper').toggleClass('limit-wrapper', to);
  148. });
  149. });
  150. api('vamtam_theme[sticky-header]', function (value) {
  151. value.bind(function (to) {
  152. requestAnimationFrame(function () {
  153. document.body.classList.toggle('sticky-header', +to);
  154. document.body.classList.remove('had-sticky-header');
  155. window.VAMTAM.stickyHeader.rebuild();
  156. });
  157. });
  158. });
  159. api('vamtam_theme[enable-header-search]', function (value) {
  160. value.bind(function (to) {
  161. (0, _helpers.toggle)($('header.main-header .search-wrapper'), +to);
  162. });
  163. });
  164. api('vamtam_theme[show-empty-header-cart]', function (value) {
  165. value.bind(function (to) {
  166. document.querySelector('.cart-dropdown').classList.toggle('show-if-empty', +to);
  167. $('body').trigger('wc_fragments_refreshed');
  168. });
  169. });
  170. api('vamtam_theme[one-page-footer]', function (value) {
  171. value.bind(function (to) {
  172. (0, _helpers.toggle)($('.footer-wrapper'), to);
  173. setTimeout(function () {
  174. window.VAMTAM.resizeElements();
  175. }, 50);
  176. });
  177. });
  178. api('vamtam_theme[page-title-layout]', function (value) {
  179. value.bind(function (to) {
  180. var header = $('header.page-header');
  181. var line = header.find('.page-header-line');
  182. header.removeClass('layout-centered layout-one-row-left layout-one-row-right layout-left-align layout-right-align').addClass('layout-' + to);
  183. if (to.match(/one-row-/)) {
  184. line.appendTo(header.find('h1'));
  185. } else {
  186. line.appendTo(header);
  187. }
  188. });
  189. });
  190. }; /* jshint esnext:true */
  191. exports.default = layout;
  192. },{"./helpers":2}],4:[function(require,module,exports){
  193. 'use strict';
  194. var _general = require('./general');
  195. var _general2 = _interopRequireDefault(_general);
  196. var _layout = require('./layout');
  197. var _layout2 = _interopRequireDefault(_layout);
  198. var _styles = require('./styles');
  199. var _styles2 = _interopRequireDefault(_styles);
  200. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  201. (function ($, undefined) {
  202. 'use strict';
  203. (0, _general2.default)(wp.customize, $);
  204. (0, _layout2.default)(wp.customize, $);
  205. (0, _styles2.default)(wp.customize, $);
  206. })(jQuery); /* jshint esnext:true */
  207. },{"./general":1,"./layout":3,"./styles":5}],5:[function(require,module,exports){
  208. 'use strict';
  209. Object.defineProperty(exports, "__esModule", {
  210. value: true
  211. });
  212. var _helpers = require('./helpers');
  213. var styles = function styles(api, $) {
  214. 'use strict';
  215. var prepare_background = function prepare_background(to) {
  216. if (to['background-image'] !== '') {
  217. to['background-image'] = 'url(' + to['background-image'] + ')';
  218. }
  219. return to;
  220. };
  221. api('vamtam_theme[top-nav-background]', function (value) {
  222. value.bind(function (to) {
  223. $('#top-nav-wrapper, #top-nav-wrapper-filler').css(prepare_background(to));
  224. });
  225. });
  226. {
  227. (function () {
  228. var compiler_options = VAMTAM_CUSTOMIZE_PREVIEW.compiler_options;
  229. var real_id = function real_id(id) {
  230. return id.replace(/vamtam_theme\[([^\]]+)]/, '$1');
  231. };
  232. var change_handler_by_type = {
  233. number: function number(to) {
  234. var id = real_id(this.id);
  235. if (VAMTAM_CUSTOMIZE_PREVIEW.percentages.indexOf(id) !== -1) {
  236. to += '%';
  237. } else if (VAMTAM_CUSTOMIZE_PREVIEW.numbers.indexOf(id) !== -1) {
  238. // as is
  239. } else {
  240. to += 'px';
  241. }
  242. document.documentElement.style.setProperty('--vamtam-' + id, to);
  243. // trigger a resize event if we change any dimension
  244. $(window).resize();
  245. },
  246. background: function background(to) {
  247. var id = real_id(this.id);
  248. to = prepare_background(to);
  249. for (var prop in to) {
  250. document.documentElement.style.setProperty('--vamtam-' + id + '-' + prop, to[prop]);
  251. }
  252. },
  253. radio: function radio(to) {
  254. var id = real_id(this.id);
  255. if ((0, _helpers.isNumeric)(to)) {
  256. change_handler_by_type.number.call(this, to);
  257. } else {
  258. document.documentElement.style.setProperty('--vamtam-' + id, to);
  259. }
  260. },
  261. select: function select(to) {
  262. var id = real_id(this.id);
  263. change_handler_by_type.radio.call(this, to);
  264. },
  265. typography: function typography(to, from) {
  266. var id = real_id(this.id);
  267. var variant = to.variant;
  268. to['font-weight'] = 'normal';
  269. to['font-style'] = 'normal';
  270. to.variant = to.variant.split(' ');
  271. if (to.variant.length === 2) {
  272. to['font-weight'] = to.variant[0];
  273. to['font-style'] = to.variant[1];
  274. } else if (to.variant[0] === 'italic') {
  275. to['font-style'] = 'italic';
  276. } else {
  277. to['font-weight'] = to.variant[0];
  278. }
  279. delete to.variant;
  280. for (var prop in to) {
  281. document.documentElement.style.setProperty('--vamtam-' + id + '-' + prop, to[prop]);
  282. }
  283. // if the font-family is changed - we need to load the new font stylesheet
  284. if (to['font-family'] !== from['font-family']) {
  285. var new_font = window.top.VAMTAM_ALL_FONTS[to['font-family']];
  286. if (new_font.gf) {
  287. var family = encodeURIComponent(to['font-family']) + ':bold,' + variant.replace(' ', '');
  288. var subset = ''; // no subset support here, only newer browser can preview Google Fonts
  289. var link = document.createElement("link");
  290. link.href = 'https://fonts.googleapis.com/css?family=' + family + '&subset=' + subset;
  291. link.type = 'text/css';
  292. link.rel = 'stylesheet';
  293. document.getElementsByTagName('head')[0].appendChild(link);
  294. }
  295. }
  296. },
  297. 'color-row': function colorRow(to) {
  298. var id = real_id(this.id);
  299. for (var prop in to) {
  300. document.documentElement.style.setProperty('--vamtam-' + id + '-' + prop, to[prop]);
  301. }
  302. if (id === 'accent-color') {
  303. // accents need readable colors
  304. for (var i = 1; i <= 8; i++) {
  305. var hex = to[i];
  306. var hsl = (0, _helpers.hexToHsl)(hex);
  307. var readable = '';
  308. var hc = '';
  309. if (hsl[2] > 80) {
  310. readable = 'hsl(' + hsl[0] + ', ' + hsl[1] + '%, ' + Math.max(0, hsl[2] - 50) + '%)'; // $color->darken( 50 );
  311. hc = '#000000';
  312. } else {
  313. readable = 'hsl(' + hsl[0] + ', ' + hsl[1] + '%, ' + Math.min(0, hsl[2] + 50) + '%)'; // $color->lighten( 50 );
  314. hc = '#ffffff';
  315. }
  316. document.documentElement.style.setProperty('--vamtam-accent-color-' + i + '-readable', readable);
  317. document.documentElement.style.setProperty('--vamtam-accent-color-' + i + '-hc', hc);
  318. document.documentElement.style.setProperty('--vamtam-accent-color-' + i + '-transparent', 'hsl(' + hsl[0] + ', ' + hsl[1] + '%, ' + hsl[2] + '%, 0)');
  319. }
  320. }
  321. },
  322. color: function color(to) {
  323. var id = real_id(this.id);
  324. document.documentElement.style.setProperty('--vamtam-' + id, to);
  325. }
  326. };
  327. // const compiler_option_handler = ;
  328. var _loop = function _loop(opt_name) {
  329. api(opt_name, function (setting) {
  330. var type = compiler_options[opt_name];
  331. if (type in change_handler_by_type) {
  332. setting.bind(change_handler_by_type[type]);
  333. } else {
  334. console.error('VamTam Customzier: Missing handler for option type ' + type + ' - option ' + opt_name);
  335. window.wpvval = setting;
  336. }
  337. });
  338. };
  339. for (var opt_name in compiler_options) {
  340. _loop(opt_name);
  341. }
  342. })();
  343. }
  344. api('vamtam_theme[page-title-background-hide-lowres]', function (value) {
  345. value.bind(function (to) {
  346. $('header.page-header').toggleClass('vamtam-hide-bg-lowres', to);
  347. });
  348. });
  349. api('vamtam_theme[main-background-hide-lowres]', function (value) {
  350. value.bind(function (to) {
  351. $('.vamtam-main').toggleClass('vamtam-hide-bg-lowres', to);
  352. });
  353. });
  354. }; /* jshint esnext:true */
  355. exports.default = styles;
  356. },{"./helpers":2}]},{},[4]);