Follow along at delocalizedham.com/d4d-stanford-2010, j/k are next/previous
$('#edit-search', this).attr('autocomplete', 'off').one('focus', function () {
var $this = $(this);
// Prefetch list of objects for this branch.
$.getJSON(Drupal.settings.apiAutoCompletePath, function (data) {
// Attach to autocomplete.
$this.autocomplete(data, {
sort: function (a, b) {
return a.value.length - b.value.length;
},
matchContains: true,
max: 200,
scroll: true,
scrollHeight: 360,
width: 300
}).result(function () {
$this.get(0).form.submit();
}).focus();
});
});
From api.js
$('#edit-search', this).attr('autocomplete', 'off').one('focus', function () {
var $this = $(this);
// Prefetch list of objects for this branch.
$.getJSON(Drupal.settings.apiAutoCompletePath, function (data) {
// Attach to autocomplete.
$this.autocomplete(data, {
sort: function (a, b) {
return a.value.length - b.value.length;
},
matchContains: true,
max: 200,
scroll: true,
scrollHeight: 360,
width: 300
}).result(function () {
$this.get(0).form.submit();
}).focus();
});
});
From api.js
$('#edit-search', this).attr('autocomplete', 'off').one('focus', function () {
var $this = $(this);
// Prefetch list of objects for this branch.
$.getJSON(Drupal.settings.apiAutoCompletePath, function (data) {
// Attach to autocomplete.
$this.autocomplete(data, {
sort: function (a, b) {
return a.value.length - b.value.length;
},
matchContains: true,
max: 200,
scroll: true,
scrollHeight: 360,
width: 300
}).result(function () {
$this.get(0).form.submit();
}).focus();
});
});
From api.js
$('#edit-search', this).attr('autocomplete', 'off').one('focus', function () {
var $this = $(this);
// Prefetch list of objects for this branch.
$.getJSON(Drupal.settings.apiAutoCompletePath, function (data) {
// Attach to autocomplete.
$this.autocomplete(data, {
sort: function (a, b) {
return a.value.length - b.value.length;
},
matchContains: true,
max: 200,
scroll: true,
scrollHeight: 360,
width: 300
}).result(function () {
$this.get(0).form.submit();
}).focus();
});
});
From api.js
options = {
matchContains: TRUE,
max: 200,
width: 300,
}
options = {
matchContains: TRUE,
max: 200,
width: 300,
}
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true,
bitwise: true, regexp: true, newcap: true, immed: true, indent: 2 */
var options = {
matchContains: true,
max: 200,
width: 300
};
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true,
bitwise: true, regexp: true, newcap: true, immed: true, indent: 2 */
$dashboardActiveSpan.find('>a.edit').click(function() {
// Hide edit link, show edit form.
$dashboardActiveSpan.find('>a').hide().end().append(Drupal.settings.dashboardPageEditForm);
$dashboardEditForm = $('#dashboard-page-edit-form').find('div.delete').hide().end();
// Correct title in case it has already been edited.
$dashboardEditForm.find('#edit-edit-title')
.attr('value', $dashboardActiveSpan.find('>a.edit').text());
// Allow AHAH form submission, but make changes active instantly.
Drupal.attachBehaviors($dashboardEditForm);
$dashboardEditFormSubmit = $dashboardEditForm.find('#edit-edit-submit').click(function() {
$dashboardActiveSpan.find('>a.edit').html(
Drupal.checkPlain($dashboardEditForm.find('#edit-edit-title').attr('value'))
+ '<span class="edit-icon"></span>'
);
dashboardRemoveEditPageForm();
});
From dashboard.js
drupal_add_js(array(
'dashboardPage' => $page->path,
'dashboardToken' => drupal_get_token('dashboard ' . $page->page_id),
'dashboardPageEditForm' => drupal_get_form('dashboard_page_edit_form', $page),
),'setting');
From dashboard.page.inc
$form['edit_submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#ahah' => array(
'event' => 'click',
'path' => 'dashboard/'. $page->path .'/rename',
),
);
function dashboard_page_rename($page) {
drupal_get_form('dashboard_page_edit_form', $page);
drupal_json(array('status' => TRUE, 'data' => ''));
}
From dashboard.page.inc
$form['edit_submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#ahah' => array(
'event' => 'click',
'path' => 'dashboard/'. $page->path .'/rename',
),
);
function dashboard_page_rename($page) {
drupal_get_form('dashboard_page_edit_form', $page);
drupal_json(array('status' => TRUE, 'data' => ''));
}
From dashboard.page.inc
$dashboardActiveSpan.find('>a.edit').click(function() {
// Hide edit link, show edit form.
$dashboardActiveSpan.find('>a').hide().end().append(Drupal.settings.dashboardPageEditForm);
$dashboardEditForm = $('#dashboard-page-edit-form').find('div.delete').hide().end();
// Correct title in case it has already been edited.
$dashboardEditForm.find('#edit-edit-title')
.attr('value', $dashboardActiveSpan.find('>a.edit').text());
// Allow AHAH form submission, but make changes active instantly.
Drupal.attachBehaviors($dashboardEditForm);
$dashboardEditFormSubmit = $dashboardEditForm.find('#edit-edit-submit').click(function() {
$dashboardActiveSpan.find('>a.edit').html(
Drupal.checkPlain($dashboardEditForm.find('#edit-edit-title').attr('value'))
+ '<span class="edit-icon"></span>'
);
dashboardRemoveEditPageForm();
});
From dashboard.js
$dashboardActiveSpan.find('>a.edit').click(function() {
// Hide edit link, show edit form.
$dashboardActiveSpan.find('>a').hide().end().append(Drupal.settings.dashboardPageEditForm);
$dashboardEditForm = $('#dashboard-page-edit-form').find('div.delete').hide().end();
// Correct title in case it has already been edited.
$dashboardEditForm.find('#edit-edit-title')
.attr('value', $dashboardActiveSpan.find('>a.edit').text());
// Allow AHAH form submission, but make changes active instantly.
Drupal.attachBehaviors($dashboardEditForm);
$dashboardEditFormSubmit = $dashboardEditForm.find('#edit-edit-submit').click(function() {
$dashboardActiveSpan.find('>a.edit').html(
Drupal.checkPlain($dashboardEditForm.find('#edit-edit-title').attr('value'))
+ '<span class="edit-icon"></span>'
);
dashboardRemoveEditPageForm();
});
From dashboard.js
drupal_add_js(array(
'dashboardPage' => $page->path,
'dashboardToken' => drupal_get_token('dashboard ' . $page->page_id),
'dashboardPageEditForm' => drupal_get_form('dashboard_page_edit_form', $page),
),'setting');jQuery.post(Drupal.settings.basePath
+ 'dashboard/' + Drupal.settings.dashboardPage + '/remove-widget', {
token: Drupal.settings.dashboardToken,
widget_id: $widget.attr('id').replace(/^widget-/, '')
});function dashboard_valid_token($page) {
return drupal_valid_token($_POST['token'], 'dashboard '. $page->page_id);
}From dashboard.page.inc, dashboard.js, and dashboard.module
Drupal.behaviors.mapPopup = function (context) {
$('a.map-popup:not(mapPopupProcessed)', context).addClass('mapPopupProcessed')
.each(function () {
var $this = $(this);
var $content = $('#' + $this.attr('id').replace(/-link$/, ''));
var options = $.extend({}, Drupal.mapPopupDefaults);
if (typeof Drupal.settings.mapPopups[$content.attr('id')] !== 'undefined') {
$.extend(options, Drupal.settings.mapPopups[$content.attr('id')]);
}
if (options.clone) {
$content = $content.clone().appendTo("body");
}
$this.data('mapPopUp', $content.show().dialog(options));
})
.click(function () {
$(this).data('mapPopUp').dialog('open');
return false;
});
};
Will be used in MAPLight.org’s upcoming redesign
<a href="non-js-fallback" class="map-popup" id="my-dialog-link">Click to open</a>
<div id="my-dialog">Dialog content</div>
Drupal.behaviors.mapPopup = function (context) {
$('a.map-popup:not(mapPopupProcessed)', context).addClass('mapPopupProcessed')
.each(function () {
var $this = $(this);
var $content = $('#' + $this.attr('id').replace(/-link$/, ''));
var options = $.extend({}, Drupal.mapPopupDefaults);
if (typeof Drupal.settings.mapPopups[$content.attr('id')] !== 'undefined') {
$.extend(options, Drupal.settings.mapPopups[$content.attr('id')]);
}
if (options.clone) {
$content = $content.clone().appendTo("body");
}
$this.data('mapPopUp', $content.show().dialog(options));
})
.click(function () {
$(this).data('mapPopUp').dialog('open');
return false;
});
};
Will be used in MAPLight.org’s upcoming redesign
Drupal.attachBehaviors = function(context) {
context = context || document;
if (Drupal.jsEnabled) {
// Execute all of them.
jQuery.each(Drupal.behaviors, function() {
console.log(this);
console.time('behavior');
this(context);
console.timeEnd('behavior');
});
}
};
Drupal’s drupal.js
Drupal.behaviors.mapExpandable = function (context) {
console.profile();
$('.map-expandable:not(.mapExpandableProcessed)', context).each(function () {
$(this).addClass('mapExpandableProcessed').one('mouseenter', function () {
$(this).children('.prompt').find('a.show-content').click(function () {
$(this).parents('.map-expandable').eq(0)
.children('.prompt').hide().end()
.children('.content').show();
return false;
}).end().end()
.children('.content').find('a.hide-content').click(function () {
$(this).parents('.map-expandable').eq(0)
.children('.prompt').show().end()
.children('.content').hide();
return false;
});
});
});
console.profileEnd();
};
Will be used in MAPLight.org’s upcoming redesign
Drupal.behaviors.mapExpandable = function (context) {
console.profile();
$('div.map-expandable:not(.mapExpandableProcessed)', context).each(function () {
$(this).addClass('mapExpandableProcessed').one('mouseenter', function () {
$(this).children('.prompt').find('a.show-content').click(function () {
$(this).parents('.map-expandable').eq(0)
.children('.prompt').hide().end()
.children('.content').show();
return false;
}).end().end()
.children('.content').find('a.hide-content').click(function () {
$(this).parents('.map-expandable').eq(0)
.children('.prompt').show().end()
.children('.content').hide();
return false;
});
});
});
console.profileEnd();
};
Will be used in MAPLight.org’s upcoming redesign
How I did the j/k paging