frankx: Dialobox JQuery - für Div-popup nötig? Refresh und Linkergänzung in eigenem Javascript

Ahoi alle

habe mit jquery und ohne ein Script gebastelt, auf ursprüngliche Anregung von Matthias, um a) auf die gesamtübersicht mit einem link zu kommen (/all) b) den refresh auf 60 sekunden zu setzen c) ein popup-div zu bekommen, dass mir anzeigt, ob neue nachrichten da sind (aber nur, wenn ich auf /, /all, /meta oder /self bin).

für diese dialogbox muss man extra ein div in den baum einhängen. das ist sicherlich overdone.

mich würden code-optimierungen interessieren.

$(document).ready(function() {
    //set links für beide foren
	var linkTitle = "/all";
	var elems = [ "#top ul li:first", "#content nav ul li:first"];
	$.each( elems, function( i, elem ) {
		$(elem).after('<li><a href="/all">' + linkTitle + '</a></li>');
	});
    // für das kleine fensterchen ein riesen aufwand - jquery ui, jquery css und hidden divbutton einhänten ...;    
	var createTooltipDialogDiv = function () {	
		cssHref = "https://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css";
		$("<link rel='stylesheet' type='text/css' href='"+ cssHref +"'>").appendTo( "head" );
		scriptName = "https://code.jquery.com/ui/1.11.4/jquery-ui.js";
		$.getScript(scriptName, function() {
			$( "<div id='dialog' style='display:none'></div>" ).appendTo( "body" )
			$("#dialog").dialog({
				title: nachrichtenZahlString + ' Nachrichten',
				buttons: {
					lesen: function () {
						$(this).dialog('close');
						top.location.href="http://forum.selfhtml.org/notifications";
					}
				}
			});
		});
	}
    var locationsList = ["http://forum.selfhtml.org/all", "http://forum.selfhtml.org/", "http://forum.selfhtml.org/meta", "http://forum.selfhtml.org/self"];
    // nur für all, meta, self und /
    if($.inArray(top.location.href, locationsList) !== -1)  {
         $('[http-equiv="refresh"]').attr('content','60; URL=http://forum.selfhtml.org/all');
        //nachrichten da? 
       	var nachrichtenZahlString = $("#notifications-display").html();
        if(parseInt(nachrichtenZahlString) > 0) {
            createTooltipDialogDiv();
        }
    } 
});

Dank und Gruß,

bob from berlin

  1. Ahoi frankx

    ich konnte die Vorschau nicht aufrufen, und auch das Posting nicht erstellen, ohne Titel und ohne Tag, scheinbar. Ich kam auf eine Leere Hauptseite /self ... ??? Jetzt geht die Vorschau übrigens.

    Dank und Gruß,

    bob from berlin

  2. Ahoi frankx

    weil ich ja jslint mag, habe ich es jetzt spaßeshalber noch jslint-konform gemacht. allerdings kriege ich das unused "i" nicht weg.

    /*jslint browser: true*/
    /*global  $*/
    /*global  top*/
    $(document).ready(function () {
        //set links fuer beide foren
        "use strict";
        var linkTitle = "/all",
            elementIdsForLinks = ["#top ul li:first", "#content nav ul li:first"],
            nachrichtenZahlString = $("#notifications-display").html(),
           // fuer das kleine fensterchen ein riesen aufwand - jquery ui, jquery css und hidden divbutton einhaengen ...
            createTooltipDialogDiv = function () {
                var cssHref = "https://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css",
                    scriptName = "https://code.jquery.com/ui/1.11.4/jquery-ui.js";
                $("<link rel='stylesheet' type='text/css' href='" + cssHref + "'>").appendTo("head");
                $.getScript(scriptName, function () {
                    $("<div id='dialog' style='display:none'></div>").appendTo("body");
                    $("#dialog").dialog({
                        title: nachrichtenZahlString + ' Nachrichten',
                        buttons: {
                            lesen: function () {
                                $(this).dialog('close');
                                top.location.href = "http://forum.selfhtml.org/notifications";
                            }
                        }
                    });
                });
            },
            locationsList = ["http://forum.selfhtml.org/all", "http://forum.selfhtml.org/", "http://forum.selfhtml.org/meta", "http://forum.selfhtml.org/self"];
        // nur fuer all, meta, self und /
        $.each(elementIdsForLinks, function (i, elem) {
            $(elem).after('<li><a href="/all">' + linkTitle + '</a></li>');
        });
        if ($.inArray(top.location.href, locationsList) !== -1) {
            $('[http-equiv="refresh"]').attr('content', '60; URL=http://forum.selfhtml.org/all');
            //nur wenn mehr als 0 nachrichten da sind:
            if (parseInt(nachrichtenZahlString, 10) > 0) {
                createTooltipDialogDiv();
            }
        }
    });
    

    jquery braucht für die funktion

    $.each(elementIdsForLinks, function (i, elem) {

    ein i und ein elem, aber das i brauche ich nicht ... ;-). weg kriegt man das nicht, oder?

    Dank und Gruß,

    bob from berlin