commit
96d942c8cc
Binary file not shown.
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 6.7 KiB |
@ -1,99 +1,113 @@ |
||||
|
||||
function createWord( word ) |
||||
{ |
||||
var s = ''; |
||||
for( var i = 0; i < word.length; i++ ) |
||||
{ |
||||
ch = word.charAt( i ); |
||||
s +=
|
||||
'<span class="upper">' + |
||||
'<span>' + ch + '</span>' + |
||||
(( i < word.length - 1 ) ? |
||||
'<span class="dash">–</span>' : '' ) + |
||||
'</span>'; |
||||
} |
||||
return s; |
||||
var s = ''; |
||||
for( var i = 0; i < word.length; i++ ) |
||||
{ |
||||
ch = word.charAt( i ); |
||||
s +=
|
||||
'<span class="upper">' + |
||||
'<span>' + ch + '</span>' + |
||||
(( i < word.length - 1 ) ? |
||||
'<span class="dash">–</span>' : '' ) + |
||||
'</span>'; |
||||
} |
||||
return s; |
||||
} |
||||
|
||||
$(document).ready(function() |
||||
{ |
||||
var w = new wcontainer( "#ub-widget" ); |
||||
var w = new wcontainer( "#ub-widget" ); |
||||
var words = ""; |
||||
|
||||
if(window.sankore) |
||||
words = (sankore.preference("ordSplWords", ""))?sankore.preference("ordSplWords", ""):"so*phis*ti*ca*ted"; |
||||
else |
||||
words = "so*phis*ti*ca*ted"; |
||||
w.setEditContent( '<div class="inputwrap"><input class="percent" value="' + words + '"></div>' ); |
||||
w.setViewContent( '<span class="upper"><span class="dash fixed">—</span></span>' ); |
||||
w.setData( "dashWidth", w.elements.container.find( "span.dash" ).outerWidth() ); |
||||
w.setViewContent( "" ); |
||||
|
||||
w.setEditContent( '<div class="inputwrap"><input class="percent" value="so*phis*ti*ca*ted"></div>' ); |
||||
w.setViewContent( '<span class="upper"><span class="dash fixed">—</span></span>' ); |
||||
w.setData( "dashWidth", w.elements.container.find( "span.dash" ).outerWidth() ); |
||||
w.setViewContent( "" ); |
||||
|
||||
// onViewMode
|
||||
w.onViewMode = function() |
||||
{ |
||||
var word = w.elements.container.find( "input" ).val().trim( ['*'] ); |
||||
// onViewMode
|
||||
w.onViewMode = function() |
||||
{ |
||||
var word = w.elements.container.find( "input" ).val().trim( ['*'] ); |
||||
|
||||
w.setData( "word", word ); |
||||
word = word.replace( /\*/g, '' ); |
||||
w.setViewContent( createWord( word ) ); |
||||
w.elements.container.find( "span.upper" ).click( function(){ |
||||
$( this ).find( "span.dash" ).toggleClass( "fixed" ); |
||||
w.adjustSize(); |
||||
w.checkAnswer(); |
||||
}); |
||||
w.checkAnswer(); |
||||
}; |
||||
w.setData( "word", word ); |
||||
word = word.replace( /\*/g, '' ); |
||||
w.setViewContent( createWord( word ) ); |
||||
w.elements.container.find( "span.upper" ).click( function(){ |
||||
$( this ).find( "span.dash" ).toggleClass( "fixed" ); |
||||
w.adjustSize(); |
||||
w.checkAnswer(); |
||||
}); |
||||
w.checkAnswer(); |
||||
}; |
||||
|
||||
// viewSize
|
||||
w.viewSize = function() |
||||
{ |
||||
var w = 0; |
||||
var h = 0; |
||||
// viewSize
|
||||
w.viewSize = function() |
||||
{ |
||||
var w = 0; |
||||
var h = 0; |
||||
|
||||
winstance.elements.containerView.find( "span.upper span:visible" ).each( function() |
||||
{ |
||||
w += $( this ).outerWidth(); |
||||
h = Math.max( h, $( this ).outerHeight() ); |
||||
}); |
||||
var dw = winstance.getData( "dashWidth" ); |
||||
winstance.elements.containerView.find( "span.upper span:visible" ).each( function() |
||||
{ |
||||
w += $( this ).outerWidth(); |
||||
h = Math.max( h, $( this ).outerHeight() ); |
||||
}); |
||||
var dw = winstance.getData( "dashWidth" ); |
||||
|
||||
return { w: w+dw, h: h }; |
||||
}; |
||||
return { |
||||
w: w+dw,
|
||||
h: h |
||||
}; |
||||
}; |
||||
|
||||
// editSize
|
||||
w.editSize = function() |
||||
{ |
||||
return { |
||||
w: winstance.elements.containerEdit.find( "input" ).outerWidth( true ), |
||||
h: winstance.elements.containerEdit.find( "input" ).outerHeight( true ), |
||||
}; |
||||
}; |
||||
// editSize
|
||||
w.editSize = function() |
||||
{ |
||||
return { |
||||
w: winstance.elements.containerEdit.find( "input" ).outerWidth( true ), |
||||
h: winstance.elements.containerEdit.find( "input" ).outerHeight( true ), |
||||
}; |
||||
}; |
||||
|
||||
|
||||
w.checkAnswer = function() |
||||
{ |
||||
var word = ""; |
||||
this.elements.container.find( "span.upper span:visible" ).each( function() |
||||
{ |
||||
if( this.className.indexOf( "fixed" ) != -1 ){ |
||||
word += '*'; |
||||
} |
||||
else if( this.className.indexOf( "dash" ) != -1 ){ |
||||
return; |
||||
} |
||||
else{ |
||||
word += $( this ).text(); |
||||
} |
||||
}); |
||||
w.checkAnswer = function() |
||||
{ |
||||
var word = ""; |
||||
this.elements.container.find( "span.upper span:visible" ).each( function() |
||||
{ |
||||
if( this.className.indexOf( "fixed" ) != -1 ){ |
||||
word += '*'; |
||||
} |
||||
else if( this.className.indexOf( "dash" ) != -1 ){ |
||||
return; |
||||
} |
||||
else{ |
||||
word += $( this ).text(); |
||||
} |
||||
}); |
||||
|
||||
if( word == this.getData( "word" ) ){ |
||||
this.elements.container.addClass( "answerRight" ); |
||||
} |
||||
else{ |
||||
this.elements.container.removeClass( "answerRight" ); |
||||
} |
||||
}; |
||||
if( word == this.getData( "word" ) ){ |
||||
this.elements.container.addClass( "answerRight" ); |
||||
} |
||||
else{ |
||||
this.elements.container.removeClass( "answerRight" ); |
||||
} |
||||
}; |
||||
|
||||
|
||||
window.w = w; |
||||
window.winstance = w; |
||||
window.w = w; |
||||
window.winstance = w; |
||||
|
||||
w.modeView(); |
||||
w.modeView(); |
||||
|
||||
$(window).mouseout(function(){ |
||||
if(window.sankore){ |
||||
sankore.setPreference("ordSplWords", w.getData("word")); |
||||
} |
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,86 @@ |
||||
#include <QDomDocument> |
||||
|
||||
#include "core/UBApplication.h" |
||||
|
||||
#include "UBLibWebView.h" |
||||
|
||||
UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent) |
||||
, mpView(NULL) |
||||
, mpWebSettings(NULL) |
||||
, mpLayout(NULL) |
||||
{ |
||||
setObjectName(name); |
||||
|
||||
setAttribute(Qt::WA_StyledBackground, true); |
||||
setStyleSheet(UBApplication::globalStyleSheet()); |
||||
|
||||
mpLayout = new QVBoxLayout(); |
||||
setLayout(mpLayout); |
||||
|
||||
mpView = new QWebView(this); |
||||
mpView->setObjectName("SearchEngineView"); |
||||
//mpView->setStyleSheet(QString("background-color:white;"));
|
||||
|
||||
mpWebSettings = QWebSettings::globalSettings(); |
||||
mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::PluginsEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); |
||||
mpWebSettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true); |
||||
mpWebSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, true); |
||||
|
||||
mpLayout->addWidget(mpView); |
||||
} |
||||
|
||||
UBLibWebView::~UBLibWebView() |
||||
{ |
||||
if(NULL != mpView) |
||||
{ |
||||
delete mpView; |
||||
mpView = NULL; |
||||
} |
||||
if(NULL != mpLayout) |
||||
{ |
||||
delete mpLayout; |
||||
mpLayout = NULL; |
||||
} |
||||
} |
||||
|
||||
void UBLibWebView::setElement(UBLibElement *elem) |
||||
{ |
||||
if(NULL != elem) |
||||
{ |
||||
QString qsWidgetName; |
||||
QString path = elem->path().toLocalFile(); |
||||
|
||||
QString qsConfigPath = QString("%0/config.xml").arg(path); |
||||
|
||||
if(QFile::exists(qsConfigPath)) |
||||
{ |
||||
QFile f(qsConfigPath); |
||||
if(f.open(QIODevice::ReadOnly)) |
||||
{ |
||||
QDomDocument domDoc; |
||||
domDoc.setContent(QString(f.readAll())); |
||||
QDomElement root = domDoc.documentElement(); |
||||
|
||||
QDomNode node = root.firstChild(); |
||||
while(!node.isNull()) |
||||
{ |
||||
if(node.toElement().tagName() == "content") |
||||
{ |
||||
QDomAttr srcAttr = node.toElement().attributeNode("src"); |
||||
qsWidgetName = srcAttr.value(); |
||||
break; |
||||
} |
||||
node = node.nextSibling(); |
||||
} |
||||
f.close(); |
||||
} |
||||
} |
||||
|
||||
mpView->load(QUrl::fromLocalFile(QString("%0/%1").arg(path).arg(qsWidgetName))); |
||||
} |
||||
} |
@ -0,0 +1,27 @@ |
||||
#ifndef UBLIBWEBVIEW_H |
||||
#define UBLIBWEBVIEW_H |
||||
|
||||
#include <QWidget> |
||||
#include <QWebView> |
||||
#include <QWebSettings> |
||||
#include <QVBoxLayout> |
||||
|
||||
#include "board/UBLibraryController.h" |
||||
|
||||
class UBLibWebView : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
UBLibWebView(QWidget* parent = 0, const char* name = "UBLibWebView"); |
||||
~UBLibWebView(); |
||||
|
||||
void setElement(UBLibElement* elem); |
||||
|
||||
private: |
||||
QWebView* mpView; |
||||
QWebSettings* mpWebSettings; |
||||
QVBoxLayout* mpLayout; |
||||
}; |
||||
|
||||
#endif // UBLIBWEBVIEW_H
|
Loading…
Reference in new issue