blocks
2 weeks ago
cleditor
2 weeks ago
codemirror
2 weeks ago
dfv
2 weeks ago
marionette
2 weeks ago
qtip
2 weeks ago
selectWoo
2 weeks ago
sprintf
2 weeks ago
timepicker
2 weeks ago
handlebars.js
2 weeks ago
jquery.pods.js
2 weeks ago
jquery.pods.upgrade.js
2 weeks ago
pods-i18n.js
2 weeks ago
pods-link-picker.js
2 weeks ago
qtip.js
2 weeks ago
pods-link-picker.js
102 lines
| 1 | // JavaScript Document |
| 2 | |
| 3 | jQuery(document).ready(function($){ |
| 4 | |
| 5 | var podsLink = { |
| 6 | wpLinkDefaults: null, |
| 7 | activeLinkPicker: null, |
| 8 | init: function() { |
| 9 | |
| 10 | // Open wpLink modal |
| 11 | $(document).on('click', '.pods-field .podsLinkPopup', function (e) { |
| 12 | // Store current field pointer |
| 13 | podsLink.activeLinkPicker = $(this).parents('.pods-link-options'); |
| 14 | $('body').addClass('modal-open-pods-field-link'); |
| 15 | |
| 16 | var url_elem = podsLink.activeLinkPicker.find('.linkPickerUrl'); |
| 17 | var text_elem = podsLink.activeLinkPicker.find('.linkPickerText'); |
| 18 | var target_elem = podsLink.activeLinkPicker.find('.linkPickerTarget'); |
| 19 | |
| 20 | wpLink.setDefaultValues = function() { |
| 21 | $('#wp-link-wrap #wp-link-url').val( url_elem.val() ); |
| 22 | $('#wp-link-wrap #wp-link-text').val( text_elem.val() ); |
| 23 | if ( target_elem.is(':checked') ) { |
| 24 | $('#wp-link-wrap #wp-link-target').prop('checked', true); |
| 25 | } else { |
| 26 | $('#wp-link-wrap #wp-link-target').prop('checked', false); |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | // save any existing default initialization |
| 31 | podsLink.wpLinkDefaults = wpLink.setDefaultValues; |
| 32 | |
| 33 | // Open modal in the dummy textarea |
| 34 | wpLink.open( 'pods-link-editor-hidden' ); |
| 35 | |
| 36 | return false; |
| 37 | }); |
| 38 | |
| 39 | // Save changes in the selected field |
| 40 | $(document).on('click', '#wp-link-submit', function(event) { |
| 41 | |
| 42 | // Is the wpLink modal open? |
| 43 | if ($('body').hasClass('modal-open-pods-field-link')) { |
| 44 | //get the href attribute and add to a textfield, or use as you see fit |
| 45 | //the links attributes (href, target) are stored in an object, which can be access via wpLink.getAttrs() |
| 46 | var linkAtts = wpLink.getAttrs(); |
| 47 | if (linkAtts.href != '') { |
| 48 | podsLink.activeLinkPicker.find('.linkPickerUrl').val(linkAtts.href); |
| 49 | } |
| 50 | //get the target attribute |
| 51 | if (linkAtts.target == '_blank') { |
| 52 | podsLink.activeLinkPicker.find('.linkPickerTarget').prop('checked', true); |
| 53 | } else { |
| 54 | podsLink.activeLinkPicker.find('.linkPickerTarget').prop('checked', false); |
| 55 | } |
| 56 | //get the text attribute |
| 57 | var linkText = $('#wp-link-wrap #wp-link-text').val(); |
| 58 | if (linkText != '') { |
| 59 | podsLink.activeLinkPicker.find('.linkPickerText').val(linkText); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // Reset wpLink modal |
| 64 | podsLink.resetLink(); |
| 65 | |
| 66 | //trap any events |
| 67 | event.preventDefault ? event.preventDefault() : event.returnValue = false; |
| 68 | event.stopPropagation(); |
| 69 | return false; |
| 70 | }); |
| 71 | |
| 72 | // Close modal without any changes |
| 73 | $(document).on('click', '#wp-link-cancel, #wp-link-close', function(event) { |
| 74 | |
| 75 | // Reset wpLink modal |
| 76 | podsLink.resetLink(); |
| 77 | |
| 78 | //trap any events |
| 79 | event.preventDefault ? event.preventDefault() : event.returnValue = false; |
| 80 | event.stopPropagation(); |
| 81 | return false; |
| 82 | }); |
| 83 | |
| 84 | }, |
| 85 | resetLink: function() { |
| 86 | $('body').removeClass('modal-open-pods-field-link'); |
| 87 | wpLink.textarea = $('body'); // to close the link dialogue, it is again expecting an wp_editor instance, so you need to give it something to set focus back to. In this case, I'm using body, but the textfield with the URL would be fine |
| 88 | wpLink.close();// close the dialogue |
| 89 | |
| 90 | // restore wplink default initialization |
| 91 | wpLink.setDefaultValues = podsLink.wpLinkDefaults; |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | // Validate that we have the right resourses |
| 96 | if ( typeof wpLink !== 'undefined' && $('#wp-link-wrap').length ) { |
| 97 | $('.pods-field .link-existing-content').show(); |
| 98 | podsLink.init(); |
| 99 | } |
| 100 | }); |
| 101 | |
| 102 |