0

For my first JavaScript application I am building a widget based designer, and use a variety of widgets based on SVG included in the main HTML body with object tags. I'm trying to associate a bootstrap tooltip when the user clicks on the widget object, however I'm getting strange errors that don't crop up when using tooltips on other non object HTML elements.

As an object tag swallows mouse events it's not possible to trigger a tooltip with a hover and the only combination I can get to work to show the tooltip is the following code (nothing else works, bootstrap complains about ):

document.getElementById(widgetName).setAttribute("title", param0);
setTimeout(function () {
     $("#" + widgetName).tooltip("show");
     }, 1);              // attribute needs to be set after the next tick so the DOM is refreshed.
setTimeout(function () { $("#" + widgetName).tooltip("hide"); }, 2000); // 2 sec delay before hiding

This code shows the tooltip but errors out with Unable to get property 'originalTitle' of undefined or null reference in IE10 after the 2 second timeout to hide the tooltip. I can't use tooltip object options (eg. the delay option) as I get the same error. Same problem in Chrome although Chrome does not report the error (no hiding though).

I'm sure it has something to do with trying to use tooltips on object tags as tooltips work normally otherwise. However I'm fairly new to JavaScript so let me know if I'm doing something dumb, and the bootstrap/Jquery code is too complex for me to trace the error.

Using: HTML5, IE10, latest twitter bootstrap, visual studio 2012 web

Thanks for any help / pointers.

UPDATE: Added code that inserts the object into the DOM

    var objWidget = document.createElement("object");
    objWidget.type = "image/svg+xml";
    objWidget.data = "widgets/" + widgetFile + "." + widgetExt      // location of widget
    objWidget.className = "widget"
    var widgetName = "objWidget" + widgetNum;
    targetDiv = "widgetContainer"
    objWidget.id = widgetName;
    document.getElementById(targetDiv).appendChild(objWidget);   // Add to Div
    var objID = document.getElementById(widgetName);
    objID.addEventListener("load", function () {      // access properties once the file is loaded
        var objDoc = objID.contentDocument;
        objDoc.addEventListener("dragstart", drag_start, false);
        objDoc.addEventListener("dragover", drag_over, false)
        objDoc.addEventListener("drop", drop, false)
        objDoc.getElementById("widget").setAttribute("data-widgetName", widgetName);   // set a data attribute on the SVG that points to the parent object as object that created the event isn't recorded in the event.currentTarget
        objID.setAttribute("draggable", "true")
        objID.style.setProperty("position", "absolute");
        objID.style.setProperty("left", objLeft + "px");
        objID.style.setProperty("top", objTop + "px");
        objID.style.setProperty("z-index", widgets[widgetNum].zOrder);
        objDoc.defaultView.loaded(widgetName);         // run widget startup routine only if it isn't a new widget
        objDoc.defaultView.addEventListener("click", widgetClick, false);
        objDoc.defaultView.addEventListener("dblclick", widgetDblClick, false);
    }, false);

Translate simple Ltk-app into Clojure seesaw / swing

I am trying to decide between Clojure and CL for an upcoming project. To get my feet wet, I was toying around with some simple GUI stuff.

Here is what I have in CL / Ltk:

(ql:quickload "ltk")

(defpackage :myed
  (:use :ltk :cl))
(in-package :myed)

(defun ed-label (fr)
  (make-instance 'label :master fr :font "Sans-Serif" :text "Editor"))

(defparameter *text-field*
  (make-instance 'text
         :font "monospaced" :takefocus :t))

(defparameter *a-tale*
  "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light")

(defun make-frame ()
  (with-ltk ()
    (let* ((f (make-instance 'frame))
       (scroll (make-instance 'scrolled-text :master f))
       (outtext (textbox scroll)))
      (pack f)
      (configure outtext :font "monospaced" :background "#aea79f" :wrap :word)
      (pack (ed-label f) :anchor :nw :side :top)
      (pack scroll :anchor :nw :expand t :fill :both)
      (pack *text-field* :anchor :sw :fill :x :ipady 10)
      (setf (text outtext) *a-tale*)
      (bind *text-field* "<KeyPress-Return>"
        (lambda (event) (format-output outtext)))
      (configure f :borderwidth 2))))

(defun format-output (target)
  "Print inputstring with newlines and > ."
  (append-text target (format nil "~%~%> ~A~%~%" (text *text-field*)))
  (clear-text *text-field*))

Two TextFields, when I input Text in the bottom window and hit Enter, newlines and a ">" get added and the text is appended in the top textfield.

In Clojure I've tried Seesaw and this:

(ns myedclj.core
  (:use [seesaw core keymap])
  (:require [seesaw.bind :as bind]))

(def outtext
    ( text
    :multi-line? true :wrap-lines? true  :editable? false))

(def ed-label (label :text "Editor"))

(def intext
  (text :multi-line? false :editable? true))

(def a-tale
  "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light")

(defn format-output
  [target]
  (.append target (str "\n\n" "> " (text intext))))

(map-key intext "ENTER" (fn [_] (format-output outtext)))

(text! outtext a-tale)

(defn make-frame []
  (frame :content (vertical-panel
                   :border 2
                   :items [ed-label
                           (scrollable outtext)
                           intext])))

(defn -main [& args]
  (-> (make-frame)
      pack!
      show!))

This is unfortunately not working. The dimensions of the windowcontents are the opposite of what I want and I don't see any scrollbars. My Swing knowledge is btw non-existent.

Any Help would be greatly appreciated.

4

1 回答 1

1

我测试您的代码(将工具提示添加到 svg 标签)请参阅:http ://bootply.com/64598 FF 和 chrome 没有问题

于 2013-06-20T20:47:41.743 回答