diff --git a/README.md b/README.md index c770832..bc31783 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # [misdirection](https://github.com/nglasl) -_The current release is **1.0.0**._ +_The current release is **1.0.0**_ - This module will allow you to set up simple/regular expression link redirection mappings and customisation, either replacing the default automated URL handling or hooking into a page not found. This is useful for something such as legacy page redirection. + This module will allow you to set up simple/regular expression link redirection + mappings and customisation, either replacing the default automated URL handling or hooking into a page not found. This is useful for something such as legacy page redirection. _**NOTE:** This repository has been pulled together using re-factored code from an existing module._ diff --git a/javascript/link-mapping-fallback.js b/javascript/link-mapping-fallback.js index 2396f64..6ea75f2 100644 --- a/javascript/link-mapping-fallback.js +++ b/javascript/link-mapping-fallback.js @@ -1,33 +1,31 @@ ;(function($) { - $(window).load(function() { - // Determine which fallback option display and functionality should be enabled. + // Determine which fallback option display and functionality should be enabled. - function toggle() { + function toggle() { - var rule = $('select.fallback-rule').val(); - if(rule) { - $('div.fallback-response').show(); - (rule === 'URL') ? $('div.fallback-to').show() : $('div.fallback-to').hide(); - } - else { - $('div.fallback-response').hide(); - $('div.fallback-to').hide(); - } - }; + var rule = $('select.fallback-rule').val(); + if(rule) { + $('div.fallback-response').show(); + (rule === 'URL') ? $('div.fallback-to').show() : $('div.fallback-to').hide(); + } + else { + $('div.fallback-response').hide(); + $('div.fallback-to').hide(); + } + }; - // Bind the events dynamically. + // Bind the events dynamically. - $('select.fallback-rule').entwine({ - onmatch: function () { + $('select.fallback-rule').entwine({ + onmatch: function () { - toggle(); - }, - onchange: function () { - - toggle(); - } - }); + toggle(); + }, + onchange: function () { + toggle(); + } }); + })(jQuery); diff --git a/javascript/link-mapping-test.js b/javascript/link-mapping-test.js index 7a27ca7..8699176 100644 --- a/javascript/link-mapping-test.js +++ b/javascript/link-mapping-test.js @@ -1,102 +1,100 @@ ;(function($) { - $(window).load(function() { - // Determine whether the test button display and functionality should be enabled. + // Determine whether the test button display and functionality should be enabled. - function enable(input) { + function enable(input) { - var URL = input ? input.val() : $('div.link-mapping-test.admin input.url').val(); - var button = $('div.link-mapping-test.admin span.test'); - if(URL.length > 0) { - button.fadeTo(250, 1, function() { + var URL = input ? input.val() : $('div.link-mapping-test.admin input.url').val(); + var button = $('div.link-mapping-test.admin span.test'); + if(URL.length > 0) { + button.fadeTo(250, 1, function() { - button.removeClass('disabled'); - }); - } - else { - button.fadeTo(250, 0.4, function() { + button.removeClass('disabled'); + }); + } + else { + button.fadeTo(250, 0.4, function() { - button.addClass('disabled'); - }); - } - }; + button.addClass('disabled'); + }); + } + }; - // Test the link mapping chain for a given URL. + // Test the link mapping chain for a given URL. - function test(input) { + function test(input) { + + var URL = input ? input.val() : $('div.link-mapping-test.admin input.url').val(); + $.getJSON('admin/misdirection/LinkMapping/getMappingChain', { + map: URL + }, + function(JSON) { + + var output = ''; + if(JSON) { + + // Construct the link mapping chain HTML representation. + + $.each(JSON, function(index, object) { - var URL = input ? input.val() : $('div.link-mapping-test.admin input.url').val(); - $.getJSON('admin/misdirection/LinkMapping/getMappingChain', { - map: URL - }, - function(JSON) { - - var output = ''; - if(JSON) { - - // Construct the link mapping chain HTML representation. - - $.each(JSON, function(index, object) { - - output += "
"; - if(object['ResponseCode'] !== 404) { - output += '

' + object['Counter'] + '

'; - output += '
Link Type ' + object['LinkType'] + '
'; - output += '
Mapped Link ' + object['MappedLink'] + '
'; - output += '
Redirect Link ' + object['RedirectLink'] + '
'; - output += '
Response Code ' + object['ResponseCode'] + '
'; - output += '
Priority ' + object['Priority'] + '
'; - } - else { - output += '

Maximum

'; - output += '
Response Code ' + object['ResponseCode'] + '
'; - } - output += '
'; - }); - } - else { output += "
"; - output += '

No Matches

'; + if(object['ResponseCode'] !== 404) { + output += '

' + object['Counter'] + '

'; + output += '
Link Type ' + object['LinkType'] + '
'; + output += '
Mapped Link ' + object['MappedLink'] + '
'; + output += '
Redirect Link ' + object['RedirectLink'] + '
'; + output += '
Response Code ' + object['ResponseCode'] + '
'; + output += '
Priority ' + object['Priority'] + '
'; + } + else { + output += '

Maximum

'; + output += '
Response Code ' + object['ResponseCode'] + '
'; + } output += '
'; - } + }); + } + else { + output += "
"; + output += '

No Matches

'; + output += '
'; + } - // Render the link mapping chain. + // Render the link mapping chain. - $('div.link-mapping-test.admin div.results').html(output); - }); - }; + $('div.link-mapping-test.admin div.results').html(output); + }); + }; - // Bind the events dynamically. + // Bind the events dynamically. - $.entwine('ss', function($) { + $.entwine('ss', function($) { - // Trigger an interface update on key press. + // Trigger an interface update on key press. - $('div.link-mapping-test.admin input.url').entwine({ - onchange: function() { + $('div.link-mapping-test.admin input.url').entwine({ + onchange: function() { - enable($(this)); - } - }); + enable($(this)); + } + }); - // Trigger an interface update and handle any test request. + // Trigger an interface update and handle any test request. - $('div.link-mapping-test.admin span.test').entwine({ - onmouseenter: function() { + $('div.link-mapping-test.admin span.test').entwine({ + onmouseenter: function() { - enable(); - }, - onclick: function() { + enable(); + }, + onclick: function() { - if(!$(this).hasClass('disabled')) { + if(!$(this).hasClass('disabled')) { - // Test the link mapping chain for the given URL, and render this to the user. + // Test the link mapping chain for the given URL, and render this to the user. - test(); - } + test(); } - }); + } }); - }); + })(jQuery);