forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLiveCSSDocument.js
More file actions
1 lines (1 loc) · 2.43 KB
/
Copy pathLiveCSSDocument.js
File metadata and controls
1 lines (1 loc) · 2.43 KB
1
define(function LiveCSSDocumentModule(require,exports,module){var _=require("thirdparty/lodash"),CSSUtils=require("language/CSSUtils"),EventDispatcher=require("utils/EventDispatcher"),LiveDocument=require("LiveDevelopment/MultiBrowserImpl/documents/LiveDocument"),PathUtils=require("thirdparty/path-utils/path-utils"),LiveCSSDocument=function LiveCSSDocument(protocol,urlResolver,doc,editor,roots){LiveDocument.apply(this,arguments),this.doc.addRef(),this.onChange=this.onChange.bind(this),this.onDeleted=this.onDeleted.bind(this),this.doc.on("change.LiveCSSDocument",this.onChange),this.doc.on("deleted.LiveCSSDocument",this.onDeleted),editor&&this._attachToEditor(editor)};(LiveCSSDocument.prototype=Object.create(LiveDocument.prototype)).constructor=LiveCSSDocument,LiveCSSDocument.prototype.parentClass=LiveDocument.prototype,EventDispatcher.makeEventDispatcher(LiveCSSDocument.prototype),LiveCSSDocument.prototype.close=function(){this.doc.off(".LiveCSSDocument"),this.doc.releaseRef(),this.parentClass.close.call(this)},LiveCSSDocument.prototype._updateBrowser=function(){var i,docUrl=this.doc.url;function makeUrlsRelativeToCss(match,quotationMark,url){var absUrl;return PathUtils.isRelativeUrl(url)?"url("+quotationMark+PathUtils.makeUrlAbsolute(url,docUrl)+quotationMark+")":match}for(i=0;i<this.roots.length;i++)if(docUrl!==this.roots[i].toString())this.trigger("updateDoc",this.roots[i]);else{var docText=this.doc.getText();docText=docText.replace(/\burl\(\s*(["']?)([^)\n]+)\1\s*\)/gi,makeUrlsRelativeToCss),this.protocol.setStylesheetText(docUrl,docText)}this.redrawHighlights()},LiveCSSDocument.prototype.updateHighlight=function(){if(this.isHighlightEnabled()&&this.editor){var editor=this.editor,selectors=[];_.each(this.editor.getSelections(),function(sel){var selector=CSSUtils.findSelectorAtDocumentPos(editor,sel.reversed?sel.end:sel.start);selector&&selectors.push(selector)}),selectors.length?this.highlightRule(selectors.join(",")):this.hideHighlight()}},LiveCSSDocument.prototype.isLiveEditingEnabled=function(){return!0},LiveCSSDocument.prototype.onChange=function(event,editor,change){this._updateBrowser()},LiveCSSDocument.prototype.onDeleted=function(event){this.close(),this.trigger("deleted",[this])},LiveCSSDocument.prototype.getSourceFromBrowser=function(){var deferred=new $.Deferred;return this.protocol.getStylesheetText(this.doc.url).then(function(res){deferred.resolve(res.text)},deferred.reject),deferred.promise()},module.exports=LiveCSSDocument});