zamtools avatar zamtools committed 55fc136

It is now possible to set question IDs in classes

Comments (0)

Files changed (3)

         <p>This question is using the default width and is only displaying its accepted answer using a per-question override.</p>
         <div id="stacktack-1227286" class="onlyShowAcceptedAnswer-true"></div>
 
+        <p>This question is using a class-based stacktack ID and is only displaying its accepted answer using the per-question override.</p>
+        <div class="stacktack-1227286 onlyShowAcceptedAnswer-true"></div>
+
         <p>This question is in a JQueryUI modal dialog.  It currently has no theme, but can be closed and dragged around the browser window.</p>
         <div id="stacktack-1701543" class="width-100percent onlyShowAcceptedAnswer-true modal-dialog"></div>
     </body>

jquery.stacktack.js

         
         return this.each(function() {
             var $this = $(this);
-            $this.filter('[id^=stacktack]').add($this.find('[id^=stacktack]')).each(function(index, value) {
+            $this.filter('[id^=stacktack], [class^=stacktack]').add($this.find('[id^=stacktack], [class^=stacktack]')).each(function(index, value) {
                 var item = $(value);
-                var questionId = /\d+$/.exec(value.id);
+                // try to retrieve the question id from the id attribute
+                var questionId = '';
+                if (value.id) {
+                    var matches = /\d+$/.exec(value.id);
+                    if (matches.length > 0) {
+                        questionId = matches[0];
+                    }
+                }
 
                 // parse override options from classes
                 var itemOptions = $.extend({}, options);
                         // if there was a split
                         if (classTokens.length > 1)
                         {
+                            // search for a stacktack id class and use if it if the questionId hasn't been set yet
+                            if (classTokens[0].toLowerCase() == 'stacktack') {
+                                questionId = classTokens[1];
+                                continue;
+                            }
+                            
                             // convert special value strings
                             for (var j = 1; j < classTokens.length; j++)
                             {
                         'answers': 'true',
                         'body': 'true'
                     },
-                    url: 'http://api.' + options.site + '/' + options.apiVersion + '/questions/' + questionId[0] + '?jsonp=?',
+                    url: 'http://api.' + options.site + '/' + options.apiVersion + '/questions/' + questionId + '?jsonp=?',
                     success: function(data) {
                         loadingElement.remove();
                         

jquery.stacktack.min.js

-(function(a){a.fn.stacktack=function(d){var b=a.extend(a.fn.stacktack.defaults,d);var e=["width","onlyshowacceptedanswer","answerlimit","filteranswers","showtags"];if(b.stylesheet){if(a("link[href="+b.stylesheet+"]").length===0){if(document.createStyleSheet){document.createStyleSheet(b.stylesheet)}else{a('<link rel="stylesheet" type="text/css" href="'+b.stylesheet+'" />').appendTo("head")}}}function c(f){return'<div class="stacktack-profile"><img src="http://www.gravatar.com/avatar/'+f.email_hash+'?d=identicon&s=32" class="stacktack-gravatar" /><a href="http://www.'+b.site+"/users/"+f.user_id+'" target="_blank">'+f.display_name+"</a><br/>"+f.reputation+"</div>"}return this.each(function(){var f=a(this);f.filter("[id^=stacktack]").add(f.find("[id^=stacktack]")).each(function(l,o){var p=a(o);var g=/\d+$/.exec(o.id);var r=a.extend({},b);if(p.attr("class").length){classes=p.attr("class").split(" ");for(var k=0;k<classes.length;k++){clas=classes[k];classTokens=clas.split("-");if(classTokens.length>1){for(var h=1;h<classTokens.length;h++){classToken=classTokens[h].toLowerCase();if(classToken==="true"||classToken==="false"){classTokens[h]==Boolean(classToken);continue}classTokens[h]=classToken.replace(/percent/i,"%")}if(a.inArray(classTokens[0].toLowerCase(),e)>-1){if(classTokens.length>2||classTokens[0].toLowerCase()=="filteranswers"){r[classTokens[0]]=classTokens.slice(1)}else{r[classTokens[0]]=classTokens[1]}}}}}var q=a('<div class="stacktack-container"></div>');if(r.width){q.css("width",r.width)}var n=a('<div class="stacktack-content"><a href="http://www.stacktack.com/" target="_blank" title="StackTack" class="stacktack-logo"><h2>StackTack</h2></a></div>');q.append(n);var m=a('<p class="stacktack-loading">Loading Question ID '+g+"</p>");n.append(m);a.ajax({dataType:"jsonp",data:{apikey:"kz4oNmbazUGoJIUyUbSaLg",answers:"true",body:"true"},url:"http://api."+b.site+"/"+b.apiVersion+"/questions/"+g[0]+"?jsonp=?",success:function(z){m.remove();var v=z.questions[0];var x=a('<div class="stacktack-question"> <div class="stacktack-question-header clearfix">'+c(v.owner)+'<h3><a href="http://www.'+b.site+"/questions/"+v.question_id+'" target="_blank">'+v.title+'</a></h3><div class="stacktack-votes">'+v.score+' Votes</div></div><div class="stacktack-question-body">'+v.body+"</div></div>");n.append(x);if(r.showTags){var w=a('<ul class="stacktack-tags"></ul>');for(var A=0;A<v.tags.length;A++){var s=a("<li>"+v.tags[A]+"</li>");w.append(s)}x.append(w)}var y=a('<div class="stacktack-answers"></div>');n.append(y);var j=[];if(v.answers.length>0){if(r.onlyShowAcceptedAnswer){for(var A=0;A<v.answers.length;A++){if(v.answers[A].accepted){j.push(A)}}}else{if(r.filterAnswers.length>0){for(var A=0;A<v.answers.length;A++){if(a.inArray(v.answers[A].answer_id.toString(),r.filterAnswers)>-1){j.push(A)}}}else{if(r.answerLimit>0){for(var A=0;A<r.answerLimit;A++){j.push(A)}}}}}for(var A=0;A<v.answers.length;A++){var B=v.answers[A];var u=a('<div class="stacktack-answer"><div class="stacktack-answer-header clearfix">'+c(B.owner)+'<h4><a href="http://www.'+b.site+"/questions/"+v.question_id+"#"+B.answer_id+'" target="_blank">Answer '+(A+1)+'</a></h4><div class="stacktack-votes">'+B.score+' Votes</div></div><div class="stacktack-answer-body">'+B.body+"</div></div>");if(B.accepted){u.addClass("stacktack-answer-accepted");u.find(".stacktack-answer-header h4").prepend('<span alt="Accepted" title="Accepted" class="stacktack-answer-check"></span>');u.find(".stacktack-votes").append(" | Accepted")}if(j.length>0){if(a.inArray(A,j)==-1){u.hide()}}y.append(u)}q.find("a").attr("target","_blank");if(j.length>0){var t=a('<a href="#" class="stacktack-answers-more">+ More Answers</a>"');t.click(function(){a(this).hide();y.find(".stacktack-answer:hidden").slideDown("fast");return false});y.append(t)}}});p.append(q)})})};a.fn.stacktack.defaults={site:"stackoverflow.com",apiVersion:"1.0",stylesheet:"http://app.stacktack.com/stacktack.min.css",answerLimit:0,onlyShowAcceptedAnswer:false,filterAnswers:[],showTags:true,width:null}})(jQuery);
+(function(a){a.fn.stacktack=function(d){var b=a.extend(a.fn.stacktack.defaults,d);var e=["width","onlyshowacceptedanswer","answerlimit","filteranswers","showtags"];if(b.stylesheet){if(a("link[href="+b.stylesheet+"]").length===0){if(document.createStyleSheet){document.createStyleSheet(b.stylesheet)}else{a('<link rel="stylesheet" type="text/css" href="'+b.stylesheet+'" />').appendTo("head")}}}function c(f){return'<div class="stacktack-profile"><img src="http://www.gravatar.com/avatar/'+f.email_hash+'?d=identicon&s=32" class="stacktack-gravatar" /><a href="http://www.'+b.site+"/users/"+f.user_id+'" target="_blank">'+f.display_name+"</a><br/>"+f.reputation+"</div>"}return this.each(function(){var f=a(this);f.filter("[id^=stacktack], [class^=stacktack]").add(f.find("[id^=stacktack], [class^=stacktack]")).each(function(m,p){var q=a(p);var g="";if(p.id){var l=/\d+$/.exec(p.id);if(l.length>0){g=l[0]}}var s=a.extend({},b);if(q.attr("class").length){classes=q.attr("class").split(" ");for(var k=0;k<classes.length;k++){clas=classes[k];classTokens=clas.split("-");if(classTokens.length>1){if(classTokens[0].toLowerCase()=="stacktack"){g=classTokens[1];continue}for(var h=1;h<classTokens.length;h++){classToken=classTokens[h].toLowerCase();if(classToken==="true"||classToken==="false"){classTokens[h]==Boolean(classToken);continue}classTokens[h]=classToken.replace(/percent/i,"%")}if(a.inArray(classTokens[0].toLowerCase(),e)>-1){if(classTokens.length>2||classTokens[0].toLowerCase()=="filteranswers"){s[classTokens[0]]=classTokens.slice(1)}else{s[classTokens[0]]=classTokens[1]}}}}}var r=a('<div class="stacktack-container"></div>');if(s.width){r.css("width",s.width)}var o=a('<div class="stacktack-content"><a href="http://www.stacktack.com/" target="_blank" title="StackTack" class="stacktack-logo"><h2>StackTack</h2></a></div>');r.append(o);var n=a('<p class="stacktack-loading">Loading Question ID '+g+"</p>");o.append(n);a.ajax({dataType:"jsonp",data:{apikey:"kz4oNmbazUGoJIUyUbSaLg",answers:"true",body:"true"},url:"http://api."+b.site+"/"+b.apiVersion+"/questions/"+g+"?jsonp=?",success:function(A){n.remove();var w=A.questions[0];var y=a('<div class="stacktack-question"> <div class="stacktack-question-header clearfix">'+c(w.owner)+'<h3><a href="http://www.'+b.site+"/questions/"+w.question_id+'" target="_blank">'+w.title+'</a></h3><div class="stacktack-votes">'+w.score+' Votes</div></div><div class="stacktack-question-body">'+w.body+"</div></div>");o.append(y);if(s.showTags){var x=a('<ul class="stacktack-tags"></ul>');for(var B=0;B<w.tags.length;B++){var t=a("<li>"+w.tags[B]+"</li>");x.append(t)}y.append(x)}var z=a('<div class="stacktack-answers"></div>');o.append(z);var j=[];if(w.answers.length>0){if(s.onlyShowAcceptedAnswer){for(var B=0;B<w.answers.length;B++){if(w.answers[B].accepted){j.push(B)}}}else{if(s.filterAnswers.length>0){for(var B=0;B<w.answers.length;B++){if(a.inArray(w.answers[B].answer_id.toString(),s.filterAnswers)>-1){j.push(B)}}}else{if(s.answerLimit>0){for(var B=0;B<s.answerLimit;B++){j.push(B)}}}}}for(var B=0;B<w.answers.length;B++){var C=w.answers[B];var v=a('<div class="stacktack-answer"><div class="stacktack-answer-header clearfix">'+c(C.owner)+'<h4><a href="http://www.'+b.site+"/questions/"+w.question_id+"#"+C.answer_id+'" target="_blank">Answer '+(B+1)+'</a></h4><div class="stacktack-votes">'+C.score+' Votes</div></div><div class="stacktack-answer-body">'+C.body+"</div></div>");if(C.accepted){v.addClass("stacktack-answer-accepted");v.find(".stacktack-answer-header h4").prepend('<span alt="Accepted" title="Accepted" class="stacktack-answer-check"></span>');v.find(".stacktack-votes").append(" | Accepted")}if(j.length>0){if(a.inArray(B,j)==-1){v.hide()}}z.append(v)}r.find("a").attr("target","_blank");if(j.length>0){var u=a('<a href="#" class="stacktack-answers-more">+ More Answers</a>"');u.click(function(){a(this).hide();z.find(".stacktack-answer:hidden").slideDown("fast");return false});z.append(u)}}});q.append(r)})})};a.fn.stacktack.defaults={site:"stackoverflow.com",apiVersion:"1.0",stylesheet:"http://app.stacktack.com/stacktack.min.css",answerLimit:0,onlyShowAcceptedAnswer:false,filterAnswers:[],showTags:true,width:null}})(jQuery);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.