Author: acydburn Date: Sun Aug 30 18:50:11 2009 New Revision: 10069 Log: Style authors are now able to define the default submit button used for form submission on ENTER keypress on forms using more than one. Prosilver uses this for the posting page(s) and registration screen. (we further test this at phpbb.com) Modified: branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js branches/phpBB-3_0_0/phpBB/styles/prosilver/template/posting_editor.html branches/phpBB-3_0_0/phpBB/styles/prosilver/template/ucp_register.html Modified: branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html ============================================================================== *** branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html (original) --- branches/phpBB-3_0_0/phpBB/docs/CHANGELOG.html Sun Aug 30 18:50:11 2009 *************** *** 284,291 **** <li>[Feature] Separate PM Reply and PM Reply to all in prosilver.</li> <li>[Feature] Place debug notices during captcha rendering in the error log - useful for debugging output already started errors.</li> <li>[Feature] Ability to define constant PHPBB_USE_BOARD_URL_PATH to use board url for images/avatars/ranks/imageset...</li> ! <li>[Feature] Added function to generate email-hash. (Bug #49195)</li> ! </ul> <a name="v304"></a><h3>1.ii. Changes since 3.0.4</h3> --- 284,291 ---- <li>[Feature] Separate PM Reply and PM Reply to all in prosilver.</li> <li>[Feature] Place debug notices during captcha rendering in the error log - useful for debugging output already started errors.</li> <li>[Feature] Ability to define constant PHPBB_USE_BOARD_URL_PATH to use board url for images/avatars/ranks/imageset...</li> ! <li>[Feature] Added function to generate Email hash. (Bug #49195)</li> ! <li>[Feature] Style authors are now able to define the default submit button used for form submission on ENTER keypress on forms using more than one. Prosilver uses this for the posting page(s) and registration screen.</li> </ul> <a name="v304"></a><h3>1.ii. Changes since 3.0.4</h3> Modified: branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php ============================================================================== *** branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php (original) --- branches/phpBB-3_0_0/phpBB/includes/ucp/ucp_pm_compose.php Sun Aug 30 18:50:11 2009 *************** *** 1163,1170 **** global $refresh, $submit, $preview; ! $refresh = $preview = true; $submit = false; } // Add User/Group [TO] --- 1163,1176 ---- global $refresh, $submit, $preview; ! $refresh = true; $submit = false; + + // Preview is only true if there was also a message entered + if (request_var('message', '')) + { + $preview = true; + } } // Add User/Group [TO] Modified: branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js ============================================================================== *** branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js (original) --- branches/phpBB-3_0_0/phpBB/styles/prosilver/template/forum_fn.js Sun Aug 30 18:50:11 2009 *************** *** 268,270 **** --- 268,403 ---- obj.SetControllerVisible(true); obj.Play(); } + + /** + * Check if the nodeName of elem is name + * @author jQuery + */ + function is_node_name(elem, name) + { + return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); + } + + /** + * Check if elem is in array, return position + * @author jQuery + */ + function is_in_array(elem, array) + { + for (var i = 0, length = array.length; i < length; i++) + // === is correct (IE) + if (array[i] === elem) + return i; + + return -1; + } + + /** + * Find Element, type and class in tree + * Not used, but may come in handy for those not using JQuery + * @author jQuery.find, Meik Sievertsen + */ + function find_in_tree(node, tag, type, class_name) + { + var result, element, i = 0, length = node.childNodes.length; + + for (element = node.childNodes[0]; i < length; element = node.childNodes[++i]) + { + if (!element || element.nodeType != 1) continue; + + if ((!tag || is_node_name(element, tag)) && (!type || element.type == type) && (!class_name || is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1)) + { + return element; + } + + if (element.childNodes.length) + result = find_in_tree(element, tag, type, class_name); + + if (result) return result; + } + } + + /** + * Usually used for onkeypress event, to submit a form on enter + */ + function submit_default_button(event, selector, class_name) + { + // Add which for key events + if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) + event.which = event.charCode || event.keyCode; + + // Keycode is not return, then return. ;) + if (event.which != 13) + return true; + + var current = selector['parentNode']; + + // Search parent form element + while (current && (!current.nodeName || current.nodeType != 1 || !is_node_name(current, 'form')) && current != document) + current = current['parentNode']; + + // Find the input submit button with the class name + //current = find_in_tree(current, 'input', 'submit', class_name); + var input_tags = current.getElementsByTagName('input'); + current = false; + + for (var i = 0, element = input_tags[0]; i < input_tags.length; element = input_tags[++i]) + { + if (element.type == 'submit' && is_in_array(class_name, (element.className || element).toString().split(/\s+/)) > -1) + current = element; + } + + if (!current) + return true; + + // Submit form + current.focus(); + current.click(); + return false; + } + + /** + * Apply onkeypress event for forcing default submit button on ENTER key press + * The jQuery snippet used is based on http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/ + * The non-jQuery code is a mimick of the jQuery code ;) + */ + function apply_onkeypress_event() + { + // jQuery code in case jQuery is used + if (jquery_present) + { + $('form input').live('keypress', function (e) + { + var default_button = $(this).parents('form').find('input[type=submit].default-submit-action'); + + if (!default_button || default_button.length <= 0) + return true; + + if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) + { + default_button.click(); + return false; + } + + return true; + }); + + return; + } + + var input_tags = document.getElementsByTagName('input'); + + for (var i = 0, element = input_tags[0]; i < input_tags.length ; element = input_tags[++i]) + { + if (element.type == 'hidden') + continue; + + // onkeydown is possible too + element.onkeypress = function (evt) { submit_default_button((evt || window.event), this, 'default-submit-action'); }; + } + } + + /** + * Detect JQuery existance. We currently do not deliver it, but some styles do, so why not benefit from it. ;) + */ + var jquery_present = typeof jQuery == 'function'; Modified: branches/phpBB-3_0_0/phpBB/styles/prosilver/template/posting_editor.html ============================================================================== *** branches/phpBB-3_0_0/phpBB/styles/prosilver/template/posting_editor.html (original) --- branches/phpBB-3_0_0/phpBB/styles/prosilver/template/posting_editor.html Sun Aug 30 18:50:11 2009 *************** *** 1,3 **** --- 1,9 ---- + <script type="text/javascript"> + // <![CDATA[ + onload_functions.push('apply_onkeypress_event()'); + // ]]> + </script> + <fieldset class="fields1"> <!-- IF ERROR --><p class="error">{ERROR}</p><!-- ENDIF --> *************** *** 184,190 **** <!-- IF S_HAS_DRAFTS --><input type="submit" accesskey="d" tabindex="8" name="load" value="{L_LOAD}" class="button2" onclick="load_draft = true;" /> <!-- ENDIF --> <!-- IF S_SAVE_ALLOWED --><input type="submit" accesskey="k" tabindex="7" name="save" value="{L_SAVE}" class="button2" /> <!-- ENDIF --> <input type="submit" tabindex="5" name="preview" value="{L_PREVIEW}" class="button1"<!-- IF not S_PRIVMSGS --> onclick="document.getElementById('postform').action += '#preview';"<!-- ENDIF --> /> ! <input type="submit" accesskey="s" tabindex="6" name="post" value="{L_SUBMIT}" class="button1" /> </fieldset> --- 190,196 ---- <!-- IF S_HAS_DRAFTS --><input type="submit" accesskey="d" tabindex="8" name="load" value="{L_LOAD}" class="button2" onclick="load_draft = true;" /> <!-- ENDIF --> <!-- IF S_SAVE_ALLOWED --><input type="submit" accesskey="k" tabindex="7" name="save" value="{L_SAVE}" class="button2" /> <!-- ENDIF --> <input type="submit" tabindex="5" name="preview" value="{L_PREVIEW}" class="button1"<!-- IF not S_PRIVMSGS --> onclick="document.getElementById('postform').action += '#preview';"<!-- ENDIF --> /> ! <input type="submit" accesskey="s" tabindex="6" name="post" value="{L_SUBMIT}" class="button1 default-submit-action" /> </fieldset> Modified: branches/phpBB-3_0_0/phpBB/styles/prosilver/template/ucp_register.html ============================================================================== *** branches/phpBB-3_0_0/phpBB/styles/prosilver/template/ucp_register.html (original) --- branches/phpBB-3_0_0/phpBB/styles/prosilver/template/ucp_register.html Sun Aug 30 18:50:11 2009 *************** *** 11,16 **** --- 11,20 ---- document.forms['register'].submit.click(); } + <!-- IF CAPTCHA_TEMPLATE and S_CONFIRM_REFRESH --> + onload_functions.push('apply_onkeypress_event()'); + <!-- ENDIF --> + // ]]> </script> *************** *** 92,106 **** </div> <!-- ENDIF --> - - <div class="panel"> <div class="inner"><span class="corners-top"><span></span></span> <fieldset class="submit-buttons"> {S_HIDDEN_FIELDS} <input type="reset" value="{L_RESET}" name="reset" class="button2" /> ! <input type="submit" name="submit" id="submit" value="{L_SUBMIT}" class="button1" /> {S_FORM_TOKEN} </fieldset> --- 96,108 ---- </div> <!-- ENDIF --> <div class="panel"> <div class="inner"><span class="corners-top"><span></span></span> <fieldset class="submit-buttons"> {S_HIDDEN_FIELDS} <input type="reset" value="{L_RESET}" name="reset" class="button2" /> ! <input type="submit" name="submit" id="submit" value="{L_SUBMIT}" class="button1 default-submit-action" /> {S_FORM_TOKEN} </fieldset> |