Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions deform/static/scripts/deform.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
/*
* Register a top-level callback to the deform.load() function
* this will be called when the DOM has finished loading. No need
* to include the call at the end of the page.
*/

$(document).ready(function(){
deform.load();
});


var deform_loaded = false;

var deform = {
Expand All @@ -30,7 +19,7 @@ var deform = {
deform_loaded = true;
}});
},


processCallbacks: function () {
$(deform.callbacks).each(function(num, item) {
Expand All @@ -49,7 +38,7 @@ var deform = {
// In order to avoid breaking accessibility:
//
// - Find each tag within the prototype node with an id
// that has the string ``deformField(\d+)`` within it, and modify
// that has the string ``deformField(\d+)`` within it, and modify
// its id to have a random component.
// - For each label referencing an change id, change the label's
// for attribute to the new id.
Expand All @@ -64,7 +53,7 @@ var deform = {
var genid = deform.randomString(6);
var idmap = {};

// replace ids containing ``deformField`` and associated label for=
// replace ids containing ``deformField`` and associated label for=
// items which point at them

$idnodes.each(function(idx, node) {
Expand Down Expand Up @@ -93,7 +82,7 @@ var deform = {
var oid = item[0];
var callback = item[1];
var newid = idmap[oid];
if (newid) {
if (newid) {
callback(newid);
}
});
Expand All @@ -114,10 +103,10 @@ var deform = {
var max_len = parseInt($before_node.attr('max_len')||'9999', 10);
var now_len = parseInt($before_node.attr('now_len')||'0', 10);
var orderable = parseInt($before_node.attr('orderable')||'0', 10);

if (now_len < max_len) {
deform.addSequenceItem($proto_node, $before_node);
deform.processSequenceButtons($oid_node, min_len, max_len,
deform.processSequenceButtons($oid_node, min_len, max_len,
now_len + 1, orderable);
}
return false;
Expand All @@ -134,7 +123,7 @@ var deform = {
if (now_len > min_len) {
$before_node.attr('now_len', now_len - 1);
$item_node.remove();
deform.processSequenceButtons($oid_node, min_len, max_len,
deform.processSequenceButtons($oid_node, min_len, max_len,
now_len-1, orderable);
}
// we removed something from the dom, trigger a change event
Expand Down Expand Up @@ -165,9 +154,9 @@ var deform = {
if (input) {
var raw = input.get(0);
if (raw) {
if (raw.type === 'text' || raw.type === 'file' ||
raw.type == 'password' || raw.type == 'text' ||
raw.type == 'textarea') {
if (raw.type === 'text' || raw.type === 'file' ||
raw.type == 'password' || raw.type == 'text' ||
raw.type == 'textarea') {
if (!input.hasClass("hasDatepicker")) {
input.focus();
}
Expand All @@ -179,11 +168,11 @@ var deform = {
randomString: function (length) {
var chr='0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
chr = chr.split('');

if (! length) {
length = Math.floor(Math.random() * chr.length);
}

var str = '';
for (var i = 0; i < length; i++) {
str += chr[Math.floor(Math.random() * chr.length)];
Expand Down