From d78482dfd89f0ef9b126afcdbbdefc6699a18474 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 11 Aug 2017 14:40:55 +0800 Subject: [PATCH] remove miniFramework --- cocos2d/core/CCGame.js | 17 +- cocos2d/core/platform/index.js | 1 - cocos2d/core/platform/miniFramework.js | 260 ------------------------- 3 files changed, 14 insertions(+), 264 deletions(-) delete mode 100644 cocos2d/core/platform/miniFramework.js diff --git a/cocos2d/core/CCGame.js b/cocos2d/core/CCGame.js index 210b0cb3a9..0096274d90 100644 --- a/cocos2d/core/CCGame.js +++ b/cocos2d/core/CCGame.js @@ -640,8 +640,8 @@ var game = { var el = this.config[game.CONFIG_KEY.id], win = window, - element = cc.$(el) || cc.$('#' + el), - localCanvas, localContainer, localConStyle; + element = (el instanceof HTMLElement) ? el : (document.querySelector(el) || document.querySelector('#' + el)), + localCanvas, localContainer; if (element.tagName === "CANVAS") { width = width || element.width; @@ -667,7 +667,18 @@ var game = { localContainer.appendChild(localCanvas); this.frame = (localContainer.parentNode === document.body) ? document.documentElement : localContainer.parentNode; - localCanvas.addClass("gameCanvas"); + function addClass (element, name) { + function hasClass (element, name) { + return (' ' + element.className + ' ').indexOf(' ' + name + ' ') > -1; + } + if (!hasClass(element, name)) { + if (element.className) { + element.className += " "; + } + element.className += name; + } + } + addClass(localCanvas, "gameCanvas"); localCanvas.setAttribute("width", width || 480); localCanvas.setAttribute("height", height || 320); localCanvas.setAttribute("tabindex", 99); diff --git a/cocos2d/core/platform/index.js b/cocos2d/core/platform/index.js index 357098ebf2..d7b7756cea 100644 --- a/cocos2d/core/platform/index.js +++ b/cocos2d/core/platform/index.js @@ -42,6 +42,5 @@ if (CC_JSB || cc.sys.isBrowser) { } if (!CC_JSB && !(CC_EDITOR && Editor.isMainProcess)) { - require('./miniFramework'); require('./CCVisibleRect'); } diff --git a/cocos2d/core/platform/miniFramework.js b/cocos2d/core/platform/miniFramework.js deleted file mode 100644 index 5cdf4898ca..0000000000 --- a/cocos2d/core/platform/miniFramework.js +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** - Copyright (c) 2008-2010 Ricardo Quesada - Copyright (c) 2011-2012 cocos2d-x.org - Copyright (c) 2013-2014 Chukong Technologies Inc. - - http://www.cocos2d-x.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -/** - * the dollar sign, classic like jquery, this selector add extra methods to HTMLElement without touching its prototype
- * it is also chainable like jquery - * @param {HTMLElement|String} x pass in a css selector in string or the whole HTMLElement - * @method $ - * @return {$} - */ -cc.$ = function (x) { - /** @lends cc.$# */ - var parent = (this === cc) ? document : this; - - var el = (x instanceof HTMLElement) ? x : parent.querySelector(x); - - if (el) { - /** - * find and return the child wth css selector (same as jquery.find) - * @lends cc.$# - * @method find - * @param {HTMLElement|String} x pass in a css selector in string or the whole HTMLElement - * @return {$} - */ - el.find = el.find || cc.$; - /** - * check if a DOMNode has a specific class - * @lends cc.$# - * @method hasClass - * @param {String} cls - * @return {Boolean} - */ - el.hasClass = el.hasClass || function (cls) { - return this.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); - }; - /** - * add a class to a DOMNode, returns self to allow chaining - * @lends cc.$# - * @method addClass - * @param {String} cls - * @return {$} - */ - el.addClass = el.addClass || function (cls) { - if (!this.hasClass(cls)) { - if (this.className) { - this.className += " "; - } - this.className += cls; - } - return this; - }; - /** - * remove a specific class from a DOMNode, returns self to allow chaining - * @lends cc.$# - * @method removeClass - * @param {String} cls - * @return {$} - */ - el.removeClass = el.removeClass || function (cls) { - if (this.hasClass(cls)) { - this.className = this.className.replace(cls, ''); - } - return this; - }; - /** - * detach it self from parent - * @lends cc.$# - * @method remove - */ - el.remove = el.remove || function () { - if (this.parentNode) - this.parentNode.removeChild(this); - return this; - }; - - /** - * add to another element as a child - * @lends cc.$# - * @method appendTo - * @param {HTMLElement|$} x - * @return {$} - */ - el.appendTo = el.appendTo || function (x) { - x.appendChild(this); - return this; - }; - - /** - * add to another element as a child and place on the top of the children list - * @lends cc.$# - * @method prependTo - * @param {HTMLElement|$} x - * @return {$} - */ - el.prependTo = el.prependTo || function (x) { - ( x.childNodes[0]) ? x.insertBefore(this, x.childNodes[0]) : x.appendChild(this); - return this; - }; - - /** - * helper function for updating the css transform - * @lends cc.$# - * @method transforms - * @return {$} - */ - el.transforms = el.transforms || function () { - this.style[cc.$.trans] = cc.$.translate(this.position) + cc.$.rotate(this.rotation) + cc.$.scale(this.scale) + cc.$.skew(this.skew); - return this; - }; - - el.position = el.position || {x: 0, y: 0}; - el.rotation = el.rotation || 0; - el.scale = el.scale || {x: 1, y: 1}; - el.skew = el.skew || {x: 0, y: 0}; - - /** - * move the element - * @memberOf cc.$# - * @method translates - * @param {Number} x in pixel - * @param {Number} y in pixel - * @return {$} - */ - el.translates = function (x, y) { - this.position.x = x; - this.position.y = y; - this.transforms(); - return this - }; - - /** - * rotate the element - * @memberOf cc.$# - * @method rotate - * @param {Number} x in degrees - * @return {$} - */ - el.rotate = function (x) { - this.rotation = x; - this.transforms(); - return this - }; - - /** - * resize the element - * @memberOf cc.$# - * @method resize - * @param {Number} x - * @param {Number} y - * @return {$} - */ - el.resize = function (x, y) { - this.scale.x = x; - this.scale.y = y; - this.transforms(); - return this - }; - - /** - * skews the element - * @memberOf cc.$# - * @method setSkew - * @param {Number} x in degrees - * @param {Number} y - * @return {$} - */ - el.setSkew = function (x, y) { - this.skew.x = x; - this.skew.y = y; - this.transforms(); - return this - }; - } - return el; -}; -//getting the prefix and css3 3d support -switch (cc.sys.browserType) { - case cc.sys.BROWSER_TYPE_FIREFOX: - cc.$.pfx = "Moz"; - cc.$.hd = true; - break; - case cc.sys.BROWSER_TYPE_CHROME: - case cc.sys.BROWSER_TYPE_SAFARI: - cc.$.pfx = "webkit"; - cc.$.hd = true; - break; - case cc.sys.BROWSER_TYPE_OPERA: - cc.$.pfx = "O"; - cc.$.hd = false; - break; - case cc.sys.BROWSER_TYPE_IE: - cc.$.pfx = "ms"; - cc.$.hd = false; - break; - default: - cc.$.pfx = "webkit"; - cc.$.hd = true; -} -//cache for prefixed transform -cc.$.trans = cc.$.pfx + "Transform"; -//helper function for constructing transform strings -cc.$.translate = (cc.$.hd) ? function (a) { - return "translate3d(" + a.x + "px, " + a.y + "px, 0) " -} : function (a) { - return "translate(" + a.x + "px, " + a.y + "px) " -}; -cc.$.rotate = (cc.$.hd) ? function (a) { - return "rotateZ(" + a + "deg) "; -} : function (a) { - return "rotate(" + a + "deg) "; -}; -cc.$.scale = function (a) { - return "scale(" + a.x + ", " + a.y + ") " -}; -cc.$.skew = function (a) { - return "skewX(" + -a.x + "deg) skewY(" + a.y + "deg)"; -}; - - -/** - * Creates a new element, and adds cc.$ methods - * @param {String} x name of the element tag to create - * @return {$} - */ -cc.$new = function (x) { - return cc.$(document.createElement(x)); -}; -cc.$.findpos = function (obj) { - var curleft = 0; - var curtop = 0; - do { - curleft += obj.offsetLeft; - curtop += obj.offsetTop; - } while (obj = obj.offsetParent); - return {x: curleft, y: curtop}; -}; -