Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

Commit

Permalink
Correcting an issue with entwine.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Glasl committed Jan 12, 2015
1 parent 6840142 commit 311c821
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 99 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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._

Expand Down
44 changes: 21 additions & 23 deletions javascript/link-mapping-fallback.js
Original file line number Diff line number Diff line change
@@ -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);
146 changes: 72 additions & 74 deletions javascript/link-mapping-test.js
Original file line number Diff line number Diff line change
@@ -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 += "<div class='result'>";
if(object['ResponseCode'] !== 404) {
output += '<h3><strong>' + object['Counter'] + '</strong></h3>';
output += '<div><strong>Link Type</strong> ' + object['LinkType'] + '</div>';
output += '<div><strong>Mapped Link</strong> ' + object['MappedLink'] + '</div>';
output += '<div><strong>Redirect Link</strong> ' + object['RedirectLink'] + '</div>';
output += '<div><strong>Response Code</strong> ' + object['ResponseCode'] + '</div>';
output += '<div><strong>Priority</strong> ' + object['Priority'] + '</div>';
}
else {
output += '<h3><strong>Maximum</strong></h3>';
output += '<div><strong>Response Code</strong> ' + object['ResponseCode'] + '</div>';
}
output += '</div>';
});
}
else {
output += "<div class='result'>";
output += '<h3><strong>No Matches</strong></h3>';
if(object['ResponseCode'] !== 404) {
output += '<h3><strong>' + object['Counter'] + '</strong></h3>';
output += '<div><strong>Link Type</strong> ' + object['LinkType'] + '</div>';
output += '<div><strong>Mapped Link</strong> ' + object['MappedLink'] + '</div>';
output += '<div><strong>Redirect Link</strong> ' + object['RedirectLink'] + '</div>';
output += '<div><strong>Response Code</strong> ' + object['ResponseCode'] + '</div>';
output += '<div><strong>Priority</strong> ' + object['Priority'] + '</div>';
}
else {
output += '<h3><strong>Maximum</strong></h3>';
output += '<div><strong>Response Code</strong> ' + object['ResponseCode'] + '</div>';
}
output += '</div>';
}
});
}
else {
output += "<div class='result'>";
output += '<h3><strong>No Matches</strong></h3>';
output += '</div>';
}

// 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);

0 comments on commit 311c821

Please sign in to comment.