initial commit of starter install drupal 7
This commit is contained in:
@@ -0,0 +1,243 @@
|
||||
/**
|
||||
* @file
|
||||
* Linkit dashboard functions
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.linkitDashboard = {
|
||||
attach: function (context, settings) {
|
||||
// Bind the insert link button.
|
||||
$('.linkit-insert', context).once('linkit-insert', function() {
|
||||
$('.linkit-insert', context).click(function() {
|
||||
// Call the insertLink() function.
|
||||
Drupal.linkit.getDialogHelper(Drupal.settings.linkit.currentInstance.helper).insertLink(Drupal.linkit.getLink());
|
||||
|
||||
// Close the dialog.
|
||||
Drupal.linkit.modalClose();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
// Bind the close link.
|
||||
$('#linkit-cancel', context).once('linkit-cancel', function() {
|
||||
$('#linkit-cancel', context).bind('click', Drupal.linkit.modalClose);
|
||||
});
|
||||
|
||||
// Run the validation if the path field is populated directly.
|
||||
$('#edit-linkit-path', context).bind('keyup paste input propertychange', function(){
|
||||
Drupal.linkit.requiredFieldsValidation();
|
||||
});
|
||||
|
||||
$(".ui-dialog-titlebar").show();
|
||||
|
||||
// Run required field validation.
|
||||
Drupal.linkit.requiredFieldsValidation();
|
||||
|
||||
if (!Drupal.settings.linkit.currentInstance.suppressProfileChanger) {
|
||||
// Make the profile changer
|
||||
Drupal.linkit.profileChanger(context);
|
||||
}
|
||||
if (Drupal.settings.linkit.IMCEurl && !$('#linkit-imce', context).length) {
|
||||
var $imceButton = $('<input />')
|
||||
.attr({type: 'button', id: 'linkit-imce', name: 'linkit-imce'})
|
||||
.addClass('form-submit')
|
||||
.val(Drupal.t('Open file browser'))
|
||||
.insertAfter($('.form-item-linkit-search', context))
|
||||
.click(function(e) {
|
||||
e.preventDefault();
|
||||
Drupal.linkit.openFileBrowser();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check for mandatory fields in the form and disable for submissions
|
||||
* if any of the fields are empty.
|
||||
*/
|
||||
Drupal.linkit.requiredFieldsValidation = function() {
|
||||
var allowed = true;
|
||||
$('#linkit-modal .required').each(function() {
|
||||
if (!$(this).val()) {
|
||||
allowed = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if (allowed) {
|
||||
$('#linkit-modal .linkit-insert')
|
||||
.removeAttr('disabled')
|
||||
.removeClass('form-button-disabled');
|
||||
}
|
||||
else {
|
||||
$('#linkit-modal .linkit-insert')
|
||||
.attr('disabled', 'disabled')
|
||||
.addClass('form-button-disabled');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Open the IMCE file browser
|
||||
*/
|
||||
Drupal.linkit.openFileBrowser = function () {
|
||||
window.open(decodeURIComponent(Drupal.settings.linkit.IMCEurl), '', 'width=760,height=560,resizable=1');
|
||||
};
|
||||
|
||||
/**
|
||||
* When a file is inserted through IMCE, this function is called.
|
||||
* See IMCE api for details.
|
||||
*
|
||||
* @param file
|
||||
* The file object that was selected inside IMCE
|
||||
* @param win
|
||||
* The IMCE window object
|
||||
*/
|
||||
Drupal.linkit.IMCECallback = function(file, win) {
|
||||
Drupal.linkit.populateFields({
|
||||
path: win.imce.decode(Drupal.settings.basePath +
|
||||
Drupal.settings.linkit.publicFilesDirectory + '/' + file.relpath)
|
||||
});
|
||||
win.close();
|
||||
};
|
||||
|
||||
/**
|
||||
* Populate fields on the dashboard.
|
||||
*
|
||||
* @param link
|
||||
* An object with the following properties (all are optional):
|
||||
* - path: The anchor's href.
|
||||
* - attributes: An object with additional attributes for the anchor element.
|
||||
*/
|
||||
Drupal.linkit.populateFields = function(link) {
|
||||
link = link || {};
|
||||
link.attributes = link.attributes || {};
|
||||
|
||||
$('#linkit-modal .linkit-path-element').val(link.path);
|
||||
|
||||
$.each(link.attributes, function(name, value) {
|
||||
$('#linkit-modal .linkit-attributes .linkit-attribute-' + name).val(value);
|
||||
});
|
||||
|
||||
// Run required field validation.
|
||||
Drupal.linkit.requiredFieldsValidation();
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a link object by extracting values from the form.
|
||||
*
|
||||
* @return
|
||||
* The link object.
|
||||
*/
|
||||
Drupal.linkit.getLink = function() {
|
||||
var link = {
|
||||
path: $('#linkit-modal .linkit-path-element ').val(),
|
||||
attributes: {}
|
||||
};
|
||||
$.each(Drupal.linkit.additionalAttributes(), function(f, name) {
|
||||
link.attributes[name] = $('#linkit-modal .linkit-attributes .linkit-attribute-' + name).val();
|
||||
});
|
||||
return link;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve a list of the currently available additional attributes in the
|
||||
* dashboard. The attribute "href" is excluded.
|
||||
*
|
||||
* @return
|
||||
* An array with the names of the attributes.
|
||||
*/
|
||||
Drupal.linkit.additionalAttributes = function() {
|
||||
var attributes = [];
|
||||
$('#linkit-modal .linkit-attributes .linkit-attribute').each(function() {
|
||||
// Remove the 'linkit_' prefix.
|
||||
attributes.push($(this).attr('name').substr(7));
|
||||
});
|
||||
return attributes;
|
||||
};
|
||||
|
||||
Drupal.linkit.profileChanger = function(context) {
|
||||
$('#linkit-profile-changer > div.form-item', context).once('linkit-change-profile', function() {
|
||||
var target = $(this);
|
||||
var toggler = $('<div id="linkit-profile-changer-toggler"></div>')
|
||||
.html(Drupal.t('Change profile'))
|
||||
.click(function() {
|
||||
target.slideToggle();
|
||||
});
|
||||
$(this).after(toggler);
|
||||
});
|
||||
|
||||
$('#linkit-profile-changer .form-radio', context).each(function() {
|
||||
var id = $(this).attr('id');
|
||||
var profile = $(this).val();
|
||||
if (typeof Drupal.ajax[id] != 'undefined') {
|
||||
// @TODO: Jquery 1.5 accept success setting to be an array of functions.
|
||||
// But we have to wait for jquery to get updated in Drupal core.
|
||||
// In the meantime we have to override it.
|
||||
Drupal.ajax[id].options.success = function (response, status) {
|
||||
if (typeof response == 'string') {
|
||||
response = $.parseJSON(response);
|
||||
}
|
||||
|
||||
// Update the autocomplete url.
|
||||
Drupal.settings.linkit.currentInstance.autocompletePathParsed = Drupal.settings.linkit.autocompletePath.replace('___profile___', profile);
|
||||
|
||||
// Call the ajax success method.
|
||||
Drupal.ajax[id].success(response, status);
|
||||
$('#linkit-profile-changer > div.form-item').slideToggle();
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Drupal.behaviors.linkitSearch = {
|
||||
attach: function(context, settings) {
|
||||
|
||||
$('.linkit-search-element').once('linkit-search', function() {
|
||||
// Create a synonym for this to reduce code confusion.
|
||||
var searchElement = $('.linkit-search-element');
|
||||
var callbacks = {
|
||||
constructURL: function(path, search) {
|
||||
return path + encodeURIComponent(search);
|
||||
},
|
||||
|
||||
insertSuggestionList: function($results, $input) {
|
||||
var top = $input.position().top + $input.outerHeight() - 5;
|
||||
|
||||
$results.width($input.outerWidth()).css({
|
||||
position: 'absolute',
|
||||
// High value because of other overlays like
|
||||
// wysiwyg fullscreen (TinyMCE) mode.
|
||||
zIndex: 211000,
|
||||
maxHeight: $(window).height() - (top + 20)
|
||||
})
|
||||
.hide()
|
||||
.insertAfter($input);
|
||||
},
|
||||
|
||||
select: function(result) {
|
||||
if (typeof result == 'undefined') {
|
||||
return false;
|
||||
}
|
||||
// Only change the link text if it is empty.
|
||||
if (typeof result.disabled != 'undefined' && result.disabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Drupal.linkit.populateFields({
|
||||
path: result.path
|
||||
});
|
||||
|
||||
// Store the result title (Used when no selection is made by the user).
|
||||
Drupal.settings.linkit.currentInstance.linkContent = result.title;
|
||||
|
||||
$('.linkit-path-element', context).focus();
|
||||
}
|
||||
}
|
||||
|
||||
searchElement.betterAutocomplete('init', Drupal.settings.linkit.currentInstance.autocompletePathParsed, Drupal.settings.linkit.currentInstance.autocomplete, callbacks);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* @file
|
||||
* Linkit field ui functions
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.linkit_field = {
|
||||
attach : function(context, settings) {
|
||||
// If there is no fields, just stop here.
|
||||
|
||||
if (settings.linkit == undefined || settings.linkit.fields == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$.each(settings.linkit.fields, function(field_name, field) {
|
||||
$('#' + field_name, context).once('linkit_field', function() {
|
||||
$('.linkit-field-' + field_name).click(function() {
|
||||
// Set profile.
|
||||
Drupal.settings.linkit.currentInstance.profile = Drupal.settings.linkit.fields[field_name].profile;
|
||||
|
||||
// Set the name of the source field..
|
||||
Drupal.settings.linkit.currentInstance.source = field_name;
|
||||
|
||||
// Set the source type.
|
||||
Drupal.settings.linkit.currentInstance.helper = 'field';
|
||||
|
||||
// Only care about selection if the element is a textarea.
|
||||
if ($('textarea#' + field_name).length) {
|
||||
var selection = Drupal.linkit.getDialogHelper('field').getSelection($('#' + field_name).get(0));
|
||||
// Save the selection.
|
||||
Drupal.settings.linkit.currentInstance.selection = selection;
|
||||
}
|
||||
|
||||
// Suppress profile changer.
|
||||
Drupal.settings.linkit.currentInstance.suppressProfileChanger = true;
|
||||
|
||||
// Create the modal.
|
||||
Drupal.linkit.createModal();
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Linkit field dialog helper.
|
||||
*/
|
||||
Drupal.linkit.registerDialogHelper('field', {
|
||||
init : function() {},
|
||||
afterInit : function () {},
|
||||
|
||||
/**
|
||||
* Insert the link into the field.
|
||||
*
|
||||
* @param {Object} link
|
||||
* The link object.
|
||||
*/
|
||||
insertLink : function(data) {
|
||||
var source = $('#' + Drupal.settings.linkit.currentInstance.source),
|
||||
field_settings = Drupal.settings.linkit.fields[Drupal.settings.linkit.currentInstance.source],
|
||||
|
||||
// Call the insert plugin.
|
||||
link = Drupal.linkit.getInsertPlugin(field_settings.insert_plugin).insert(data, field_settings);
|
||||
|
||||
if (typeof Drupal.settings.linkit.currentInstance.selection != 'undefined') {
|
||||
// Replace the selection and insert the link there.
|
||||
this.replaceSelection(source.get(0), Drupal.settings.linkit.currentInstance.selection, link);
|
||||
}
|
||||
else {
|
||||
// Replace the field value.
|
||||
this.replaceFieldValue(source.get(0), link);
|
||||
}
|
||||
|
||||
// Link field can have a title field. If they have, we populate the title
|
||||
// field with the search result title if any.
|
||||
if (typeof field_settings.title_field != 'undefined' && typeof Drupal.settings.linkit.currentInstance.linkContent != 'undefined') {
|
||||
this.replaceFieldValue($('#' + field_settings.title_field).get(0), Drupal.settings.linkit.currentInstance.linkContent);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Get field selection.
|
||||
*/
|
||||
getSelection : function(e) {
|
||||
// Mozilla and DOM 3.0.
|
||||
if ('selectionStart' in e) {
|
||||
var l = e.selectionEnd - e.selectionStart;
|
||||
return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
|
||||
}
|
||||
// IE.
|
||||
else if(document.selection) {
|
||||
e.focus();
|
||||
var r = document.selection.createRange(),
|
||||
tr = e.createTextRange(),
|
||||
tr2 = tr.duplicate();
|
||||
tr2.moveToBookmark(r.getBookmark());
|
||||
tr.setEndPoint('EndToStart',tr2);
|
||||
|
||||
if (r == null || tr == null) {
|
||||
return { start: e.value.length, end: e.value.length, length: 0, text: '' };
|
||||
}
|
||||
|
||||
// For some reason IE doesn't always count the \n and \r in the length.
|
||||
var text_part = r.text.replace(/[\r\n]/g,'.'),
|
||||
text_whole = e.value.replace(/[\r\n]/g,'.'),
|
||||
the_start = text_whole.indexOf(text_part, tr.text.length);
|
||||
return { start: the_start, end: the_start + text_part.length, length: text_part.length, text: r.text };
|
||||
}
|
||||
// Browser not supported.
|
||||
else {
|
||||
return { start: e.value.length, end: e.value.length, length: 0, text: '' };
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Replace the field selection.
|
||||
*/
|
||||
replaceSelection : function (e, selection, text) {
|
||||
var start_pos = selection.start;
|
||||
var end_pos = start_pos + text.length;
|
||||
e.value = e.value.substr(0, start_pos) + text + e.value.substr(selection.end, e.value.length);
|
||||
},
|
||||
|
||||
/**
|
||||
* Replace the field value.
|
||||
*/
|
||||
replaceFieldValue : function (e, text) {
|
||||
e.value = text;
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* @file
|
||||
* Linkit dialog functions.
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
|
||||
// Create the Linkit namespaces.
|
||||
Drupal.linkit = Drupal.linkit || {};
|
||||
Drupal.linkit.currentInstance = Drupal.linkit.currentInstance || {};
|
||||
Drupal.linkit.dialogHelper = Drupal.linkit.dialogHelper || {};
|
||||
Drupal.linkit.insertPlugins = Drupal.linkit.insertPlugins || {};
|
||||
|
||||
/**
|
||||
* Create the modal dialog.
|
||||
*/
|
||||
Drupal.linkit.createModal = function() {
|
||||
// Create the modal dialog element.
|
||||
Drupal.linkit.createModalElement()
|
||||
// Create jQuery UI Dialog.
|
||||
.dialog(Drupal.linkit.modalOptions())
|
||||
// Remove the title bar from the modal.
|
||||
.siblings(".ui-dialog-titlebar").hide();
|
||||
|
||||
// Make the modal seem "fixed".
|
||||
$(window).bind("scroll resize", function() {
|
||||
$('#linkit-modal').dialog('option', 'position', ['center', 50]);
|
||||
});
|
||||
|
||||
// Get modal content.
|
||||
Drupal.linkit.getDashboard();
|
||||
};
|
||||
|
||||
/**
|
||||
* Create and append the modal element.
|
||||
*/
|
||||
Drupal.linkit.createModalElement = function() {
|
||||
// Create a new div and give it an ID of linkit-modal.
|
||||
// This is the dashboard container.
|
||||
var linkitModal = $('<div id="linkit-modal"></div>');
|
||||
|
||||
// Create a modal div in the <body>.
|
||||
$('body').append(linkitModal);
|
||||
|
||||
return linkitModal;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default jQuery dialog options used when creating the Linkit modal.
|
||||
*/
|
||||
Drupal.linkit.modalOptions = function() {
|
||||
return {
|
||||
dialogClass: 'linkit-wrapper',
|
||||
modal: true,
|
||||
draggable: false,
|
||||
resizable: false,
|
||||
width: 520,
|
||||
position: ['center', 50],
|
||||
minHeight: 0,
|
||||
zIndex: 210000,
|
||||
close: Drupal.linkit.modalClose,
|
||||
open: function (event, ui) {
|
||||
// Change the overlay style.
|
||||
$('.ui-widget-overlay').css({
|
||||
opacity: 0.5,
|
||||
filter: 'Alpha(Opacity=50)',
|
||||
backgroundColor: '#FFFFFF'
|
||||
});
|
||||
},
|
||||
title: 'Linkit'
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Close the Linkit modal.
|
||||
*/
|
||||
Drupal.linkit.modalClose = function (e) {
|
||||
$('#linkit-modal').dialog('destroy').remove();
|
||||
// Make sure the current intstance settings are removed when the modal is
|
||||
// closed.
|
||||
Drupal.settings.linkit.currentInstance = {};
|
||||
|
||||
// The event object does not have a preventDefault member in
|
||||
// Internet Explorer prior to version 9.
|
||||
if (e && e.preventDefault) {
|
||||
e.preventDefault();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Drupal.linkit.getDashboard = function () {
|
||||
// Create the AJAX object.
|
||||
var ajax_settings = {};
|
||||
ajax_settings.event = 'LinkitDashboard';
|
||||
ajax_settings.url = Drupal.settings.linkit.dashboardPath + Drupal.settings.linkit.currentInstance.profile;
|
||||
ajax_settings.progress = {
|
||||
type: 'throbber',
|
||||
message : Drupal.t('Loading Linkit dashboard...')
|
||||
};
|
||||
|
||||
Drupal.ajax['linkit-modal'] = new Drupal.ajax('linkit-modal', $('#linkit-modal')[0], ajax_settings);
|
||||
|
||||
// @TODO: Jquery 1.5 accept success setting to be an array of functions.
|
||||
// But we have to wait for jquery to get updated in Drupal core.
|
||||
// In the meantime we have to override it.
|
||||
Drupal.ajax['linkit-modal'].options.success = function (response, status) {
|
||||
if (typeof response == 'string') {
|
||||
response = $.parseJSON(response);
|
||||
}
|
||||
|
||||
// Call the ajax success method.
|
||||
Drupal.ajax['linkit-modal'].success(response, status);
|
||||
// Run the afterInit function.
|
||||
var helper = Drupal.settings.linkit.currentInstance.helper;
|
||||
Drupal.linkit.getDialogHelper(helper).afterInit();
|
||||
|
||||
// Set focus in the search field.
|
||||
$('#linkit-modal .linkit-search-element').focus();
|
||||
};
|
||||
|
||||
// Update the autocomplete url.
|
||||
Drupal.settings.linkit.currentInstance.autocompletePathParsed =
|
||||
Drupal.settings.linkit.autocompletePath.replace('___profile___', Drupal.settings.linkit.currentInstance.profile);
|
||||
|
||||
// Trigger the ajax event.
|
||||
$('#linkit-modal').trigger('LinkitDashboard');
|
||||
};
|
||||
|
||||
/**
|
||||
* Register new dialog helper.
|
||||
*/
|
||||
Drupal.linkit.registerDialogHelper = function(name, helper) {
|
||||
Drupal.linkit.dialogHelper[name] = helper;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a dialog helper.
|
||||
*/
|
||||
Drupal.linkit.getDialogHelper = function(name) {
|
||||
return Drupal.linkit.dialogHelper[name];
|
||||
};
|
||||
|
||||
/**
|
||||
* Register new insert plugins.
|
||||
*/
|
||||
Drupal.linkit.registerInsertPlugin = function(name, plugin) {
|
||||
Drupal.linkit.insertPlugins[name] = plugin;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get an insert plugin.
|
||||
*/
|
||||
Drupal.linkit.getInsertPlugin = function(name) {
|
||||
return Drupal.linkit.insertPlugins[name];
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user