function retrieveDefinition(title, keyword){
var tempURL = "/immigration/css-js/definitions-return.asp?pairingDefinition="+keyword;
$.ajax({
url: tempURL,
cache: false,
success: function(html){
popupModalMessage(title, html);
}
});
}
function popupModalMessage(title, body) {
jQuery('body').append('
'+body+'
');
placeholder = jQuery('#modalDialog');
//initialize the dialog
placeholder.dialog({
resizable: false,
modal: true
});
//destroy the dialog and placeholder when it's closed
placeholder.bind('dialogclose', function() {
placeholder.dialog('destroy');
placeholder.remove();
});
}
$(document).ready(function() {
// this is the array of words and definitions that will be output by the php / asp
var wordArray = [
['Accompanying dependant','Accompanying+dependant'],
['Alberta Immigrant Nominee Program','Alberta+Immigrant+Nominee+Program'],
['Alberta Provincial Nominee','Alberta+Provincial+Nominee'],
['Canadian citizen','Canadian+citizen'],
['Canadian Society of Immigration Consultants (CSIC)','Canadian+Society+of+Immigration+Consultants+%28CSIC%29'],
['Certificate of Nomination','Certificate+of+Nomination'],
['CIC','CIC'],
['Citizenship and Immigration Canada (CIC) Visa Office','Citizenship+and+Immigration+Canada+%28CIC%29+Visa+Office'],
['Common-law partner','Common%2Dlaw+partner'],
['Conjugal partner','Conjugal+partner'],
['National Occupational Classification','National+Occupational+Classification'],
['International Graduate','International+Graduate'],
['Candidate','Candidate'],
['Consulate','Consulate'],
['Dependent children','Dependent+children'],
['Alberta Employer','Alberta+Employer'],
['Embassy','Embassy'],
['Foreign national','Foreign+national'],
['High Commission','High+Commission'],
['Labour Market Opinion (LMO)','Labour+Market+Opinion+%28LMO%29'],
['Non-accompanying dependent','Non%2Daccompanying+dependent'],
['Permanent resident','Permanent+resident'],
['Permanent Resident Card','Permanent+Resident+Card'],
['Permanent resident visa','Permanent+resident+visa'],
['Principal applicant','Principal+applicant'],
['Refugee claimant','Refugee+claimant'],
['Semi-skilled worker','Semi%2Dskilled+worker'],
['Spouse','Spouse'],
['Study permit','Study+permit'],
['Temporary foreign worker','Temporary+foreign+worker'],
['Visitor visa','Visitor+visa'],
['Work permit','Work+permit']
];
var y = 0;
for (y=0; y', '', '#content', 1);
}
//wraps all instances of needle with the specified prepend/append strings. The haystack is a jQuery selector.
function wrapString(needle, prependString, appendString, haystackSelector, limit) {
var excludedTags = ['omit', 'h1', 'h2', 'h3', 'h4', 'img', 'a']; //matches inside these tags will not be wrapped
if (!limit) {
limit = 100; //default search/replace limit
}
var haystack = ' ' + jQuery(haystackSelector).html(); //the preceding space ensures that the first match is never first in the content
//hack to omit the contents of ..
from the search
var omittedContent = jQuery(haystackSelector + '> #breadcrumb').html();
if (omittedContent) {
haystack = haystack.replace(omittedContent, '');
}
//generate the regex - notice the patern capture brackets which includes the matched text in the match/split array
var regex = new RegExp('\\b' + needle + '\\b', 'gi');
//split the haystack into an array in the form: notMatched, matched, notMatched etc
var matches = haystack.match(regex);
if (matches === null) {
return; //there are no matches
}
var nonMatches = haystack.split(regex);
haystack = '';
var i = 0;
do {
if (nonMatches[i]) {
haystack += nonMatches[i];
}
if (matches[i]) {
//check for unclosed excluded tags in the content preceding the match
if (!insideTags(haystack, excludedTags)) {
if (limit) {
matches[i] = prependString + matches[i] + appendString;
limit--; //limit the total number of matches
}
}
haystack += matches[i];
}
i++;
} while (i < matches.length || i < nonMatches.length)
haystack = haystack.replace('', omittedContent); //end hack - reinsert the ommitted content
jQuery(haystackSelector).html(haystack);
}
//detect any unclosed tags that are in the tagArray.
function insideTags(content, tagArray) {
var origContent = content;
//unclosed alt, class, id, title attributes are always considered to be part of the tagArray
var regex = new RegExp('<[a-z0-9 ]+="[^">]*$', 'gi');
if (content.match(regex)) {
return true;
}
//strip out complete single part tags eg. . This leaves the incomplete/enclosing single-part tags and all the multi-part tags
var regex = new RegExp('<[^>]*\/>', 'gi');
content = content.split(regex);
content = content.join('');
var singlePartTags = 'img, hr, br, link' + ','; //note the trailing comma which is needed for the indexOf search to work
//an unclosed tag is evidenced by having more opening tags than closing tags
for (i = 0; i < tagArray.length; i++) {
//distinguish between single part html tags (img, hr etc) and multipart tags (div, p, span etc)
if (singlePartTags.indexOf(tagArray[i]+',') != -1) {
if (content.indexOf(tagArray[i] + ',') != -1) {
//unclosed single-part tags (we've already stripped out the complete single-part tags)
return true;
}
}
else {
//find unclosed multi-part tags eg. ...
var regex = new RegExp('<' + tagArray[i], 'gi');
var openingTags = content.match(regex);
openingTags = (openingTags) ? openingTags.length : 0;
var regex = new RegExp('<\/' + tagArray[i] + '>', 'gi');
var closingTags = content.match(regex);
closingTags = (closingTags) ? closingTags.length : 0;
if (openingTags - closingTags > 0) {
return true;
}
}
}
return false; //no open HTML tags from the tagArray found in the content - nor any open attribute declarations
}
});