Browse Source

Merge pull request #167 from Spuds/SomeFixins

Update js (topic & script) to improve function plus and some general cleanup
emanuele45 12 years ago
parent
commit
aadeaf6259

+ 4 - 4
Sources/Memberlist.php

@@ -603,12 +603,12 @@ function printMemberListRows($request)
 		array(
 		)
 	);
-	list ($MOST_POSTS) = $smcFunc['db_fetch_row']($result);
+	list ($most_posts) = $smcFunc['db_fetch_row']($result);
 	$smcFunc['db_free_result']($result);
 
 	// Avoid division by zero...
-	if ($MOST_POSTS == 0)
-		$MOST_POSTS = 1;
+	if ($most_posts == 0)
+		$most_posts = 1;
 
 	$members = array();
 	while ($row = $smcFunc['db_fetch_assoc']($request))
@@ -624,7 +624,7 @@ function printMemberListRows($request)
 			continue;
 
 		$context['members'][$member] = $memberContext[$member];
-		$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $MOST_POSTS);
+		$context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts);
 		$context['members'][$member]['registered_date'] = strftime('%Y-%m-%d', $context['members'][$member]['registered_timestamp']);
 	}
 }

+ 1 - 1
Sources/Packages.php

@@ -1571,7 +1571,7 @@ function list_getPackages($start, $items_per_page, $sort, $params, $installed)
 
 	if (empty($packages))
 		foreach ($context['modification_types'] as $type)
-			$packages[$type] = arra();
+			$packages[$type] = array();
 
 	if ($dir = @opendir($boarddir . '/Packages'))
 	{

+ 3 - 3
Sources/Post.php

@@ -18,7 +18,7 @@ if (!defined('SMF'))
 	die('Hacking attempt...');
 
 /**
- * handles showing the post screen, loading the post to be modified, and loading any post quoted.
+ * Handles showing the post screen, loading the post to be modified, and loading any post quoted.
  *
  * - additionally handles previews of posts.
  * - @uses the Post template and language file, main sub template.
@@ -2045,7 +2045,7 @@ function Post2()
 }
 
 /**
- * handle the announce topic function (action=announce).
+ * Handle the announce topic function (action=announce).
  *
  * checks the topic announcement permissions and loads the announcement template.
  * requires the announce_topic permission.
@@ -2504,7 +2504,7 @@ function getTopic()
 }
 
 /**
- * loads a post an inserts it into the current editing text box.
+ * Loads a post an inserts it into the current editing text box.
  * uses the Post language file.
  * uses special (sadly browser dependent) javascript to parse entities for internationalization reasons.
  * accessed with ?action=quotefast.

+ 3 - 3
Sources/Security.php

@@ -1022,9 +1022,9 @@ function isAllowedTo($permission, $boards = null)
 
 /**
  * Return the boards a user has a certain (board) permission on. (array(0) if all.)
- * returns a list of boards on which the user is allowed to do the specified permission.
- * Returns an array with only a 0 in it if the user has permission to do this on every board.
- * Returns an empty array if he or she cannot do this on any board.
+ *  - returns a list of boards on which the user is allowed to do the specified permission.
+ *  - returns an array with only a 0 in it if the user has permission to do this on every board.
+ *  - returns an empty array if he or she cannot do this on any board.
  * If check_access is true will also make sure the group has proper access to that board.
  *
  * @param array $permissions

+ 4 - 4
Sources/Subs-Auth.php

@@ -17,7 +17,7 @@ if (!defined('SMF'))
 	die('Hacking attempt...');
 
 /**
- * sets the SMF-style login cookie and session based on the id_member and password passed.
+ * Sets the SMF-style login cookie and session based on the id_member and password passed.
  * - password should be already encrypted with the cookie salt.
  * - logs the user out if id_member is zero.
  * - sets the cookie and session to last the number of seconds specified by cookie_length.
@@ -247,7 +247,7 @@ function adminLogin($type = 'admin')
 }
 
 /**
- * used by the adminLogin() function.
+ * Used by the adminLogin() function.
  * if 'value' is an array, the function is called recursively.
  *
  * @param string $key
@@ -399,7 +399,7 @@ function findMembers($names, $use_wildcards = false, $buddies_only = false, $max
 }
 
 /**
- * called by index.php?action=findmember.
+ * Called by index.php?action=findmember.
  * - is used as a popup for searching members.
  * - uses sub template find_members of the Help template.
  * - also used to add members for PM's sent using wap2/imode protocol.
@@ -471,7 +471,7 @@ function JSMembers()
 }
 
 /**
- * outputs each member name on its own line.
+ * Outputs each member name on its own line.
  * - used by javascript to find members matching the request.
  */
 function RequestMembers()

+ 1 - 1
Sources/Subs.php

@@ -3610,7 +3610,7 @@ function create_button($name, $alt, $label = '', $custom = '', $force_use = fals
 /**
  * Empty out the cache in use as best it can
  *
- * it may only remove the files of a certain type (if the $type parameter is given)
+ * It may only remove the files of a certain type (if the $type parameter is given)
  * Type can be user, data or left blank
  * 	- user clears out user data
  *  - data clears out system / opcode data

+ 1 - 1
Sources/Who.php

@@ -723,7 +723,7 @@ function Credits($in_admin = false)
 		),
 	);
 
-	// support for mods that use the <credits> tag via the package manager
+	// Support for mods that use the <credits> tag via the package manager
 	$context['credits_modifications'] = array();
 	if (($mods = cache_get_data('mods_credits', 86400)) === null)
 	{

+ 5 - 9
Themes/default/MessageIndex.template.php

@@ -252,7 +252,7 @@ function template_main()
 						</div>
 					</td>
 					<td class="', $alternate_class, ' subject">
-						<div ', (!empty($topic['quick_mod']['modify']) ? 'id="topic_' . $topic['first_post']['id'] . '" onmouseout="mouse_on_div = 0;" onmouseover="mouse_on_div = 1;" ondblclick="modify_topic(\'' . $topic['id'] . '\', \'' . $topic['first_post']['id'] . '\');"' : ''), '>';
+						<div ', (!empty($topic['quick_mod']['modify']) ? 'id="topic_' . $topic['first_post']['id'] . '"  ondblclick="oQuickModifyTopic.modify_topic(\'' . $topic['id'] . '\', \'' . $topic['first_post']['id'] . '\');"' : ''), '>';
 
 			// [WIP] Methinks the orange icons look better if they aren't all over the page.
 			// Is this topic new? (assuming they are logged in!)
@@ -425,14 +425,10 @@ function template_main()
 	echo '
 <script type="text/javascript" src="', $settings['default_theme_url'], '/scripts/topic.js"></script>
 <script type="text/javascript"><!-- // --><![CDATA[
-
-	// Hide certain bits during topic edit.
-	hide_prefixes.push("lockicon", "stickyicon", "pages", "newicon");
-
-	// Use it to detect when we\'ve stopped editing.
-	document.onclick = modify_topic_click;
-
-	var mouse_on_div;
+	var oQuickModifyTopic = new QuickModifyTopic({
+		aHidePrefixes: Array("lockicon", "stickyicon", "pages", "newicon"),
+		bMouseOnDiv: false,
+	});
 // ]]></script>';
 }
 

+ 1 - 1
Themes/default/scripts/jquery.sceditor.js

@@ -3480,7 +3480,7 @@
 				if (popup_exists)
 				{
 					this.options.emoticons.more = this.options.emoticons.popup;
-					moreButton = $('<div class="sceditor-more-button" />').attr({class: "sceditor-more"}).text('[' + this._('More') + ']').click(function () {
+					moreButton = $('<div class="sceditor-more-button" />').attr({'class': "sceditor-more"}).text('[' + this._('More') + ']').click(function () {
 						if ($(".sceditor-smileyPopup").length > 0)
 						{
 							$(".sceditor-smileyPopup").fadeIn('fast');

+ 2 - 4
Themes/default/scripts/script.js

@@ -1196,11 +1196,9 @@ IconList.prototype.openPopup = function (oDiv, iMessageId)
 		this.oContainerDiv.style.display = 'none';
 		this.oContainerDiv.style.cursor = 'pointer';
 		this.oContainerDiv.style.position = 'absolute';
-		this.oContainerDiv.style.width = oDiv.offsetWidth + 'px';
 		this.oContainerDiv.style.background = this.opt.sContainerBackground;
 		this.oContainerDiv.style.border = this.opt.sContainerBorder;
-		this.oContainerDiv.style.padding = '1px';
-		this.oContainerDiv.style.textAlign = 'center';
+		this.oContainerDiv.style.padding = '6px 0px';
 		document.body.appendChild(this.oContainerDiv);
 
 		// Start to fetch its contents.
@@ -1230,7 +1228,7 @@ IconList.prototype.onIconsReceived = function (oXMLDoc)
 	var sItems = '';
 
 	for (var i = 0, n = icons.length; i < n; i++)
-		sItems += '<div onmouseover="' + this.opt.sBackReference + '.onItemHover(this, true)" onmouseout="' + this.opt.sBackReference + '.onItemHover(this, false);" onmousedown="' + this.opt.sBackReference + '.onItemMouseDown(this, \'' + icons[i].getAttribute('value') + '\');" style="padding: 3px 0px 3px 0px; margin-left: auto; margin-right: auto; border: ' + this.opt.sItemBorder + '; background: ' + this.opt.sItemBackground + '"><img src="' + icons[i].getAttribute('url') + '" alt="' + icons[i].getAttribute('name') + '" title="' + icons[i].firstChild.nodeValue + '" /></div>';
+		sItems += '<span onmouseover="' + this.opt.sBackReference + '.onItemHover(this, true)" onmouseout="' + this.opt.sBackReference + '.onItemHover(this, false);" onmousedown="' + this.opt.sBackReference + '.onItemMouseDown(this, \'' + icons[i].getAttribute('value') + '\');" style="padding: 2px 3px; line-height: 20px; border: ' + this.opt.sItemBorder + '; background: ' + this.opt.sItemBackground + '"><img src="' + icons[i].getAttribute('url') + '" alt="' + icons[i].getAttribute('name') + '" title="' + icons[i].firstChild.nodeValue + '" style="vertical-align: middle" /></span>';
 
 	setInnerHTML(this.oContainerDiv, sItems);
 	this.oContainerDiv.style.display = 'block';

+ 5 - 5
Themes/default/scripts/smf_jquery_plugins.js

@@ -137,18 +137,18 @@
 					$('body').append('<div id="' + oSettings.tooltipID + '" class="' + oSettings.tooltipClass + '"><div id="' + oSettings.tooltipTextID + '" style="display:none;"></div></div>');
 					
 					// load information in to our newly created div
-					var $tt = $('#' + oSettings.tooltipID);
-					var $ttContent = $('#' + oSettings.tooltipID + ' #' + oSettings.tooltipTextID);
+					var tt = $('#' + oSettings.tooltipID);
+					var ttContent = $('#' + oSettings.tooltipID + ' #' + oSettings.tooltipTextID);
 					
 					if (oSettings.tooltipContent == 'html')
-						$ttContent.html($(this).children('.' + oSettings.tooltipSwapClass).html());
+						ttContent.html($(this).children('.' + oSettings.tooltipSwapClass).html());
 					else
-						$ttContent.text($(this).children('.' + oSettings.tooltipSwapClass).text());
+						ttContent.text($(this).children('.' + oSettings.tooltipSwapClass).text());
 					
 					oSettings.tooltipContent
 					
 					// show then position or it may postion off screen
-					$tt.show();
+					tt.show();
 					showTooltip();
 					positionTooltip(event);
 				}

+ 158 - 83
Themes/default/scripts/topic.js

@@ -1,66 +1,134 @@
-var cur_topic_id, cur_msg_id, buff_subject, cur_subject_div, in_edit_mode = 0;
-var hide_prefixes = Array();
+// *** QuickModifyTopic object.
+function QuickModifyTopic(oOptions)
+{
+	this.opt = oOptions;
+	this.aHidePrefixes = this.opt.aHidePrefixes;
+	this.iCurTopicId = 0;
+	this.sCurMessageId = '';
+	this.sBuffSubject = '';
+	this.oCurSubjectDiv = null;
+	this.oTopicModHandle = document;
+	this.bInEditMode = false;
+	this.bMouseOnDiv = false;
+	this.bXmlHttpCapable = this.isXmlHttpCapable();
+	this.init();
+}
 
-function modify_topic(topic_id, first_msg_id)
+// @todo Determine if this is even needed anymore opera meh
+// Ajax supported?
+QuickModifyTopic.prototype.isXmlHttpCapable = function ()
 {
-	if (!('XMLHttpRequest' in window))
-		return;
+	if (typeof(window.XMLHttpRequest) == 'undefined')
+		return false;
 
+	// Opera didn't always support POST requests. So test it first.
 	if ('opera' in window)
 	{
 		var oTest = new XMLHttpRequest();
 		if (!('setRequestHeader' in oTest))
-			return;
+			return false;
 	}
 
+	return true;
+}
+
+// Used to initialise the object event handlers
+QuickModifyTopic.prototype.init = function ()
+{
+	// Attach some events to it so we can respond to actions
+	this.oTopicModHandle.instanceRef = this;
+
+	// detect and act on keypress
+	this.oTopicModHandle.onkeydown = function (oEvent) {return this.instanceRef.modify_topic_keypress(oEvent);};
+
+	// Used to detect when we've stopped editing.
+	this.oTopicModHandle.onclick = function (oEvent) {return this.instanceRef.modify_topic_click(oEvent);};
+}
+
+// called from the double click in the div
+QuickModifyTopic.prototype.modify_topic = function (topic_id, first_msg_id)
+{
 	// Add backwards compatibility with old themes.
 	if (typeof(cur_session_var) == 'undefined')
 		cur_session_var = 'sesc';
 
-	if (in_edit_mode == 1)
+	// already editing
+	if (this.bInEditMode)
 	{
-		if (cur_topic_id == topic_id)
+		// same message then just return, otherwise drop out of this edit.
+		if (this.iCurTopicId == topic_id)
 			return;
 		else
-			modify_topic_cancel();
+			this.modify_topic_cancel();
 	}
 
-	in_edit_mode = 1;
-	mouse_on_div = 1;
-	cur_topic_id = topic_id;
+	this.bInEditMode = true;
+	this.bMouseOnDiv = true;
+	this.iCurTopicId = topic_id;
 
-	if (typeof window.ajax_indicator == "function")
-		ajax_indicator(true);
-	getXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "action=quotefast;quote=" + first_msg_id + ";modify;xml", onDocReceived_modify_topic);
+	// Get the topics current subject 
+	ajax_indicator(true);
+	sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=quotefast;quote=" + first_msg_id + ";modify;xml", '', this.onDocReceived_modify_topic);
 }
 
-function onDocReceived_modify_topic(XMLDoc)
+// callback function from the modify_topic ajax call
+QuickModifyTopic.prototype.onDocReceived_modify_topic = function (XMLDoc)
 {
-	cur_msg_id = XMLDoc.getElementsByTagName("message")[0].getAttribute("id");
+	// If it is not valid then clean up
+	if (!XMLDoc || !XMLDoc.getElementsByTagName('message'))
+	{
+		this.modify_topic_cancel();
+		return true;
+	}
+	
+	this.sCurMessageId = XMLDoc.getElementsByTagName("message")[0].getAttribute("id");
+	this.oCurSubjectDiv = document.getElementById('msg_' + this.sCurMessageId.substr(4));
+	this.sBuffSubject = getInnerHTML(this.oCurSubjectDiv);
 
-	cur_subject_div = document.getElementById('msg_' + cur_msg_id.substr(4));
-	buff_subject = getInnerHTML(cur_subject_div);
+	// Here we hide any other things they want hidden on edit.
+	this.set_hidden_topic_areas('none');
 
-	// Here we hide any other things they want hiding on edit.
-	set_hidden_topic_areas('none');
+	// Show we are in edit mode and allow the edit
+	ajax_indicator(false);
+	this.modify_topic_show_edit(XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue);
+}
 
-	modify_topic_show_edit(XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue);
-	if (typeof window.ajax_indicator == "function")
-		ajax_indicator(false);
+// Cancel out of an edit and return things to back to what they were
+QuickModifyTopic.prototype.modify_topic_cancel = function ()
+{
+	setInnerHTML(this.oCurSubjectDiv, this.sBuffSubject);
+	this.set_hidden_topic_areas('');
+	this.bInEditMode = false;
+	
+	return false;
 }
 
-function modify_topic_cancel()
+// Simply restore/show any hidden bits during topic editing.
+QuickModifyTopic.prototype.set_hidden_topic_areas = function (set_style)
 {
-	setInnerHTML(cur_subject_div, buff_subject);
-	set_hidden_topic_areas('');
+	for (var i = 0; i < this.aHidePrefixes.length; i++)
+	{
+		if (document.getElementById(this.aHidePrefixes[i] + this.sCurMessageId.substr(4)) != null)
+			document.getElementById(this.aHidePrefixes[i] + this.sCurMessageId.substr(4)).style.display = set_style;
+	}
+}
 
-	in_edit_mode = 0;
-	return false;
+// For templating, shown that an inline edit is being made.
+QuickModifyTopic.prototype.modify_topic_show_edit = function (subject)
+{
+	// Just template the subject.
+	setInnerHTML(this.oCurSubjectDiv, '<input type="text" name="subject" value="' + subject + '" size="60" style="width: 95%;" maxlength="80" class="input_text" /><input type="hidden" name="topic" value="' + this.iCurTopicId + '" /><input type="hidden" name="msg" value="' + this.sCurMessageId.substr(4) + '" />');
+	
+	// attach mouse over and out events to this new div
+	this.oCurSubjectDiv.instanceRef = this;
+	this.oCurSubjectDiv.onmouseout = function (oEvent) {return this.instanceRef.modify_topic_mouseout(oEvent);};
+	this.oCurSubjectDiv.onmouseover = function (oEvent) {return this.instanceRef.modify_topic_mouseover(oEvent);};
 }
 
-function modify_topic_save(cur_session_id, cur_session_var)
+// Yup thats right, save it
+QuickModifyTopic.prototype.modify_topic_save = function (cur_session_id, cur_session_var)
 {
-	if (!in_edit_mode)
+	if (!this.bInEditMode)
 		return true;
 
 	// Add backwards compatibility with old themes.
@@ -72,18 +140,22 @@ function modify_topic_save(cur_session_id, cur_session_var)
 	x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value);
 	x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value);
 
-	if (typeof window.ajax_indicator == "function")
-		ajax_indicator(true);
-	sendXMLDocument(smf_prepareScriptUrl(smf_scripturl) + "action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements['topic'].value) + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), modify_topic_done);
+	// send in the call to save the updated topic subject
+	ajax_indicator(true);
+	sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements['topic'].value) + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), this.modify_topic_done);
 
 	return false;
 }
 
-function modify_topic_done(XMLDoc)
+// done with the edit, if all went well show the new topic title
+QuickModifyTopic.prototype.modify_topic_done = function (XMLDoc)
 {
-	if (!XMLDoc)
+	ajax_indicator(false);
+	
+	// If it is not valid then clean up
+	if (!XMLDoc || !XMLDoc.getElementsByTagName('subject'))
 	{
-		modify_topic_cancel();
+		this.modify_topic_cancel();
 		return true;
 	}
 
@@ -91,33 +163,68 @@ function modify_topic_done(XMLDoc)
 	var subject = message.getElementsByTagName("subject")[0];
 	var error = message.getElementsByTagName("error")[0];
 
-	if (typeof window.ajax_indicator == "function")
-		ajax_indicator(false);
+	// No subject or other error>
 
 	if (!subject || error)
 		return false;
 
-	subjectText = subject.childNodes[0].nodeValue;
-
-	modify_topic_hide_edit(subjectText);
-
-	set_hidden_topic_areas('');
-
-	in_edit_mode = 0;
+	this.modify_topic_hide_edit(subject.childNodes[0].nodeValue);
+	this.set_hidden_topic_areas('');
+	this.bInEditMode = false;
 
 	return false;
 }
 
-// Simply restore any hidden bits during topic editing.
-function set_hidden_topic_areas(set_style)
+// Done with the edit, put in new subject and link.
+QuickModifyTopic.prototype.modify_topic_hide_edit = function (subject)
+{
+	// Re-template the subject!
+	setInnerHTML(this.oCurSubjectDiv, '<a href="' + smf_scripturl + '?topic=' + this.iCurTopicId + '.0">' + subject + '<' +'/a>');
+}
+
+// keypress event ... like enter or escape
+QuickModifyTopic.prototype.modify_topic_keypress = function (oEvent)
 {
-	for (var i = 0; i < hide_prefixes.length; i++)
+	if (typeof(oEvent.keyCode) != "undefined")
 	{
-		if (document.getElementById(hide_prefixes[i] + cur_msg_id.substr(4)) != null)
-			document.getElementById(hide_prefixes[i] + cur_msg_id.substr(4)).style.display = set_style;
+		if (oEvent.keyCode == 27)
+		{
+			this.modify_topic_cancel();
+			if (typeof(oEvent.preventDefault) == "undefined")
+				oEvent.returnValue = false;
+			else
+				oEvent.preventDefault();
+		}
+		else if (oEvent.keyCode == 13)
+		{
+			this.modify_topic_save(smf_session_id, smf_session_var);
+			if (typeof(oEvent.preventDefault) == "undefined")
+				oEvent.returnValue = false;
+			else
+				oEvent.preventDefault();
+		}
 	}
 }
 
+// A click event to signal the finish of the edit 
+QuickModifyTopic.prototype.modify_topic_click = function (oEvent)
+{
+	if (this.bInEditMode && !this.bMouseOnDiv)
+		this.modify_topic_save(smf_session_id, smf_session_var);
+}
+
+// Moved out of the editing div
+QuickModifyTopic.prototype.modify_topic_mouseout = function (oEvent)
+{
+	this.bMouseOnDiv = false;
+}
+
+// Moved back over the editing div
+QuickModifyTopic.prototype.modify_topic_mouseover = function (oEvent)
+{
+	this.bMouseOnDiv = true;
+}
+
 // *** QuickReply object.
 function QuickReply(oOptions)
 {
@@ -628,38 +735,6 @@ function expandThumb(thumbID)
 	return false;
 }
 
-// For templating, shown when an inline edit is made.
-function modify_topic_show_edit(subject)
-{
-	// Just template the subject.
-	setInnerHTML(cur_subject_div, '<input type="text" name="subject" value="' + subject + '" size="60" style="width: 95%;" maxlength="80" onkeypress="modify_topic_keypress(event)" class="input_text" /><input type="hidden" name="topic" value="' + cur_topic_id + '" /><input type="hidden" name="msg" value="' + cur_msg_id.substr(4) + '" />');
-}
-
-function modify_topic_click()
-{
-	if (in_edit_mode == 1 && mouse_on_div == 0)
-		modify_topic_save(smf_sesion_id, smf_session_var);
-}
-
-function modify_topic_keypress(oEvent)
-{
-	if (typeof(oEvent.keyCode) != "undefined" && oEvent.keyCode == 13)
-	{
-		modify_topic_save(smf_sesion_id, smf_session_var);
-		if (typeof(oEvent.preventDefault) == "undefined")
-			oEvent.returnValue = false;
-		else
-			oEvent.preventDefault();
-	}
-}
-
-// And the reverse for hiding it.
-function modify_topic_hide_edit(subject)
-{
-	// Re-template the subject!
-	setInnerHTML(cur_subject_div, '<a href="' + smf_scripturl + '?topic=' + cur_topic_id + '.0">' + subject + '<' +'/a>');
-}
-
 function ignore_toggles(msgids, text)
 {
 	for (i = 0; i < msgids.length; i++)