Skip to content

Commit

Permalink
move autocomplete actions into callbackParams
Browse files Browse the repository at this point in the history
  • Loading branch information
scc committed Jan 30, 2007
1 parent 1e3d27c commit d007348
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 43 deletions.
36 changes: 30 additions & 6 deletions plugins/Ajax/htdocs/images/common.js
Expand Up @@ -264,23 +264,47 @@ function tagsOpenAndEnter(id, tagname, is_admin, type) {
tagsShowBody(id, is_admin, tagname, type);
}

function attachCompleter( obj, id, is_admin, type, tagDomain ) {
function completer_renameMenu( s, params ) {
if ( s )
params._sourceEl.innerHTML = s;
}

function completer_setTag( s, params ) {
createTag(s, params._id, params._type);
var tagField = document.getElementById('newtags-'+params._id);
if ( tagField ) {
var s = tagField.value.slice(-1);
if ( s.length && s != " " )
tagField.value += " ";
tagField.value += s;
}
}

function completer_handleNeverDisplay( s, params ) {
if ( s == "neverdisplay" )
admin_neverdisplay("", "firehose", params._id);
}

function attachCompleter( obj, id, is_admin, type, tagDomain, customize ) {
if ( YAHOO.util.Dom.isSafari )
return false;

var disable = YAHOO.util.Dom.getStyle(obj, '-slashdot-disable-tag-completer');
if ( disable == "true" )
return false;

var callbackParams = new Object();
callbackParams._id = id;
callbackParams._is_admin = is_admin;
callbackParams._type = type;
if ( customize === undefined )
customize = new Object();
customize._id = id;
customize._is_admin = is_admin;
customize._type = type;
if ( tagDomain != 0 && customize.queryOnAttach === undefined )
customize.queryOnAttach = true;

if ( !YAHOO.slashdot.gCompleterWidget )
YAHOO.slashdot.gCompleterWidget = new YAHOO.slashdot.AutoCompleteWidget();

YAHOO.slashdot.gCompleterWidget.attach(obj, callbackParams, tagDomain);
YAHOO.slashdot.gCompleterWidget.attach(obj, customize, tagDomain);
return false;
}

Expand Down
42 changes: 9 additions & 33 deletions plugins/Ajax/htdocs/images/sd_autocomplete.js
Expand Up @@ -302,7 +302,6 @@ YAHOO.slashdot.storyOpts = [

YAHOO.slashdot.dataSources = [tagsDS, actionsDS, sectionsDS, topicsDS, feedbackDS, storyDS, fhitemDS, fhtabsDS ];


YAHOO.slashdot.AutoCompleteWidget = function()
{
this._widget = document.getElementById("ac-select-widget");
Expand Down Expand Up @@ -364,6 +363,11 @@ YAHOO.slashdot.AutoCompleteWidget.prototype._show = function( obj, callbackParam
this._callbackParams = callbackParams;
this._callbackParams._tagDomain = tagDomain;
this._completer = this._newCompleter(tagDomain);

if ( typeof callbackParams.yui == "object" )
for ( var field in callbackParams.yui )
this._completer[field] = callbackParams.yui[field];


// widget must be visible to move
YAHOO.util.Dom.removeClass(this._widget, "hidden");
Expand Down Expand Up @@ -427,10 +431,10 @@ YAHOO.slashdot.AutoCompleteWidget.prototype.attach = function( obj, callbackPara

if ( newSourceEl )
{
callbackParams._sourceEl = newSourceEl;
this._show(newSourceEl, callbackParams, tagDomain);
if ( tagDomain != 0 )
if ( callbackParams.queryOnAttach )
this._completer.sendQuery("");

}
}

Expand All @@ -447,37 +451,9 @@ YAHOO.slashdot.AutoCompleteWidget.prototype._onItemSelectEvent = function( type,
{
var tagname = args[2];
var p = me._callbackParams;

// only change the 'menu' title when that title is a tag you are replacing
if ( tagname && me._needsSpareInput() && (p._tagDomain < 4 && p.TagDomain > 6) )
{
me._sourceEl.innerHTML = tagname;
}
if ( p.action0 !== undefined ) p.action0(tagname, p);
me._hide();

// really need to move this into a separate function...
// at least when there is more than just p._type=='firehose'
if ( p._tagDomain != 0 && p._tagDomain != 5 && p._tagDomain !=7 )
{
// save the new tag immediately
createTag(tagname, p._id, p._type);

// and if the user tags field exists, add it there (but don't show or hide the field)
var tagField = document.getElementById('newtags-' + p._id);
if ( tagField )
{
var s = tagField.value.slice(-1);
if ( s.length && s != " " )
tagField.value += " ";
tagField.value += tagname;
}
}

if (p._tagDomain == 5) {
if(tagname == "neverdisplay") {
admin_neverdisplay("", "firehose", p._id);
}
}
if ( p.action1 !== undefined ) p.action1(tagname, p);
}

YAHOO.slashdot.AutoCompleteWidget.prototype._onTextboxBlurEvent = function( type, args, me )
Expand Down
2 changes: 1 addition & 1 deletion plugins/FireHose/templates/firehose_tabs;misc;default
Expand Up @@ -17,7 +17,7 @@ __template__
[% UNLESS nodiv %]<ul class="menu" id="fhtablist">[% END %]
[% FOREACH tab = tabs %]
<li id="fhtab-[% tab.tabid %]"[% IF tab.active %] class="active"[% END %]>
[% IF tab.active %]<span id="tab-form-[% tab.tabid %]" class="hide"><input type="text" onfocus="attachCompleter(this, '[% tab.tabid %]', '[% user.is_admin && !user.firehose_usermode %]','firehosetab', '7')" id="tab-input-[% tab.tabid %]" size=12" value="[% tab.tabname | strip_literal %]" onkeyup="handleEnter(event, firehose_save_tab, '[% tab.tabid %]')"></span>[% END %]
[% IF tab.active %]<span id="tab-form-[% tab.tabid %]" class="hide"><input type="text" onfocus="attachCompleter(this, '[% tab.tabid %]', '[% user.is_admin && !user.firehose_usermode %]','firehosetab', 7)" id="tab-input-[% tab.tabid %]" size=12" value="[% tab.tabname | strip_literal %]" onkeyup="handleEnter(event, firehose_save_tab, '[% tab.tabid %]')"></span>[% END %]
<a href="[% IF tab.active %]#[% ELSE %]?tab=[% tab.tabname | strip_attribute %][% END %]" id="tab-text-[% tab.tabid %]"[% IF tab.active %] onClick="firehose_open_tab('[% tab.tabid %]'); return false;"[% END %]>[% tab.tabname | strip_literal %]</a> [% IF tab.active && tab.tabname != "untitled" %]<span id="fhtabdel"><a href="#" onclick="firehose_remove_tab([% tab.tabid %])">[X]</a></span>[% END %]</li>
[% END %]
[% UNLESS nodiv %]</ul>[% END %]
Expand Down
2 changes: 1 addition & 1 deletion plugins/FireHose/templates/firehose_tags_top;misc;default
Expand Up @@ -16,7 +16,7 @@ __template__
parts = t.split(":");
is_menu = user.tags_canwrite_stories && parts.1.defined && parts.1;
is_link = !is_menu && parts.1.defined && !parts.1; %]
<span class="tagname">[%- IF is_menu -%]<span class="tagmenu"><a onClick="attachCompleter(this, '[% id %]','[% user.is_admin && !user.firehose_usermode %]','firehose', [% parts.1 %])">[%- ELSIF is_link -%]<a href="/tags/[% parts.0 | strip_html %]">[%- END -%][%- parts.0 | strip_html -%][%- IF is_menu || is_link %]</a>[% END -%][%- IF is_menu %]</span>[% END -%]</span>[% IF !loop.last() %],
<span class="tagname">[%- IF is_menu -%]<span class="tagmenu"><a onClick="attachCompleter(this, '[% id %]','[% user.is_admin && !user.firehose_usermode %]','firehose', [% parts.1 %], {action0:completer_renameMenu})">[%- ELSIF is_link -%]<a href="/tags/[% parts.0 | strip_html %]">[%- END -%][%- parts.0 | strip_html -%][%- IF is_menu || is_link %]</a>[% END -%][%- IF is_menu %]</span>[% END -%]</span>[% IF !loop.last() %],
[% END -%]
[%- END %]
[% IF item.type == "story" %][% IF user.is_admin %][% PROCESS signoff stoid=item.srcid fhid = item.id %] [% PROCESS neverdisplay stoid=item.srcid fhid=item.id %][% END %][% END %]
Expand Down
Expand Up @@ -20,7 +20,7 @@ __template__
<span id="tags-top-[% id %]">
[% PROCESS firehose_tags_top id = id tags_top = tags_top -%]
</span>
[%- IF user.tags_canwrite_stories && (user.firehose_usermode || !user.is_admin) %], <span class="tagmenu"><a onClick="attachCompleter(this,'[% id %]','[% user.is_admin && !user.firehose_usermode %]','firehose', 4)">feedback</a></span>[% END %]
[%- IF user.tags_canwrite_stories && (user.firehose_usermode || !user.is_admin) %], <span class="tagmenu"><a onClick="attachCompleter(this,'[% id %]','[% user.is_admin && !user.firehose_usermode %]','firehose', 4, {action1:completer_setTag})">feedback</a></span>[% END %]
<i>([% IF user.is_admin && !user.firehose_usermode -%]<span id="note-form-[% item.id %]" class="hide"><input type="text" id="note-input-[% item.id %]" value="[% item.note | strip_attribute %]" size="30" onkeyup="handleEnter(event, firehose_save_note, '[% id %]')"> <input type="button" value="note" onclick="firehose_save_note('[% item.id %]')"></span><a id="note-text-[% item.id %]" onclick="firehose_open_note('[% item.id %]')">[% IF !item.note %]Note[% END %][% item.note | strip_literal %]</a>
[%- ELSE -%]<a href="/faq/tags.shtml">tagging beta</a>
[%- END -%])</i>
Expand Down
2 changes: 1 addition & 1 deletion plugins/Tags/templates/tagsstorydivtagbox;misc;default
Expand Up @@ -23,7 +23,7 @@ __template__
<span class="tagname"><a href="/tags/[% t | strip_html %]">[% t | strip_html %]</a></span>[% IF !loop.last() || story.is_future %], [% END -%]
[%- END %]
[%- END %]
[%- IF user.tags_canwrite_stories && story.is_future %]<span class="tagmenu"><a onClick="attachCompleter(this, '[% sidenc %]','[% user.is_admin %]','stories', 4)">feedback</a></span>[% END %]
[%- IF user.tags_canwrite_stories && story.is_future %]<span class="tagmenu"><a onClick="attachCompleter(this, '[% sidenc %]','[% user.is_admin %]','stories', 4, {action1:completer_setTag})">feedback</a></span>[% END %]
<i>(<a href="/faq/tags.shtml">tagging beta</a>)</i>
</div>

Expand Down

0 comments on commit d007348

Please sign in to comment.