[Jifty-commit] jifty branch, js-refactor, created. f8a357f5814c172a7646155ff7ff8ca96cae99a1
Jifty commits
jifty-commit at lists.jifty.org
Thu Jan 14 18:11:54 EST 2010
The branch, js-refactor has been created
at f8a357f5814c172a7646155ff7ff8ca96cae99a1 (commit)
- Log -----------------------------------------------------------------
commit f8a357f5814c172a7646155ff7ff8ca96cae99a1
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Jan 14 18:11:09 2010 -0500
Kill bps_utils.js and move into Jifty.Utils
diff --git a/doc/js-refactor b/doc/js-refactor
new file mode 100644
index 0000000..09dabbf
--- /dev/null
+++ b/doc/js-refactor
@@ -0,0 +1,5 @@
+bps_util.js
+ focusElementById removed
+ custom onload hook code removed
+ buttonToLink, updateParentField, createCalendarLink, createDateTimeLink moved to Jifty.Utils
+
diff --git a/share/web/static/js/bps_util.js b/share/web/static/js/bps_util.js
deleted file mode 100644
index 012e92b..0000000
--- a/share/web/static/js/bps_util.js
+++ /dev/null
@@ -1,105 +0,0 @@
-// XXX TODO This library should likely be refactored to use behaviour
-
-function focusElementById(id) {
- var e = document.getElementById(id);
- if (e) e.focus();
-}
-
-function updateParentField(field, value) {
- if (window.opener) {
- window.opener.document.getElementById(field).value = value;
- window.close();
- }
-}
-
-function createCalendarLink(id) {
- return Jifty.Calendar.registerDateWidget( id );
-}
-
-function createDateTimeLink(id) {
- return Jifty.DateTime.registerDateTimeWidget( id );
-}
-
-JSAN.use("DOM.Events");
-
-function buttonToLink(e) {
- var link = document.createElement("a");
- link.setAttribute("href","#");
- link.setAttribute("name",e.getAttribute("name"));
-
- var form = Jifty.Form.Element.getForm(e);
- var onclick = e.getAttribute("onclick");
-
- /* Simple buttons that don't use any JS need us to create an onclick
- for them that makes sure the original button's name gets passed
- and the form submitted normally (without any Ajax-ness)
- */
- if ( !onclick ) {
- DOM.Events.addListener( link, "click", function(ev) {
- var a = ev.target;
- var hidden = document.createElement("input");
- hidden.setAttribute("type", "hidden");
- hidden.setAttribute("name", a.getAttribute("name"));
- a["virtualform"].appendChild( hidden );
- if ( a["virtualform"].onsubmit )
- a["virtualform"].onsubmit();
- a["virtualform"].submit();
- });
- }
- link.setAttribute("onclick", onclick);
- link.setAttribute("title", e.getAttribute("title"));
-
- link.className = e.className;
- link["virtualform"] = form;
- link.appendChild(document.createTextNode(e.getAttribute("value")));
-
- e.parentNode.insertBefore(link, e.nextSibling);
- e.parentNode.removeChild(e);
- return link;
-}
-
-// onload handlers
-
-var onLoadStack = new Array();
-var onLoadLastStack = new Array();
-var onLoadExecuted = 0;
-
-function onLoadHook(commandStr) {
- if(typeof(commandStr) == "string") {
- onLoadStack[onLoadStack.length] = commandStr;
- return true;
- }
- return false;
-}
-
-// some things *really* need to be done after everything else
-function onLoadLastHook(commandStr) {
- if(typeof(commandStr) == "string"){
- onLoadLastStack[onLoadLastStack.length] = commandStr;
- return true;
- }
- return false;
-}
-
-function doOnLoadHooks() {
- if(onLoadExecuted) return;
- for (var x=0; x < onLoadStack.length; x++) {
- eval(onLoadStack[x]);
- }
- for (var x=0; x < onLoadLastStack.length; x++) {
- eval(onLoadLastStack[x]);
- }
- onLoadExecuted = 1;
-}
-
-
-if (typeof window.onload != 'function') {
- window.onload = doOnLoadHooks;
-} else {
- var oldonload = window.onload;
-
- window.onload = function() {
- oldonload();
- doOnLoadHooks();
- }
-}
diff --git a/share/web/static/js/jifty.js b/share/web/static/js/jifty.js
index b00a139..037ac9a 100644
--- a/share/web/static/js/jifty.js
+++ b/share/web/static/js/jifty.js
@@ -724,7 +724,7 @@ Behaviour.register({
},
'input.date': function(e) {
if ( !jQuery(e).hasClass('has_calendar_link') ) {
- createCalendarLink(e);
+ Jifty.Utils.createCalendarLink(e);
jQuery(e).addClass('has_calendar_link');
}
},
@@ -733,7 +733,7 @@ Behaviour.register({
},
'input.datetime': function(e) {
if ( !jQuery(e).hasClass('has_datetime_link') ) {
- createDateTimeLink(e);
+ Jifty.Utils.createDateTimeLink(e);
var button = document.createElement('input');
button.setAttribute('type', 'button');
@@ -757,7 +757,7 @@ Behaviour.register({
}
},
'input.button_as_link': function(e) {
- buttonToLink(e);
+ Jifty.Utils.buttonToLink(e);
},
"input.date, input.text": function(e) {
/* XXX TODO: Figure out how to make our enter handler detect
diff --git a/share/web/static/js/jifty_utils.js b/share/web/static/js/jifty_utils.js
index da8c04b..802301c 100644
--- a/share/web/static/js/jifty_utils.js
+++ b/share/web/static/js/jifty_utils.js
@@ -1,7 +1,60 @@
if (typeof Jifty == "undefined") Jifty = { };
-Jifty.Utils = {
+Jifty.Utils = {};
+
+jQuery.extend(Jifty.Utils, {
+ buttonToLink: function(e) {
+ var link = document.createElement("a");
+ link.setAttribute("href","#");
+ link.setAttribute("name",e.getAttribute("name"));
+
+ var form = Jifty.Form.Element.getForm(e);
+ var onclick = e.getAttribute("onclick");
+
+ /* Simple buttons that don't use any JS need us to create an onclick
+ for them that makes sure the original button's name gets passed
+ and the form submitted normally (without any Ajax-ness)
+ */
+ if ( !onclick ) {
+ jQuery( link ).click(function(ev) {
+ var a = ev.target;
+ var hidden = document.createElement("input");
+ hidden.setAttribute("type", "hidden");
+ hidden.setAttribute("name", a.getAttribute("name"));
+ a["virtualform"].appendChild( hidden );
+ if ( a["virtualform"].onsubmit )
+ a["virtualform"].onsubmit();
+ a["virtualform"].submit();
+ });
+ }
+ link.setAttribute("onclick", onclick);
+ link.setAttribute("title", e.getAttribute("title"));
+
+ link.className = e.className;
+ link["virtualform"] = form;
+ link.appendChild(document.createTextNode(e.getAttribute("value")));
+
+ e.parentNode.insertBefore(link, e.nextSibling);
+ e.parentNode.removeChild(e);
+ return link;
+ },
+
+ updateParentField: function(field, value) {
+ if (window.opener) {
+ window.opener.document.getElementById(field).value = value;
+ window.close();
+ }
+ },
+
+ createCalendarLink: function(id) {
+ return Jifty.Calendar.registerDateWidget( id );
+ },
+
+ createDateTimeLink: function(id) {
+ return Jifty.DateTime.registerDateTimeWidget( id );
+ },
+
/* From http://blog.firetree.net/2005/07/04/javascript-find-position/ */
findPosX: function(obj)
{
@@ -142,7 +195,7 @@ Jifty.Utils = {
stripScripts: function(str) {
return str.replace(/<script(.|\s)*?\/script>/g, "");
}
-};
+});
/* This sets Jifty.Utils.isMSIE to true in IE */
/* @cc_on
diff --git a/share/web/templates/helpers/calendar.html b/share/web/templates/helpers/calendar.html
index fbfe41a..dd8e8df 100644
--- a/share/web/templates/helpers/calendar.html
+++ b/share/web/templates/helpers/calendar.html
@@ -21,7 +21,7 @@
<td>
% if ($day) {
% my $datestr = sprintf('%04d-%02d-%02d', $DisplayedYear, $DisplayedMonth, $day);
- <a href="#" onclick="updateParentField('<% $field %>','<% $datestr %>'); return false;"><% $day %></a>
+ <a href="#" onclick="Jifty.Utils.updateParentField('<% $field %>','<% $datestr %>'); return false;"><% $day %></a>
% } else {
% }
@@ -32,13 +32,13 @@
</table>
<span class="calendar today">
% my $datestr = sprintf('%04d-%02d-%02d', $today[5]+1900,$today[4]+1, $today[3]);
- <a href="#" onclick="updateParentField('<% $field %>','<% $datestr %>'); return false;">Today</a>
+ <a href="#" onclick="Jifty.Utils.updateParentField('<% $field %>','<% $datestr %>'); return false;">Today</a>
</span>
<span class="calendar tomorrow">
% my @tomorrow = localtime(time()+86400);
% $datestr = sprintf('%04d-%02d-%02d', $tomorrow[5]+1900,$tomorrow[4]+1, $tomorrow[3]);
- <a href="#" onclick="updateParentField('<% $field %>','<% $datestr %>'); return false;">Tomorrow</a>
+ <a href="#" onclick="Jifty.Utils.updateParentField('<% $field %>','<% $datestr %>'); return false;">Tomorrow</a>
</span>
</div>
</div>
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list