image-widget.deprecated.js
8 years ago
image-widget.deprecated.upload-fixer.js
8 years ago
image-widget.js
8 years ago
index.php
8 years ago
image-widget.deprecated.upload-fixer.js
108 lines
| 1 | jQuery(document).ready(function() { |
| 2 | |
| 3 | jQuery('form#image-form').submit(function(){ |
| 4 | var wp_ref = jQuery("input[name='_wp_http_referer']").val(); |
| 5 | // _wp_http_referer only contains the widget_sp_image if the |
| 6 | // previous action was pressing the add image link in an Image Widget |
| 7 | // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/String/indexOf |
| 8 | if( wp_ref.indexOf('widget_sp_image') != -1 ) { |
| 9 | var parsed_url = parse_url(wp_ref); |
| 10 | var nw_action_url = jQuery('form#image-form').attr('action'); |
| 11 | |
| 12 | // make sure the widget_sp_image is not part of the form action url |
| 13 | // so we will add it to fix the context |
| 14 | if( nw_action_url.indexOf('widget_sp_image') == -1 ) { |
| 15 | nw_action_url = nw_action_url + '&' + parsed_url.query; |
| 16 | jQuery('form#image-form').attr('action', nw_action_url); |
| 17 | } |
| 18 | } |
| 19 | return true; |
| 20 | }); |
| 21 | |
| 22 | //also update the filter form with a new hidden field |
| 23 | //is the filter form present on the page? |
| 24 | if (jQuery("form#filter").length>0) { |
| 25 | |
| 26 | //code for retrieving GET vars (we want the value of widget_id) |
| 27 | var widget_id = ''; |
| 28 | document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () { |
| 29 | function decode(s) { |
| 30 | return decodeURIComponent(s.split("+").join(" ")); |
| 31 | } |
| 32 | |
| 33 | var key = decode(arguments[1]); |
| 34 | if (key == 'widget_id') { |
| 35 | widget_id = decode(arguments[2]); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | if (widget_id.length > 0) {//do we have a value? |
| 40 | |
| 41 | //insert hidden field into form |
| 42 | jQuery('form#filter').append( |
| 43 | jQuery('<input/>') |
| 44 | .attr('type', 'hidden') |
| 45 | .attr('name', 'widget_id') |
| 46 | .val(widget_id) |
| 47 | ); |
| 48 | } |
| 49 | } |
| 50 | }); |
| 51 | |
| 52 | |
| 53 | /* |
| 54 | * Thanks to http://github.com/kvz/phpjs/raw/master/functions/url/parse_url.js |
| 55 | */ |
| 56 | function parse_url (str, component) { |
| 57 | // http://kevin.vanzonneveld.net |
| 58 | // + original by: Steven Levithan (http://blog.stevenlevithan.com) |
| 59 | // + reimplemented by: Brett Zamir (http://brett-zamir.me) |
| 60 | // + input by: Lorenzo Pisani |
| 61 | // + input by: Tony |
| 62 | // + improved by: Brett Zamir (http://brett-zamir.me) |
| 63 | // % note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js |
| 64 | // % note: blog post at http://blog.stevenlevithan.com/archives/parseuri |
| 65 | // % note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js |
| 66 | // % note: Does not replace invalid characters with '_' as in PHP, nor does it return false with |
| 67 | // % note: a seriously malformed URL. |
| 68 | // % note: Besides function name, is essentially the same as parseUri as well as our allowing |
| 69 | // % note: an extra slash after the scheme/protocol (to allow file:/// as in PHP) |
| 70 | // * example 1: parse_url('http://username:password@hostname/path?arg=value#anchor'); |
| 71 | // * returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'} |
| 72 | var key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', |
| 73 | 'relative', 'path', 'directory', 'file', 'query', 'fragment'], |
| 74 | ini = (this.php_js && this.php_js.ini) || {}, |
| 75 | mode = (ini['phpjs.parse_url.mode'] && |
| 76 | ini['phpjs.parse_url.mode'].local_value) || 'php', |
| 77 | parser = { |
| 78 | php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, |
| 79 | strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, |
| 80 | loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) |
| 81 | }; |
| 82 | |
| 83 | var m = parser[mode].exec(str), |
| 84 | uri = {}, |
| 85 | i = 14; |
| 86 | while (i--) { |
| 87 | if (m[i]) { |
| 88 | uri[key[i]] = m[i]; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (component) { |
| 93 | return uri[component.replace('PHP_URL_', '').toLowerCase()]; |
| 94 | } |
| 95 | if (mode !== 'php') { |
| 96 | var name = (ini['phpjs.parse_url.queryKey'] && |
| 97 | ini['phpjs.parse_url.queryKey'].local_value) || 'queryKey'; |
| 98 | parser = /(?:^|&)([^&=]*)=?([^&]*)/g; |
| 99 | uri[name] = {}; |
| 100 | uri[key[12]].replace(parser, function ($0, $1, $2) { |
| 101 | if ($1) {uri[name][$1] = $2;} |
| 102 | }); |
| 103 | } |
| 104 | delete uri.source; |
| 105 | return uri; |
| 106 | } |
| 107 | |
| 108 | /* /wp-admin/media-upload.php?type=image&widget_id=widget_sp_image-11& */ |