Jeremy Newman : rewrite javascript handlers for jquery, and merge files, cleanup

Jeremy Newman jnewman at winehq.org
Mon Nov 21 08:38:08 CST 2016


Module: appdb
Branch: master
Commit: 9c186b30f360ee3e65b697c7d0381f745bcfa609
URL:    http://source.winehq.org/git/appdb.git/?a=commit;h=9c186b30f360ee3e65b697c7d0381f745bcfa609

Author: Jeremy Newman <jnewman at codeweavers.com>
Date:   Tue Nov 15 12:18:22 2016 -0600

rewrite javascript handlers for jquery, and merge files, cleanup

---

 scripts.js | 120 --------------------------------------------------
 utils.js   | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 127 insertions(+), 139 deletions(-)

diff --git a/scripts.js b/scripts.js
deleted file mode 100644
index 524489d..0000000
--- a/scripts.js
+++ /dev/null
@@ -1,120 +0,0 @@
-function openWin(fileToOpen,nameOfWindow,width,height) {
-	myWindow = window.open("",nameOfWindow,"menubar=no,scrollbars=yes,status=no,width="+width+",height="+height);
-	myWindow.document.open();
-	myWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">');
-	myWindow.document.write('<html><head><title>Screenshot Viewer</title>')
-	myWindow.document.write('<style type="text/css">');
-	myWindow.document.write('body { margin: 0; padding: 0; background-color: lightgrey; }');
-	myWindow.document.write('img { border: 0; }');
-	myWindow.document.write('p { display: inline; }');
-	myWindow.document.write('</style></head><body>');
-	myWindow.document.write('<a onclick="self.close();" href=""><img src="'+ fileToOpen +'" alt="Screenshot"></a>');
-	myWindow.document.write('</body></html>');
-	myWindow.document.close();
-}
-
-function deleteURL(text, url) {
-	if (confirm(text)) {
-	   self.location = url;
-	}
-}
-
-function ChangeTr(tableRow, bRowActive, sHighlightColor, sInactiveColor,
-                       sTextDecorationHighlight, sTextDecorationInactive)
-{
-    if (bRowActive)
-    {
-        tableRow.style.backgroundColor = sHighlightColor;
-        tableRow.style.cursor = "hand";
-        tableRow.style.textDecoration = sTextDecorationHighlight;
-    }
-    else
-    {
-        tableRow.style.backgroundColor = sInactiveColor;
-        tableRow.style.cursor = "pointer";
-        tableRow.style.textDecoration = sTextDecorationInactive;
-    }
-}
-
-function DoNav(sUrl)
-{
-    document.location.href = sUrl;
-}
-
-/**
- * commentId is the uniquely identifying comment id from the database.
- * It is also used as the div id for the comment body.
- */
-function showComment(commentid)
-{
-  elem = $(commentid);
-  if(elem.visible() && !elem.empty())
-  {
-    elem.hide();
-  }
-  else
-  {
-   // Cache the contents of the comment body so we don't need to hit db again.
-    if(elem.empty())
-    {
-      new Ajax.Updater(commentid, 'comment_body.php', { 
-        method: 'get',
-        parameters: {
-          iCommentId: commentid    
-        }
-      });
-    }
-    elem.show();
-  }
-}
-/* provide a hint to the user about the selected rating */
-var ratingdesc=[
-		"",
-		" Works flawlessly out of the box - no problems ",
-		" Works flawlessly with DLL overrides, third party software or other settings ",
-		" Works excellently for normal use;works fine in singleplayer but not multi ",
-		" Works but has issues for normal use ",
-		" Does not run or cannot be installed with Wine "
-		];
-var ratingstyle =[
-		  "",
-		  "platinum",
-		  "gold",
-		  "silver",
-		  "bronze",
-		  "garbage"
-		  ];
-function showHint(o){
-    if(o)
-	{
-	    $('hint').innerHTML=ratingdesc[o.selectedIndex];
-	    $w($('hint').className).map( function(x){ $('hint').removeClassName(x); }) 
-	    $('hint').addClassName(ratingstyle[o.selectedIndex]);
-	}
-}
-/* too many people still call Wine "WINE" */
-function bind_tolowerWINE()
-{
-    [
-     $('app_editor'),
-     $('version_editor'),
-     $('Test1'), 
-     $('Test2'), 
-     $('Test3'),
-     $('extra_comments')].map( function(x) 
-			       { 
-				 if(x) 
-				   { 
-				    x.observe('change', tolowerWINE);
-				   }
-			       });
-}
-function tolowerWINE(o)
-      {
-	o.element().value = o.element().value.replace(/WINE([^A-Z]+)|(WINE)$/g,"Wine$1");
-      }
-/* executed when document is ready */
-document.observe("dom:loaded", function() {
-	showHint($('ratingSelect'));
-	bind_tolowerWINE();
-    });
diff --git a/utils.js b/utils.js
index 24d5806..099e61a 100644
--- a/utils.js
+++ b/utils.js
@@ -1,23 +1,131 @@
 /*
-  Misc JavaScipt for WineHQ
-*/
-
-// include a file from js scripts dir
-function include_dom (script_filename) {
-    var html_doc = document.getElementsByTagName('head').item(0);
-    var js = document.createElement('script');
-    js.setAttribute('language', 'javascript');
-    js.setAttribute('type', 'text/javascript');
-    js.setAttribute('src', script_filename);
-    html_doc.appendChild(js);
-    return false;
-}
+ *   Misc JavaScipt for WineHQ Application Database
+ */
+
+// welcome
+console.log('Welcome to the %cWineHQ%c AppDB',
+            'color: #490708; font-size: 48pt; font-style: italic; font-weight: bold;',
+            'color: #95493A; font-size: 48pt; font-style: italic; font-weight: bold;');
+
+// execute on when document ready
+$(document).ready(function()
+{
+    // rating hints
+    (function()
+    {
+        var ratingdesc=[
+                "",
+                " Works flawlessly out of the box - no problems ",
+                " Works flawlessly with DLL overrides, third party software or other settings ",
+                " Works excellently for normal use;works fine in singleplayer but not multi ",
+                " Works but has issues for normal use ",
+                " Does not run or cannot be installed with Wine "
+                ];
+        var ratingstyle =[
+                  "",
+                  "platinum",
+                  "gold",
+                  "silver",
+                  "bronze",
+                  "garbage"
+                  ];
+        var changeRatingSelect = function()
+        {
+            var sel = $("#ratingSelect").prop('selectedIndex');
+            $("#hint").attr('class', '');
+            $("#hint").html(ratingdesc[sel]);
+            $("#hint").addClass(ratingstyle[sel]);
+        };
+        $("#ratingSelect").change(function(){changeRatingSelect()});
+        changeRatingSelect();
+    })();
+
+    // load nested forum comment
+    $('.showComment').each(function()
+    {
+        $(this).click(function(e)
+        {
+            e.preventDefault();
+            var id = $(this).data('id');
+            $("#comment-"+id).html('<i class="fa fa-spinner fa-spin fa-fw"></a>');
+            $.get('comment_body.php', {iCommentId: id}, function(comment)
+            {
+                $("#comment-"+id).html(comment);
+            });
+        });
+    });
 
-// load and execute jquery IE6 PNG fix
-include_dom("/jquery.pngfix.js");
-jQuery(function($) {
-    $("img[@src$=png]").pngfix(); /* all img tags with .png extension */
-    $("#tabs li").pngfix(); /* top tabs li backgrounds */
+    // debug log clicker
+    $("div#dlogt").toggleClick(
+    function()
+    {
+        $('div#dlogp').slideDown();
+    },
+    function()
+    {
+        $('div#dlogp').slideUp();
+    });
 });
 
-// done
+/*
+ * jQuery old style toggle replacement
+ * this useful object was removed in jquery 1.9
+ */
+$.fn.toggleClick = function(){
+    var functions = arguments ;
+    return this.click(function(){
+            var iteration = $(this).data('iteration') || 0;
+            functions[iteration].apply(this, arguments);
+            iteration = (iteration + 1) % functions.length ;
+            $(this).data('iteration', iteration);
+    });
+};
+
+// open Window (FIXME: replace with an inline screenshot viewer)
+function openWin(fileToOpen,nameOfWindow,width,height) {
+    myWindow = window.open("",nameOfWindow,"menubar=no,scrollbars=yes,status=no,width="+width+",height="+height);
+    myWindow.document.open();
+    myWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">');
+    myWindow.document.write('<html><head><title>Screenshot Viewer</title>')
+    myWindow.document.write('<style type="text/css">');
+    myWindow.document.write('body { margin: 0; padding: 0; background-color: lightgrey; }');
+    myWindow.document.write('img { border: 0; }');
+    myWindow.document.write('p { display: inline; }');
+    myWindow.document.write('</style></head><body>');
+    myWindow.document.write('<a onclick="self.close();" href=""><img src="'+ fileToOpen +'" alt="Screenshot"></a>');
+    myWindow.document.write('</body></html>');
+    myWindow.document.close();
+}
+
+// confirmation message (FIXME: replace with jquery utils: dialog)
+function deleteURL(text, url) {
+    if (confirm(text)) {
+       self.location = url;
+    }
+}
+
+// row color change
+function ChangeTr(tableRow, bRowActive, sHighlightColor, sInactiveColor,
+                       sTextDecorationHighlight, sTextDecorationInactive)
+{
+    if (bRowActive)
+    {
+        tableRow.style.backgroundColor = sHighlightColor;
+        tableRow.style.cursor = "hand";
+        tableRow.style.textDecoration = sTextDecorationHighlight;
+    }
+    else
+    {
+        tableRow.style.backgroundColor = sInactiveColor;
+        tableRow.style.cursor = "pointer";
+        tableRow.style.textDecoration = sTextDecorationInactive;
+    }
+}
+
+// doNav
+function DoNav(sUrl)
+{
+    document.location.href = sUrl;
+}
+
+// done
\ No newline at end of file




More information about the wine-cvs mailing list