X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=roojs-core-debug.js;h=9fe5f9630bd2e80440153cd4d6e783d43cfcc5fe;hb=5b1a708cf006e24f8f6eb81a4e9723dad77c31cd;hp=ae172277e70ef4f8a3d086c0360fcd26483982b8;hpb=f9482da4c2d662aeb60c6474adf719a69442f69c;p=roojs1 diff --git a/roojs-core-debug.js b/roojs-core-debug.js index ae172277e7..9fe5f9630b 100644 --- a/roojs-core-debug.js +++ b/roojs-core-debug.js @@ -53,15 +53,35 @@ Roo.apply = function(o, c, defaults){ var isStrict = document.compatMode == "CSS1Compat", isOpera = ua.indexOf("opera") > -1, isSafari = (/webkit|khtml/).test(ua), + isFirefox = ua.indexOf("firefox") > -1, isIE = ua.indexOf("msie") > -1, isIE7 = ua.indexOf("msie 7") > -1, + isIE11 = /trident.*rv\:11\./.test(ua), + isEdge = ua.indexOf("edge") > -1, isGecko = !isSafari && ua.indexOf("gecko") > -1, isBorderBox = isIE && !isStrict, isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1), isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1), isLinux = (ua.indexOf("linux") != -1), isSecure = window.location.href.toLowerCase().indexOf("https") === 0, - isTouch = 'ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch; + isIOS = /iphone|ipad/.test(ua), + isAndroid = /android/.test(ua), + isTouch = (function() { + try { + if (ua.indexOf('chrome') != -1 && ua.indexOf('android') == -1) { + window.addEventListener('touchstart', function __set_has_touch__ () { + Roo.isTouch = true; + window.removeEventListener('touchstart', __set_has_touch__); + }); + return false; // no touch on chrome!? + } + document.createEvent("TouchEvent"); + return true; + } catch (e) { + return false; + } + + })(); // remove css image flicker if(isIE && !isIE7){ try{ @@ -303,7 +323,7 @@ Roo.factory(conf, Roo.data); return c; } if (ns[c.xtype]) { - if (Roo.debug) Roo.log("Roo.Factory(" + c.xtype + ")"); + if (Roo.debug) { Roo.log("Roo.Factory(" + c.xtype + ")"); } var ret = new ns[c.xtype](c); ret.xns = false; return ret; @@ -322,8 +342,8 @@ Roo.factory(conf, Roo.data); if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) { return; // alerT? } - console.log(s); + console.log(s); }, /** * Takes an object and converts it to an encoded URL. e.g. Roo.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value. @@ -602,10 +622,16 @@ Roo.factory(conf, Roo.data); /** @type Boolean */ isSafari : isSafari, /** @type Boolean */ + isFirefox : isFirefox, + /** @type Boolean */ isIE : isIE, /** @type Boolean */ isIE7 : isIE7, /** @type Boolean */ + isIE11 : isIE11, + /** @type Boolean */ + isEdge : isEdge, + /** @type Boolean */ isGecko : isGecko, /** @type Boolean */ isBorderBox : isBorderBox, @@ -616,6 +642,10 @@ Roo.factory(conf, Roo.data); /** @type Boolean */ isMac : isMac, /** @type Boolean */ + isIOS : isIOS, + /** @type Boolean */ + isAndroid : isAndroid, + /** @type Boolean */ isTouch : isTouch, /** @@ -646,7 +676,10 @@ Roo.factory(conf, Roo.data); })(); Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data", - "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout", "Roo.app", "Roo.ux"); + "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout", + "Roo.app", "Roo.ux", + "Roo.bootstrap", + "Roo.bootstrap.dash"); /* * Based on: * Ext JS Library 1.1.1 @@ -852,6 +885,8 @@ var s = String.format('
{1}
', cls, text); return Roo.util.Format.htmlEncode(args[i]); }); } + + }); /** @@ -873,7 +908,31 @@ sort = (sort == 'ASC' ? 'DESC' : 'ASC'); String.prototype.toggle = function(value, other){ return this == value ? other : value; -};/* +}; + + +/** + * Remove invalid unicode characters from a string + * + * @return {String} The clean string + */ +String.prototype.unicodeClean = function () { + return this.replace(/[\s\S]/g, + function(character) { + if (character.charCodeAt()< 256) { + return character; + } + try { + encodeURIComponent(character); + } catch(e) { + return ''; + } + return character; + } + ); +}; + +/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. @@ -914,13 +973,14 @@ Roo.applyIf(Number.prototype, { */ Roo.applyIf(Array.prototype, { /** + * * Checks whether or not the specified object exists in the array. * @param {Object} o The object to check for * @return {Number} The index of o in the array (or -1 if it is not found) */ indexOf : function(o){ for (var i = 0, len = this.length; i < len; i++){ - if(this[i] == o) return i; + if(this[i] == o) { return i; } } return -1; }, @@ -942,15 +1002,16 @@ Roo.applyIf(Array.prototype, { map : function(fun ) { var len = this.length >>> 0; - if (typeof fun != "function") + if (typeof fun != "function") { throw new TypeError(); - + } var res = new Array(len); var thisp = arguments[1]; for (var i = 0; i < len; i++) { - if (i in this) + if (i in this) { res[i] = fun.call(thisp, this[i], i, this); + } } return res; @@ -959,7 +1020,8 @@ Roo.applyIf(Array.prototype, { }); - /* + +/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. @@ -1222,6 +1284,7 @@ Date.parseDate = function(input, format) { /** * @private */ + Date.createParser = function(format) { var funcName = "parse" + Date.parseFunctions.count++; var regexNum = Date.parseRegexes.length; @@ -1234,6 +1297,7 @@ Date.createParser = function(format) { + "y = d.getFullYear();\n" + "m = d.getMonth();\n" + "d = d.getDate();\n" + + "if (typeof(input) !== 'string') { input = input.toString(); }\n" + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" + "if (results && results.length > 0) {"; var regex = ""; @@ -1663,8 +1727,8 @@ Date.prototype.clearTime = function(clone){ }; // private -// safari setMonth is broken -if(Roo.isSafari){ +// safari setMonth is broken -- check that this is only donw once... +if(Roo.isSafari && typeof(Date.brokenSetMonth) == 'undefined'){ Date.brokenSetMonth = Date.prototype.setMonth; Date.prototype.setMonth = function(num){ if(num <= -1){ @@ -1734,7 +1798,7 @@ document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00' */ Date.prototype.add = function(interval, value){ var d = this.clone(); - if (!interval || value === 0) return d; + if (!interval || value === 0) { return d; } switch(interval.toLowerCase()){ case Date.MILLI: d.setMilliseconds(this.getMilliseconds() + value); @@ -4128,7 +4192,7 @@ Roo.DomHelper = function(){ } b += "<" + o.tag; for(var attr in o){ - if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") continue; + if(attr == "tag" || attr == "children" || attr == "cn" || attr == "html" || typeof o[attr] == "function") { continue; } if(attr == "style"){ var s = o["style"]; if(typeof s == "function"){ @@ -4211,13 +4275,15 @@ Roo.DomHelper = function(){ for(var attr in o){ if(attr == "tag" || attr == "ns" ||attr == "xmlns" ||attr == "children" || attr == "cn" || attr == "html" || - attr == "style" || typeof o[attr] == "function") continue; + attr == "style" || typeof o[attr] == "function") { continue; } if(attr=="cls" && Roo.isIE){ el.className = o["cls"]; }else{ - if(useSet) el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]); - else el[attr] = o[attr]; + if(useSet) { el.setAttribute(attr=="cls" ? 'class' : attr, o[attr]);} + else { + el[attr] = o[attr]; + } } } Roo.DomHelper.applyStyles(el, o.style); @@ -4601,6 +4667,7 @@ Roo.Template.prototype = { * @return {String} The HTML fragment */ applyTemplate : function(values){ + Roo.log(["applyTemplate", values]); try { if(this.compiled){ @@ -6007,10 +6074,10 @@ Roo.util.Observable.releaseCapture = function(o){ var ls = this.listeners, scope, len = ls.length; if(len > 0){ this.firing = true; - var args = Array.prototype.slice.call(arguments, 0); + var args = Array.prototype.slice.call(arguments, 0); for(var i = 0; i < len; i++){ - var l = ls[i]; - if(l.fireFn.apply(l.scope||this.obj||window, arguments) === false){ + var l = ls[i]; + if(l.fireFn.apply(l.scope||this.obj||window, args) === false){ this.firing = false; return false; } @@ -6021,6 +6088,51 @@ Roo.util.Observable.releaseCapture = function(o){ } }; })();/* + * RooJS Library + * Copyright(c) 2007-2017, Roo J Solutions Ltd + * + * Licence LGPL + * + */ + +/** + * @class Roo.Document + * @extends Roo.util.Observable + * This is a convience class to wrap up the main document loading code.. , rather than adding Roo.onReady(......) + * + * @param {Object} config the methods and properties of the 'base' class for the application. + * + * Generic Page handler - implement this to start your app.. + * + * eg. + * MyProject = new Roo.Document({ + events : { + 'load' : true // your events.. + }, + listeners : { + 'ready' : function() { + // fired on Roo.onReady() + } + } + * + */ +Roo.Document = function(cfg) { + + this.addEvents({ + 'ready' : true + }); + Roo.util.Observable.call(this,cfg); + + var _this = this; + + Roo.onReady(function() { + _this.fireEvent('ready'); + },null,false); + + +} + +Roo.extend(Roo.Document, Roo.util.Observable, {});/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. @@ -6044,6 +6156,8 @@ Roo.EventManager = function(){ var E = Roo.lib.Event; var D = Roo.lib.Dom; + + var fireDocReady = function(){ if(!docReadyState){ @@ -6118,14 +6232,44 @@ Roo.EventManager = function(){ }, o.delay || 10); }; }; + var transitionEndVal = false; + + var transitionEnd = function() + { + if (transitionEndVal) { + return transitionEndVal; + } + var el = document.createElement('div'); + + var transEndEventNames = { + WebkitTransition : 'webkitTransitionEnd', + MozTransition : 'transitionend', + OTransition : 'oTransitionEnd otransitionend', + transition : 'transitionend' + }; + + for (var name in transEndEventNames) { + if (el.style[name] !== undefined) { + transitionEndVal = transEndEventNames[name]; + return transitionEndVal ; + } + } + } + var listen = function(element, ename, opt, fn, scope){ var o = (!opt || typeof opt == "boolean") ? {} : opt; fn = fn || o.fn; scope = scope || o.scope; var el = Roo.getDom(element); + + if(!el){ throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.'; } + + if (ename == 'transitionend') { + ename = transitionEnd(); + } var h = function(e){ e = Roo.EventObject.setEvent(e); var t; @@ -6162,9 +6306,14 @@ Roo.EventManager = function(){ if(o.buffer){ h = createBuffered(h, o); } + fn._handlers = fn._handlers || []; + + fn._handlers.push([Roo.id(el), ename, h]); - + + + E.on(el, ename, h); if(ename == "mousewheel" && el.addEventListener){ // workaround for jQuery el.addEventListener("DOMMouseScroll", h, false); @@ -6510,6 +6659,8 @@ Roo.onReady(function(){ var cls = [ Roo.isIE ? "roo-ie" + : Roo.isIE11 ? "roo-ie11" + : Roo.isEdge ? "roo-edge" : Roo.isGecko ? "roo-gecko" : Roo.isOpera ? "roo-opera" : Roo.isSafari ? "roo-safari" : ""]; @@ -6520,6 +6671,12 @@ Roo.onReady(function(){ if(Roo.isLinux){ cls.push("roo-linux"); } + if(Roo.isIOS){ + cls.push("roo-ios"); + } + if(Roo.isTouch){ + cls.push("roo-touch"); + } if(Roo.isBorderBox){ cls.push('roo-border-box'); } @@ -6981,6 +7138,7 @@ if(opt.anim.isAnimated()){ * @type String */ defaultUnit : "px", + /** * Sets the element's visibility mode. When setVisible() is called it * will use this to determine whether to set the visibility or the display property. @@ -6998,7 +7156,7 @@ if(opt.anim.isAnimated()){ */ enableDisplayMode : function(display){ this.setVisibilityMode(El.DISPLAY); - if(typeof display != "undefined") this.originalDisplay = display; + if(typeof display != "undefined") { this.originalDisplay = display; } return this; }, @@ -7040,6 +7198,37 @@ if(opt.anim.isAnimated()){ var p = Roo.fly(this.dom.parentNode, '_internal'); return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null; }, + + /** + * Looks at the scrollable parent element + */ + findScrollableParent : function() + { + var overflowRegex = /(auto|scroll)/; + + if(this.getStyle('position') === 'fixed'){ + return Roo.isAndroid ? Roo.get(document.documentElement) : Roo.get(document.body); + } + + var excludeStaticParent = this.getStyle('position') === "absolute"; + + for (var parent = this; (parent = Roo.get(parent.dom.parentNode));){ + + if (excludeStaticParent && parent.getStyle('position') === "static") { + continue; + } + + if (overflowRegex.test(parent.getStyle('overflow') + parent.getStyle('overflow-x') + parent.getStyle('overflow-y'))){ + return parent; + } + + if(parent.dom.nodeName.toLowerCase() == 'body'){ + return Roo.isAndroid ? Roo.get(document.documentElement) : Roo.get(document.body); + } + } + + return Roo.isAndroid ? Roo.get(document.documentElement) : Roo.get(document.body); + }, /** * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child). @@ -7219,7 +7408,7 @@ if(opt.anim.isAnimated()){ this.setHeight(oldHeight); // restore original height this.setHeight(height, animate, duration, function(){ this.unclip(); - if(typeof onComplete == "function") onComplete(); + if(typeof onComplete == "function") { onComplete(); } }.createDelegate(this), easing); } }.createDelegate(this), 0); @@ -8931,18 +9120,19 @@ if(opt.anim.isAnimated()){ */ mask : function(msg, msgCls) { - if(this.getStyle("position") == "static"){ + if(this.getStyle("position") == "static" && this.dom.tagName !== 'BODY'){ this.setStyle("position", "relative"); } if(!this._mask){ this._mask = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask"}, true); } + this.addClass("x-masked"); this._mask.setDisplayed(true); // we wander var z = 0; - var dom = this.dom + var dom = this.dom; while (dom && dom.style) { if (!isNaN(parseInt(dom.style.zIndex))) { z = Math.max(z, parseInt(dom.style.zIndex)); @@ -8958,11 +9148,24 @@ if(opt.anim.isAnimated()){ if(typeof msg == 'string'){ if(!this._maskMsg){ - this._maskMsg = Roo.DomHelper.append(this.dom, {cls:"roo-el-mask-msg", cn:{tag:'div'}}, true); + this._maskMsg = Roo.DomHelper.append(this.dom, { + cls: "roo-el-mask-msg", + cn: [ + { + tag: 'i', + cls: 'fa fa-spinner fa-spin' + }, + { + tag: 'div' + } + ] + }, true); } var mm = this._maskMsg; mm.dom.className = msgCls ? "roo-el-mask-msg " + msgCls : "roo-el-mask-msg"; - mm.dom.firstChild.innerHTML = msg; + if (mm.dom.lastChild) { // weird IE issue? + mm.dom.lastChild.innerHTML = msg; + } mm.setDisplayed(true); mm.center(this); mm.setStyle('z-index', z + 102); @@ -9315,12 +9518,15 @@ if(opt.anim.isAnimated()){ var el = this.dom; useSet = typeof useSet == 'undefined' ? (el.setAttribute ? true : false) : useSet; for(var attr in o){ - if(attr == "style" || typeof o[attr] == "function") continue; + if(attr == "style" || typeof o[attr] == "function") { continue; } if(attr=="cls"){ el.className = o["cls"]; }else{ - if(useSet) el.setAttribute(attr, o[attr]); - else el[attr] = o[attr]; + if(useSet) { + el.setAttribute(attr, o[attr]); + } else { + el[attr] = o[attr]; + } } } if(o.style){ @@ -9569,7 +9775,7 @@ if(opt.anim.isAnimated()){ /** * Sets or Returns the value the dom attribute value - * @param {String} name The attribute name + * @param {String|Object} name The attribute name (or object to set multiple attributes) * @param {String} value (optional) The value to set the attribute to * @return {String} The attribute value */ @@ -9578,6 +9784,14 @@ if(opt.anim.isAnimated()){ this.dom.setAttribute(name, arguments[1]); return arguments[1]; } + if (typeof(name) == 'object') { + for(var i in name) { + this.attr(i, name[i]); + } + return name; + } + + if (!this.dom.hasAttribute(name)) { return undefined; } @@ -10920,7 +11134,9 @@ Roo.CompositeElement = function(els){ Roo.CompositeElement.prototype = { isComposite: true, addElements : function(els){ - if(!els) return this; + if(!els) { + return this; + } if(typeof els == "string"){ els = Roo.Element.selectorFunction(els); } @@ -10946,12 +11162,15 @@ Roo.CompositeElement.prototype = { /** * Filters this composite to only elements that match the passed selector. * @param {String} selector A string CSS selector + * @param {Boolean} inverse return inverse filter (not matches) * @return {CompositeElement} this */ - filter : function(selector){ + filter : function(selector, inverse){ var els = []; + inverse = inverse || false; this.each(function(el){ - if(el.is(selector)){ + var match = inverse ? !el.is(selector) : el.is(selector); + if(match){ els[els.length] = el.dom; } }); @@ -11253,16 +11472,17 @@ Roo.CompositeElementLite.prototype.on = Roo.CompositeElementLite.prototype.addLi * @class Roo.data.Connection * @extends Roo.util.Observable * The class encapsulates a connection to the page's originating domain, allowing requests to be made - * either to a configured URL, or to a URL specified at request time.

- *

+ * either to a configured URL, or to a URL specified at request time. + * * Requests made by this class are asynchronous, and will return immediately. No data from * the server will be available to the statement immediately following the {@link #request} call. - * To process returned data, use a callback in the request options object, or an event listener.


- *

+ * To process returned data, use a callback in the request options object, or an event listener. + * * Note: If you are doing a file upload, you will not get a normal response object sent back to * your callback or event handler. Since the upload is handled via in IFRAME, there is no XMLHttpRequest. * The response object is created using the innerHTML of the IFRAME's document as the responseText - * property and, if present, the IFRAME's XML document as the responseXML property.


+ * property and, if present, the IFRAME's XML document as the responseXML property. + * * This means that a valid XML or HTML document must be returned. If JSON data is required, it is suggested * that it be placed either inside a <textarea> in an HTML document and retrieved from the responseText * using a regex, or inside a CDATA section in an XML document and retrieved from the responseXML using @@ -11394,6 +11614,11 @@ Roo.extend(Roo.data.Connection, Roo.util.Observable, { url = url || form.action; var enctype = form.getAttribute("enctype"); + + if (o.formData) { + return this.doFormDataUpload(o,p,url); + } + if(o.isUpload || (enctype && enctype.toLowerCase() == 'multipart/form-data')){ return this.doFormUpload(o, p, url); } @@ -11435,7 +11660,9 @@ Roo.extend(Roo.data.Connection, Roo.util.Observable, { url += (url.indexOf('?') != -1 ? '&' : '?') + p; p = ''; } + Roo.lib.Ajax.useDefaultHeader = typeof(o.headers) == 'undefined' || typeof(o.headers['Content-Type']) == 'undefined'; this.transId = Roo.lib.Ajax.request(method, url, cb, p, o); + Roo.lib.Ajax.useDefaultHeader == true; return this.transId; }else{ Roo.callback(o.callback, o.scope, [o, null, null]); @@ -11571,7 +11798,40 @@ Roo.extend(Roo.data.Connection, Roo.util.Observable, { form.removeChild(hiddens[i]); } } + }, + // this is a 'formdata version???' + + + doFormDataUpload : function(o, ps, url) + { + var form = Roo.getDom(o.form); + form.enctype = form.encoding = 'multipart/form-data'; + var formData = o.formData === true ? new FormData(form) : o.formData; + + var cb = { + success: this.handleResponse, + failure: this.handleFailure, + scope: this, + argument: {options: o}, + timeout : o.timeout || this.timeout + }; + + if(typeof o.autoAbort == 'boolean'){ // options gets top priority + if(o.autoAbort){ + this.abort(); + } + }else if(this.autoAbort !== false){ + this.abort(); + } + + //Roo.lib.Ajax.defaultPostHeader = null; + Roo.lib.Ajax.useDefaultHeader = false; + this.transId = Roo.lib.Ajax.request( "POST", url, cb, o.formData, o); + Roo.lib.Ajax.useDefaultHeader = true; + + } + }); /* * Based on: @@ -13008,7 +13268,9 @@ mc.add(otherEl); indexOf : function(o){ if(!this.items.indexOf){ for(var i = 0, len = this.items.length; i < len; i++){ - if(this.items[i] == o) return i; + if(this.items[i] == o) { + return i; + } } return -1; }else{ @@ -13024,7 +13286,9 @@ mc.add(otherEl); indexOfKey : function(key){ if(!this.keys.indexOf){ for(var i = 0, len = this.keys.length; i < len; i++){ - if(this.keys[i] == key) return i; + if(this.keys[i] == key) { + return i; + } } return -1; }else{ @@ -13038,6 +13302,9 @@ mc.add(otherEl); * @return {Object} The item associated with the passed key. */ item : function(key){ + if (key === 'length') { + return null; + } var item = typeof this.map[key] != "undefined" ? this.map[key] : this.items[key]; return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype! }, @@ -13558,12 +13825,15 @@ Roo.util.Format = function(){ * eventually this should probably emulate php's number_format * @param {Number/String} value The numeric value to format * @param {Number} decimals number of decimal places + * @param {String} delimiter for thousands (default comma) * @return {String} The formatted currency string */ - number : function(v,decimals) + number : function(v, decimals, thousandsDelimiter) { // multiply and round. decimals = typeof(decimals) == 'undefined' ? 2 : decimals; + thousandsDelimiter = typeof(thousandsDelimiter) == 'undefined' ? ',' : thousandsDelimiter; + var mul = Math.pow(10, decimals); var zero = String(mul).substring(1); v = (Math.round((v-0)*mul))/mul; @@ -13575,13 +13845,12 @@ Roo.util.Format = function(){ var ps = v.split('.'); var whole = ps[0]; - var r = /(\d+)(\d{3})/; // add comma's - while (r.test(whole)) { - whole = whole.replace(r, '$1' + ',' + '$2'); - } + if(thousandsDelimiter.length != 0) { + whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, thousandsDelimiter ); + } var sub = ps[1] ? // has decimals.. @@ -14723,7 +14992,9 @@ Roo.extend(Roo.state.Provider, Roo.util.Observable, { decodeValue : function(cookie){ var re = /^(a|n|d|b|s|o)\:(.*)$/; var matches = re.exec(unescape(cookie)); - if(!matches || !matches[1]) return; // non state cookie + if(!matches || !matches[1]) { + return; // non state cookie + } var type = matches[1]; var v = matches[2]; switch(type){ @@ -14770,7 +15041,9 @@ Roo.extend(Roo.state.Provider, Roo.util.Observable, { var flat = ""; for(var i = 0, len = v.length; i < len; i++){ flat += this.encodeValue(v[i]); - if(i != len-1) flat += "^"; + if(i != len-1) { + flat += "^"; + } } enc = "a:" + flat; }else if(typeof v == "object"){ @@ -15113,7 +15386,7 @@ Roo.Component = function(config){ destroy : true }); if(!this.id){ - this.id = "ext-comp-" + (++Roo.Component.AUTO_ID); + this.id = "roo-comp-" + (++Roo.Component.AUTO_ID); } Roo.ComponentMgr.register(this); Roo.Component.superclass.constructor.call(this); @@ -15153,7 +15426,7 @@ Roo.extend(Roo.Component, Roo.util.Observable, { * Whether the component can move the Dom node when rendering (defaults to true). */ allowDomMove : true, - /** @cfg {String} hideMode + /** @cfg {String} hideMode (display|visibility) * How this component should hidden. Supported values are * "visibility" (css visibility), "offsets" (negative offset position) and * "display" (css display) - defaults to "display". @@ -15166,7 +15439,7 @@ Roo.extend(Roo.Component, Roo.util.Observable, { /** * @cfg {String} actionMode * which property holds the element that used for hide() / show() / disable() / enable() - * default is 'el' + * default is 'el' for forms you probably want to set this to fieldEl */ actionMode : "el", @@ -15181,40 +15454,49 @@ Roo.extend(Roo.Component, Roo.util.Observable, { * @param {String/HTMLElement/Element} container (optional) The element this component should be rendered into. If it is being applied to existing markup, this should be left off. */ render : function(container, position){ - if(!this.rendered && this.fireEvent("beforerender", this) !== false){ - if(!container && this.el){ - this.el = Roo.get(this.el); - container = this.el.dom.parentNode; - this.allowDomMove = false; - } - this.container = Roo.get(container); - this.rendered = true; - if(position !== undefined){ - if(typeof position == 'number'){ - position = this.container.dom.childNodes[position]; - }else{ - position = Roo.getDom(position); - } - } - this.onRender(this.container, position || null); - if(this.cls){ - this.el.addClass(this.cls); - delete this.cls; - } - if(this.style){ - this.el.applyStyles(this.style); - delete this.style; - } - this.fireEvent("render", this); - this.afterRender(this.container); - if(this.hidden){ - this.hide(); - } - if(this.disabled){ - this.disable(); + + if(this.rendered){ + return this; + } + + if(this.fireEvent("beforerender", this) === false){ + return false; + } + + if(!container && this.el){ + this.el = Roo.get(this.el); + container = this.el.dom.parentNode; + this.allowDomMove = false; + } + this.container = Roo.get(container); + this.rendered = true; + if(position !== undefined){ + if(typeof position == 'number'){ + position = this.container.dom.childNodes[position]; + }else{ + position = Roo.getDom(position); } } + this.onRender(this.container, position || null); + if(this.cls){ + this.el.addClass(this.cls); + delete this.cls; + } + if(this.style){ + this.el.applyStyles(this.style); + delete this.style; + } + this.fireEvent("render", this); + this.afterRender(this.container); + if(this.hidden){ + this.hide(); + } + if(this.disabled){ + this.disable(); + } + return this; + }, /** @private */ @@ -15730,6 +16012,9 @@ Roo.extend(Roo.BoxComponent, Roo.Component, { * @class Roo.XComponent * A delayed Element creator... * Or a way to group chunks of interface together. + * technically this is a wrapper around a tree of Roo elements (which defines a 'module'), + * used in conjunction with XComponent.build() it will create an instance of each element, + * then call addxtype() to build the User interface. * * Mypart.xyx = new Roo.XComponent({ @@ -15753,6 +16038,43 @@ Roo.extend(Roo.BoxComponent, Roo.Component, { * It can be used to build a big heiracy, with parent etc. * or you can just use this to render a single compoent to a dom element * MYPART.render(Roo.Element | String(id) | dom_element ) + * + * + * Usage patterns. + * + * Classic Roo + * + * Roo is designed primarily as a single page application, so the UI build for a standard interface will + * expect a single 'TOP' level module normally indicated by the 'parent' of the XComponent definition being defined as false. + * + * Each sub module is expected to have a parent pointing to the class name of it's parent module. + * + * When the top level is false, a 'Roo.BorderLayout' is created and the element is flagged as 'topModule' + * - if mulitple topModules exist, the last one is defined as the top module. + * + * Embeded Roo + * + * When the top level or multiple modules are to embedded into a existing HTML page, + * the parent element can container '#id' of the element where the module will be drawn. + * + * Bootstrap Roo + * + * Unlike classic Roo, the bootstrap tends not to be used as a single page. + * it relies more on a include mechanism, where sub modules are included into an outer page. + * This is normally managed by the builder tools using Roo.apply( options, Included.Sub.Module ) + * + * Bootstrap Roo Included elements + * + * Our builder application needs the ability to preview these sub compoennts. They will normally have parent=false set, + * hence confusing the component builder as it thinks there are multiple top level elements. + * + * String Over-ride & Translations + * + * Our builder application writes all the strings as _strings and _named_strings. This is to enable the translation of elements, + * and also the 'overlaying of string values - needed when different versions of the same application with different text content + * are needed. @see Roo.XComponent.overlayString + * + * * * @extends Roo.util.Observable * @constructor @@ -15853,66 +16175,162 @@ Roo.extend(Roo.XComponent, Roo.util.Observable, { el = el || false; var hp = this.parent ? 1 : 0; + Roo.debug && Roo.log(this); + + var tree = this._tree ? this._tree() : this.tree(); + if (!el && typeof(this.parent) == 'string' && this.parent.substring(0,1) == '#') { // if parent is a '#.....' string, then let's use that.. - var ename = this.parent.substr(1) - this.parent = (this.parent == '#bootstrap') ? { el : true} : false; // flags it as a top module... - el = Roo.get(ename); + var ename = this.parent.substr(1); + this.parent = false; + Roo.debug && Roo.log(ename); + switch (ename) { + case 'bootstrap-body': + if (typeof(tree.el) != 'undefined' && tree.el == document.body) { + // this is the BorderLayout standard? + this.parent = { el : true }; + break; + } + if (["Nest", "Content", "Grid", "Tree"].indexOf(tree.xtype) > -1) { + // need to insert stuff... + this.parent = { + el : new Roo.bootstrap.layout.Border({ + el : document.body, + + center: { + titlebar: false, + autoScroll:false, + closeOnTab: true, + tabPosition: 'top', + //resizeTabs: true, + alwaysShowTabs: true, + hideTabs: false + //minTabWidth: 140 + } + }) + + }; + break; + } + + if (typeof(Roo.bootstrap.Body) != 'undefined' ) { + this.parent = { el : new Roo.bootstrap.Body() }; + Roo.debug && Roo.log("setting el to doc body"); + + } else { + throw "Container is bootstrap body, but Roo.bootstrap.Body is not defined"; + } + break; + case 'bootstrap': + this.parent = { el : true}; + // fall through + default: + el = Roo.get(ename); + if (typeof(Roo.bootstrap) != 'undefined' && tree['|xns'] == 'Roo.bootstrap') { + this.parent = { el : true}; + } + + break; + } + + if (!el && !this.parent) { - Roo.log("Warning - element can not be found :#" + ename ); + Roo.debug && Roo.log("Warning - element can not be found :#" + ename ); return; } } + Roo.debug && Roo.log("EL:"); + Roo.debug && Roo.log(el); + Roo.debug && Roo.log("this.parent.el:"); + Roo.debug && Roo.log(this.parent.el); + + + // altertive root elements ??? - we need a better way to indicate these. + var is_alt = Roo.XComponent.is_alt || + (typeof(tree.el) != 'undefined' && tree.el == document.body) || + (typeof(Roo.bootstrap) != 'undefined' && tree.xns == Roo.bootstrap) || + (typeof(Roo.mailer) != 'undefined' && tree.xns == Roo.mailer) ; + + + + if (!this.parent && is_alt) { + //el = Roo.get(document.body); + this.parent = { el : true }; + } + + if (!this.parent) { + Roo.debug && Roo.log("no parent - creating one"); + el = el ? Roo.get(el) : false; - // it's a top level one.. - this.parent = { - el : new Roo.BorderLayout(el || document.body, { + if (typeof(Roo.BorderLayout) == 'undefined' ) { - center: { - titlebar: false, - autoScroll:false, - closeOnTab: true, - tabPosition: 'top', - //resizeTabs: true, - alwaysShowTabs: el && hp? false : true, - hideTabs: el || !hp ? true : false, - minTabWidth: 140 - } - }) + this.parent = { + el : new Roo.bootstrap.layout.Border({ + el: el || document.body, + + center: { + titlebar: false, + autoScroll:false, + closeOnTab: true, + tabPosition: 'top', + //resizeTabs: true, + alwaysShowTabs: false, + hideTabs: true, + minTabWidth: 140, + overflow: 'visible' + } + }) + }; + } else { + + // it's a top level one.. + this.parent = { + el : new Roo.BorderLayout(el || document.body, { + center: { + titlebar: false, + autoScroll:false, + closeOnTab: true, + tabPosition: 'top', + //resizeTabs: true, + alwaysShowTabs: el && hp? false : true, + hideTabs: el || !hp ? true : false, + minTabWidth: 140 + } + }) + }; } } - if (!this.parent.el) { - // probably an old style ctor, which has been disabled. - return; - - } + if (!this.parent.el) { + // probably an old style ctor, which has been disabled. + return; + + } // The 'tree' method is '_tree now' - var tree = this._tree ? this._tree() : this.tree(); tree.region = tree.region || this.region; - - Roo.log('tree'); - Roo.log(tree); - + var is_body = false; if (this.parent.el === true) { // bootstrap... - body.. + if (el) { + tree.el = el; + } this.parent.el = Roo.factory(tree); + is_body = true; } - Roo.log('this.parent.el'); - Roo.log(this.parent.el); - this.el = this.parent.el.addxtype(tree); + + this.el = this.parent.el.addxtype(tree, undefined, is_body); this.fireEvent('built', this); this.panel = this.el; this.layout = this.panel.layout; - this.parentLayout = this.parent.layout || false; + this.parentLayout = this.parent.layout || false; } @@ -15955,7 +16373,22 @@ Roo.apply(Roo.XComponent, { elmodules : [], - + /** + * @property is_alt + * Is an alternative Root - normally used by bootstrap or other systems, + * where the top element in the tree can wrap 'body' + * @type {boolean} (default false) + */ + + is_alt : false, + /** + * @property build_from_html + * Build elements from html - used by bootstrap HTML stuff + * - this is cleared after build is completed + * @type {boolean} (default false) + */ + + build_from_html : false, /** * Register components to be built later. * @@ -15992,7 +16425,7 @@ Roo.apply(Roo.XComponent, { break; default: - if (obj.disabled) { + if (obj.disabled || obj.region == '#disabled') { return; } break; @@ -16056,7 +16489,7 @@ Roo.apply(Roo.XComponent, { try { obj.parent = this.toObject(opar); } catch(e) { - Roo.log("parent:toObject failed: " + e.toString()); + Roo.debug && Roo.log("parent:toObject failed: " + e.toString()); return; } @@ -16075,7 +16508,7 @@ Roo.apply(Roo.XComponent, { return; } if (obj.parent.constructor != Roo.XComponent) { - Roo.log("Warning : Object Parent is not instance of XComponent:" + obj.name) + Roo.debug && Roo.log("Warning : Object Parent is not instance of XComponent:" + obj.name) } if (!obj.parent.modules) { obj.parent.modules = new Roo.util.MixedCollection(false, @@ -16158,9 +16591,13 @@ Roo.apply(Roo.XComponent, { * */ - build : function() + build : function(opts) { + if (typeof(opts) != 'undefined') { + Roo.apply(this,opts); + } + this.preBuild(); var mods = this.buildOrder(); @@ -16181,6 +16618,7 @@ Roo.apply(Roo.XComponent, { msg: msg, width:450, progress:true, + buttons : false, closable:false, modal: false @@ -16195,6 +16633,8 @@ Roo.apply(Roo.XComponent, { if (!this.hideProgress && Roo.MessageBox) { Roo.MessageBox.hide(); } + Roo.XComponent.build_from_html = false; // reset, so dialogs will be build from javascript + Roo.XComponent.event.fireEvent('buildcomplete', _this.topModule); // THE END... @@ -16216,7 +16656,7 @@ Roo.apply(Roo.XComponent, { " of " + total + (m.name ? (' - ' + m.name) : ''); Roo.debug && Roo.log(msg); - if (!this.hideProgress && Roo.MessageBox) { + if (!_this.hideProgress && Roo.MessageBox) { Roo.MessageBox.updateProgress( (total - mods.length)/total, msg ); } @@ -16244,7 +16684,32 @@ Roo.apply(Roo.XComponent, { }, - + /** + * Overlay a set of modified strings onto a component + * This is dependant on our builder exporting the strings and 'named strings' elements. + * + * @param {Object} element to overlay on - eg. Pman.Dialog.Login + * @param {Object} associative array of 'named' string and it's new value. + * + */ + overlayStrings : function( component, strings ) + { + if (typeof(component['_named_strings']) == 'undefined') { + throw "ERROR: component does not have _named_strings"; + } + for ( var k in strings ) { + var md = typeof(component['_named_strings'][k]) == 'undefined' ? false : component['_named_strings'][k]; + if (md !== false) { + component['_strings'][md] = strings[k]; + } else { + Roo.log('could not find named string: ' + k + ' in'); + Roo.log(component); + } + + } + + }, + /** * Event Object. @@ -16294,4 +16759,5728 @@ Roo.XComponent.event = new Roo.util.Observable({ }); Roo.XComponent.on = Roo.XComponent.event.on.createDelegate(Roo.XComponent.event); - \ No newline at end of file + // + /** + * marked - a markdown parser + * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) + * https://github.com/chjj/marked + */ + + +/** + * + * Roo.Markdown - is a very crude wrapper around marked.. + * + * usage: + * + * alert( Roo.Markdown.toHtml("Markdown *rocks*.") ); + * + * Note: move the sample code to the bottom of this + * file before uncommenting it. + * + */ + +Roo.Markdown = {}; +Roo.Markdown.toHtml = function(text) { + + var c = new Roo.Markdown.marked.setOptions({ + renderer: new Roo.Markdown.marked.Renderer(), + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: true, + smartypants: false + }); + // A FEW HACKS!!? + + text = text.replace(/\\\n/g,' '); + return Roo.Markdown.marked(text); +}; +// +// converter +// +// Wraps all "globals" so that the only thing +// exposed is makeHtml(). +// +(function() { + + /** + * eval:var:escape + * eval:var:unescape + * eval:var:replace + */ + + /** + * Helpers + */ + + var escape = function (html, encode) { + return html + .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + } + + var unescape = function (html) { + // explicitly match decimal, hex, and named HTML entities + return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) { + n = n.toLowerCase(); + if (n === 'colon') { return ':'; } + if (n.charAt(0) === '#') { + return n.charAt(1) === 'x' + ? String.fromCharCode(parseInt(n.substring(2), 16)) + : String.fromCharCode(+n.substring(1)); + } + return ''; + }); + } + + var replace = function (regex, opt) { + regex = regex.source; + opt = opt || ''; + return function self(name, val) { + if (!name) { return new RegExp(regex, opt); } + val = val.source || val; + val = val.replace(/(^|[^\[])\^/g, '$1'); + regex = regex.replace(name, val); + return self; + }; + } + + + /** + * eval:var:noop + */ + var noop = function () {} + noop.exec = noop; + + /** + * eval:var:merge + */ + var merge = function (obj) { + var i = 1 + , target + , key; + + for (; i < arguments.length; i++) { + target = arguments[i]; + for (key in target) { + if (Object.prototype.hasOwnProperty.call(target, key)) { + obj[key] = target[key]; + } + } + } + + return obj; + } + + + /** + * Block-Level Grammar + */ + + + + + var block = { + newline: /^\n+/, + code: /^( {4}[^\n]+\n*)+/, + fences: noop, + hr: /^( *[-*_]){3,} *(?:\n+|$)/, + heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, + nptable: noop, + lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, + blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/, + list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, + html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, + def: /^ *\[([^\]]+)\]: *]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, + table: noop, + paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/, + text: /^[^\n]+/ + }; + + block.bullet = /(?:[*+-]|\d+\.)/; + block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/; + block.item = replace(block.item, 'gm') + (/bull/g, block.bullet) + (); + + block.list = replace(block.list) + (/bull/g, block.bullet) + ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))') + ('def', '\\n+(?=' + block.def.source + ')') + (); + + block.blockquote = replace(block.blockquote) + ('def', block.def) + (); + + block._tag = '(?!(?:' + + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' + + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' + + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b'; + + block.html = replace(block.html) + ('comment', //) + ('closed', /<(tag)[\s\S]+?<\/\1>/) + ('closing', /])*?>/) + (/tag/g, block._tag) + (); + + block.paragraph = replace(block.paragraph) + ('hr', block.hr) + ('heading', block.heading) + ('lheading', block.lheading) + ('blockquote', block.blockquote) + ('tag', '<' + block._tag) + ('def', block.def) + (); + + /** + * Normal Block Grammar + */ + + block.normal = merge({}, block); + + /** + * GFM Block Grammar + */ + + block.gfm = merge({}, block.normal, { + fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/, + paragraph: /^/, + heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ + }); + + block.gfm.paragraph = replace(block.paragraph) + ('(?!', '(?!' + + block.gfm.fences.source.replace('\\1', '\\2') + '|' + + block.list.source.replace('\\1', '\\3') + '|') + (); + + /** + * GFM + Tables Block Grammar + */ + + block.tables = merge({}, block.gfm, { + nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, + table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ + }); + + /** + * Block Lexer + */ + + var Lexer = function (options) { + this.tokens = []; + this.tokens.links = {}; + this.options = options || marked.defaults; + this.rules = block.normal; + + if (this.options.gfm) { + if (this.options.tables) { + this.rules = block.tables; + } else { + this.rules = block.gfm; + } + } + } + + /** + * Expose Block Rules + */ + + Lexer.rules = block; + + /** + * Static Lex Method + */ + + Lexer.lex = function(src, options) { + var lexer = new Lexer(options); + return lexer.lex(src); + }; + + /** + * Preprocessing + */ + + Lexer.prototype.lex = function(src) { + src = src + .replace(/\r\n|\r/g, '\n') + .replace(/\t/g, ' ') + .replace(/\u00a0/g, ' ') + .replace(/\u2424/g, '\n'); + + return this.token(src, true); + }; + + /** + * Lexing + */ + + Lexer.prototype.token = function(src, top, bq) { + var src = src.replace(/^ +$/gm, '') + , next + , loose + , cap + , bull + , b + , item + , space + , i + , l; + + while (src) { + // newline + if (cap = this.rules.newline.exec(src)) { + src = src.substring(cap[0].length); + if (cap[0].length > 1) { + this.tokens.push({ + type: 'space' + }); + } + } + + // code + if (cap = this.rules.code.exec(src)) { + src = src.substring(cap[0].length); + cap = cap[0].replace(/^ {4}/gm, ''); + this.tokens.push({ + type: 'code', + text: !this.options.pedantic + ? cap.replace(/\n+$/, '') + : cap + }); + continue; + } + + // fences (gfm) + if (cap = this.rules.fences.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'code', + lang: cap[2], + text: cap[3] || '' + }); + continue; + } + + // heading + if (cap = this.rules.heading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[1].length, + text: cap[2] + }); + continue; + } + + // table no leading pipe (gfm) + if (top && (cap = this.rules.nptable.exec(src))) { + src = src.substring(cap[0].length); + + item = { + type: 'table', + header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3].replace(/\n$/, '').split('\n') + }; + + for (i = 0; i < item.align.length; i++) { + if (/^ *-+: *$/.test(item.align[i])) { + item.align[i] = 'right'; + } else if (/^ *:-+: *$/.test(item.align[i])) { + item.align[i] = 'center'; + } else if (/^ *:-+ *$/.test(item.align[i])) { + item.align[i] = 'left'; + } else { + item.align[i] = null; + } + } + + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = item.cells[i].split(/ *\| */); + } + + this.tokens.push(item); + + continue; + } + + // lheading + if (cap = this.rules.lheading.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'heading', + depth: cap[2] === '=' ? 1 : 2, + text: cap[1] + }); + continue; + } + + // hr + if (cap = this.rules.hr.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'hr' + }); + continue; + } + + // blockquote + if (cap = this.rules.blockquote.exec(src)) { + src = src.substring(cap[0].length); + + this.tokens.push({ + type: 'blockquote_start' + }); + + cap = cap[0].replace(/^ *> ?/gm, ''); + + // Pass `top` to keep the current + // "toplevel" state. This is exactly + // how markdown.pl works. + this.token(cap, top, true); + + this.tokens.push({ + type: 'blockquote_end' + }); + + continue; + } + + // list + if (cap = this.rules.list.exec(src)) { + src = src.substring(cap[0].length); + bull = cap[2]; + + this.tokens.push({ + type: 'list_start', + ordered: bull.length > 1 + }); + + // Get each top-level item. + cap = cap[0].match(this.rules.item); + + next = false; + l = cap.length; + i = 0; + + for (; i < l; i++) { + item = cap[i]; + + // Remove the list item's bullet + // so it is seen as the next token. + space = item.length; + item = item.replace(/^ *([*+-]|\d+\.) +/, ''); + + // Outdent whatever the + // list item contains. Hacky. + if (~item.indexOf('\n ')) { + space -= item.length; + item = !this.options.pedantic + ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') + : item.replace(/^ {1,4}/gm, ''); + } + + // Determine whether the next list item belongs here. + // Backpedal if it does not belong in this list. + if (this.options.smartLists && i !== l - 1) { + b = block.bullet.exec(cap[i + 1])[0]; + if (bull !== b && !(bull.length > 1 && b.length > 1)) { + src = cap.slice(i + 1).join('\n') + src; + i = l - 1; + } + } + + // Determine whether item is loose or not. + // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/ + // for discount behavior. + loose = next || /\n\n(?!\s*$)/.test(item); + if (i !== l - 1) { + next = item.charAt(item.length - 1) === '\n'; + if (!loose) { loose = next; } + } + + this.tokens.push({ + type: loose + ? 'loose_item_start' + : 'list_item_start' + }); + + // Recurse. + this.token(item, false, bq); + + this.tokens.push({ + type: 'list_item_end' + }); + } + + this.tokens.push({ + type: 'list_end' + }); + + continue; + } + + // html + if (cap = this.rules.html.exec(src)) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: this.options.sanitize + ? 'paragraph' + : 'html', + pre: !this.options.sanitizer + && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'), + text: cap[0] + }); + continue; + } + + // def + if ((!bq && top) && (cap = this.rules.def.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.links[cap[1].toLowerCase()] = { + href: cap[2], + title: cap[3] + }; + continue; + } + + // table (gfm) + if (top && (cap = this.rules.table.exec(src))) { + src = src.substring(cap[0].length); + + item = { + type: 'table', + header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n') + }; + + for (i = 0; i < item.align.length; i++) { + if (/^ *-+: *$/.test(item.align[i])) { + item.align[i] = 'right'; + } else if (/^ *:-+: *$/.test(item.align[i])) { + item.align[i] = 'center'; + } else if (/^ *:-+ *$/.test(item.align[i])) { + item.align[i] = 'left'; + } else { + item.align[i] = null; + } + } + + for (i = 0; i < item.cells.length; i++) { + item.cells[i] = item.cells[i] + .replace(/^ *\| *| *\| *$/g, '') + .split(/ *\| */); + } + + this.tokens.push(item); + + continue; + } + + // top-level paragraph + if (top && (cap = this.rules.paragraph.exec(src))) { + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'paragraph', + text: cap[1].charAt(cap[1].length - 1) === '\n' + ? cap[1].slice(0, -1) + : cap[1] + }); + continue; + } + + // text + if (cap = this.rules.text.exec(src)) { + // Top-level should never reach here. + src = src.substring(cap[0].length); + this.tokens.push({ + type: 'text', + text: cap[0] + }); + continue; + } + + if (src) { + throw new + Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return this.tokens; + }; + + /** + * Inline-Level Grammar + */ + + var inline = { + escape: /^\\([\\`*{}\[\]()#+\-.!_>])/, + autolink: /^<([^ >]+(@|:\/)[^ >]+)>/, + url: noop, + tag: /^|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/, + link: /^!?\[(inside)\]\(href\)/, + reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/, + nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/, + strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/, + em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, + code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/, + br: /^ {2,}\n(?!\s*$)/, + del: noop, + text: /^[\s\S]+?(?=[\\?(?:\s+['"]([\s\S]*?)['"])?\s*/; + + inline.link = replace(inline.link) + ('inside', inline._inside) + ('href', inline._href) + (); + + inline.reflink = replace(inline.reflink) + ('inside', inline._inside) + (); + + /** + * Normal Inline Grammar + */ + + inline.normal = merge({}, inline); + + /** + * Pedantic Inline Grammar + */ + + inline.pedantic = merge({}, inline.normal, { + strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/, + em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/ + }); + + /** + * GFM Inline Grammar + */ + + inline.gfm = merge({}, inline.normal, { + escape: replace(inline.escape)('])', '~|])')(), + url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/, + del: /^~~(?=\S)([\s\S]*?\S)~~/, + text: replace(inline.text) + (']|', '~]|') + ('|', '|https?://|') + () + }); + + /** + * GFM + Line Breaks Inline Grammar + */ + + inline.breaks = merge({}, inline.gfm, { + br: replace(inline.br)('{2,}', '*')(), + text: replace(inline.gfm.text)('{2,}', '*')() + }); + + /** + * Inline Lexer & Compiler + */ + + var InlineLexer = function (links, options) { + this.options = options || marked.defaults; + this.links = links; + this.rules = inline.normal; + this.renderer = this.options.renderer || new Renderer; + this.renderer.options = this.options; + + if (!this.links) { + throw new + Error('Tokens array requires a `links` property.'); + } + + if (this.options.gfm) { + if (this.options.breaks) { + this.rules = inline.breaks; + } else { + this.rules = inline.gfm; + } + } else if (this.options.pedantic) { + this.rules = inline.pedantic; + } + } + + /** + * Expose Inline Rules + */ + + InlineLexer.rules = inline; + + /** + * Static Lexing/Compiling Method + */ + + InlineLexer.output = function(src, links, options) { + var inline = new InlineLexer(links, options); + return inline.output(src); + }; + + /** + * Lexing/Compiling + */ + + InlineLexer.prototype.output = function(src) { + var out = '' + , link + , text + , href + , cap; + + while (src) { + // escape + if (cap = this.rules.escape.exec(src)) { + src = src.substring(cap[0].length); + out += cap[1]; + continue; + } + + // autolink + if (cap = this.rules.autolink.exec(src)) { + src = src.substring(cap[0].length); + if (cap[2] === '@') { + text = cap[1].charAt(6) === ':' + ? this.mangle(cap[1].substring(7)) + : this.mangle(cap[1]); + href = this.mangle('mailto:') + text; + } else { + text = escape(cap[1]); + href = text; + } + out += this.renderer.link(href, null, text); + continue; + } + + // url (gfm) + if (!this.inLink && (cap = this.rules.url.exec(src))) { + src = src.substring(cap[0].length); + text = escape(cap[1]); + href = text; + out += this.renderer.link(href, null, text); + continue; + } + + // tag + if (cap = this.rules.tag.exec(src)) { + if (!this.inLink && /^/i.test(cap[0])) { + this.inLink = false; + } + src = src.substring(cap[0].length); + out += this.options.sanitize + ? this.options.sanitizer + ? this.options.sanitizer(cap[0]) + : escape(cap[0]) + : cap[0]; + continue; + } + + // link + if (cap = this.rules.link.exec(src)) { + src = src.substring(cap[0].length); + this.inLink = true; + out += this.outputLink(cap, { + href: cap[2], + title: cap[3] + }); + this.inLink = false; + continue; + } + + // reflink, nolink + if ((cap = this.rules.reflink.exec(src)) + || (cap = this.rules.nolink.exec(src))) { + src = src.substring(cap[0].length); + link = (cap[2] || cap[1]).replace(/\s+/g, ' '); + link = this.links[link.toLowerCase()]; + if (!link || !link.href) { + out += cap[0].charAt(0); + src = cap[0].substring(1) + src; + continue; + } + this.inLink = true; + out += this.outputLink(cap, link); + this.inLink = false; + continue; + } + + // strong + if (cap = this.rules.strong.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.strong(this.output(cap[2] || cap[1])); + continue; + } + + // em + if (cap = this.rules.em.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.em(this.output(cap[2] || cap[1])); + continue; + } + + // code + if (cap = this.rules.code.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.codespan(escape(cap[2], true)); + continue; + } + + // br + if (cap = this.rules.br.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.br(); + continue; + } + + // del (gfm) + if (cap = this.rules.del.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.del(this.output(cap[1])); + continue; + } + + // text + if (cap = this.rules.text.exec(src)) { + src = src.substring(cap[0].length); + out += this.renderer.text(escape(this.smartypants(cap[0]))); + continue; + } + + if (src) { + throw new + Error('Infinite loop on byte: ' + src.charCodeAt(0)); + } + } + + return out; + }; + + /** + * Compile Link + */ + + InlineLexer.prototype.outputLink = function(cap, link) { + var href = escape(link.href) + , title = link.title ? escape(link.title) : null; + + return cap[0].charAt(0) !== '!' + ? this.renderer.link(href, title, this.output(cap[1])) + : this.renderer.image(href, title, escape(cap[1])); + }; + + /** + * Smartypants Transformations + */ + + InlineLexer.prototype.smartypants = function(text) { + if (!this.options.smartypants) { return text; } + return text + // em-dashes + .replace(/---/g, '\u2014') + // en-dashes + .replace(/--/g, '\u2013') + // opening singles + .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018') + // closing singles & apostrophes + .replace(/'/g, '\u2019') + // opening doubles + .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c') + // closing doubles + .replace(/"/g, '\u201d') + // ellipses + .replace(/\.{3}/g, '\u2026'); + }; + + /** + * Mangle Links + */ + + InlineLexer.prototype.mangle = function(text) { + if (!this.options.mangle) { return text; } + var out = '' + , l = text.length + , i = 0 + , ch; + + for (; i < l; i++) { + ch = text.charCodeAt(i); + if (Math.random() > 0.5) { + ch = 'x' + ch.toString(16); + } + out += '&#' + ch + ';'; + } + + return out; + }; + + /** + * Renderer + */ + + /** + * eval:var:Renderer + */ + + var Renderer = function (options) { + this.options = options || {}; + } + + Renderer.prototype.code = function(code, lang, escaped) { + if (this.options.highlight) { + var out = this.options.highlight(code, lang); + if (out != null && out !== code) { + escaped = true; + code = out; + } + } else { + // hack!!! - it's already escapeD? + escaped = true; + } + + if (!lang) { + return '
'
+          + (escaped ? code : escape(code, true))
+          + '\n
'; + } + + return '
'
+        + (escaped ? code : escape(code, true))
+        + '\n
\n'; + }; + + Renderer.prototype.blockquote = function(quote) { + return '
\n' + quote + '
\n'; + }; + + Renderer.prototype.html = function(html) { + return html; + }; + + Renderer.prototype.heading = function(text, level, raw) { + return '' + + text + + '\n'; + }; + + Renderer.prototype.hr = function() { + return this.options.xhtml ? '
\n' : '
\n'; + }; + + Renderer.prototype.list = function(body, ordered) { + var type = ordered ? 'ol' : 'ul'; + return '<' + type + '>\n' + body + '\n'; + }; + + Renderer.prototype.listitem = function(text) { + return '
  • ' + text + '
  • \n'; + }; + + Renderer.prototype.paragraph = function(text) { + return '

    ' + text + '

    \n'; + }; + + Renderer.prototype.table = function(header, body) { + return '\n' + + '\n' + + header + + '\n' + + '\n' + + body + + '\n' + + '
    \n'; + }; + + Renderer.prototype.tablerow = function(content) { + return '\n' + content + '\n'; + }; + + Renderer.prototype.tablecell = function(content, flags) { + var type = flags.header ? 'th' : 'td'; + var tag = flags.align + ? '<' + type + ' style="text-align:' + flags.align + '">' + : '<' + type + '>'; + return tag + content + '\n'; + }; + + // span level renderer + Renderer.prototype.strong = function(text) { + return '' + text + ''; + }; + + Renderer.prototype.em = function(text) { + return '' + text + ''; + }; + + Renderer.prototype.codespan = function(text) { + return '' + text + ''; + }; + + Renderer.prototype.br = function() { + return this.options.xhtml ? '
    ' : '
    '; + }; + + Renderer.prototype.del = function(text) { + return '' + text + ''; + }; + + Renderer.prototype.link = function(href, title, text) { + if (this.options.sanitize) { + try { + var prot = decodeURIComponent(unescape(href)) + .replace(/[^\w:]/g, '') + .toLowerCase(); + } catch (e) { + return ''; + } + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) { + return ''; + } + } + var out = '
    '; + return out; + }; + + Renderer.prototype.image = function(href, title, text) { + var out = '' + text + '' : '>'; + return out; + }; + + Renderer.prototype.text = function(text) { + return text; + }; + + /** + * Parsing & Compiling + */ + /** + * eval:var:Parser + */ + + var Parser= function (options) { + this.tokens = []; + this.token = null; + this.options = options || marked.defaults; + this.options.renderer = this.options.renderer || new Renderer; + this.renderer = this.options.renderer; + this.renderer.options = this.options; + } + + /** + * Static Parse Method + */ + + Parser.parse = function(src, options, renderer) { + var parser = new Parser(options, renderer); + return parser.parse(src); + }; + + /** + * Parse Loop + */ + + Parser.prototype.parse = function(src) { + this.inline = new InlineLexer(src.links, this.options, this.renderer); + this.tokens = src.reverse(); + + var out = ''; + while (this.next()) { + out += this.tok(); + } + + return out; + }; + + /** + * Next Token + */ + + Parser.prototype.next = function() { + return this.token = this.tokens.pop(); + }; + + /** + * Preview Next Token + */ + + Parser.prototype.peek = function() { + return this.tokens[this.tokens.length - 1] || 0; + }; + + /** + * Parse Text Tokens + */ + + Parser.prototype.parseText = function() { + var body = this.token.text; + + while (this.peek().type === 'text') { + body += '\n' + this.next().text; + } + + return this.inline.output(body); + }; + + /** + * Parse Current Token + */ + + Parser.prototype.tok = function() { + switch (this.token.type) { + case 'space': { + return ''; + } + case 'hr': { + return this.renderer.hr(); + } + case 'heading': { + return this.renderer.heading( + this.inline.output(this.token.text), + this.token.depth, + this.token.text); + } + case 'code': { + return this.renderer.code(this.token.text, + this.token.lang, + this.token.escaped); + } + case 'table': { + var header = '' + , body = '' + , i + , row + , cell + , flags + , j; + + // header + cell = ''; + for (i = 0; i < this.token.header.length; i++) { + flags = { header: true, align: this.token.align[i] }; + cell += this.renderer.tablecell( + this.inline.output(this.token.header[i]), + { header: true, align: this.token.align[i] } + ); + } + header += this.renderer.tablerow(cell); + + for (i = 0; i < this.token.cells.length; i++) { + row = this.token.cells[i]; + + cell = ''; + for (j = 0; j < row.length; j++) { + cell += this.renderer.tablecell( + this.inline.output(row[j]), + { header: false, align: this.token.align[j] } + ); + } + + body += this.renderer.tablerow(cell); + } + return this.renderer.table(header, body); + } + case 'blockquote_start': { + var body = ''; + + while (this.next().type !== 'blockquote_end') { + body += this.tok(); + } + + return this.renderer.blockquote(body); + } + case 'list_start': { + var body = '' + , ordered = this.token.ordered; + + while (this.next().type !== 'list_end') { + body += this.tok(); + } + + return this.renderer.list(body, ordered); + } + case 'list_item_start': { + var body = ''; + + while (this.next().type !== 'list_item_end') { + body += this.token.type === 'text' + ? this.parseText() + : this.tok(); + } + + return this.renderer.listitem(body); + } + case 'loose_item_start': { + var body = ''; + + while (this.next().type !== 'list_item_end') { + body += this.tok(); + } + + return this.renderer.listitem(body); + } + case 'html': { + var html = !this.token.pre && !this.options.pedantic + ? this.inline.output(this.token.text) + : this.token.text; + return this.renderer.html(html); + } + case 'paragraph': { + return this.renderer.paragraph(this.inline.output(this.token.text)); + } + case 'text': { + return this.renderer.paragraph(this.parseText()); + } + } + }; + + + /** + * Marked + */ + /** + * eval:var:marked + */ + var marked = function (src, opt, callback) { + if (callback || typeof opt === 'function') { + if (!callback) { + callback = opt; + opt = null; + } + + opt = merge({}, marked.defaults, opt || {}); + + var highlight = opt.highlight + , tokens + , pending + , i = 0; + + try { + tokens = Lexer.lex(src, opt) + } catch (e) { + return callback(e); + } + + pending = tokens.length; + /** + * eval:var:done + */ + var done = function(err) { + if (err) { + opt.highlight = highlight; + return callback(err); + } + + var out; + + try { + out = Parser.parse(tokens, opt); + } catch (e) { + err = e; + } + + opt.highlight = highlight; + + return err + ? callback(err) + : callback(null, out); + }; + + if (!highlight || highlight.length < 3) { + return done(); + } + + delete opt.highlight; + + if (!pending) { return done(); } + + for (; i < tokens.length; i++) { + (function(token) { + if (token.type !== 'code') { + return --pending || done(); + } + return highlight(token.text, token.lang, function(err, code) { + if (err) { return done(err); } + if (code == null || code === token.text) { + return --pending || done(); + } + token.text = code; + token.escaped = true; + --pending || done(); + }); + })(tokens[i]); + } + + return; + } + try { + if (opt) { opt = merge({}, marked.defaults, opt); } + return Parser.parse(Lexer.lex(src, opt), opt); + } catch (e) { + e.message += '\nPlease report this to https://github.com/chjj/marked.'; + if ((opt || marked.defaults).silent) { + return '

    An error occured:

    '
    +            + escape(e.message + '', true)
    +            + '
    '; + } + throw e; + } + } + + /** + * Options + */ + + marked.options = + marked.setOptions = function(opt) { + merge(marked.defaults, opt); + return marked; + }; + + marked.defaults = { + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: false, + sanitizer: null, + mangle: true, + smartLists: false, + silent: false, + highlight: null, + langPrefix: 'lang-', + smartypants: false, + headerPrefix: '', + renderer: new Renderer, + xhtml: false + }; + + /** + * Expose + */ + + marked.Parser = Parser; + marked.parser = Parser.parse; + + marked.Renderer = Renderer; + + marked.Lexer = Lexer; + marked.lexer = Lexer.lex; + + marked.InlineLexer = InlineLexer; + marked.inlineLexer = InlineLexer.output; + + marked.parse = marked; + + Roo.Markdown.marked = marked; + +})();/* + * Based on: + * Ext JS Library 1.1.1 + * Copyright(c) 2006-2007, Ext JS, LLC. + * + * Originally Released Under LGPL - original licence link has changed is not relivant. + * + * Fork - LGPL + *