Brak opisu

um-functions.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /*
  2. Plugin Name: Ultimate Member
  3. Description: Frontend scripts
  4. Version: 2.1.16
  5. Author: Ultimate Member
  6. Author URI: http://ultimatemember.com/
  7. */
  8. if ( typeof (window.UM) !== 'object' ) {
  9. window.UM = {};
  10. }
  11. UM.dropdown = {
  12. /**
  13. * Hide the menu
  14. * @param {object} menu
  15. * @returns {undefined}
  16. */
  17. hide: function (menu) {
  18. var $menu = jQuery(menu);
  19. $menu.parents('div').find('a').removeClass('active');
  20. $menu.hide();
  21. },
  22. /**
  23. * Hide all menus
  24. * @returns {undefined}
  25. */
  26. hideAll: function () {
  27. var $menu = jQuery('.um-dropdown');
  28. $menu.parents('div').find('a').removeClass('active');
  29. $menu.hide();
  30. },
  31. /**
  32. * Update the menu position
  33. * @param {object} menu
  34. * @returns {undefined}
  35. */
  36. setPosition: function (menu) {
  37. var $menu = jQuery(menu),
  38. menu_width = 200;
  39. var direction = jQuery('html').attr('dir'),
  40. element = $menu.attr('data-element'),
  41. position = $menu.attr('data-position'),
  42. trigger = $menu.attr('data-trigger');
  43. var $element = element && jQuery(element).length ? jQuery(element) : ($menu.siblings('a').length ? $menu.siblings('a').first() : $menu.parent());
  44. $element.addClass('um-trigger-menu-on-' + trigger);
  45. var gap_right = 0,
  46. left_p = ($element.outerWidth() - menu_width) / 2,
  47. top_p = $element.outerHeight(),
  48. coord = $element.offset();
  49. // profile photo
  50. if ( $element.is('.um-profile-photo') ) {
  51. var $imgBox = $element.find('.um-profile-photo-img');
  52. if ( $element.closest('div.uimob500').length ) {
  53. top_p = $element.outerHeight() - $imgBox.outerHeight() / 4;
  54. } else {
  55. left_p = ($imgBox.outerWidth() - menu_width) / 2;
  56. top_p = $imgBox.outerHeight() / 4;
  57. }
  58. }
  59. // cover photo
  60. if ( $element.is('.um-cover') ) {
  61. var $imgBox = $element.find('.um-cover-e');
  62. if ( $element.closest('div.uimob500').length ) {
  63. left_p = ($imgBox.outerWidth() - menu_width) / 2;
  64. top_p = $imgBox.outerHeight() / 2 + 24;
  65. } else {
  66. left_p = ($imgBox.outerWidth() - menu_width) / 2;
  67. top_p = $imgBox.outerHeight() / 2 + 46;
  68. }
  69. }
  70. // position
  71. if ( position === 'lc' && direction === 'rtl' ) {
  72. position = 'rc';
  73. }
  74. if( $element.outerWidth() < menu_width ){
  75. if ( direction === 'rtl' && coord.left < menu_width*0.5 ){
  76. position = 'rc';
  77. } else if ( direction !== 'rtl' && (window.innerWidth - coord.left - $element.outerWidth()) < menu_width*0.5 ){
  78. position = 'lc';
  79. }
  80. }
  81. switch ( position ) {
  82. case 'lc':
  83. gap_right = $element.width() + 17;
  84. $menu.css({
  85. 'top': 0,
  86. 'width': menu_width,
  87. 'left': 'auto',
  88. 'right': gap_right + 'px',
  89. 'text-align': 'center'
  90. });
  91. $menu.find('.um-dropdown-arr').css({
  92. 'top': '4px',
  93. 'left': 'auto',
  94. 'right': '-17px'
  95. }).find('i').removeClass().addClass('um-icon-arrow-right-b');
  96. break;
  97. case 'rc':
  98. gap_right = $element.width() + 25;
  99. $menu.css({
  100. 'top': 0,
  101. 'width': menu_width,
  102. 'left': gap_right + 'px',
  103. 'right': 'auto',
  104. 'text-align': 'center'
  105. });
  106. $menu.find('.um-dropdown-arr').css({
  107. 'top': '4px',
  108. 'left': '-17px',
  109. 'right': 'auto'
  110. }).find('i').removeClass().addClass('um-icon-arrow-left-b');
  111. break;
  112. case 'bc':
  113. default:
  114. var top_offset = $menu.data('top-offset');
  115. if ( typeof top_offset !== 'undefined' ) {
  116. top_p += top_offset;
  117. }
  118. $menu.css({
  119. 'top': top_p + 6,
  120. 'width': menu_width,
  121. 'left': left_p,
  122. 'right': 'auto',
  123. 'text-align': 'center'
  124. });
  125. $menu.find('.um-dropdown-arr').css({
  126. 'top': '-17px',
  127. 'left': ($menu.width() / 2) - 12,
  128. 'right': 'auto'
  129. }).find('i').removeClass().addClass('um-icon-arrow-up-b');
  130. break;
  131. }
  132. },
  133. /**
  134. * Show the menu
  135. * @param {object} menu
  136. * @returns {undefined}
  137. */
  138. show: function (menu) {
  139. var $menu = jQuery(menu);
  140. UM.dropdown.hideAll();
  141. UM.dropdown.setPosition($menu);
  142. $menu.show();
  143. }
  144. };
  145. /**
  146. * Hide all menus
  147. * @deprecated since 2.1.16, use UM.dropdown.hideAll() instead
  148. * @returns {undefined}
  149. */
  150. function UM_hide_menus() {
  151. UM.dropdown.hideAll();
  152. }
  153. /**
  154. * Update menu position
  155. */
  156. function UM_domenus() {
  157. jQuery('.um-dropdown').each( function( i, menu ) {
  158. UM.dropdown.setPosition( menu );
  159. });
  160. }
  161. function UM_check_password_matched() {
  162. jQuery(document).on('keyup', 'input[data-key=user_password],input[data-key=confirm_user_password]', function(e) {
  163. var value = jQuery('input[data-key=user_password]').val();
  164. var match = jQuery('input[data-key=confirm_user_password]').val();
  165. var field = jQuery('input[data-key=user_password],input[data-key=confirm_user_password]');
  166. if(!value && !match) {
  167. field.removeClass('um-validate-matched').removeClass('um-validate-not-matched');
  168. } else if(value !== match) {
  169. field.removeClass('um-validate-matched').addClass('um-validate-not-matched');
  170. } else {
  171. field.removeClass('um-validate-not-matched').addClass('um-validate-matched');
  172. }
  173. });
  174. }
  175. function um_responsive(){
  176. jQuery('.um').each(function(){
  177. element_width = jQuery(this).width();
  178. if ( element_width <= 340 ) {
  179. jQuery(this).removeClass('uimob340');
  180. jQuery(this).removeClass('uimob500');
  181. jQuery(this).removeClass('uimob800');
  182. jQuery(this).removeClass('uimob960');
  183. jQuery(this).addClass('uimob340');
  184. } else if ( element_width <= 500 ) {
  185. jQuery(this).removeClass('uimob340');
  186. jQuery(this).removeClass('uimob500');
  187. jQuery(this).removeClass('uimob800');
  188. jQuery(this).removeClass('uimob960');
  189. jQuery(this).addClass('uimob500');
  190. } else if ( element_width <= 800 ) {
  191. jQuery(this).removeClass('uimob340');
  192. jQuery(this).removeClass('uimob500');
  193. jQuery(this).removeClass('uimob800');
  194. jQuery(this).removeClass('uimob960');
  195. jQuery(this).addClass('uimob800');
  196. } else if ( element_width <= 960 ) {
  197. jQuery(this).removeClass('uimob340');
  198. jQuery(this).removeClass('uimob500');
  199. jQuery(this).removeClass('uimob800');
  200. jQuery(this).removeClass('uimob960');
  201. jQuery(this).addClass('uimob960');
  202. } else if ( element_width > 960 ) {
  203. jQuery(this).removeClass('uimob340');
  204. jQuery(this).removeClass('uimob500');
  205. jQuery(this).removeClass('uimob800');
  206. jQuery(this).removeClass('uimob960');
  207. }
  208. if ( jQuery('.um-account-nav').length > 0 && jQuery('.um-account-side').is(':visible') && jQuery('.um-account-tab:visible').length == 0 ) {
  209. jQuery('.um-account-side li a.current').trigger('click');
  210. }
  211. jQuery(this).css('opacity',1);
  212. });
  213. jQuery('.um-cover, .um-member-cover, .um-cover-e').each(function(){
  214. var elem = jQuery(this);
  215. var ratio = elem.data('ratio');
  216. var width = elem.width();
  217. var ratios = ratio.split(':');
  218. calcHeight = Math.round( width / ratios[0] ) + 'px';
  219. elem.height( calcHeight );
  220. elem.find('.um-cover-add').height( calcHeight );
  221. });
  222. UM_domenus();
  223. }
  224. function initImageUpload_UM( trigger ) {
  225. if (trigger.data('upload_help_text')){
  226. upload_help_text = '<span class="help">' + trigger.data('upload_help_text') + '</span>';
  227. } else {
  228. upload_help_text = '';
  229. }
  230. if ( trigger.data('icon') ) {
  231. icon = '<span class="icon"><i class="'+ trigger.data('icon') + '"></i></span>';
  232. } else {
  233. icon = '';
  234. }
  235. if ( trigger.data('upload_text') ) {
  236. upload_text = '<span class="str">' + trigger.data('upload_text') + '</span>';
  237. } else {
  238. upload_text = '';
  239. }
  240. var user_id = 0;
  241. if( jQuery('#um_upload_single:visible').data('user_id') ){
  242. user_id = jQuery('#um_upload_single:visible').data('user_id');
  243. }
  244. trigger.uploadFile({
  245. url: wp.ajax.settings.url,
  246. method: "POST",
  247. multiple: false,
  248. formData: {
  249. action: 'um_imageupload',
  250. key: trigger.data('key'),
  251. set_id: trigger.data('set_id'),
  252. set_mode: trigger.data('set_mode'),
  253. _wpnonce: trigger.data('nonce'),
  254. timestamp: trigger.data('timestamp'),
  255. user_id: user_id
  256. },
  257. fileName: trigger.data('key'),
  258. allowedTypes: trigger.data('allowed_types'),
  259. maxFileSize: trigger.data('max_size'),
  260. dragDropStr: icon + upload_text + upload_help_text,
  261. sizeErrorStr: trigger.data('max_size_error'),
  262. extErrorStr: trigger.data('extension_error'),
  263. maxFileCountErrorStr: trigger.data('max_files_error'),
  264. maxFileCount: 1,
  265. showDelete: false,
  266. showAbort: false,
  267. showDone: false,
  268. showFileCounter: false,
  269. showStatusAfterSuccess: true,
  270. returnType: 'json',
  271. onSubmit:function(files){
  272. trigger.parents('.um-modal-body').find('.um-error-block').remove();
  273. },
  274. onSuccess:function( files, response, xhr ){
  275. trigger.selectedFiles = 0;
  276. if ( response.success && response.success == false || typeof response.data.error !== 'undefined' ) {
  277. trigger.parents('.um-modal-body').append('<div class="um-error-block">'+response.data.error+'</div>');
  278. trigger.parents('.um-modal-body').find('.upload-statusbar').hide(0);
  279. um_modal_responsive();
  280. } else {
  281. jQuery.each( response.data, function( i, d ) {
  282. var img_id = trigger.parents('.um-modal-body').find('.um-single-image-preview img');
  283. var img_id_h = trigger.parents('.um-modal-body').find('.um-single-image-preview');
  284. var cache_ts = new Date();
  285. img_id.attr("src", d.url + "?"+cache_ts.getTime() );
  286. img_id.data("file", d.file );
  287. img_id.on( 'load', function() {
  288. trigger.parents('.um-modal-body').find('.um-modal-btn.um-finish-upload.disabled').removeClass('disabled');
  289. trigger.parents('.um-modal-body').find('.ajax-upload-dragdrop,.upload-statusbar').hide(0);
  290. img_id_h.show(0);
  291. um_modal_responsive();
  292. });
  293. });
  294. }
  295. },
  296. onError: function ( e ){
  297. console.log( e );
  298. }
  299. });
  300. }
  301. function initFileUpload_UM( trigger ) {
  302. if (trigger.data('upload_help_text')){
  303. upload_help_text = '<span class="help">' + trigger.data('upload_help_text') + '</span>';
  304. } else {
  305. upload_help_text = '';
  306. }
  307. if ( trigger.data('icon') ) {
  308. icon = '<span class="icon"><i class="'+ trigger.data('icon') + '"></i></span>';
  309. } else {
  310. icon = '';
  311. }
  312. if ( trigger.data('upload_text') ) {
  313. upload_text = '<span class="str">' + trigger.data('upload_text') + '</span>';
  314. } else {
  315. upload_text = '';
  316. }
  317. if( jQuery('#um_upload_single:visible').data('user_id') ){
  318. user_id = jQuery('#um_upload_single:visible').data('user_id');
  319. }
  320. trigger.uploadFile({
  321. url: wp.ajax.settings.url,
  322. method: "POST",
  323. multiple: false,
  324. formData: {
  325. action: 'um_fileupload',
  326. key: trigger.data('key'),
  327. set_id: trigger.data('set_id'),
  328. user_id: trigger.data('user_id'),
  329. set_mode: trigger.data('set_mode'),
  330. _wpnonce: trigger.data('nonce'),
  331. timestamp: trigger.data('timestamp')
  332. },
  333. fileName: trigger.data('key'),
  334. allowedTypes: trigger.data('allowed_types'),
  335. maxFileSize: trigger.data('max_size'),
  336. dragDropStr: icon + upload_text + upload_help_text,
  337. sizeErrorStr: trigger.data('max_size_error'),
  338. extErrorStr: trigger.data('extension_error'),
  339. maxFileCountErrorStr: trigger.data('max_files_error'),
  340. maxFileCount: 1,
  341. showDelete: false,
  342. showAbort: false,
  343. showDone: false,
  344. showFileCounter: false,
  345. showStatusAfterSuccess: true,
  346. onSubmit:function(files){
  347. trigger.parents('.um-modal-body').find('.um-error-block').remove();
  348. },
  349. onSuccess:function( files, response ,xhr ){
  350. trigger.selectedFiles = 0;
  351. if ( response.success && response.success == false || typeof response.data.error !== 'undefined' ) {
  352. trigger.parents('.um-modal-body').append('<div class="um-error-block">'+ response.data.error+'</div>');
  353. trigger.parents('.um-modal-body').find('.upload-statusbar').hide(0);
  354. setTimeout(function(){
  355. um_modal_responsive();
  356. },1000);
  357. } else {
  358. jQuery.each( response.data , function(key, value) {
  359. trigger.parents('.um-modal-body').find('.um-modal-btn.um-finish-upload.disabled').removeClass('disabled');
  360. trigger.parents('.um-modal-body').find('.ajax-upload-dragdrop,.upload-statusbar').hide(0);
  361. trigger.parents('.um-modal-body').find('.um-single-file-preview').show(0);
  362. if ( key == 'icon' ) {
  363. trigger.parents('.um-modal-body').find('.um-single-fileinfo i').removeClass().addClass( value );
  364. } else if ( key == 'icon_bg' ) {
  365. trigger.parents('.um-modal-body').find('.um-single-fileinfo span.icon').css({'background-color' : value } );
  366. } else if ( key == 'filename' ) {
  367. trigger.parents('.um-modal-body').find('.um-single-fileinfo a').attr('data-file', value );
  368. }else if( key == 'original_name' ){
  369. trigger.parents('.um-modal-body').find('.um-single-fileinfo a').attr('data-orignal-name', value );
  370. trigger.parents('.um-modal-body').find('.um-single-fileinfo span.filename').html( value );
  371. } else if ( key == 'url' ) {
  372. trigger.parents('.um-modal-body').find('.um-single-fileinfo a').attr('href', value);
  373. }
  374. });
  375. setTimeout(function(){
  376. um_modal_responsive();
  377. },1000);
  378. }
  379. },
  380. onError: function ( e ){
  381. console.log( e );
  382. }
  383. });
  384. }
  385. function initCrop_UM() {
  386. var target_img = jQuery('.um-modal .um-single-image-preview img').first();
  387. var target_img_parent = jQuery('.um-modal .um-single-image-preview');
  388. var crop_data = target_img.parent().attr('data-crop');
  389. var min_width = target_img.parent().attr('data-min_width');
  390. var min_height = target_img.parent().attr('data-min_height');
  391. var ratio = target_img.parent().attr('data-ratio');
  392. if ( jQuery('.um-modal').find('#um_upload_single').attr('data-ratio') ) {
  393. var ratio = jQuery('.um-modal').find('#um_upload_single').attr('data-ratio');
  394. var ratio_split = ratio.split(':');
  395. var ratio = ratio_split[0];
  396. }
  397. if ( target_img.length ) {
  398. if ( target_img.attr('src') != '' ) {
  399. var max_height = jQuery(window).height() - ( jQuery('.um-modal-footer a').height() + 20 ) - 50 - ( jQuery('.um-modal-header:visible').height() );
  400. target_img.css({'height' : 'auto'});
  401. target_img_parent.css({'height' : 'auto'});
  402. if ( jQuery(window).height() <= 400 ) {
  403. target_img_parent.css({ 'height': max_height +'px', 'max-height' : max_height + 'px' });
  404. target_img.css({ 'height' : 'auto' });
  405. } else {
  406. target_img.css({ 'height': 'auto', 'max-height' : max_height + 'px' });
  407. target_img_parent.css({ 'height': target_img.height(), 'max-height' : max_height + 'px' });
  408. }
  409. if ( crop_data == 'square' ) {
  410. var opts = {
  411. minWidth: min_width,
  412. minHeight: min_height,
  413. dragCrop: false,
  414. aspectRatio: 1.0,
  415. zoomable: false,
  416. rotatable: false,
  417. dashed: false,
  418. done: function(data) {
  419. target_img.parent().attr('data-coord', Math.round(data.x) + ',' + Math.round(data.y) + ',' + Math.round(data.width) + ',' + Math.round(data.height) );
  420. }
  421. };
  422. } else if ( crop_data == 'cover' ) {
  423. if( Math.round( min_width / ratio ) > 0 ){
  424. min_height = Math.round( min_width / ratio )
  425. }
  426. var opts = {
  427. minWidth: min_width,
  428. minHeight: min_height,
  429. dragCrop: false,
  430. aspectRatio: ratio,
  431. zoomable: false,
  432. rotatable: false,
  433. dashed: false,
  434. done: function(data) {
  435. target_img.parent().attr('data-coord', Math.round(data.x) + ',' + Math.round(data.y) + ',' + Math.round(data.width) + ',' + Math.round(data.height) );
  436. }
  437. };
  438. } else if ( crop_data == 'user' ) {
  439. var opts = {
  440. minWidth: min_width,
  441. minHeight: min_height,
  442. dragCrop: true,
  443. aspectRatio: "auto",
  444. zoomable: false,
  445. rotatable: false,
  446. dashed: false,
  447. done: function(data) {
  448. target_img.parent().attr('data-coord', Math.round(data.x) + ',' + Math.round(data.y) + ',' + Math.round(data.width) + ',' + Math.round(data.height) );
  449. }
  450. };
  451. }
  452. if ( crop_data != 0 ) {
  453. target_img.cropper( opts );
  454. jQuery('.um-single-image-preview img.cropper-hidden').cropper('destroy');
  455. jQuery('.um-single-image-preview img.lazyloaded').addClass('cropper-hidden');
  456. jQuery('.um-single-image-preview img.lazyloaded').removeClass('lazyloaded');
  457. jQuery('.um-single-image-preview .cropper-container').append('<div class="um-clear"></div>');
  458. }
  459. }
  460. }
  461. }
  462. function um_new_modal( id, size, isPhoto, source ) {
  463. var modalOverlay = jQuery('.um-modal-overlay');
  464. if ( modalOverlay.length !== 0 ) {
  465. modalOverlay.hide();
  466. modalOverlay.next('.um-modal').hide();
  467. }
  468. jQuery('.tipsy').hide();
  469. UM.dropdown.hideAll();
  470. jQuery( 'body,html,textarea' ).css( 'overflow', 'hidden' );
  471. jQuery( document ).bind( "touchmove", function(e){e.preventDefault();});
  472. jQuery( '.um-modal' ).on('touchmove', function(e){e.stopPropagation();});
  473. var $tpl = jQuery( '<div class="um-modal-overlay"></div><div class="um-modal"></div>' );
  474. var $modal = $tpl.filter('.um-modal');
  475. $modal.append( jQuery( '#' + id ) );
  476. jQuery('body').append( $tpl );
  477. if ( isPhoto ) {
  478. var photo_ = jQuery('<img src="' + source + '" />'),
  479. photo_maxw = jQuery(window).width() - 60,
  480. photo_maxh = jQuery(window).height() - jQuery(window).height() * 0.25;
  481. photo_.on( 'load', function() {
  482. $modal.find('.um-modal-photo').html( photo_ );
  483. $modal.addClass('is-photo').css({
  484. 'width': photo_.width(),
  485. 'margin-left': '-' + photo_.width() / 2 + 'px'
  486. }).show().children().show();
  487. photo_.css({
  488. 'opacity': 0,
  489. 'max-width': photo_maxw,
  490. 'max-height': photo_maxh
  491. }).animate({'opacity' : 1}, 1000);
  492. um_modal_responsive();
  493. });
  494. } else {
  495. $modal.addClass('no-photo').show().children().show();
  496. um_modal_size( size );
  497. initImageUpload_UM( jQuery('.um-modal:visible .um-single-image-upload') );
  498. initFileUpload_UM( jQuery('.um-modal:visible .um-single-file-upload') );
  499. um_modal_responsive();
  500. }
  501. }
  502. function um_modal_responsive() {
  503. var w = window.innerWidth
  504. || document.documentElement.clientWidth
  505. || document.body.clientWidth;
  506. var h = window.innerHeight
  507. || document.documentElement.clientHeight
  508. || document.body.clientHeight;
  509. var modal = jQuery('.um-modal:visible').not('.um-modal-hidden');
  510. var photo_modal = modal.find('.um-modal-body.photo:visible');
  511. if ( photo_modal.length ) {
  512. modal.removeClass('uimob340');
  513. modal.removeClass('uimob500');
  514. var photo_ = jQuery('.um-modal-photo img');
  515. var photo_maxw = w - 60;
  516. var photo_maxh = h - ( h * 0.25 );
  517. photo_.css({'opacity': 0});
  518. photo_.css({'max-width': photo_maxw });
  519. photo_.css({'max-height': photo_maxh });
  520. modal.css({
  521. 'width': photo_.width(),
  522. 'margin-left': '-' + photo_.width() / 2 + 'px'
  523. });
  524. photo_.animate({'opacity' : 1}, 1000);
  525. var half_gap = ( h - modal.innerHeight() ) / 2 + 'px';
  526. modal.animate({ 'bottom' : half_gap }, 300);
  527. } else if ( modal.length ) {
  528. modal.removeClass('uimob340');
  529. modal.removeClass('uimob500');
  530. if ( w <= 340 ) {
  531. modal.addClass('uimob340');
  532. initCrop_UM();
  533. modal.animate({ 'bottom' : 0 }, 300);
  534. } else if ( w <= 500 ) {
  535. modal.addClass('uimob500');
  536. initCrop_UM();
  537. modal.animate({ 'bottom' : 0 }, 300);
  538. } else if ( w <= 800 ) {
  539. initCrop_UM();
  540. var half_gap = ( h - modal.innerHeight() ) / 2 + 'px';
  541. modal.animate({ 'bottom' : half_gap }, 300);
  542. } else if ( w <= 960 ) {
  543. initCrop_UM();
  544. var half_gap = ( h - modal.innerHeight() ) / 2 + 'px';
  545. modal.animate({ 'bottom' : half_gap }, 300);
  546. } else if ( w > 960 ) {
  547. initCrop_UM();
  548. var half_gap = ( h - modal.innerHeight() ) / 2 + 'px';
  549. modal.animate({ 'bottom' : half_gap }, 300);
  550. }
  551. }
  552. }
  553. function um_remove_modal() {
  554. jQuery('img.cropper-hidden').cropper('destroy');
  555. jQuery('body,html,textarea').css("overflow", "auto");
  556. jQuery(document).unbind('touchmove');
  557. jQuery('body > .um-modal div[id^="um_"]').hide().appendTo('body');
  558. jQuery('body > .um-modal, body > .um-modal-overlay').remove();
  559. }
  560. function um_modal_size( aclass ) {
  561. jQuery('.um-modal:visible').not('.um-modal-hidden').addClass( aclass );
  562. }
  563. /**
  564. * Maybe deprecated
  565. *
  566. * @deprecated since 2.1.16
  567. *
  568. * @param id
  569. * @param value
  570. */
  571. function um_modal_add_attr( id, value ) {
  572. jQuery('.um-modal:visible').not('.um-modal-hidden').data( id, value );
  573. }
  574. function prepare_Modal() {
  575. if ( jQuery('.um-popup-overlay').length == 0 ) {
  576. jQuery('body').append('<div class="um-popup-overlay"></div>');
  577. jQuery('body').append('<div class="um-popup"></div>');
  578. jQuery('.um-popup').addClass('loading');
  579. jQuery("body,html").css({ overflow: 'hidden' });
  580. }
  581. }
  582. function remove_Modal() {
  583. if ( jQuery('.um-popup-overlay').length ) {
  584. wp.hooks.doAction( 'um_before_modal_removed', jQuery('.um-popup') );
  585. jQuery('.tipsy').remove();
  586. jQuery('.um-popup').empty().remove();
  587. jQuery('.um-popup-overlay').empty().remove();
  588. jQuery("body,html").css({ overflow: 'auto' });
  589. }
  590. }
  591. function show_Modal( contents ) {
  592. if ( jQuery('.um-popup-overlay').length ) {
  593. jQuery('.um-popup').removeClass('loading').html( contents );
  594. jQuery('.um-tip-n').tipsy({gravity: 'n', opacity: 1, offset: 3 });
  595. jQuery('.um-tip-w').tipsy({gravity: 'w', opacity: 1, offset: 3 });
  596. jQuery('.um-tip-e').tipsy({gravity: 'e', opacity: 1, offset: 3 });
  597. jQuery('.um-tip-s').tipsy({gravity: 's', opacity: 1, offset: 3 });
  598. }
  599. }
  600. function responsive_Modal() {
  601. if ( jQuery('.um-popup-overlay').length ) {
  602. ag_height = jQuery(window).height() - jQuery('.um-popup .um-popup-header').outerHeight() - jQuery('.um-popup .um-popup-footer').outerHeight() - 80;
  603. if ( ag_height > 350 ) {
  604. ag_height = 350;
  605. }
  606. if ( jQuery('.um-popup-autogrow:visible').length ) {
  607. jQuery('.um-popup-autogrow:visible').css({'height': ag_height + 'px'});
  608. } else if ( jQuery('.um-popup-autogrow2:visible').length ) {
  609. jQuery('.um-popup-autogrow2:visible').css({'max-height': ag_height + 'px'});
  610. }
  611. }
  612. }
  613. function um_reset_field( dOm ){
  614. //console.log(dOm);
  615. jQuery(dOm)
  616. .find('div.um-field-area')
  617. .find('input,textarea,select')
  618. .not(':button, :submit, :reset, :hidden')
  619. .val('')
  620. .prop('checked', false)
  621. .prop('selected', false);
  622. }
  623. jQuery(function(){
  624. // Submit search form on keypress 'Enter'
  625. jQuery(".um-search form *").on( 'keypress', function(e){
  626. if (e.which == 13) {
  627. jQuery('.um-search form').trigger('submit');
  628. return false;
  629. }
  630. });
  631. if( jQuery('input[data-key=user_password],input[data-key=confirm_user_password]').length == 2 ) {
  632. UM_check_password_matched();
  633. }
  634. });
  635. function um_selected( selected, current ){
  636. if( selected == current ){
  637. return "selected='selected'";
  638. }
  639. }