-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from touchapp/feat/surveyAndDD
Feat/survey and dd
- Loading branch information
Showing
14 changed files
with
345 additions
and
47 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Core/Core/View/Base/Webview/Models/DragAndDropCssInjection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// DragAndDropCssInjection.swift | ||
// Core | ||
// | ||
// Created by Vadim Kuznetsov on 4.01.24. | ||
// | ||
|
||
import WebKit | ||
|
||
public struct DragAndDropCssInjection: WebViewScriptInjectionProtocol, CSSInjectionProtocol { | ||
public var id: String = "DragAndDropCSSInjection" | ||
public var messages: [WebviewMessage]? | ||
public var injectionTime: WKUserScriptInjectionTime = .atDocumentStart | ||
|
||
public var script: String { | ||
cssScript(with: css) | ||
} | ||
|
||
var css: String { | ||
""" | ||
.xblock--drag-and-drop .drag-container { | ||
-webkit-user-select: none !important; | ||
-ms-user-select: none !important; | ||
user-select: none !important; | ||
} | ||
""" | ||
} | ||
|
||
public init() {} | ||
|
||
public static func == (lhs: DragAndDropCssInjection, rhs: DragAndDropCssInjection) -> Bool { | ||
lhs.script == rhs.script | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Core/Core/View/Base/Webview/Models/SurveyCssInjection.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// SurveyCssInjection.swift | ||
// Core | ||
// | ||
// Created by Vadim Kuznetsov on 4.01.24. | ||
// | ||
|
||
import WebKit | ||
|
||
public struct SurveyCssInjection: WebViewScriptInjectionProtocol, CSSInjectionProtocol { | ||
public var id: String = "SurveyCSSInjection" | ||
public var messages: [WebviewMessage]? | ||
public var injectionTime: WKUserScriptInjectionTime = .atDocumentStart | ||
|
||
public var script: String { | ||
cssScript(with: css) | ||
} | ||
|
||
var css: String { | ||
""" | ||
.survey-table:not(.poll-results) .survey-option .visible-mobile-only { | ||
width: calc(100% - 21px) !important; | ||
} | ||
.survey-percentage .percentage { | ||
width: 54px !important; | ||
} | ||
""" | ||
} | ||
|
||
public init() {} | ||
|
||
public static func == (lhs: SurveyCssInjection, rhs: SurveyCssInjection) -> Bool { | ||
lhs.script == rhs.script | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// WebviewInjection.swift | ||
// Core | ||
// | ||
// Created by Vadim Kuznetsov on 4.01.24. | ||
// | ||
|
||
import WebKit | ||
public struct WebviewInjection: WebViewScriptInjectionProtocol { | ||
public var id: String | ||
public var script: String | ||
public var messages: [WebviewMessage]? | ||
public var injectionTime: WKUserScriptInjectionTime | ||
init( | ||
id: String, | ||
script: String, | ||
messages: [WebviewMessage]? = nil, | ||
injectionTime: WKUserScriptInjectionTime = .atDocumentEnd | ||
) { | ||
self.id = id | ||
self.script = script | ||
self.messages = messages | ||
self.injectionTime = injectionTime | ||
} | ||
|
||
public static func == (lhs: WebviewInjection, rhs: WebviewInjection) -> Bool { | ||
lhs.id == rhs.id && | ||
lhs.script == rhs.script && | ||
lhs.injectionTime == rhs.injectionTime && | ||
lhs.messages == rhs.messages | ||
} | ||
} | ||
|
||
public extension WebviewInjection { | ||
|
||
static var surveyCSS: WebviewInjection { | ||
SurveyCssInjection() | ||
.webviewInjection() | ||
} | ||
|
||
static var dragAndDropCss: WebviewInjection { | ||
DragAndDropCssInjection() | ||
.webviewInjection() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// WebviewMessage.swift | ||
// Core | ||
// | ||
// Created by Vadim Kuznetsov on 4.01.24. | ||
// | ||
|
||
import WebKit | ||
public struct WebviewMessage: Equatable { | ||
var name: String | ||
var handler: (Any, WKWebView?) -> Void | ||
|
||
public static func == (lhs: WebviewMessage, rhs: WebviewMessage) -> Bool { | ||
lhs.name == rhs.name | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Core/Core/View/Base/Webview/Protocols/CSSInjectionProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// CSSInjectionProtocol.swift | ||
// Core | ||
// | ||
// Created by Vadim Kuznetsov on 4.01.24. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol CSSInjectionProtocol { | ||
func cssScript(with css: String) -> String | ||
} | ||
|
||
extension CSSInjectionProtocol { | ||
public func cssScript(with css: String) -> String { | ||
""" | ||
window.addEventListener("load", () => { | ||
var css = `\(css)`, | ||
head = document.head || document.getElementsByTagName('head')[0], | ||
style = document.createElement('style'); | ||
head.appendChild(style); | ||
style.type = 'text/css'; | ||
if (style.styleSheet) { | ||
style.styleSheet.cssText = css; | ||
} else { | ||
style.appendChild(document.createTextNode(css)); | ||
} | ||
}) | ||
""" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Core/Core/View/Base/Webview/Protocols/WebViewScriptInjectionProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// WebViewScriptInjectionProtocol.swift | ||
// Core | ||
// | ||
// Created by Vadim Kuznetsov on 4.01.24. | ||
// | ||
|
||
import WebKit | ||
public protocol WebViewScriptInjectionProtocol: Equatable, Identifiable { | ||
var id: String { get } | ||
var script: String { get } | ||
var messages: [WebviewMessage]? { get } | ||
var injectionTime: WKUserScriptInjectionTime { get } | ||
} | ||
|
||
extension WebViewScriptInjectionProtocol { | ||
public func webviewInjection() -> WebviewInjection { | ||
WebviewInjection( | ||
id: self.id, | ||
script: self.script, | ||
messages: self.messages, | ||
injectionTime: self.injectionTime | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.