image-widget
Last commit date
lang
15 years ago
views
15 years ago
image-widget-fix-browser-upload.js
14 years ago
image-widget.js
14 years ago
image-widget.php
14 years ago
readme.txt
14 years ago
screenshot-1.png
16 years ago
screenshot-2.png
16 years ago
screenshot-3.png
16 years ago
image-widget-fix-browser-upload.js
84 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 | |
| 23 | |
| 24 | /* |
| 25 | * Thanks to http://github.com/kvz/phpjs/raw/master/functions/url/parse_url.js |
| 26 | */ |
| 27 | function parse_url (str, component) { |
| 28 | // http://kevin.vanzonneveld.net |
| 29 | // + original by: Steven Levithan (http://blog.stevenlevithan.com) |
| 30 | // + reimplemented by: Brett Zamir (http://brett-zamir.me) |
| 31 | // + input by: Lorenzo Pisani |
| 32 | // + input by: Tony |
| 33 | // + improved by: Brett Zamir (http://brett-zamir.me) |
| 34 | // % note: Based on http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js |
| 35 | // % note: blog post at http://blog.stevenlevithan.com/archives/parseuri |
| 36 | // % note: demo at http://stevenlevithan.com/demo/parseuri/js/assets/parseuri.js |
| 37 | // % note: Does not replace invalid characters with '_' as in PHP, nor does it return false with |
| 38 | // % note: a seriously malformed URL. |
| 39 | // % note: Besides function name, is essentially the same as parseUri as well as our allowing |
| 40 | // % note: an extra slash after the scheme/protocol (to allow file:/// as in PHP) |
| 41 | // * example 1: parse_url('http://username:password@hostname/path?arg=value#anchor'); |
| 42 | // * returns 1: {scheme: 'http', host: 'hostname', user: 'username', pass: 'password', path: '/path', query: 'arg=value', fragment: 'anchor'} |
| 43 | var key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', |
| 44 | 'relative', 'path', 'directory', 'file', 'query', 'fragment'], |
| 45 | ini = (this.php_js && this.php_js.ini) || {}, |
| 46 | mode = (ini['phpjs.parse_url.mode'] && |
| 47 | ini['phpjs.parse_url.mode'].local_value) || 'php', |
| 48 | parser = { |
| 49 | php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, |
| 50 | strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, |
| 51 | loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) |
| 52 | }; |
| 53 | |
| 54 | var m = parser[mode].exec(str), |
| 55 | uri = {}, |
| 56 | i = 14; |
| 57 | while (i--) { |
| 58 | if (m[i]) { |
| 59 | uri[key[i]] = m[i]; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if (component) { |
| 64 | return uri[component.replace('PHP_URL_', '').toLowerCase()]; |
| 65 | } |
| 66 | if (mode !== 'php') { |
| 67 | var name = (ini['phpjs.parse_url.queryKey'] && |
| 68 | ini['phpjs.parse_url.queryKey'].local_value) || 'queryKey'; |
| 69 | parser = /(?:^|&)([^&=]*)=?([^&]*)/g; |
| 70 | uri[name] = {}; |
| 71 | uri[key[12]].replace(parser, function ($0, $1, $2) { |
| 72 | if ($1) {uri[name][$1] = $2;} |
| 73 | }); |
| 74 | } |
| 75 | delete uri.source; |
| 76 | return uri; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | /* /wp-admin/media-upload.php?type=image&widget_id=widget_sp_image-11& */ |
| 83 | |
| 84 |